1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 00:19:00 +03:00

Delete SelfBanCommand, failsafe involving bots issuing commands, optimized prefixes

This commit is contained in:
Octol1ttle 2022-10-18 23:46:43 +05:00
parent c0ae850fb8
commit 9921fd564b
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
3 changed files with 20 additions and 37 deletions

View file

@ -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<string, Regex> 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;

View file

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

View file

@ -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<IMessage, ulong> messageCached, SocketMessage messageSocket,