diff --git a/Boyfriend/CommandHandler.cs b/Boyfriend/CommandHandler.cs index 0cd494b..097993e 100644 --- a/Boyfriend/CommandHandler.cs +++ b/Boyfriend/CommandHandler.cs @@ -15,6 +15,7 @@ public static class CommandHandler { }; private static readonly Dictionary RegexCache = new(); + private static readonly Regex MentionRegex = new(Regex.Escape("<@855023234407333888>")); public static readonly StringBuilder StackedReplyMessage = new(); public static readonly StringBuilder StackedPublicFeedback = new(); @@ -43,7 +44,8 @@ public static class CommandHandler { foreach (var line in list) { currentLine++; foreach (var command in Commands) { - if (!command.Aliases.Contains(regex.Replace(line, "", 1).ToLower().Split()[0])) + var lineNoMention = MentionRegex.Replace(line, "", 1); + if (!command.Aliases.Contains(regex.Replace(lineNoMention, "", 1).Trim().ToLower().Split()[0])) continue; await context.Channel.TriggerTypingAsync(); @@ -58,7 +60,8 @@ public static class CommandHandler { if (currentLine != list.Length) continue; if (ConfigWriteScheduled) await Boyfriend.WriteGuildConfig(guild.Id); - await message.ReplyAsync(StackedReplyMessage.ToString(), false, null, AllowedMentions.None); + if (StackedReplyMessage.Length > 0) + await message.ReplyAsync(StackedReplyMessage.ToString(), false, null, AllowedMentions.None); var adminChannel = Utils.GetAdminLogChannel(guild.Id); var systemChannel = guild.SystemChannel; diff --git a/Boyfriend/Commands/SettingsCommand.cs b/Boyfriend/Commands/SettingsCommand.cs index 42bfb1c..0a7fabc 100644 --- a/Boyfriend/Commands/SettingsCommand.cs +++ b/Boyfriend/Commands/SettingsCommand.cs @@ -32,14 +32,12 @@ public class SettingsCommand : Command { format = "<#{0}>"; else currentValue = Messages.ChannelNotSpecified; - } - else if (setting.Key.EndsWith("Role")) { + } else if (setting.Key.EndsWith("Role")) { if (guild.GetRole(Convert.ToUInt64(currentValue)) != null) format = "<@&{0}>"; else currentValue = Messages.RoleNotSpecified; - } - else { + } else { if (IsBool(currentValue)) currentValue = YesOrNo(currentValue is "true"); else @@ -84,10 +82,7 @@ public class SettingsCommand : Command { return Task.CompletedTask; } } - } - else { - value = "reset"; - } + } else { value = "reset"; } if (IsBool(Boyfriend.DefaultConfig[selectedSetting]) && !IsBool(value)) { value = value switch { @@ -117,9 +112,9 @@ public class SettingsCommand : Command { var formattedValue = selectedSetting switch { "WelcomeMessage" => Utils.Wrap(Messages.DefaultWelcomeMessage), "EventStartedReceivers" => Utils.Wrap(Boyfriend.DefaultConfig[selectedSetting])!, - _ => value is "reset" or "default" - ? IsBool(value) ? YesOrNo(value is "true") : string.Format(formatting, value) - : Messages.SettingNotDefined + _ => value is "reset" or "default" ? Messages.SettingNotDefined + : IsBool(value) ? YesOrNo(value is "true") + : string.Format(formatting, value) }; if (value is "reset" or "default") { @@ -127,8 +122,7 @@ public class SettingsCommand : Command { config[selectedSetting] = Messages.DefaultWelcomeMessage; else config[selectedSetting] = Boyfriend.DefaultConfig[selectedSetting]; - } - else { + } else { if (value == config[selectedSetting]) { Error(string.Format(Messages.SettingsNothingChanged, localizedSelectedSetting, formattedValue), false); return Task.CompletedTask; diff --git a/Boyfriend/EventHandler.cs b/Boyfriend/EventHandler.cs index 4b09fd7..d47ff07 100644 --- a/Boyfriend/EventHandler.cs +++ b/Boyfriend/EventHandler.cs @@ -1,6 +1,5 @@ using Boyfriend.Commands; using Discord; -using Discord.Commands; using Discord.Rest; using Discord.WebSocket; @@ -82,9 +81,8 @@ public class EventHandler { prevFailsafe = prevsArray[2].Content; } - if (!(message.HasStringPrefix(guildConfig["Prefix"], ref argPos) || - message.HasMentionPrefix(Boyfriend.Client.CurrentUser, ref argPos)) || user == guild.CurrentUser || - (user.IsBot && (message.Content.Contains(prev) || message.Content.Contains(prevFailsafe)))) + if (user == guild.CurrentUser || (user.IsBot && + (message.Content.Contains(prev) || message.Content.Contains(prevFailsafe)))) return; await CommandHandler.HandleCommand(message); @@ -180,4 +178,4 @@ public class EventHandler { await channel.SendMessageAsync(string.Format(Messages.EventCompleted, Utils.Wrap(scheduledEvent.Name), Utils.Wrap(scheduledEvent.StartTime.Subtract(DateTimeOffset.Now).Negate().ToString()))); } -} \ No newline at end of file +}