2017-05-28 01:51:22 +02:00
|
|
|
|
using Discord;
|
2016-08-16 14:57:47 +02:00
|
|
|
|
using Discord.Commands;
|
2016-12-17 01:16:14 +01:00
|
|
|
|
using Discord.WebSocket;
|
2016-12-11 01:42:58 +01:00
|
|
|
|
using NadekoBot.Extensions;
|
2016-08-16 14:57:47 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 21:42:36 +02:00
|
|
|
|
using NadekoBot.Common.Attributes;
|
|
|
|
|
using NadekoBot.Modules.Games.Services;
|
2016-08-16 14:57:47 +02:00
|
|
|
|
|
2016-08-20 22:35:27 +02:00
|
|
|
|
namespace NadekoBot.Modules.Games
|
2016-08-16 14:57:47 +02:00
|
|
|
|
{
|
2016-09-08 22:46:38 +02:00
|
|
|
|
public partial class Games
|
2016-08-16 14:57:47 +02:00
|
|
|
|
{
|
2016-12-16 20:45:46 +01:00
|
|
|
|
[Group]
|
2017-07-15 18:34:34 +02:00
|
|
|
|
public class PollCommands : NadekoSubmodule<PollService>
|
2016-08-16 14:57:47 +02:00
|
|
|
|
{
|
2017-06-19 15:42:10 +02:00
|
|
|
|
private readonly DiscordSocketClient _client;
|
2017-05-27 10:19:27 +02:00
|
|
|
|
|
2017-07-15 18:34:34 +02:00
|
|
|
|
public PollCommands(DiscordSocketClient client)
|
2017-05-27 10:19:27 +02:00
|
|
|
|
{
|
|
|
|
|
_client = client;
|
|
|
|
|
}
|
2016-08-16 14:57:47 +02:00
|
|
|
|
|
2016-12-16 20:45:46 +01:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireUserPermission(GuildPermission.ManageMessages)]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
public Task Poll([Remainder] string arg = null)
|
2017-06-24 07:23:59 +02:00
|
|
|
|
=> InternalStartPoll(arg);
|
2016-08-16 14:57:47 +02:00
|
|
|
|
|
2017-01-08 18:08:57 +01:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireUserPermission(GuildPermission.ManageMessages)]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
public async Task PollStats()
|
|
|
|
|
{
|
2017-07-15 18:34:34 +02:00
|
|
|
|
if (!_service.ActivePolls.TryGetValue(Context.Guild.Id, out var poll))
|
2017-01-08 18:08:57 +01:00
|
|
|
|
return;
|
|
|
|
|
|
2017-03-05 22:40:29 +01:00
|
|
|
|
await Context.Channel.EmbedAsync(poll.GetStats(GetText("current_poll_results")));
|
2017-01-08 18:08:57 +01:00
|
|
|
|
}
|
2017-06-24 07:23:59 +02:00
|
|
|
|
|
|
|
|
|
private async Task InternalStartPoll(string arg)
|
2016-08-16 14:57:47 +02:00
|
|
|
|
{
|
2017-07-15 18:34:34 +02:00
|
|
|
|
if(await _service.StartPoll((ITextChannel)Context.Channel, Context.Message, arg) == false)
|
2017-03-05 22:40:29 +01:00
|
|
|
|
await ReplyErrorLocalized("poll_already_running").ConfigureAwait(false);
|
2016-08-16 14:57:47 +02:00
|
|
|
|
}
|
2016-12-16 20:45:46 +01:00
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireUserPermission(GuildPermission.ManageMessages)]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
public async Task Pollend()
|
2016-08-16 14:57:47 +02:00
|
|
|
|
{
|
2016-12-16 20:45:46 +01:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
|
|
|
|
|
2017-07-15 18:34:34 +02:00
|
|
|
|
_service.ActivePolls.TryRemove(channel.Guild.Id, out var poll);
|
2016-12-16 20:45:46 +01:00
|
|
|
|
await poll.StopPoll().ConfigureAwait(false);
|
2016-08-16 14:57:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-29 06:13:22 +02:00
|
|
|
|
|
2016-08-16 14:57:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|