Add traces to the !roll command
This commit is contained in:
parent
3299ac4eab
commit
aa826f962d
1 changed files with 14 additions and 2 deletions
|
@ -11,6 +11,7 @@ using Geekbot.Core.Extensions;
|
||||||
using Geekbot.Core.GuildSettingsManager;
|
using Geekbot.Core.GuildSettingsManager;
|
||||||
using Geekbot.Core.KvInMemoryStore;
|
using Geekbot.Core.KvInMemoryStore;
|
||||||
using Geekbot.Core.RandomNumberGenerator;
|
using Geekbot.Core.RandomNumberGenerator;
|
||||||
|
using Sentry;
|
||||||
|
|
||||||
namespace Geekbot.Bot.Commands.Games.Roll
|
namespace Geekbot.Bot.Commands.Games.Roll
|
||||||
{
|
{
|
||||||
|
@ -34,10 +35,14 @@ namespace Geekbot.Bot.Commands.Games.Roll
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var inputSpan = Transaction.StartChild("CommandInput");
|
||||||
var number = _randomNumberGenerator.Next(1, 100);
|
var number = _randomNumberGenerator.Next(1, 100);
|
||||||
int.TryParse(stuff, out var guess);
|
int.TryParse(stuff, out var guess);
|
||||||
|
inputSpan.Finish();
|
||||||
|
|
||||||
if (guess <= 100 && guess > 0)
|
if (guess <= 100 && guess > 0)
|
||||||
{
|
{
|
||||||
|
var prevRollCheckSpan = Transaction.StartChild("PrevRollCheck");
|
||||||
var kvKey = $"{Context?.Guild?.Id ?? 0}:{Context.User.Id}:RollsPrevious";
|
var kvKey = $"{Context?.Guild?.Id ?? 0}:{Context.User.Id}:RollsPrevious";
|
||||||
|
|
||||||
var prevRoll = _kvInMemoryStore.Get<RollTimeout>(kvKey);
|
var prevRoll = _kvInMemoryStore.Get<RollTimeout>(kvKey);
|
||||||
|
@ -48,29 +53,36 @@ namespace Geekbot.Bot.Commands.Games.Roll
|
||||||
Localization.Roll.NoPrevGuess,
|
Localization.Roll.NoPrevGuess,
|
||||||
Context.Message.Author.Mention,
|
Context.Message.Author.Mention,
|
||||||
DateLocalization.FormatDateTimeAsRemaining(prevRoll.GuessedOn.AddDays(1))));
|
DateLocalization.FormatDateTimeAsRemaining(prevRoll.GuessedOn.AddDays(1))));
|
||||||
|
Transaction.Status = SpanStatus.InvalidArgument;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_kvInMemoryStore.Set(kvKey, new RollTimeout {LastGuess = guess, GuessedOn = DateTime.Now});
|
_kvInMemoryStore.Set(kvKey, new RollTimeout {LastGuess = guess, GuessedOn = DateTime.Now});
|
||||||
|
prevRollCheckSpan.Finish();
|
||||||
|
|
||||||
await ReplyAsync(string.Format(Localization.Roll.Rolled, Context.Message.Author.Mention, number, guess));
|
await ReplyAsync(string.Format(Localization.Roll.Rolled, Context.Message.Author.Mention, number, guess));
|
||||||
if (guess == number)
|
if (guess == number)
|
||||||
{
|
{
|
||||||
|
var correctGuessSpan = Transaction.StartChild("CorrectGuess");
|
||||||
await ReplyAsync(string.Format(Localization.Roll.Gratz, Context.Message.Author));
|
await ReplyAsync(string.Format(Localization.Roll.Gratz, Context.Message.Author));
|
||||||
var user = await GetUser(Context.User.Id);
|
var user = await GetUser(Context.User.Id);
|
||||||
user.Rolls += 1;
|
user.Rolls += 1;
|
||||||
_database.Rolls.Update(user);
|
_database.Rolls.Update(user);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
|
correctGuessSpan.Finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await ReplyAsync(string.Format(Localization.Roll.RolledNoGuess, Context.Message.Author.Mention, number));
|
await ReplyAsync(string.Format(Localization.Roll.RolledNoGuess, Context.Message.Author.Mention, number));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Transaction.Status = SpanStatus.Ok;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
await ErrorHandler.HandleCommandException(e, Context);
|
await ErrorHandler.HandleCommandException(e, Context);
|
||||||
|
Transaction.Status = SpanStatus.InternalError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue