refactoring of command parsing in discord bot
This commit is contained in:
parent
3a34ec2045
commit
fb26986a58
|
@ -177,24 +177,23 @@ public class DiscordBot
|
||||||
//run command
|
//run command
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string? resp = null;
|
string? args = null;
|
||||||
if (string.IsNullOrEmpty(localSettings.Prefix))
|
if (string.IsNullOrEmpty(localSettings.Prefix))
|
||||||
{
|
{
|
||||||
await arg.Channel.TriggerTypingAsync();
|
args = message;
|
||||||
resp = string.Join('\n', CommandHandler.GetResult(message).ReturnStrings);
|
|
||||||
}
|
}
|
||||||
else if (message.StartsWith(localSettings.Prefix))
|
else if (message.StartsWith(localSettings.Prefix))
|
||||||
{
|
{
|
||||||
await arg.Channel.TriggerTypingAsync();
|
args = message[localSettings.Prefix.Length..];
|
||||||
resp = string.Join('\n', CommandHandler.GetResult(message[localSettings.Prefix.Length..]).ReturnStrings);
|
|
||||||
}
|
}
|
||||||
else if (message.StartsWith($"<@{client!.CurrentUser.Id}>"))
|
else if (message.StartsWith($"<@{client!.CurrentUser.Id}>"))
|
||||||
{
|
{
|
||||||
await arg.Channel.TriggerTypingAsync();
|
args = message[client!.CurrentUser.Mention.Length..].TrimStart();
|
||||||
resp = string.Join('\n', CommandHandler.GetResult(message[client!.CurrentUser.Mention.Length..].TrimStart()).ReturnStrings);
|
|
||||||
}
|
}
|
||||||
if (resp != null)
|
if (args != null)
|
||||||
{
|
{
|
||||||
|
await arg.Channel.TriggerTypingAsync();
|
||||||
|
string resp = string.Join('\n', CommandHandler.GetResult(args).ReturnStrings);
|
||||||
if (localSettings.LogCommands)
|
if (localSettings.LogCommands)
|
||||||
{
|
{
|
||||||
logger.Info($"\"{arg.Author.Username}\" ran the command: \"{message}\" via discord");
|
logger.Info($"\"{arg.Author.Username}\" ran the command: \"{message}\" via discord");
|
||||||
|
|
Loading…
Reference in New Issue