NadekoBot/NadekoBot.Modules.Games/PollCommands.cs

60 lines
2.0 KiB
C#
Raw Normal View History

using Discord;
using Discord.Commands;
2016-12-17 00:16:14 +00:00
using Discord.WebSocket;
using NadekoBot.Extensions;
using System.Threading.Tasks;
2017-07-17 19:42:36 +00:00
using NadekoBot.Common.Attributes;
using NadekoBot.Modules.Games.Services;
namespace NadekoBot.Modules.Games
{
public partial class Games
{
2016-12-16 19:45:46 +00:00
[Group]
2017-07-15 16:34:34 +00:00
public class PollCommands : NadekoSubmodule<PollService>
{
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-12-16 19:45:46 +00:00
[NadekoCommand, Usage, Description, Aliases]
[RequireUserPermission(GuildPermission.ManageMessages)]
[RequireContext(ContextType.Guild)]
public Task Poll([Remainder] string arg = null)
=> InternalStartPoll(arg);
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
}
private async Task InternalStartPoll(string arg)
{
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-12-16 19:45:46 +00:00
[NadekoCommand, Usage, Description, Aliases]
[RequireUserPermission(GuildPermission.ManageMessages)]
[RequireContext(ContextType.Guild)]
public async Task Pollend()
{
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);
}
}
}
}