diff --git a/NadekoBot/Commands/TriviaCommand.cs b/NadekoBot/Commands/TriviaCommand.cs index d9e00884..2ed0a84e 100644 --- a/NadekoBot/Commands/TriviaCommand.cs +++ b/NadekoBot/Commands/TriviaCommand.cs @@ -12,9 +12,12 @@ namespace NadekoBot.Commands { public override Func DoFunc() => async e => { TriviaGame trivia; - if (!runningTrivias.TryGetValue(e.Server, out trivia)) { - if(runningTrivias.TryAdd(e.Server, new TriviaGame(e))) + if (!runningTrivias.TryGetValue(e.Server, out trivia)) { + var triviaGame = new TriviaGame(e); + if (runningTrivias.TryAdd(e.Server, triviaGame)) await e.Channel.SendMessage("**Trivia game started!**\nFirst player to get to 10 points wins! You have 30 seconds per question.\nUse command `tq` if game was started by accident.**"); + else + await triviaGame.StopGame(); } else await e.Channel.SendMessage("Trivia game is already running on this server.\n" + trivia.CurrentQuestion); }; diff --git a/NadekoBot/Commands/TriviaCommand.cs~RF13c91205.TMP b/NadekoBot/Commands/TriviaCommand.cs~RF13c91205.TMP new file mode 100644 index 00000000..d9e00884 --- /dev/null +++ b/NadekoBot/Commands/TriviaCommand.cs~RF13c91205.TMP @@ -0,0 +1,53 @@ +using System; +using System.Threading.Tasks; +using Discord.Commands; +using NadekoBot.Extensions; +using System.Collections.Concurrent; +using Discord; +using TriviaGame = NadekoBot.Classes.Trivia.TriviaGame; + +namespace NadekoBot.Commands { + class Trivia : DiscordCommand { + public static ConcurrentDictionary runningTrivias = new ConcurrentDictionary(); + + public override Func DoFunc() => async e => { + TriviaGame trivia; + if (!runningTrivias.TryGetValue(e.Server, out trivia)) { + if(runningTrivias.TryAdd(e.Server, new TriviaGame(e))) + await e.Channel.SendMessage("**Trivia game started!**\nFirst player to get to 10 points wins! You have 30 seconds per question.\nUse command `tq` if game was started by accident.**"); + } else + await e.Channel.SendMessage("Trivia game is already running on this server.\n" + trivia.CurrentQuestion); + }; + + public override void Init(CommandGroupBuilder cgb) { + cgb.CreateCommand("t") + .Description("Starts a game of trivia.") + .Alias("-t") + .Do(DoFunc()); + + cgb.CreateCommand("tl") + .Description("Shows a current trivia leaderboard.") + .Alias("-tl") + .Alias("tlb") + .Alias("-tlb") + .Do(async e=> { + TriviaGame trivia; + if (runningTrivias.TryGetValue(e.Server, out trivia)) + await e.Channel.SendMessage(trivia.GetLeaderboard()); + else + await e.Channel.SendMessage("No trivia is running on this server."); + }); + + cgb.CreateCommand("tq") + .Description("Quits current trivia after current question.") + .Alias("-tq") + .Do(async e=> { + TriviaGame trivia; + if (runningTrivias.TryGetValue(e.Server, out trivia)) { + await trivia.StopGame(); + } else + await e.Channel.SendMessage("No trivia is running on this server."); + }); + } + } +} diff --git a/NadekoBot/bin/Debug/Discord.Net.Audio.dll b/NadekoBot/bin/Debug/Discord.Net.Audio.dll index 3c1178d6..e77213cc 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.Audio.dll and b/NadekoBot/bin/Debug/Discord.Net.Audio.dll differ diff --git a/NadekoBot/bin/Debug/Discord.Net.Commands.dll b/NadekoBot/bin/Debug/Discord.Net.Commands.dll index 51d3973b..5f43c5bf 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.Commands.dll and b/NadekoBot/bin/Debug/Discord.Net.Commands.dll differ diff --git a/NadekoBot/bin/Debug/Discord.Net.Modules.dll b/NadekoBot/bin/Debug/Discord.Net.Modules.dll index e0c10031..49327983 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.Modules.dll and b/NadekoBot/bin/Debug/Discord.Net.Modules.dll differ diff --git a/NadekoBot/bin/Debug/Discord.Net.dll b/NadekoBot/bin/Debug/Discord.Net.dll index 06891e26..255a3168 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.dll and b/NadekoBot/bin/Debug/Discord.Net.dll differ diff --git a/NadekoBot/bin/Debug/data/nadekobot.sqlite b/NadekoBot/bin/Debug/data/nadekobot.sqlite index a1ab4f5c..a956a5a4 100644 Binary files a/NadekoBot/bin/Debug/data/nadekobot.sqlite and b/NadekoBot/bin/Debug/data/nadekobot.sqlite differ