Trivia nohint added (>t nohint) closes #194

This commit is contained in:
Master Kwoth 2016-04-09 16:55:22 +02:00
parent 873037a238
commit 0e510b4aa7
2 changed files with 25 additions and 21 deletions

View File

@ -20,6 +20,7 @@ namespace NadekoBot.Classes.Trivia
private int QuestionDurationMiliseconds { get; } = 30000;
private int HintTimeoutMiliseconds { get; } = 6000;
public bool ShowHints { get; set; } = true;
private CancellationTokenSource triviaCancelSource { get; set; }
public TriviaQuestion CurrentQuestion { get; private set; }
@ -32,8 +33,9 @@ namespace NadekoBot.Classes.Trivia
public int WinRequirement { get; } = 10;
public TriviaGame(CommandEventArgs e)
public TriviaGame(CommandEventArgs e, bool showHints)
{
ShowHints = showHints;
server = e.Server;
channel = e.Channel;
Task.Run(StartGame);
@ -68,7 +70,8 @@ namespace NadekoBot.Classes.Trivia
{
//hint
await Task.Delay(HintTimeoutMiliseconds, token);
await channel.SendMessage($":exclamation:**Hint:** {CurrentQuestion.GetHint()}");
if (ShowHints)
await channel.SendMessage($":exclamation:**Hint:** {CurrentQuestion.GetHint()}");
//timeout
await Task.Delay(QuestionDurationMiliseconds - HintTimeoutMiliseconds, token);

View File

@ -1,8 +1,7 @@
using Discord.Commands;
using NadekoBot.Modules;
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.Linq;
using TriviaGame = NadekoBot.Classes.Trivia.TriviaGame;
namespace NadekoBot.Commands
@ -11,26 +10,28 @@ namespace NadekoBot.Commands
{
public static ConcurrentDictionary<ulong, TriviaGame> RunningTrivias = new ConcurrentDictionary<ulong, TriviaGame>();
public Func<CommandEventArgs, Task> DoFunc() => async e =>
{
TriviaGame trivia;
if (!RunningTrivias.TryGetValue(e.Server.Id, out trivia))
{
var triviaGame = new TriviaGame(e);
if (RunningTrivias.TryAdd(e.Server.Id, 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);
};
internal override void Init(CommandGroupBuilder cgb)
{
cgb.CreateCommand(Module.Prefix + "t")
.Description("Starts a game of trivia.")
.Do(DoFunc());
.Description($"Starts a game of trivia. You can add nohint to prevent hints." +
"First player to get to 10 points wins. 30 seconds per question." +
$"\n**Usage**:`{Module.Prefix}t nohint`")
.Parameter("args", ParameterType.Multiple)
.Do(async e =>
{
TriviaGame trivia;
if (!RunningTrivias.TryGetValue(e.Server.Id, out trivia))
{
var showHints = !e.Args.Contains("nohint");
var triviaGame = new TriviaGame(e, showHints);
if (RunningTrivias.TryAdd(e.Server.Id, triviaGame))
await e.Channel.SendMessage("**Trivia game started!**");
else
await triviaGame.StopGame();
}
else
await e.Channel.SendMessage("Trivia game is already running on this server.\n" + trivia.CurrentQuestion);
});
cgb.CreateCommand(Module.Prefix + "tl")
.Description("Shows a current trivia leaderboard.")