From 90ccc576b57fac70d344066467b2a1084e117828 Mon Sep 17 00:00:00 2001 From: Nora <51166756+AnalogFeelings@users.noreply.github.com> Date: Wed, 27 Nov 2024 20:47:10 +0100 Subject: [PATCH] [Bot -> Library] Replace some emoji sequences with constants. --- Source/SammBot.Library/Constants.cs | 85 ++++++++++++++++--- .../Extensions/EmbedExtensions.cs | 4 +- .../Extensions/StringExtensions.cs | 25 ------ .../Extensions/StringExtensionsTests.cs | 23 ----- Source/SammBot/Modules/FunModule.cs | 12 +-- Source/SammBot/Modules/ModerationModule.cs | 4 +- Source/SammBot/Modules/RandomModule.cs | 10 +-- .../SammBot/Services/EventLoggingService.cs | 6 +- 8 files changed, 93 insertions(+), 76 deletions(-) diff --git a/Source/SammBot.Library/Constants.cs b/Source/SammBot.Library/Constants.cs index ee7f4dc..1ed9673 100644 --- a/Source/SammBot.Library/Constants.cs +++ b/Source/SammBot.Library/Constants.cs @@ -27,6 +27,16 @@ namespace SammBot.Library; /// public static class Constants { + /// + /// The bot's name. + /// + public const string BOT_NAME = "Samm-Bot"; + + /// + /// The bot's config file's filename. + /// + public const string CONFIG_FILE = "config.json"; + /// /// Color to represent a success. /// @@ -42,16 +52,6 @@ public static class Constants /// public static readonly Color VeryBadColor = new Color(221, 46, 68); - /// - /// The bot's name. - /// - public const string BOT_NAME = "Samm-Bot"; - - /// - /// The bot's config file's filename. - /// - public const string CONFIG_FILE = "config.json"; - /// /// Allows only users to be notified from a message. /// @@ -74,4 +74,69 @@ public static class Constants new JsonStringEnumConverter() } }; + + /// + /// A warning emoji. + /// + public const string WARNING_EMOJI = "\u26A0\uFE0F"; + + /// + /// An emoji for a white heavy checkmark. + /// + public const string WHITE_CHECKMARK_EMOJI = "\u2705"; + + /// + /// An emoji for a slot machine. + /// + public const string SLOT_MACHINE_EMOJI = "\U0001f3b0"; + + /// + /// An emoji for a cat face. + /// + public const string CAT_EMOJI = "\U0001f431"; + + /// + /// An emoji for a dog face. + /// + public const string DOG_EMOJI = "\U0001f436"; + + /// + /// An emoji for a fox face. + /// + public const string FOX_EMOJI = "\U0001f98a"; + + /// + /// An emoji for a duck. + /// + public const string DUCK_EMOJI = "\U0001f986"; + + /// + /// An emoji for a game die. + /// + public const string DIE_EMOJI = "\U0001f3b2"; + + /// + /// An emoji for a cross mark. + /// + public const string CROSS_MARK_EMOJI = "\u274C"; + + /// + /// An emoji for a broken heart. + /// + public const string BROKEN_HEART_EMOJI = "\U0001f494"; + + /// + /// An emoji for a red heart. + /// + public const string RED_HEART_EMOJI = "\u2764\uFE0F"; + + /// + /// An emoji for a heart with a ribbon. + /// + public const string RIBBON_HEART_EMOJI = "\U0001f49d"; + + /// + /// An emoji for a heart with sparkles. + /// + public const string SPARKLE_HEART_EMOJI = "\U0001f496"; } \ No newline at end of file diff --git a/Source/SammBot.Library/Extensions/EmbedExtensions.cs b/Source/SammBot.Library/Extensions/EmbedExtensions.cs index 0ab87d9..5ca64f5 100644 --- a/Source/SammBot.Library/Extensions/EmbedExtensions.cs +++ b/Source/SammBot.Library/Extensions/EmbedExtensions.cs @@ -59,7 +59,7 @@ public static EmbedBuilder BuildSuccessEmbed(this EmbedBuilder builder, ShardedI { EmbedBuilder defaultEmbed = builder.BuildDefaultEmbed(context); - defaultEmbed.Title = "\u2705 Success"; + defaultEmbed.Title = $"{Constants.WHITE_CHECKMARK_EMOJI} Success"; defaultEmbed.Color = Constants.GoodColor; return defaultEmbed; @@ -75,7 +75,7 @@ public static EmbedBuilder BuildErrorEmbed(this EmbedBuilder builder, ShardedInt { EmbedBuilder defaultEmbed = builder.BuildDefaultEmbed(context); - defaultEmbed.Title = "\u26A0\uFE0F An error has occurred"; + defaultEmbed.Title = $"{Constants.WARNING_EMOJI} An error has occurred"; defaultEmbed.Color = Constants.BadColor; return defaultEmbed; diff --git a/Source/SammBot.Library/Extensions/StringExtensions.cs b/Source/SammBot.Library/Extensions/StringExtensions.cs index ec0ca85..2f910e1 100644 --- a/Source/SammBot.Library/Extensions/StringExtensions.cs +++ b/Source/SammBot.Library/Extensions/StringExtensions.cs @@ -51,31 +51,6 @@ public static string TemplateReplace(this string targetString, Dictionary - /// Converts a country code such as "ES" to its unicode emoji codepoint. - /// - /// The country code string to convert. - /// The unicode codepoint for the country's flag. - public static string CountryCodeToFlag(this string countryCode) - { - return string.Concat(countryCode.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5))); - } - - /// - /// Makes the first letter of a string uppercase. - /// - /// The string to capitalize. - /// The capitalized string. - /// Thrown if the string is null or white-space. - public static string CapitalizeFirst(this string target) - { - ArgumentException.ThrowIfNullOrWhiteSpace(target, nameof(target)); - - string resultString = char.ToUpper(target.First()) + target.Substring(1).ToLower(); - - return resultString; - } /// /// Calculates the Damerau-Levenshtein distance between a source and a target diff --git a/Source/SammBot.Tests/Extensions/StringExtensionsTests.cs b/Source/SammBot.Tests/Extensions/StringExtensionsTests.cs index edfe085..d4152a3 100644 --- a/Source/SammBot.Tests/Extensions/StringExtensionsTests.cs +++ b/Source/SammBot.Tests/Extensions/StringExtensionsTests.cs @@ -48,29 +48,6 @@ public void TemplateReplaceTest() Assert.IsTrue(actual == expected, $"Expected \"{expected}\", got \"{actual}\"."); } - [TestMethod] - public void CountryCodeToFlagTest() - { - string actualFirst = "ES".CountryCodeToFlag(); - string expectedFirst = "\U0001f1ea\U0001f1f8"; - - Assert.IsTrue(actualFirst == expectedFirst, $"Expected \"{expectedFirst}\", got \"{actualFirst}\"."); - - string actualSecond = "US".CountryCodeToFlag(); - string expectedSecond = "\U0001f1fa\U0001f1f8"; - - Assert.IsTrue(actualSecond == expectedSecond, $"Expected \"{expectedSecond}\", got \"{actualSecond}\"."); - } - - [TestMethod] - public void CapitalizeFirstTest() - { - string actual = "lorem ipsum".CapitalizeFirst(); - string expected = "Lorem ipsum"; - - Assert.IsTrue(actual == expected, $"Expected \"{expected}\", got \"{actual}\"."); - } - [TestMethod] public void DamerauDistanceTest() { diff --git a/Source/SammBot/Modules/FunModule.cs b/Source/SammBot/Modules/FunModule.cs index bb31211..1257099 100644 --- a/Source/SammBot/Modules/FunModule.cs +++ b/Source/SammBot/Modules/FunModule.cs @@ -38,7 +38,7 @@ namespace SammBot.Modules; [PrettyName("Fun")] [Group("fun", "Games and fun!")] -[ModuleEmoji("\U0001F3B2")] +[ModuleEmoji(Constants.DIE_EMOJI)] public class FunModule : InteractionModuleBase { private readonly HttpService _httpService; @@ -253,27 +253,27 @@ public async Task ShipUsersAsync { case 0: percentageText = "Incompatible!"; - percentageEmoji = "\u274C"; + percentageEmoji = Constants.CROSS_MARK_EMOJI; break; case < 25: percentageText = "Awful!"; - percentageEmoji = "\U0001f494"; + percentageEmoji = Constants.BROKEN_HEART_EMOJI; break; case < 50: percentageText = "Not Bad!"; - percentageEmoji = "\u2764\uFE0F"; + percentageEmoji = Constants.RED_HEART_EMOJI; break; case < 75: percentageText = "Decent!"; - percentageEmoji = "\U0001f49d"; + percentageEmoji = Constants.RIBBON_HEART_EMOJI; break; case < 85: percentageText = "True Love!"; - percentageEmoji = "\U0001f496"; + percentageEmoji = Constants.SPARKLE_HEART_EMOJI; break; case < 100: diff --git a/Source/SammBot/Modules/ModerationModule.cs b/Source/SammBot/Modules/ModerationModule.cs index da2c2fe..b033183 100644 --- a/Source/SammBot/Modules/ModerationModule.cs +++ b/Source/SammBot/Modules/ModerationModule.cs @@ -144,7 +144,7 @@ string reason { EmbedBuilder directMessageEmbed = new EmbedBuilder().BuildDefaultEmbed(Context); - directMessageEmbed.Title = "\u26A0\uFE0F You have been warned"; + directMessageEmbed.Title = $"{Constants.WARNING_EMOJI} You have been warned"; directMessageEmbed.Description = "You may see all of your warnings with the `/mod warns` command in the server."; directMessageEmbed.Color = Constants.BadColor; @@ -222,7 +222,7 @@ SocketGuildUser targetUser foreach (UserWarning warning in filteredWarnings) { - replyEmbed.Description += $"\u26A0\uFE0F **ID**: `{warning.Id}`\n"; + replyEmbed.Description += $"{Constants.WARNING_EMOJI} **ID**: `{warning.Id}`\n"; replyEmbed.Description += $"**· Creation Date**: \n"; replyEmbed.Description += $"**· Reason**: {warning.Reason.Truncate(48)}\n\n"; } diff --git a/Source/SammBot/Modules/RandomModule.cs b/Source/SammBot/Modules/RandomModule.cs index df02ae8..8f4f8ef 100644 --- a/Source/SammBot/Modules/RandomModule.cs +++ b/Source/SammBot/Modules/RandomModule.cs @@ -35,7 +35,7 @@ namespace SammBot.Modules; [PrettyName("Random")] [Group("random", "Random crazyness!")] -[ModuleEmoji("\U0001f3b0")] +[ModuleEmoji(Constants.SLOT_MACHINE_EMOJI)] public class RandomModule : InteractionModuleBase { private readonly HttpService _httpService; @@ -60,7 +60,7 @@ public async Task GetCatAsync() CatImage retrievedImage = retrievedImages.First(); EmbedBuilder replyEmbed = new EmbedBuilder().BuildDefaultEmbed(Context); - replyEmbed.Title = "\U0001f431 Random Cat"; + replyEmbed.Title = $"{Constants.CAT_EMOJI} Random Cat"; replyEmbed.Color = new Color(255, 204, 77); replyEmbed.ImageUrl = retrievedImage.Url; @@ -84,7 +84,7 @@ public async Task GetDogAsync() DogImage retrievedImage = retrievedImages.First(); EmbedBuilder replyEmbed = new EmbedBuilder().BuildDefaultEmbed(Context); - replyEmbed.Title = "\U0001f436 Random Dog"; + replyEmbed.Title = $"{Constants.DOG_EMOJI} Random Dog"; replyEmbed.Color = new Color(217, 158, 130); replyEmbed.ImageUrl = retrievedImage.Url; @@ -107,7 +107,7 @@ public async Task GetFoxAsync() EmbedBuilder replyEmbed = new EmbedBuilder().BuildDefaultEmbed(Context); - replyEmbed.Title = "\U0001f98a Random Fox"; + replyEmbed.Title = $"{Constants.FOX_EMOJI} Random Fox"; replyEmbed.Color = new Color(241, 143, 38); replyEmbed.ImageUrl = repliedImage.ImageUrl; @@ -130,7 +130,7 @@ public async Task GetDuckAsync() EmbedBuilder replyEmbed = new EmbedBuilder().BuildDefaultEmbed(Context); - replyEmbed.Title = "\U0001f986 Random Duck"; + replyEmbed.Title = $"{Constants.DUCK_EMOJI} Random Duck"; replyEmbed.Color = new Color(62, 114, 29); replyEmbed.ImageUrl = repliedImage.ImageUrl; diff --git a/Source/SammBot/Services/EventLoggingService.cs b/Source/SammBot/Services/EventLoggingService.cs index 13075ae..635c831 100644 --- a/Source/SammBot/Services/EventLoggingService.cs +++ b/Source/SammBot/Services/EventLoggingService.cs @@ -169,7 +169,7 @@ public async Task OnMessageDeleted(Cacheable cachedMessage, Cac { EmbedBuilder replyEmbed = new EmbedBuilder(); - replyEmbed.Title = "\u274C Message Deleted"; + replyEmbed.Title = $"{Constants.CROSS_MARK_EMOJI} Message Deleted"; replyEmbed.Description = "A message has been deleted."; replyEmbed.WithColor(Constants.VeryBadColor); @@ -236,7 +236,7 @@ public async Task OnMessagesBulkDeleted(IReadOnlyCollection