public CommandHandlerService(IServiceProvider services, DiscordSocketClient client, CommandService commands, PrefixManagerService pm) { this.services = services; this.client = client; this.commands = commands; this.pm = pm; }
private async Task ProcessCommandAsync(SocketMessage arg) { // Source filter if (arg.Source != MessageSource.User) { return; } var message = (SocketUserMessage)arg; // Get the prefix string pfx; try { pfx = await GetPrefix(arg); } catch (Exception e) { string src = message.Channel is IGuildChannel gc ? $"{gc.Guild.Name} ({gc.Guild.Id})" : $"{message.Channel.Name}"; Logger.GetLogger("Commands").Warning($"Failed to get prefix. {src}", e); return; } // Command check int argPos = 0; if (message.HasStringPrefix(pfx, ref argPos)) { // Refresh the cached prefix if (message.Channel is IGuildChannel c) { pm.RestoreCache(c.GuildId).Release(); } var context = new SocketCommandContext(client, message); // Log message for debugging (doesn't check if the command exists) Logger.GetLogger("Commands").Debug($"Executing command: {GetExecutionInfo(context)}"); // Execute command await commands.ExecuteAsync(context, argPos, services); } else if (message.Content.TrimEnd() == $"{pm.DefaultPrefix}prefix") { // Info var context = new SocketCommandContext(client, message); Logger.GetLogger("Commands").Debug($"Executing prefix get with default prefix: {GetExecutionInfo(context)}"); var ts = await TranslationManager.CreateFor(context.Channel); message.Channel.SendMessageAsync(embed: EmbedFactory.CreateSuccess() .WithTitle(ts.GetMessage("commands/prefix:embed_title")) .WithDescription(MessageFormatter.Format(ts.GetMessage("commands/prefix:my_prefix_is"), PrefixManagerService.PrettyPrefix(pfx))) .Build()).Release(); } }