diff --git a/Boyfriend/CommandProcessor.cs b/Boyfriend/CommandProcessor.cs index b9e4562..c4cfbc1 100644 --- a/Boyfriend/CommandProcessor.cs +++ b/Boyfriend/CommandProcessor.cs @@ -17,12 +17,11 @@ public sealed class CommandProcessor { public static readonly ICommand[] Commands = { new BanCommand(), new ClearCommand(), new HelpCommand(), new KickCommand(), new MuteCommand(), new PingCommand(), - new SelfBanCommand(), new SettingsCommand(), new UnbanCommand(), new UnmuteCommand() }; private static readonly Dictionary RegexCache = new(); - private static readonly Regex MentionRegex = new(Regex.Escape("<@855023234407333888>")); + private static readonly Regex MentionRegex = new(Regex.Escape("<@855023234407333888>"), RegexOptions.Compiled); private readonly StringBuilder _stackedPrivateFeedback = new(); private readonly StringBuilder _stackedPublicFeedback = new(); private readonly StringBuilder _stackedReplyMessage = new(); @@ -49,7 +48,7 @@ public sealed class CommandProcessor { Regex regex; if (RegexCache.ContainsKey(config["Prefix"])) { regex = RegexCache[config["Prefix"]]; } else { - regex = new Regex(Regex.Escape(config["Prefix"])); + regex = new Regex(Regex.Escape(config["Prefix"]), RegexOptions.Compiled | RegexOptions.IgnoreCase); RegexCache.Add(config["Prefix"], regex); } @@ -273,13 +272,6 @@ public sealed class CommandProcessor { } public bool CanInteractWith(SocketGuildUser user, string action) { - if (Context.Guild.Owner.Id == Context.User.Id) return true; - if (Context.Guild.Owner.Id == user.Id) { - Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{CantInteract}{Utils.GetMessage($"UserCannot{action}Owner")}", Context.Message); - return false; - } - if (Context.User.Id == user.Id) { Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{CantInteract}{Utils.GetMessage($"UserCannot{action}Themselves")}", Context.Message); @@ -292,13 +284,19 @@ public sealed class CommandProcessor { return false; } + if (Context.Guild.Owner.Id == user.Id) { + Utils.SafeAppendToBuilder(_stackedReplyMessage, + $"{CantInteract}{Utils.GetMessage($"UserCannot{action}Owner")}", Context.Message); + return false; + } + if (Context.Guild.CurrentUser.Hierarchy <= user.Hierarchy) { Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{CantInteract}{Utils.GetMessage($"BotCannot{action}Target")}", Context.Message); return false; } - if (GetMember().Hierarchy > user.Hierarchy) return true; + if (Context.Guild.Owner.Id == Context.User.Id || GetMember().Hierarchy > user.Hierarchy) return true; Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{CantInteract}{Utils.GetMessage($"UserCannot{action}Target")}", Context.Message); return false; diff --git a/Boyfriend/Commands/SelfBanCommand.cs b/Boyfriend/Commands/SelfBanCommand.cs deleted file mode 100644 index aca49a4..0000000 --- a/Boyfriend/Commands/SelfBanCommand.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Boyfriend.Commands; - -public sealed class SelfBanCommand : ICommand { - public string[] Aliases { get; } = { "cavepleaselisten" }; - - public async Task RunAsync(CommandProcessor cmd, string[] args, string[] cleanArgs) { - await BanCommand.BanUser(cmd, cmd.Context.User, TimeSpan.FromMilliseconds(-1), ""); - } -} diff --git a/Boyfriend/EventHandler.cs b/Boyfriend/EventHandler.cs index 2818ba1..02750bd 100644 --- a/Boyfriend/EventHandler.cs +++ b/Boyfriend/EventHandler.cs @@ -62,28 +62,22 @@ public static class EventHandler { Utils.Wrap(msg.CleanContent)), guild.Id, mention); } - private static async Task MessageReceivedEvent(SocketMessage messageParam) { - if (messageParam is not SocketUserMessage { Author: SocketGuildUser user } message) return; + private static Task MessageReceivedEvent(SocketMessage messageParam) { + if (messageParam is not SocketUserMessage { Author: SocketGuildUser user } message) return Task.CompletedTask; var guild = user.Guild; Utils.SetCurrentLanguage(guild.Id); - var prev = ""; - var prevFailsafe = ""; - var prevs = await message.Channel.GetMessagesAsync(3).FlattenAsync(); - var prevsArray = prevs as IMessage[] ?? prevs.ToArray(); - - if (prevsArray.Length >= 3) { - prev = prevsArray[1].Content; - prevFailsafe = prevsArray[2].Content; - } - - if (user == guild.CurrentUser || (user.IsBot && - (message.Content.Contains(prev) || message.Content.Contains(prevFailsafe)))) - return; - - _ = new CommandProcessor(message).HandleCommandAsync(); + _ = message.CleanContent.ToLower() switch { + "whoami" => message.ReplyAsync("`nobody`"), + "сука !!" => message.ReplyAsync("`root`"), + "воооо" => message.ReplyAsync("`removing /...`"), + "op ??" => message.ReplyAsync( + "некоторые пасхальные цитаты которые вы могли найти были легально взяты у <@573772175572729876>"), + _ => new CommandProcessor(message).HandleCommandAsync() + }; + return Task.CompletedTask; } private static async Task MessageUpdatedEvent(Cacheable messageCached, SocketMessage messageSocket,