NadekoBot/src/NadekoBot/Modules/Games/Commands/PollCommands.cs

68 lines
2.4 KiB
C#
Raw Normal View History

using Discord;
using Discord.Commands;
2016-12-17 00:16:14 +00:00
using Discord.WebSocket;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using System.Threading.Tasks;
using NadekoBot.Services.Games;
namespace NadekoBot.Modules.Games
{
public partial class Games
{
2016-12-16 19:45:46 +00:00
[Group]
2017-02-19 14:18:40 +00:00
public class PollCommands : NadekoSubmodule
{
2017-05-27 08:19:27 +00:00
private readonly DiscordShardedClient _client;
private readonly PollService _polls;
2017-05-27 08:19:27 +00:00
public PollCommands(DiscordShardedClient client, PollService polls)
2017-05-27 08:19:27 +00:00
{
_client = client;
_polls = polls;
2017-05-27 08:19:27 +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)
=> InternalStartPoll(arg, false);
2016-12-16 19:45:46 +00:00
[NadekoCommand, Usage, Description, Aliases]
[RequireUserPermission(GuildPermission.ManageMessages)]
[RequireContext(ContextType.Guild)]
public Task PublicPoll([Remainder] string arg = null)
=> InternalStartPoll(arg, true);
2017-01-08 17:08:57 +00:00
[NadekoCommand, Usage, Description, Aliases]
[RequireUserPermission(GuildPermission.ManageMessages)]
[RequireContext(ContextType.Guild)]
public async Task PollStats()
{
if (!_polls.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
}
2016-12-16 19:45:46 +00:00
private async Task InternalStartPoll(string arg, bool isPublic = false)
{
if(await _polls.StartPoll((ITextChannel)Context.Channel, Context.Message, arg, isPublic) == 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;
_polls.ActivePolls.TryRemove(channel.Guild.Id, out var poll);
2016-12-16 19:45:46 +00:00
await poll.StopPoll().ConfigureAwait(false);
}
}
}
}