2016-08-16 13:29:48 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using Discord.WebSocket;
|
2016-12-11 00:42:58 +00:00
|
|
|
|
using NadekoBot.Extensions;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using NadekoBot.Services;
|
2016-08-16 13:29:48 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using NadekoBot.Common.Attributes;
|
|
|
|
|
using NadekoBot.Modules.Games.Common.Trivia;
|
2017-10-04 22:51:12 +00:00
|
|
|
|
using NadekoBot.Modules.Games.Services;
|
2016-08-16 13:29:48 +00:00
|
|
|
|
|
2016-08-20 20:35:27 +00:00
|
|
|
|
namespace NadekoBot.Modules.Games
|
2016-08-16 13:29:48 +00:00
|
|
|
|
{
|
2016-09-08 20:46:38 +00:00
|
|
|
|
public partial class Games
|
2016-08-16 13:29:48 +00:00
|
|
|
|
{
|
|
|
|
|
[Group]
|
2017-10-04 22:51:12 +00:00
|
|
|
|
public class TriviaCommands : NadekoSubmodule<GamesService>
|
2016-08-16 13:29:48 +00:00
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly CurrencyService _cs;
|
2017-06-19 13:42:10 +00:00
|
|
|
|
private readonly DiscordSocketClient _client;
|
2017-07-20 03:10:39 +00:00
|
|
|
|
private readonly IBotConfigProvider _bc;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
|
2017-07-20 03:10:39 +00:00
|
|
|
|
public TriviaCommands(DiscordSocketClient client, IBotConfigProvider bc, CurrencyService cs)
|
2017-05-27 08:19:27 +00:00
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
_cs = cs;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
_client = client;
|
|
|
|
|
_bc = bc;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-16 13:29:48 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-31 10:55:12 +00:00
|
|
|
|
public Task Trivia([Remainder] string additionalArgs = "")
|
2017-03-23 11:09:15 +00:00
|
|
|
|
=> InternalTrivia(10, additionalArgs);
|
2016-12-25 12:09:22 +00:00
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-03-23 11:09:15 +00:00
|
|
|
|
public Task Trivia(int winReq = 10, [Remainder] string additionalArgs = "")
|
|
|
|
|
=> InternalTrivia(winReq, additionalArgs);
|
|
|
|
|
|
|
|
|
|
public async Task InternalTrivia(int winReq, string additionalArgs = "")
|
2016-08-16 13:29:48 +00:00
|
|
|
|
{
|
2017-01-01 12:26:17 +00:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-08-16 13:29:48 +00:00
|
|
|
|
|
2017-03-25 06:39:50 +00:00
|
|
|
|
additionalArgs = additionalArgs?.Trim()?.ToLowerInvariant();
|
|
|
|
|
|
2016-12-25 12:09:22 +00:00
|
|
|
|
var showHints = !additionalArgs.Contains("nohint");
|
2017-03-23 11:09:15 +00:00
|
|
|
|
var isPokemon = additionalArgs.Contains("pokemon");
|
2016-12-25 12:09:22 +00:00
|
|
|
|
|
2017-05-29 04:13:22 +00:00
|
|
|
|
var trivia = new TriviaGame(_strings, _client, _bc, _cs, channel.Guild, channel, showHints, winReq, isPokemon);
|
2017-10-04 22:51:12 +00:00
|
|
|
|
if (_service.RunningTrivias.TryAdd(channel.Guild.Id, trivia))
|
2016-08-16 13:29:48 +00:00
|
|
|
|
{
|
2016-12-25 12:09:22 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await trivia.StartGame().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
finally
|
2016-08-16 13:29:48 +00:00
|
|
|
|
{
|
2017-10-04 22:51:12 +00:00
|
|
|
|
_service.RunningTrivias.TryRemove(channel.Guild.Id, out trivia);
|
2016-12-25 12:09:22 +00:00
|
|
|
|
await trivia.EnsureStopped().ConfigureAwait(false);
|
|
|
|
|
}
|
2017-03-23 11:09:15 +00:00
|
|
|
|
return;
|
2016-08-16 13:29:48 +00:00
|
|
|
|
}
|
2017-03-23 11:09:15 +00:00
|
|
|
|
|
2017-02-23 22:30:38 +00:00
|
|
|
|
await Context.Channel.SendErrorAsync(GetText("trivia_already_running") + "\n" + trivia.CurrentQuestion)
|
|
|
|
|
.ConfigureAwait(false);
|
2016-08-16 13:29:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-16 13:29:48 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task Tl()
|
2016-08-16 13:29:48 +00:00
|
|
|
|
{
|
2016-12-16 18:43:57 +00:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-08-16 13:29:48 +00:00
|
|
|
|
|
2017-10-04 22:51:12 +00:00
|
|
|
|
if (_service.RunningTrivias.TryGetValue(channel.Guild.Id, out TriviaGame trivia))
|
2016-12-25 07:10:27 +00:00
|
|
|
|
{
|
2017-02-23 22:30:38 +00:00
|
|
|
|
await channel.SendConfirmAsync(GetText("leaderboard"), trivia.GetLeaderboard()).ConfigureAwait(false);
|
2016-12-25 07:10:27 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-23 22:30:38 +00:00
|
|
|
|
await ReplyErrorLocalized("trivia_none").ConfigureAwait(false);
|
2016-08-16 13:29:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-16 13:29:48 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task Tq()
|
2016-08-16 13:29:48 +00:00
|
|
|
|
{
|
2016-12-16 18:43:57 +00:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-08-16 13:29:48 +00:00
|
|
|
|
|
2017-10-04 22:51:12 +00:00
|
|
|
|
if (_service.RunningTrivias.TryGetValue(channel.Guild.Id, out TriviaGame trivia))
|
2016-08-16 13:29:48 +00:00
|
|
|
|
{
|
|
|
|
|
await trivia.StopGame().ConfigureAwait(false);
|
2016-12-25 07:10:27 +00:00
|
|
|
|
return;
|
2016-08-16 13:29:48 +00:00
|
|
|
|
}
|
2016-12-25 07:10:27 +00:00
|
|
|
|
|
2017-02-23 22:30:38 +00:00
|
|
|
|
await ReplyErrorLocalized("trivia_none").ConfigureAwait(false);
|
2016-08-16 13:29:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|