forked from TeamInklings/Octobot
Allow mentions to act as command prefixes + bug fixes
This commit is contained in:
parent
2493e317d0
commit
b2b54b7fd4
3 changed files with 15 additions and 20 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Reference in a new issue