From fb26986a583542bea77ac1bff1284d30ff0c720c Mon Sep 17 00:00:00 2001 From: TheUbMunster Date: Sat, 24 Dec 2022 05:54:10 -0700 Subject: [PATCH] refactoring of command parsing in discord bot --- Server/DiscordBot.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Server/DiscordBot.cs b/Server/DiscordBot.cs index b92bef0..ae11209 100644 --- a/Server/DiscordBot.cs +++ b/Server/DiscordBot.cs @@ -177,24 +177,23 @@ public class DiscordBot //run command try { - string? resp = null; + string? args = null; if (string.IsNullOrEmpty(localSettings.Prefix)) { - await arg.Channel.TriggerTypingAsync(); - resp = string.Join('\n', CommandHandler.GetResult(message).ReturnStrings); + args = message; } else if (message.StartsWith(localSettings.Prefix)) { - await arg.Channel.TriggerTypingAsync(); - resp = string.Join('\n', CommandHandler.GetResult(message[localSettings.Prefix.Length..]).ReturnStrings); + args = message[localSettings.Prefix.Length..]; } else if (message.StartsWith($"<@{client!.CurrentUser.Id}>")) { - await arg.Channel.TriggerTypingAsync(); - resp = string.Join('\n', CommandHandler.GetResult(message[client!.CurrentUser.Mention.Length..].TrimStart()).ReturnStrings); + args = message[client!.CurrentUser.Mention.Length..].TrimStart(); } - if (resp != null) + if (args != null) { + await arg.Channel.TriggerTypingAsync(); + string resp = string.Join('\n', CommandHandler.GetResult(args).ReturnStrings); if (localSettings.LogCommands) { logger.Info($"\"{arg.Author.Username}\" ran the command: \"{message}\" via discord");