From 15c42a6ef5148f9b21830637ba99279448531919 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Tue, 6 Dec 2022 18:20:41 +0300 Subject: [PATCH] Reply emojis are now taken from a single file --- Boyfriend/CommandProcessor.cs | 36 +++++++++++------------ Boyfriend/Commands/BanCommand.cs | 2 +- Boyfriend/Commands/HelpCommand.cs | 2 +- Boyfriend/Commands/KickCommand.cs | 2 +- Boyfriend/Commands/MuteCommand.cs | 12 ++++---- Boyfriend/Commands/PingCommand.cs | 2 +- Boyfriend/Commands/SettingsCommand.cs | 18 ++++++------ Boyfriend/Commands/UnmuteCommand.cs | 4 +-- Boyfriend/{Prefixes.cs => ReplyEmojis.cs} | 6 ++-- 9 files changed, 42 insertions(+), 42 deletions(-) rename Boyfriend/{Prefixes.cs => ReplyEmojis.cs} (83%) diff --git a/Boyfriend/CommandProcessor.cs b/Boyfriend/CommandProcessor.cs index 9280941..f1e9c69 100644 --- a/Boyfriend/CommandProcessor.cs +++ b/Boyfriend/CommandProcessor.cs @@ -73,7 +73,7 @@ public sealed class CommandProcessor { } public void Reply(string response, string? customEmoji = null) { - Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{customEmoji ?? Prefixes.Success} {response}", Context.Message); + Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{customEmoji ?? ReplyEmojis.Success} {response}", Context.Message); } public void Audit(string action, bool isPublic = true) { @@ -105,14 +105,14 @@ public sealed class CommandProcessor { public string? GetRemaining(string[] from, int startIndex, string? argument) { if (startIndex >= from.Length && argument is not null) Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{Prefixes.MissingArgument} {Utils.GetMessage($"Missing{argument}")}", Context.Message); + $"{ReplyEmojis.MissingArgument} {Utils.GetMessage($"Missing{argument}")}", Context.Message); else return string.Join(" ", from, startIndex, from.Length - startIndex); return null; } public SocketUser? GetUser(string[] args, string[] cleanArgs, int index, string? argument) { if (index >= args.Length) { - Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{Prefixes.MissingArgument} {Messages.MissingUser}", + Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}", Context.Message); return null; } @@ -120,14 +120,14 @@ public sealed class CommandProcessor { var user = Boyfriend.Client.GetUser(Utils.ParseMention(args[index])); if (user is null && argument is not null) Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{Prefixes.InvalidArgument} {string.Format(Messages.InvalidUser, Utils.Wrap(cleanArgs[index]))}", + $"{ReplyEmojis.InvalidArgument} {string.Format(Messages.InvalidUser, Utils.Wrap(cleanArgs[index]))}", Context.Message); return user; } public bool HasPermission(GuildPermission permission) { if (!Context.Guild.CurrentUser.GuildPermissions.Has(permission)) { - Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{Prefixes.NoAccess} {Utils.GetMessage($"BotCannot{permission}")}", + Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.NoAccess} {Utils.GetMessage($"BotCannot{permission}")}", Context.Message); return false; } @@ -135,7 +135,7 @@ public sealed class CommandProcessor { if (Context.Guild.GetUser(Context.User.Id).GuildPermissions.Has(permission) || Context.Guild.OwnerId == Context.User.Id) return true; - Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{Prefixes.NoAccess} {Utils.GetMessage($"UserCannot{permission}")}", + Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.NoAccess} {Utils.GetMessage($"UserCannot{permission}")}", Context.Message); return false; } @@ -146,7 +146,7 @@ public sealed class CommandProcessor { public SocketGuildUser? GetMember(string[] args, string[] cleanArgs, int index, string? argument) { if (index >= args.Length) { - Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{Prefixes.MissingArgument} {Messages.MissingMember}", + Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingMember}", Context.Message); return null; } @@ -154,7 +154,7 @@ public sealed class CommandProcessor { var member = Context.Guild.GetUser(Utils.ParseMention(args[index])); if (member is null && argument is not null) Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{Prefixes.InvalidArgument} {string.Format(Messages.InvalidMember, Utils.Wrap(cleanArgs[index]))}", + $"{ReplyEmojis.InvalidArgument} {string.Format(Messages.InvalidMember, Utils.Wrap(cleanArgs[index]))}", Context.Message); return member; } @@ -165,7 +165,7 @@ public sealed class CommandProcessor { public ulong? GetBan(string[] args, int index) { if (index >= args.Length) { - Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{Prefixes.MissingArgument} {Messages.MissingUser}", + Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}", Context.Message); return null; } @@ -182,14 +182,14 @@ public sealed class CommandProcessor { public int? GetNumberRange(string[] args, int index, int min, int max, string? argument) { if (index >= args.Length) { Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{Prefixes.MissingArgument} {string.Format(Messages.MissingNumber, min.ToString(), max.ToString())}", + $"{ReplyEmojis.MissingArgument} {string.Format(Messages.MissingNumber, min.ToString(), max.ToString())}", Context.Message); return null; } if (!int.TryParse(args[index], out var i)) { Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{Prefixes.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}Invalid"), min.ToString(), max.ToString(), Utils.Wrap(args[index]))}", + $"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}Invalid"), min.ToString(), max.ToString(), Utils.Wrap(args[index]))}", Context.Message); return null; } @@ -197,14 +197,14 @@ public sealed class CommandProcessor { if (argument is null) return i; if (i < min) { Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{Prefixes.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}TooSmall"), min.ToString())}", + $"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}TooSmall"), min.ToString())}", Context.Message); return null; } if (i <= max) return i; Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{Prefixes.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}TooLarge"), max.ToString())}", + $"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}TooLarge"), max.ToString())}", Context.Message); return null; } @@ -246,31 +246,31 @@ public sealed class CommandProcessor { public bool CanInteractWith(SocketGuildUser user, string action) { if (Context.User.Id == user.Id) { Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{Prefixes.CantInteract} {Utils.GetMessage($"UserCannot{action}Themselves")}", Context.Message); + $"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Themselves")}", Context.Message); return false; } if (Context.Guild.CurrentUser.Id == user.Id) { Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{Prefixes.CantInteract} {Utils.GetMessage($"UserCannot{action}Bot")}", Context.Message); + $"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Bot")}", Context.Message); return false; } if (Context.Guild.Owner.Id == user.Id) { Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{Prefixes.CantInteract} {Utils.GetMessage($"UserCannot{action}Owner")}", Context.Message); + $"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Owner")}", Context.Message); return false; } if (Context.Guild.CurrentUser.Hierarchy <= user.Hierarchy) { Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{Prefixes.CantInteract} {Utils.GetMessage($"BotCannot{action}Target")}", Context.Message); + $"{ReplyEmojis.CantInteract} {Utils.GetMessage($"BotCannot{action}Target")}", Context.Message); return false; } if (Context.Guild.Owner.Id == Context.User.Id || GetMember().Hierarchy > user.Hierarchy) return true; Utils.SafeAppendToBuilder(_stackedReplyMessage, - $"{Prefixes.CantInteract} {Utils.GetMessage($"UserCannot{action}Target")}", Context.Message); + $"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Target")}", Context.Message); return false; } } diff --git a/Boyfriend/Commands/BanCommand.cs b/Boyfriend/Commands/BanCommand.cs index aa5cbf3..561edb1 100644 --- a/Boyfriend/Commands/BanCommand.cs +++ b/Boyfriend/Commands/BanCommand.cs @@ -29,7 +29,7 @@ public sealed class BanCommand : ICommand { var feedback = string.Format(Messages.FeedbackUserBanned, toBan.Mention, Utils.GetHumanizedTimeOffset(duration), Utils.Wrap(reason)); - cmd.Reply(feedback, Prefixes.Banned); + cmd.Reply(feedback, ReplyEmojis.Banned); cmd.Audit(feedback); if (duration.TotalSeconds > 0) diff --git a/Boyfriend/Commands/HelpCommand.cs b/Boyfriend/Commands/HelpCommand.cs index 60489aa..0fc91d8 100644 --- a/Boyfriend/Commands/HelpCommand.cs +++ b/Boyfriend/Commands/HelpCommand.cs @@ -12,7 +12,7 @@ public sealed class HelpCommand : ICommand { foreach (var command in CommandProcessor.Commands) toSend.Append( $"\n`{prefix}{command.Aliases[0]}`: {Utils.GetMessage($"CommandDescription{command.Aliases[0].Titleize()}")}"); - cmd.Reply(toSend.ToString(), Prefixes.Help); + cmd.Reply(toSend.ToString(), ReplyEmojis.Help); toSend.Clear(); return Task.CompletedTask; diff --git a/Boyfriend/Commands/KickCommand.cs b/Boyfriend/Commands/KickCommand.cs index 3ffda59..9e4cfe4 100644 --- a/Boyfriend/Commands/KickCommand.cs +++ b/Boyfriend/Commands/KickCommand.cs @@ -24,7 +24,7 @@ public sealed class KickCommand : ICommand { await toKick.KickAsync(guildKickMessage); var format = string.Format(Messages.FeedbackMemberKicked, toKick.Mention, Utils.Wrap(reason)); - cmd.Reply(format, Prefixes.Kicked); + cmd.Reply(format, ReplyEmojis.Kicked); cmd.Audit(format); } } diff --git a/Boyfriend/Commands/MuteCommand.cs b/Boyfriend/Commands/MuteCommand.cs index eaf3471..b01f1f1 100644 --- a/Boyfriend/Commands/MuteCommand.cs +++ b/Boyfriend/Commands/MuteCommand.cs @@ -20,7 +20,7 @@ public sealed class MuteCommand : ICommand { || (toMute.TimedOutUntil is not null && toMute.TimedOutUntil.Value.ToUnixTimeSeconds() > DateTimeOffset.Now.ToUnixTimeSeconds())) { - cmd.Reply(Messages.MemberAlreadyMuted, Prefixes.Error); + cmd.Reply(Messages.MemberAlreadyMuted, ReplyEmojis.Error); return; } @@ -30,7 +30,7 @@ public sealed class MuteCommand : ICommand { foreach (var roleId in mutedRemovedRoles) await toMute.AddRoleAsync(roleId); rolesRemoved.Remove(toMute.Id); cmd.ConfigWriteScheduled = true; - cmd.Reply(Messages.RolesReturned, Prefixes.Warning); + cmd.Reply(Messages.RolesReturned, ReplyEmojis.Warning); } if (cmd.HasPermission(GuildPermission.ModerateMembers) && cmd.CanInteractWith(toMute, "Mute")) @@ -55,7 +55,7 @@ public sealed class MuteCommand : ICommand { rolesRemoved.Add(userRole.Id); } catch (HttpException e) { cmd.Reply(string.Format(Messages.RoleRemovalFailed, $"<@&{userRole}>", Utils.Wrap(e.Reason)), - Prefixes.Warning); + ReplyEmojis.Warning); } Boyfriend.GetRemovedRoles(guild.Id).Add(toMute.Id, rolesRemoved.AsReadOnly()); @@ -68,12 +68,12 @@ public sealed class MuteCommand : ICommand { await Task.FromResult(Utils.DelayedUnmuteAsync(cmd, toMute, Messages.PunishmentExpired, duration)); } else { if (!hasDuration || duration.TotalDays > 28) { - cmd.Reply(Messages.DurationRequiredForTimeOuts, Prefixes.Error); + cmd.Reply(Messages.DurationRequiredForTimeOuts, ReplyEmojis.Error); return; } if (toMute.IsBot) { - cmd.Reply(Messages.CannotTimeOutBot, Prefixes.Error); + cmd.Reply(Messages.CannotTimeOutBot, ReplyEmojis.Error); return; } @@ -83,7 +83,7 @@ public sealed class MuteCommand : ICommand { var feedback = string.Format(Messages.FeedbackMemberMuted, toMute.Mention, Utils.GetHumanizedTimeOffset(duration), Utils.Wrap(reason)); - cmd.Reply(feedback, Prefixes.Muted); + cmd.Reply(feedback, ReplyEmojis.Muted); cmd.Audit(feedback); } } diff --git a/Boyfriend/Commands/PingCommand.cs b/Boyfriend/Commands/PingCommand.cs index 6501a0d..88034a5 100644 --- a/Boyfriend/Commands/PingCommand.cs +++ b/Boyfriend/Commands/PingCommand.cs @@ -10,7 +10,7 @@ public sealed class PingCommand : ICommand { .Append(Math.Abs(DateTimeOffset.Now.Subtract(cmd.Context.Message.Timestamp).TotalMilliseconds)) .Append(Messages.Milliseconds); - cmd.Reply(builder.ToString(), Prefixes.Ping); + cmd.Reply(builder.ToString(), ReplyEmojis.Ping); builder.Clear(); return Task.CompletedTask; diff --git a/Boyfriend/Commands/SettingsCommand.cs b/Boyfriend/Commands/SettingsCommand.cs index f1060d9..58b7120 100644 --- a/Boyfriend/Commands/SettingsCommand.cs +++ b/Boyfriend/Commands/SettingsCommand.cs @@ -33,7 +33,7 @@ public sealed class SettingsCommand : ICommand { .AppendFormat(format, currentValue).AppendLine(); } - cmd.Reply(currentSettings.ToString(), Prefixes.Settings); + cmd.Reply(currentSettings.ToString(), ReplyEmojis.Settings); currentSettings.Clear(); return Task.CompletedTask; } @@ -51,7 +51,7 @@ public sealed class SettingsCommand : ICommand { } if (!exists) { - cmd.Reply(Messages.SettingDoesntExist, Prefixes.Error); + cmd.Reply(Messages.SettingDoesntExist, ReplyEmojis.Error); return Task.CompletedTask; } @@ -64,7 +64,7 @@ public sealed class SettingsCommand : ICommand { value = value.Replace(" ", "").ToLower(); if (value.StartsWith(",") || value.Count(x => x is ',') > 1 || (!value.Contains("interested") && !value.Contains("users") && !value.Contains("role"))) { - cmd.Reply(Messages.InvalidSettingValue, Prefixes.Error); + cmd.Reply(Messages.InvalidSettingValue, ReplyEmojis.Error); return Task.CompletedTask; } } @@ -77,7 +77,7 @@ public sealed class SettingsCommand : ICommand { _ => value }; if (!IsBool(value)) { - cmd.Reply(Messages.InvalidSettingValue, Prefixes.Error); + cmd.Reply(Messages.InvalidSettingValue, ReplyEmojis.Error); return Task.CompletedTask; } } @@ -106,22 +106,22 @@ public sealed class SettingsCommand : ICommand { } else { if (value == config[selectedSetting]) { cmd.Reply(string.Format(Messages.SettingsNothingChanged, localizedSelectedSetting, formattedValue), - Prefixes.Error); + ReplyEmojis.Error); return Task.CompletedTask; } if (selectedSetting is "Lang" && !Utils.CultureInfoCache.ContainsKey(value)) { - cmd.Reply(Messages.LanguageNotSupported, Prefixes.Error); + cmd.Reply(Messages.LanguageNotSupported, ReplyEmojis.Error); return Task.CompletedTask; } if (selectedSetting.EndsWith("Channel") && guild.GetTextChannel(mention) is null) { - cmd.Reply(Messages.InvalidChannel, Prefixes.Error); + cmd.Reply(Messages.InvalidChannel, ReplyEmojis.Error); return Task.CompletedTask; } if (selectedSetting.EndsWith("Role") && guild.GetRole(mention) is null) { - cmd.Reply(Messages.InvalidRole, Prefixes.Error); + cmd.Reply(Messages.InvalidRole, ReplyEmojis.Error); return Task.CompletedTask; } @@ -138,7 +138,7 @@ public sealed class SettingsCommand : ICommand { cmd.ConfigWriteScheduled = true; var replyFormat = string.Format(Messages.FeedbackSettingsUpdated, localizedSelectedSetting, formattedValue); - cmd.Reply(replyFormat, Prefixes.SettingsSet); + cmd.Reply(replyFormat, ReplyEmojis.SettingsSet); cmd.Audit(replyFormat, false); return Task.CompletedTask; } diff --git a/Boyfriend/Commands/UnmuteCommand.cs b/Boyfriend/Commands/UnmuteCommand.cs index d32f8b5..f312231 100644 --- a/Boyfriend/Commands/UnmuteCommand.cs +++ b/Boyfriend/Commands/UnmuteCommand.cs @@ -34,7 +34,7 @@ public sealed class UnmuteCommand : ICommand { } else { if (toUnmute.TimedOutUntil is null || toUnmute.TimedOutUntil.Value.ToUnixTimeSeconds() < DateTimeOffset.Now.ToUnixTimeSeconds()) { - cmd.Reply(Messages.MemberNotMuted, Prefixes.Error); + cmd.Reply(Messages.MemberNotMuted, ReplyEmojis.Error); return; } @@ -42,7 +42,7 @@ public sealed class UnmuteCommand : ICommand { } var feedback = string.Format(Messages.FeedbackMemberUnmuted, toUnmute.Mention, Utils.Wrap(reason)); - cmd.Reply(feedback, Prefixes.Unmuted); + cmd.Reply(feedback, ReplyEmojis.Unmuted); cmd.Audit(feedback); } } diff --git a/Boyfriend/Prefixes.cs b/Boyfriend/ReplyEmojis.cs similarity index 83% rename from Boyfriend/Prefixes.cs rename to Boyfriend/ReplyEmojis.cs index dbb7295..9460621 100644 --- a/Boyfriend/Prefixes.cs +++ b/Boyfriend/ReplyEmojis.cs @@ -1,15 +1,15 @@ namespace Boyfriend; -public static class Prefixes { +public static class ReplyEmojis { public const string Success = ":white_check_mark:"; public const string Warning = ":warning: "; public const string Error = ":x:"; public const string MissingArgument = ":keyboard:"; public const string InvalidArgument = ":construction:"; - public const string NoAccess = ":no_entry_sign:"; + public const string NoPermission = ":no_entry_sign:"; public const string CantInteract = ":vertical_traffic_light:"; public const string Help = ":page_facing_up:"; - public const string Settings = ":gear:"; + public const string SettingsList = ":gear:"; public const string SettingsSet = ":control_knobs:"; public const string Ping = ":signal_strength:"; public const string Banned = ":hammer:";