Cleanup all interaction commands for .net6

This commit is contained in:
Daan Boerlage 2021-11-07 00:16:11 +01:00
parent 47299dd1de
commit d0bc5810a9
Signed by: daan
GPG key ID: FCE070E1E4956606
7 changed files with 139 additions and 157 deletions

View file

@ -1,6 +1,3 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Geekbot.Commands.Karma; using Geekbot.Commands.Karma;
using Geekbot.Core.Database; using Geekbot.Core.Database;
using Geekbot.Core.Interactions; using Geekbot.Core.Interactions;

View file

@ -1,4 +1,3 @@
using System.Threading.Tasks;
using Geekbot.Commands.Karma; using Geekbot.Commands.Karma;
using Geekbot.Core.Database; using Geekbot.Core.Database;
using Geekbot.Core.Interactions; using Geekbot.Core.Interactions;

View file

@ -1,4 +1,3 @@
using System.Threading.Tasks;
using Geekbot.Commands.Karma; using Geekbot.Commands.Karma;
using Geekbot.Core.Database; using Geekbot.Core.Database;
using Geekbot.Core.Interactions; using Geekbot.Core.Interactions;

View file

@ -1,4 +1,3 @@
using System.Threading.Tasks;
using Geekbot.Commands.Karma; using Geekbot.Commands.Karma;
using Geekbot.Core.Database; using Geekbot.Core.Database;
using Geekbot.Core.Interactions; using Geekbot.Core.Interactions;

View file

@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Geekbot.Core.Converters; using Geekbot.Core.Converters;
using Geekbot.Core.Database; using Geekbot.Core.Database;
using Geekbot.Core.Highscores; using Geekbot.Core.Highscores;
@ -10,93 +6,92 @@ using Geekbot.Core.Interactions.ApplicationCommand;
using Geekbot.Core.Interactions.Request; using Geekbot.Core.Interactions.Request;
using Geekbot.Core.Interactions.Response; using Geekbot.Core.Interactions.Response;
namespace Geekbot.Web.Commands namespace Geekbot.Web.Commands;
public class Rank : InteractionBase
{ {
public class Rank : InteractionBase private readonly DatabaseContext _database;
private readonly IEmojiConverter _emojiConverter;
private readonly IHighscoreManager _highscoreManager;
public Rank(DatabaseContext database, IEmojiConverter emojiConverter, IHighscoreManager highscoreManager)
{ {
private readonly DatabaseContext _database; _database = database;
private readonly IEmojiConverter _emojiConverter; _emojiConverter = emojiConverter;
private readonly IHighscoreManager _highscoreManager; _highscoreManager = highscoreManager;
public Rank(DatabaseContext database, IEmojiConverter emojiConverter, IHighscoreManager highscoreManager)
{
_database = database;
_emojiConverter = emojiConverter;
_highscoreManager = highscoreManager;
}
private struct Options
{
internal const string Counter = "counter";
internal const string Amount = "amount";
internal const string Season = "season";
}
public override Command GetCommandInfo()
{
return new Command()
{
Name = "rank",
Description = "BETA: Highscores for various counters",
Type = CommandType.ChatInput,
Options = new List<Option>()
{
new ()
{
Name = Options.Counter,
Description = "The counter to show",
Required = true,
Type = OptionType.String,
Choices = Enumerable.Select(
Enum.GetNames<HighscoreTypes>(),
highscoreType => new OptionChoice()
{
Name = highscoreType,
Value = highscoreType
}).ToList()
},
new ()
{
Name = Options.Amount,
Description = "Amount of positions to show in the list",
Required = false,
Type = OptionType.Integer
},
new ()
{
Name = Options.Season,
Description = "Select the season, only applies for the seasons counter",
Required = false,
Type = OptionType.String
}
}
};
}
public override Task<InteractionResponse> Exec(Interaction interaction)
{
var counterTypeOption = interaction.Data.Options.Find(o => o.Name == Options.Counter);
var amountOption = interaction.Data.Options.Find(o => o.Name == Options.Amount);
var seasonOption = interaction.Data.Options.Find(o => o.Name == Options.Season);
var res = new Geekbot.Commands.Rank(_database, _emojiConverter, _highscoreManager)
.Run(
counterTypeOption?.Value.GetString() ?? HighscoreTypes.messages.ToString(),
amountOption?.Value.GetInt32() ?? 10,
seasonOption?.Value.GetString() ?? string.Empty,
ulong.Parse(interaction.GuildId),
"...");
var interactionResponse = new InteractionResponse()
{
Type = InteractionResponseType.ChannelMessageWithSource,
Data = new InteractionResponseData()
{
Content = res
}
};
return Task.FromResult(SimpleResponse(res));
}
} }
}
private struct Options
{
internal const string Counter = "counter";
internal const string Amount = "amount";
internal const string Season = "season";
}
public override Command GetCommandInfo()
{
return new Command()
{
Name = "rank",
Description = "BETA: Highscores for various counters",
Type = CommandType.ChatInput,
Options = new List<Option>()
{
new ()
{
Name = Options.Counter,
Description = "The counter to show",
Required = true,
Type = OptionType.String,
Choices = Enumerable.Select(
Enum.GetNames<HighscoreTypes>(),
highscoreType => new OptionChoice()
{
Name = highscoreType,
Value = highscoreType
}).ToList()
},
new ()
{
Name = Options.Amount,
Description = "Amount of positions to show in the list",
Required = false,
Type = OptionType.Integer
},
new ()
{
Name = Options.Season,
Description = "Select the season, only applies for the seasons counter",
Required = false,
Type = OptionType.String
}
}
};
}
public override Task<InteractionResponse> Exec(Interaction interaction)
{
var counterTypeOption = interaction.Data.Options.Find(o => o.Name == Options.Counter);
var amountOption = interaction.Data.Options.Find(o => o.Name == Options.Amount);
var seasonOption = interaction.Data.Options.Find(o => o.Name == Options.Season);
var res = new Geekbot.Commands.Rank(_database, _emojiConverter, _highscoreManager)
.Run(
counterTypeOption?.Value.GetString() ?? HighscoreTypes.messages.ToString(),
amountOption?.Value.GetInt32() ?? 10,
seasonOption?.Value.GetString() ?? string.Empty,
ulong.Parse(interaction.GuildId),
"...");
var interactionResponse = new InteractionResponse()
{
Type = InteractionResponseType.ChannelMessageWithSource,
Data = new InteractionResponseData()
{
Content = res
}
};
return Task.FromResult(SimpleResponse(res));
}
}

