2017-10-15 07:39:46 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using Discord.WebSocket;
|
|
|
|
|
using NadekoBot.Extensions;
|
|
|
|
|
using NadekoBot.Core.Services;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using NadekoBot.Common.Attributes;
|
|
|
|
|
using NadekoBot.Modules.Games.Common.Trivia;
|
|
|
|
|
using NadekoBot.Modules.Games.Services;
|
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Games
|
|
|
|
|
{
|
|
|
|
|
public partial class Games
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
|
|
|
|
public class TriviaCommands : NadekoSubmodule<GamesService>
|
|
|
|
|
{
|
2017-11-06 09:01:38 +00:00
|
|
|
|
private readonly IDataCache _cache;
|
2017-10-15 07:39:46 +00:00
|
|
|
|
private readonly CurrencyService _cs;
|
|
|
|
|
private readonly DiscordSocketClient _client;
|
|
|
|
|
private readonly IBotConfigProvider _bc;
|
|
|
|
|
|
2017-11-06 09:01:38 +00:00
|
|
|
|
public TriviaCommands(DiscordSocketClient client, IDataCache cache,
|
|
|
|
|
IBotConfigProvider bc, CurrencyService cs)
|
2017-10-15 07:39:46 +00:00
|
|
|
|
{
|
2017-11-06 09:01:38 +00:00
|
|
|
|
_cache = cache;
|
2017-10-15 07:39:46 +00:00
|
|
|
|
_cs = cs;
|
|
|
|
|
_client = client;
|
|
|
|
|
_bc = bc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
public Task Trivia([Remainder] string additionalArgs = "")
|
|
|
|
|
=> InternalTrivia(10, additionalArgs);
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
public Task Trivia(int winReq = 10, [Remainder] string additionalArgs = "")
|
|
|
|
|
=> InternalTrivia(winReq, additionalArgs);
|
|
|
|
|
|
|
|
|
|
public async Task InternalTrivia(int winReq, string additionalArgs = "")
|
|
|
|
|
{
|
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
|
|
|
|
|
|
|
|
|
additionalArgs = additionalArgs?.Trim()?.ToLowerInvariant();
|
|
|
|
|
|
|
|
|
|
var showHints = !additionalArgs.Contains("nohint");
|
|
|
|
|
var isPokemon = additionalArgs.Contains("pokemon");
|
|
|
|
|
|
2017-11-06 09:01:38 +00:00
|
|
|
|
var trivia = new TriviaGame(_strings, _client, _bc, _cache, _cs, channel.Guild, channel, showHints, winReq, isPokemon);
|
2017-10-15 07:39:46 +00:00
|
|
|
|
if (_service.RunningTrivias.TryAdd(channel.Guild.Id, trivia))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await trivia.StartGame().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_service.RunningTrivias.TryRemove(channel.Guild.Id, out trivia);
|
|
|
|
|
await trivia.EnsureStopped().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Context.Channel.SendErrorAsync(GetText("trivia_already_running") + "\n" + trivia.CurrentQuestion)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
public async Task Tl()
|
|
|
|
|
{
|
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
|
|
|
|
|
|
|
|
|
if (_service.RunningTrivias.TryGetValue(channel.Guild.Id, out TriviaGame trivia))
|
|
|
|
|
{
|
|
|
|
|
await channel.SendConfirmAsync(GetText("leaderboard"), trivia.GetLeaderboard()).ConfigureAwait(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await ReplyErrorLocalized("trivia_none").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
public async Task Tq()
|
|
|
|
|
{
|
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
|
|
|
|
|
|
|
|
|
if (_service.RunningTrivias.TryGetValue(channel.Guild.Id, out TriviaGame trivia))
|
|
|
|
|
{
|
|
|
|
|
await trivia.StopGame().ConfigureAwait(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await ReplyErrorLocalized("trivia_none").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|