Cleanup all interaction commands for .net6
This commit is contained in:
parent
47299dd1de
commit
d0bc5810a9
7 changed files with 139 additions and 157 deletions
|
@ -1,6 +1,3 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Geekbot.Commands.Karma;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Interactions;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System.Threading.Tasks;
|
||||
using Geekbot.Commands.Karma;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Interactions;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System.Threading.Tasks;
|
||||
using Geekbot.Commands.Karma;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Interactions;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System.Threading.Tasks;
|
||||
using Geekbot.Commands.Karma;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Interactions;
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Geekbot.Core.Converters;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Highscores;
|
||||
|
@ -10,93 +6,92 @@ using Geekbot.Core.Interactions.ApplicationCommand;
|
|||
using Geekbot.Core.Interactions.Request;
|
||||
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;
|
||||
private readonly IEmojiConverter _emojiConverter;
|
||||
private readonly IHighscoreManager _highscoreManager;
|
||||
_database = database;
|
||||
_emojiConverter = emojiConverter;
|
||||
_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";
|
||||
}
|
||||
|
||||
private struct Options
|
||||
public override Command GetCommandInfo()
|
||||
{
|
||||
return new Command()
|
||||
{
|
||||
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>()
|
||||
{
|
||||
Name = "rank",
|
||||
Description = "BETA: Highscores for various counters",
|
||||
Type = CommandType.ChatInput,
|
||||
Options = new List<Option>()
|
||||
new ()
|
||||
{
|
||||
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
|
||||
}
|
||||
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)
|
||||
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);
|
||||
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()
|
||||
{
|
||||
Type = InteractionResponseType.ChannelMessageWithSource,
|
||||
Data = new InteractionResponseData()
|
||||
{
|
||||
Content = res
|
||||
}
|
||||
};
|
||||
Content = res
|
||||
}
|
||||
};
|
||||
|
||||
return Task.FromResult(SimpleResponse(res));
|
||||
}
|
||||
return Task.FromResult(SimpleResponse(res));
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
using System.Threading.Tasks;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Interactions;
|
||||
using Geekbot.Core.Interactions.ApplicationCommand;
|
||||
|
@ -7,60 +6,59 @@ using Geekbot.Core.Interactions.Response;
|
|||
using Geekbot.Core.KvInMemoryStore;
|
||||
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;
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||
_kvInMemoryStore = kvInMemoryStore;
|
||||
_database = database;
|
||||
_randomNumberGenerator = randomNumberGenerator;
|
||||
}
|
||||
|
||||
public Roll(IKvInMemoryStore kvInMemoryStore, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator)
|
||||
{
|
||||
_kvInMemoryStore = kvInMemoryStore;
|
||||
_database = database;
|
||||
_randomNumberGenerator = randomNumberGenerator;
|
||||
}
|
||||
private struct Options
|
||||
{
|
||||
internal const string Guess = "guess";
|
||||
}
|
||||
|
||||
private struct Options
|
||||
public override Command GetCommandInfo()
|
||||
{
|
||||
return new Command()
|
||||
{
|
||||
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()
|
||||
{
|
||||
Name = "roll",
|
||||
Description = "BETA: Roll and see if you can guess the correct number",
|
||||
Type = CommandType.ChatInput,
|
||||
Options = new()
|
||||
new Option()
|
||||
{
|
||||
new Option()
|
||||
{
|
||||
Name = Options.Guess,
|
||||
Description = "A number between 1 and 100 (inclusive)",
|
||||
Required = true,
|
||||
Type = OptionType.Integer
|
||||
}
|
||||
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();
|
||||
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
|
||||
);
|
||||
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);
|
||||
}
|
||||
return SimpleResponse(res);
|
||||
}
|
||||
}
|
|
@ -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.ApplicationCommand;
|
||||
using Geekbot.Core.Interactions.Embed;
|
||||
using Geekbot.Core.Interactions.Request;
|
||||
using Geekbot.Core.Interactions.Response;
|
||||
|
||||
|
|
Loading…
Reference in a new issue