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