mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
- Removed NadekoCommand and Aliases attribute from all commands
- All commands must be marked as partial - Added [Cmd] Attribute to all commands - Cmd Attribute comes from the source generator which adds [NadekoCommand] and [Aliases] Attribute to each command - Should be updated in the future probably to be more performant and maybe add extra data to the commands - Started reorganizing modules and submodules
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#nullable disable
|
||||
using Discord.Interactions;
|
||||
using NadekoBot.Common.Configs;
|
||||
using NadekoBot.Db;
|
||||
using System.Collections.Immutable;
|
||||
@@ -10,9 +9,9 @@ namespace NadekoBot.Services;
|
||||
|
||||
public class CommandHandler : INService
|
||||
{
|
||||
private const int GlobalCommandsCooldown = 750;
|
||||
private const int GLOBAL_COMMANDS_COOLDOWN = 750;
|
||||
|
||||
private const float _oneThousandth = 1.0f / 1000;
|
||||
private const float ONE_THOUSANDTH = 1.0f / 1000;
|
||||
|
||||
public event Func<IUserMessage, CommandInfo, Task> CommandExecuted = delegate { return Task.CompletedTask; };
|
||||
public event Func<CommandInfo, ITextChannel, string, Task> CommandErrored = delegate { return Task.CompletedTask; };
|
||||
@@ -33,7 +32,7 @@ public class CommandHandler : INService
|
||||
private readonly ConcurrentDictionary<ulong, string> _prefixes;
|
||||
private readonly Timer _clearUsersOnShortCooldown;
|
||||
private readonly DbService _db;
|
||||
private readonly InteractionService _interactions;
|
||||
// private readonly InteractionService _interactions;
|
||||
|
||||
public CommandHandler(
|
||||
DiscordSocketClient client,
|
||||
@@ -42,8 +41,8 @@ public class CommandHandler : INService
|
||||
BotConfigService bss,
|
||||
Bot bot,
|
||||
IBehaviourExecutor behaviourExecutor,
|
||||
IServiceProvider services,
|
||||
InteractionService interactions)
|
||||
// InteractionService interactions,
|
||||
IServiceProvider services)
|
||||
{
|
||||
_client = client;
|
||||
_commandService = commandService;
|
||||
@@ -52,15 +51,15 @@ public class CommandHandler : INService
|
||||
_behaviourExecutor = behaviourExecutor;
|
||||
_db = db;
|
||||
_services = services;
|
||||
_interactions = interactions;
|
||||
// _interactions = interactions;
|
||||
|
||||
_clearUsersOnShortCooldown = new(_ =>
|
||||
{
|
||||
UsersOnShortCooldown.Clear();
|
||||
},
|
||||
null,
|
||||
GlobalCommandsCooldown,
|
||||
GlobalCommandsCooldown);
|
||||
GLOBAL_COMMANDS_COOLDOWN,
|
||||
GLOBAL_COMMANDS_COOLDOWN);
|
||||
|
||||
_prefixes = bot.AllGuildConfigs.Where(x => x.Prefix != null)
|
||||
.ToDictionary(x => x.GuildId, x => x.Prefix)
|
||||
@@ -135,15 +134,15 @@ public class CommandHandler : INService
|
||||
public Task StartHandling()
|
||||
{
|
||||
_client.MessageReceived += MessageReceivedHandler;
|
||||
_client.SlashCommandExecuted += SlashCommandExecuted;
|
||||
// _client.SlashCommandExecuted += SlashCommandExecuted;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task SlashCommandExecuted(SocketSlashCommand arg)
|
||||
{
|
||||
var ctx = new SocketInteractionContext<SocketSlashCommand>(_client, arg);
|
||||
await _interactions.ExecuteCommandAsync(ctx, _services);
|
||||
}
|
||||
// private async Task SlashCommandExecuted(SocketSlashCommand arg)
|
||||
// {
|
||||
// var ctx = new SocketInteractionContext<SocketSlashCommand>(_client, arg);
|
||||
// await _interactions.ExecuteCommandAsync(ctx, _services);
|
||||
// }
|
||||
|
||||
private Task LogSuccessfulExecution(IUserMessage usrMsg, ITextChannel channel, params int[] execPoints)
|
||||
{
|
||||
@@ -153,7 +152,7 @@ public class CommandHandler : INService
|
||||
Server: {Server}
|
||||
Channel: {Channel}
|
||||
Message: {Message}",
|
||||
string.Join("/", execPoints.Select(x => (x * _oneThousandth).ToString("F3"))),
|
||||
string.Join("/", execPoints.Select(x => (x * ONE_THOUSANDTH).ToString("F3"))),
|
||||
usrMsg.Author + " [" + usrMsg.Author.Id + "]",
|
||||
channel is null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]",
|
||||
channel is null ? "PRIVATE" : channel.Name + " [" + channel.Id + "]",
|
||||
@@ -180,7 +179,7 @@ public class CommandHandler : INService
|
||||
Channel: {Channel}
|
||||
Message: {Message}
|
||||
Error: {ErrorMessage}",
|
||||
string.Join("/", execPoints.Select(x => (x * _oneThousandth).ToString("F3"))),
|
||||
string.Join("/", execPoints.Select(x => (x * ONE_THOUSANDTH).ToString("F3"))),
|
||||
usrMsg.Author + " [" + usrMsg.Author.Id + "]",
|
||||
channel is null ? "DM" : channel.Guild.Name + " [" + channel.Guild.Id + "]",
|
||||
channel is null ? "DM" : channel.Name + " [" + channel.Id + "]",
|
||||
|
Reference in New Issue
Block a user