Allow mentions to act as command prefixes + bug fixes

This commit is contained in:
l1ttleO 2022-08-05 21:01:06 +05:00
parent 2493e317d0
commit b2b54b7fd4
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
3 changed files with 15 additions and 20 deletions

View file

@ -15,6 +15,7 @@ public static class CommandHandler {
};
private static readonly Dictionary<string, Regex> 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,6 +60,7 @@ public static class CommandHandler {
if (currentLine != list.Length) continue;
if (ConfigWriteScheduled) await Boyfriend.WriteGuildConfig(guild.Id);
if (StackedReplyMessage.Length > 0)
await message.ReplyAsync(StackedReplyMessage.ToString(), false, null, AllowedMentions.None);
var adminChannel = Utils.GetAdminLogChannel(guild.Id);

View file

@ -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;

View file

@ -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);