private async Task HandleCommandAsync(SocketMessage socketMessage) { if (socketMessage is SocketUserMessage msg && !msg.Author.IsBot) { int argPos = 0; if (!msg.HasStringPrefix("$", ref argPos) && !msg.HasMentionPrefix(Client.CurrentUser, ref argPos)) { return; } ICommandContext context = new SocketCommandContext(Client, msg); string cmdName = (msg.HasMentionPrefix(Client.CurrentUser, ref argPos) ? msg.ToString().Split(' ')[1] : msg.ToString().Split(' ')[0].Substring(1)).ToLower(); string cmdText = StringUtilities.After(msg.ToString(), cmdName, true).ToLower(); if (Commands.Search(cmdName).IsSuccess) { await LogInfo("User (" + msg.Author.Username + ")<" + msg.Author.Id + "> has run command \"$" + cmdName + (cmdText != "" ? " " + cmdText : "") + "\"."); if (!CommandList.ContainsKey(cmdName)) { await context.Channel.SendMessageAsync("Hey! The command **" + msg.ToString().Split(' ')[0] + "** looks like something I could run, " + "but I can't. Is there another bot that handles that command? I don't know if there are. I'm just a terminal bot, I can't see!"); await LogInfo("> > Command failed! Command exists, but is not registered!"); return; } } IResult result = await Commands.ExecuteAsync(context, argPos, Services); if (!result.IsSuccess && result.Error != CommandError.UnknownCommand) { await context.Channel.SendMessageAsync(result.ErrorReason); await LogInfo("> > Command failed! Reason: " + result.ErrorReason); } } }
public static string After(this string input, string substring) { return(StringUtilities.After(input, substring)); }