mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 09:09:00 +03:00
29 lines
No EOL
941 B
C#
29 lines
No EOL
941 B
C#
using System.Reflection;
|
|
using Discord.Commands;
|
|
using Discord.WebSocket;
|
|
|
|
namespace Boyfriend;
|
|
|
|
public class CommandHandler {
|
|
private readonly DiscordSocketClient _client = Boyfriend.Client;
|
|
private readonly CommandService _commands = new CommandService();
|
|
|
|
public async Task InstallCommandsAsync() {
|
|
_client.MessageReceived += HandleCommandAsync;
|
|
await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), null);
|
|
}
|
|
|
|
private async Task HandleCommandAsync(SocketMessage messageParam) {
|
|
if (messageParam is not SocketUserMessage message) return;
|
|
var argPos = 0;
|
|
|
|
if (!(message.HasCharPrefix('!', ref argPos) ||
|
|
message.HasMentionPrefix(_client.CurrentUser, ref argPos)) ||
|
|
message.Author.IsBot)
|
|
return;
|
|
|
|
var context = new SocketCommandContext(_client, message);
|
|
|
|
await _commands.ExecuteAsync(context, argPos, null);
|
|
}
|
|
} |