diff --git a/Source/SammBot.Library/Constants.cs b/Source/SammBot.Library/Constants.cs index 1ed9673..ee7f4dc 100644 --- a/Source/SammBot.Library/Constants.cs +++ b/Source/SammBot.Library/Constants.cs @@ -27,16 +27,6 @@ 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. /// @@ -52,6 +42,16 @@ 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,69 +74,4 @@ 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 5ca64f5..0ab87d9 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 = $"{Constants.WHITE_CHECKMARK_EMOJI} Success"; + defaultEmbed.Title = "\u2705 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 = $"{Constants.WARNING_EMOJI} An error has occurred"; + defaultEmbed.Title = "\u26A0\uFE0F 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 2f910e1..ec0ca85 100644 --- a/Source/SammBot.Library/Extensions/StringExtensions.cs +++ b/Source/SammBot.Library/Extensions/StringExtensions.cs @@ -51,6 +51,31 @@ 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 d4152a3..edfe085 100644 --- a/Source/SammBot.Tests/Extensions/StringExtensionsTests.cs +++ b/Source/SammBot.Tests/Extensions/StringExtensionsTests.cs @@ -48,6 +48,29 @@ 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 1257099..bb31211 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(Constants.DIE_EMOJI)] +[ModuleEmoji("\U0001F3B2")] public class FunModule : InteractionModuleBase { private readonly HttpService _httpService; @@ -253,27 +253,27 @@ public async Task ShipUsersAsync { case 0: percentageText = "Incompatible!"; - percentageEmoji = Constants.CROSS_MARK_EMOJI; + percentageEmoji = "\u274C"; break; case < 25: percentageText = "Awful!"; - percentageEmoji = Constants.BROKEN_HEART_EMOJI; + percentageEmoji = "\U0001f494"; break; case < 50: percentageText = "Not Bad!"; - percentageEmoji = Constants.RED_HEART_EMOJI; + percentageEmoji = "\u2764\uFE0F"; break; case < 75: percentageText = "Decent!"; - percentageEmoji = Constants.RIBBON_HEART_EMOJI; + percentageEmoji = "\U0001f49d"; break; case < 85: percentageText = "True Love!"; - percentageEmoji = Constants.SPARKLE_HEART_EMOJI; + percentageEmoji = "\U0001f496"; break; case < 100: diff --git a/Source/SammBot/Modules/ModerationModule.cs b/Source/SammBot/Modules/ModerationModule.cs index b033183..da2c2fe 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 = $"{Constants.WARNING_EMOJI} You have been warned"; + directMessageEmbed.Title = "\u26A0\uFE0F 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 += $"{Constants.WARNING_EMOJI} **ID**: `{warning.Id}`\n"; + replyEmbed.Description += $"\u26A0\uFE0F **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 8f4f8ef..df02ae8 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(Constants.SLOT_MACHINE_EMOJI)] +[ModuleEmoji("\U0001f3b0")] 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 = $"{Constants.CAT_EMOJI} Random Cat"; + replyEmbed.Title = "\U0001f431 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 = $"{Constants.DOG_EMOJI} Random Dog"; + replyEmbed.Title = "\U0001f436 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 = $"{Constants.FOX_EMOJI} Random Fox"; + replyEmbed.Title = "\U0001f98a 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 = $"{Constants.DUCK_EMOJI} Random Duck"; + replyEmbed.Title = "\U0001f986 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 635c831..13075ae 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 = $"{Constants.CROSS_MARK_EMOJI} Message Deleted"; + replyEmbed.Title = "\u274C Message Deleted"; replyEmbed.Description = "A message has been deleted."; replyEmbed.WithColor(Constants.VeryBadColor); @@ -236,7 +236,7 @@ public async Task OnMessagesBulkDeleted(IReadOnlyCollection