just in case

This commit is contained in:
Master Kwoth 2016-02-29 03:48:31 +01:00
parent 57e6cd2e49
commit f06ab16a2f
7 changed files with 58 additions and 2 deletions

View File

@ -12,9 +12,12 @@ namespace NadekoBot.Commands {
public override Func<CommandEventArgs, Task> 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);
};

View File

@ -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<Server, TriviaGame> runningTrivias = new ConcurrentDictionary<Server, TriviaGame>();
public override Func<CommandEventArgs, Task> 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.");
});
}
}
}

Binary file not shown.