forked from TeamInklings/Octobot
Delete SelfBanCommand, failsafe involving bots issuing commands, optimized prefixes
This commit is contained in:
parent
c0ae850fb8
commit
9921fd564b
3 changed files with 20 additions and 37 deletions
|
@ -17,12 +17,11 @@ public sealed class CommandProcessor {
|
||||||
public static readonly ICommand[] Commands = {
|
public static readonly ICommand[] Commands = {
|
||||||
new BanCommand(), new ClearCommand(), new HelpCommand(),
|
new BanCommand(), new ClearCommand(), new HelpCommand(),
|
||||||
new KickCommand(), new MuteCommand(), new PingCommand(),
|
new KickCommand(), new MuteCommand(), new PingCommand(),
|
||||||
new SelfBanCommand(),
|
|
||||||
new SettingsCommand(), new UnbanCommand(), new UnmuteCommand()
|
new SettingsCommand(), new UnbanCommand(), new UnmuteCommand()
|
||||||
};
|
};
|
||||||
|
|
||||||
private static readonly Dictionary<string, Regex> RegexCache = new();
|
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 _stackedPrivateFeedback = new();
|
||||||
private readonly StringBuilder _stackedPublicFeedback = new();
|
private readonly StringBuilder _stackedPublicFeedback = new();
|
||||||
private readonly StringBuilder _stackedReplyMessage = new();
|
private readonly StringBuilder _stackedReplyMessage = new();
|
||||||
|
@ -49,7 +48,7 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
Regex regex;
|
Regex regex;
|
||||||
if (RegexCache.ContainsKey(config["Prefix"])) { regex = RegexCache[config["Prefix"]]; } else {
|
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);
|
RegexCache.Add(config["Prefix"], regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,13 +272,6 @@ public sealed class CommandProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanInteractWith(SocketGuildUser user, string action) {
|
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) {
|
if (Context.User.Id == user.Id) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{CantInteract}{Utils.GetMessage($"UserCannot{action}Themselves")}", Context.Message);
|
$"{CantInteract}{Utils.GetMessage($"UserCannot{action}Themselves")}", Context.Message);
|
||||||
|
@ -292,13 +284,19 @@ public sealed class CommandProcessor {
|
||||||
return false;
|
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) {
|
if (Context.Guild.CurrentUser.Hierarchy <= user.Hierarchy) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{CantInteract}{Utils.GetMessage($"BotCannot{action}Target")}", Context.Message);
|
$"{CantInteract}{Utils.GetMessage($"BotCannot{action}Target")}", Context.Message);
|
||||||
return false;
|
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,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{CantInteract}{Utils.GetMessage($"UserCannot{action}Target")}", Context.Message);
|
$"{CantInteract}{Utils.GetMessage($"UserCannot{action}Target")}", Context.Message);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -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), "");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -62,28 +62,22 @@ public static class EventHandler {
|
||||||
Utils.Wrap(msg.CleanContent)), guild.Id, mention);
|
Utils.Wrap(msg.CleanContent)), guild.Id, mention);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task MessageReceivedEvent(SocketMessage messageParam) {
|
private static Task MessageReceivedEvent(SocketMessage messageParam) {
|
||||||
if (messageParam is not SocketUserMessage { Author: SocketGuildUser user } message) return;
|
if (messageParam is not SocketUserMessage { Author: SocketGuildUser user } message) return Task.CompletedTask;
|
||||||
|
|
||||||
var guild = user.Guild;
|
var guild = user.Guild;
|
||||||
|
|
||||||
Utils.SetCurrentLanguage(guild.Id);
|
Utils.SetCurrentLanguage(guild.Id);
|
||||||
|
|
||||||
var prev = "";
|
_ = message.CleanContent.ToLower() switch {
|
||||||
var prevFailsafe = "";
|
"whoami" => message.ReplyAsync("`nobody`"),
|
||||||
var prevs = await message.Channel.GetMessagesAsync(3).FlattenAsync();
|
"сука !!" => message.ReplyAsync("`root`"),
|
||||||
var prevsArray = prevs as IMessage[] ?? prevs.ToArray();
|
"воооо" => message.ReplyAsync("`removing /...`"),
|
||||||
|
"op ??" => message.ReplyAsync(
|
||||||
if (prevsArray.Length >= 3) {
|
"некоторые пасхальные цитаты которые вы могли найти были легально взяты у <@573772175572729876>"),
|
||||||
prev = prevsArray[1].Content;
|
_ => new CommandProcessor(message).HandleCommandAsync()
|
||||||
prevFailsafe = prevsArray[2].Content;
|
};
|
||||||
}
|
return Task.CompletedTask;
|
||||||
|
|
||||||
if (user == guild.CurrentUser || (user.IsBot &&
|
|
||||||
(message.Content.Contains(prev) || message.Content.Contains(prevFailsafe))))
|
|
||||||
return;
|
|
||||||
|
|
||||||
_ = new CommandProcessor(message).HandleCommandAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task MessageUpdatedEvent(Cacheable<IMessage, ulong> messageCached, SocketMessage messageSocket,
|
private static async Task MessageUpdatedEvent(Cacheable<IMessage, ulong> messageCached, SocketMessage messageSocket,
|
||||||
|
|
Reference in a new issue