View file

@ -1,4 +1,3 @@
using System.Threading.Tasks;
using Geekbot.Core.Database; using Geekbot.Core.Database;
using Geekbot.Core.Interactions; using Geekbot.Core.Interactions;
using Geekbot.Core.Interactions.ApplicationCommand; using Geekbot.Core.Interactions.ApplicationCommand;
@ -7,60 +6,59 @@ using Geekbot.Core.Interactions.Response;
using Geekbot.Core.KvInMemoryStore; using Geekbot.Core.KvInMemoryStore;
using Geekbot.Core.RandomNumberGenerator; using Geekbot.Core.RandomNumberGenerator;
namespace Geekbot.Web.Commands namespace Geekbot.Web.Commands;
public class Roll : InteractionBase
{ {
public class Roll : InteractionBase private readonly IKvInMemoryStore _kvInMemoryStore;
private readonly DatabaseContext _database;
private readonly IRandomNumberGenerator _randomNumberGenerator;
public Roll(IKvInMemoryStore kvInMemoryStore, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator)
{ {
private readonly IKvInMemoryStore _kvInMemoryStore; _kvInMemoryStore = kvInMemoryStore;
private readonly DatabaseContext _database; _database = database;
private readonly IRandomNumberGenerator _randomNumberGenerator; _randomNumberGenerator = randomNumberGenerator;
public Roll(IKvInMemoryStore kvInMemoryStore, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator)
{
_kvInMemoryStore = kvInMemoryStore;
_database = database;
_randomNumberGenerator = randomNumberGenerator;
}
private struct Options
{
internal const string Guess = "guess";
}
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 = Options.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 == Options.Guess);
var guess = guessOption.Value.GetInt32();
var res = await new Geekbot.Commands.Roll.Roll(_kvInMemoryStore, _database, _randomNumberGenerator)
.RunFromInteraction(
interaction.GuildId,
interaction.Member.User.Id,
interaction.Member.Nick ?? interaction.Member.User.Username,
guess
);
return SimpleResponse(res);
}
} }
}
private struct Options
{
internal const string Guess = "guess";
}
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 = Options.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 == Options.Guess);
var guess = guessOption.Value.GetInt32();
var res = await new Geekbot.Commands.Roll.Roll(_kvInMemoryStore, _database, _randomNumberGenerator)
.RunFromInteraction(
interaction.GuildId,
interaction.Member.User.Id,
interaction.Member.Nick ?? interaction.Member.User.Username,
guess
);
return SimpleResponse(res);
}
}

View file

@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using Geekbot.Core.Interactions; using Geekbot.Core.Interactions;
using Geekbot.Core.Interactions.ApplicationCommand; using Geekbot.Core.Interactions.ApplicationCommand;
using Geekbot.Core.Interactions.Embed;
using Geekbot.Core.Interactions.Request; using Geekbot.Core.Interactions.Request;
using Geekbot.Core.Interactions.Response; using Geekbot.Core.Interactions.Response;