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) private struct Options
{ {
_database = database; internal const string Counter = "counter";
_emojiConverter = emojiConverter; internal const string Amount = "amount";
_highscoreManager = highscoreManager; internal const string Season = "season";
} }
private struct Options public override Command GetCommandInfo()
{
return new Command()
{ {
internal const string Counter = "counter"; Name = "rank",
internal const string Amount = "amount"; Description = "BETA: Highscores for various counters",
internal const string Season = "season"; Type = CommandType.ChatInput,
} Options = new List<Option>()
public override Command GetCommandInfo()
{
return new Command()
{ {
Name = "rank", new ()
Description = "BETA: Highscores for various counters",
Type = CommandType.ChatInput,
Options = new List<Option>()
{ {
new () Name = Options.Counter,
{ Description = "The counter to show",
Name = Options.Counter, Required = true,
Description = "The counter to show", Type = OptionType.String,
Required = true, Choices = Enumerable.Select(
Type = OptionType.String, Enum.GetNames<HighscoreTypes>(),
Choices = Enumerable.Select( highscoreType => new OptionChoice()
Enum.GetNames<HighscoreTypes>(), {
highscoreType => new OptionChoice() Name = highscoreType,
{ Value = highscoreType
Name = highscoreType, }).ToList()
Value = highscoreType },
}).ToList() new ()
}, {
new () Name = Options.Amount,
{ Description = "Amount of positions to show in the list",
Name = Options.Amount, Required = false,
Description = "Amount of positions to show in the list", Type = OptionType.Integer
Required = false, },
Type = OptionType.Integer new ()
}, {
new () Name = Options.Season,
{ Description = "Select the season, only applies for the seasons counter",
Name = Options.Season, Required = false,
Description = "Select the season, only applies for the seasons counter", Type = OptionType.String
Required = false,
Type = OptionType.String
}
} }
}; }
} };
}
public override Task<InteractionResponse> Exec(Interaction interaction) 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()
{ {
var counterTypeOption = interaction.Data.Options.Find(o => o.Name == Options.Counter); Type = InteractionResponseType.ChannelMessageWithSource,
var amountOption = interaction.Data.Options.Find(o => o.Name == Options.Amount); Data = new InteractionResponseData()
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, Content = res
Data = new InteractionResponseData() }
{ };
Content = res
}
};
return Task.FromResult(SimpleResponse(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) private struct Options
{ {
_kvInMemoryStore = kvInMemoryStore; internal const string Guess = "guess";
_database = database; }
_randomNumberGenerator = randomNumberGenerator;
}
private struct Options public override Command GetCommandInfo()
{
return new Command()
{ {
internal const string Guess = "guess"; Name = "roll",
} Description = "BETA: Roll and see if you can guess the correct number",
Type = CommandType.ChatInput,
public override Command GetCommandInfo() Options = new()
{
return new Command()
{ {
Name = "roll", new Option()
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)",
Name = Options.Guess, Required = true,
Description = "A number between 1 and 100 (inclusive)", Type = OptionType.Integer
Required = true,
Type = OptionType.Integer
}
} }
}; }
} };
}
public override async Task<InteractionResponse> Exec(Interaction interaction) public override async Task<InteractionResponse> Exec(Interaction interaction)
{ {
var guessOption = interaction.Data.Options.Find(o => o.Name == Options.Guess); var guessOption = interaction.Data.Options.Find(o => o.Name == Options.Guess);
var guess = guessOption.Value.GetInt32(); var guess = guessOption.Value.GetInt32();
var res = await new Geekbot.Commands.Roll.Roll(_kvInMemoryStore, _database, _randomNumberGenerator) var res = await new Geekbot.Commands.Roll.Roll(_kvInMemoryStore, _database, _randomNumberGenerator)
.RunFromInteraction( .RunFromInteraction(
interaction.GuildId, interaction.GuildId,
interaction.Member.User.Id, interaction.Member.User.Id,
interaction.Member.Nick ?? interaction.Member.User.Username, interaction.Member.Nick ?? interaction.Member.User.Username,
guess guess
); );
return SimpleResponse(res); 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;