Add roll interaction

This commit is contained in:
Daan Boerlage 2021-09-20 02:14:25 +02:00
parent d17ca4c556
commit d2b9daac57
Signed by: daan
GPG key ID: FCE070E1E4956606

62
src/Web/Commands/Roll.cs Normal file
View file

@ -0,0 +1,62 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Geekbot.Core.Interactions;
using Geekbot.Core.Interactions.ApplicationCommand;
using Geekbot.Core.Interactions.Request;
using Geekbot.Core.Interactions.Resolved;
using Geekbot.Core.Interactions.Response;
using Geekbot.Core.RandomNumberGenerator;
namespace Geekbot.Web.Commands
{
public class Roll : InteractionBase
{
public override Command GetCommandInfo()
{
return new Command()
{
Name = "roll",
Description = "BETA: Roll and see if you can guess the correct number",
Type = CommandType.ChatInput,
Options = new()
{
new Option()
{
Name = "guess",
Description = "A number between 1 and 100 (inclusive)",
Required = true,
Type = OptionType.Integer
}
}
};
}
public override async Task<InteractionResponse> Exec(Interaction interaction)
{
var guessOption = interaction.Data.Options.Find(o => o.Name == "guess");
var guess = guessOption.Value.GetInt32();
var number = new RandomNumberGenerator().Next(1, 100);
var replyContent = "";
if (guess <= 100 && guess > 0)
{
replyContent = $"{interaction?.Member?.User?.Mention}, you rolled {number}, your guess was {guess}";
}
else
{
replyContent = $"{interaction?.Member?.User?.Mention}, you rolled {number}";
}
return new InteractionResponse()
{
Type = InteractionResponseType.ChannelMessageWithSource,
Data = new InteractionResponseData()
{
Content = replyContent
}
};
}
}
}