refactoring of command parsing in discord bot

This commit is contained in:
TheUbMunster 2022-12-24 05:54:10 -07:00
parent 3a34ec2045
commit fb26986a58
1 changed files with 7 additions and 8 deletions

View File

@ -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");