Skip to content

Commit

Permalink
[Bot -> Library] Replace some emoji sequences with constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogFeelings committed Nov 27, 2024
1 parent 0f8fd2f commit 90ccc57
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 76 deletions.
85 changes: 75 additions & 10 deletions Source/SammBot.Library/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ namespace SammBot.Library;
/// </summary>
public static class Constants
{
/// <summary>
/// The bot's name.
/// </summary>
public const string BOT_NAME = "Samm-Bot";

/// <summary>
/// The bot's config file's filename.
/// </summary>
public const string CONFIG_FILE = "config.json";

/// <summary>
/// Color to represent a success.
/// </summary>
Expand All @@ -42,16 +52,6 @@ public static class Constants
/// </summary>
public static readonly Color VeryBadColor = new Color(221, 46, 68);

/// <summary>
/// The bot's name.
/// </summary>
public const string BOT_NAME = "Samm-Bot";

/// <summary>
/// The bot's config file's filename.
/// </summary>
public const string CONFIG_FILE = "config.json";

/// <summary>
/// Allows only users to be notified from a message.
/// </summary>
Expand All @@ -74,4 +74,69 @@ public static class Constants
new JsonStringEnumConverter()
}
};

/// <summary>
/// A warning emoji.
/// </summary>
public const string WARNING_EMOJI = "\u26A0\uFE0F";

/// <summary>
/// An emoji for a white heavy checkmark.
/// </summary>
public const string WHITE_CHECKMARK_EMOJI = "\u2705";

/// <summary>
/// An emoji for a slot machine.
/// </summary>
public const string SLOT_MACHINE_EMOJI = "\U0001f3b0";

/// <summary>
/// An emoji for a cat face.
/// </summary>
public const string CAT_EMOJI = "\U0001f431";

/// <summary>
/// An emoji for a dog face.
/// </summary>
public const string DOG_EMOJI = "\U0001f436";

/// <summary>
/// An emoji for a fox face.
/// </summary>
public const string FOX_EMOJI = "\U0001f98a";

/// <summary>
/// An emoji for a duck.
/// </summary>
public const string DUCK_EMOJI = "\U0001f986";

/// <summary>
/// An emoji for a game die.
/// </summary>
public const string DIE_EMOJI = "\U0001f3b2";

/// <summary>
/// An emoji for a cross mark.
/// </summary>
public const string CROSS_MARK_EMOJI = "\u274C";

/// <summary>
/// An emoji for a broken heart.
/// </summary>
public const string BROKEN_HEART_EMOJI = "\U0001f494";

/// <summary>
/// An emoji for a red heart.
/// </summary>
public const string RED_HEART_EMOJI = "\u2764\uFE0F";

/// <summary>
/// An emoji for a heart with a ribbon.
/// </summary>
public const string RIBBON_HEART_EMOJI = "\U0001f49d";

/// <summary>
/// An emoji for a heart with sparkles.
/// </summary>
public const string SPARKLE_HEART_EMOJI = "\U0001f496";
}
4 changes: 2 additions & 2 deletions Source/SammBot.Library/Extensions/EmbedExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
25 changes: 0 additions & 25 deletions Source/SammBot.Library/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,6 @@ public static string TemplateReplace(this string targetString, Dictionary<string

return targetString;
}

/// <summary>
/// Converts a country code such as "ES" to its unicode emoji codepoint.
/// </summary>
/// <param name="countryCode">The country code string to convert.</param>
/// <returns>The unicode codepoint for the country's flag.</returns>
public static string CountryCodeToFlag(this string countryCode)
{
return string.Concat(countryCode.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5)));
}

/// <summary>
/// Makes the first letter of a string uppercase.
/// </summary>
/// <param name="target">The string to capitalize.</param>
/// <returns>The capitalized string.</returns>
/// <exception cref="ArgumentException">Thrown if the string is null or white-space.</exception>
public static string CapitalizeFirst(this string target)
{
ArgumentException.ThrowIfNullOrWhiteSpace(target, nameof(target));

string resultString = char.ToUpper(target.First()) + target.Substring(1).ToLower();

return resultString;
}

/// <summary>
/// Calculates the Damerau-Levenshtein distance between a source and a target
Expand Down
23 changes: 0 additions & 23 deletions Source/SammBot.Tests/Extensions/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
12 changes: 6 additions & 6 deletions Source/SammBot/Modules/FunModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace SammBot.Modules;

[PrettyName("Fun")]
[Group("fun", "Games and fun!")]
[ModuleEmoji("\U0001F3B2")]
[ModuleEmoji(Constants.DIE_EMOJI)]
public class FunModule : InteractionModuleBase<ShardedInteractionContext>
{
private readonly HttpService _httpService;
Expand Down Expand Up @@ -253,27 +253,27 @@ public async Task<RuntimeResult> 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:
Expand Down
4 changes: 2 additions & 2 deletions Source/SammBot/Modules/ModerationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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**: <t:{warning.Date}:F>\n";
replyEmbed.Description += $"**· Reason**: {warning.Reason.Truncate(48)}\n\n";
}
Expand Down
10 changes: 5 additions & 5 deletions Source/SammBot/Modules/RandomModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace SammBot.Modules;

[PrettyName("Random")]
[Group("random", "Random crazyness!")]
[ModuleEmoji("\U0001f3b0")]
[ModuleEmoji(Constants.SLOT_MACHINE_EMOJI)]
public class RandomModule : InteractionModuleBase<ShardedInteractionContext>
{
private readonly HttpService _httpService;
Expand All @@ -60,7 +60,7 @@ public async Task<RuntimeResult> 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;

Expand All @@ -84,7 +84,7 @@ public async Task<RuntimeResult> 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;

Expand All @@ -107,7 +107,7 @@ public async Task<RuntimeResult> 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;

Expand All @@ -130,7 +130,7 @@ public async Task<RuntimeResult> 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;

Expand Down
6 changes: 3 additions & 3 deletions Source/SammBot/Services/EventLoggingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public async Task OnMessageDeleted(Cacheable<IMessage, ulong> 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);

Expand Down Expand Up @@ -236,7 +236,7 @@ public async Task OnMessagesBulkDeleted(IReadOnlyCollection<Cacheable<IMessage,
{
EmbedBuilder replyEmbed = new EmbedBuilder();

replyEmbed.Title = "\u274C Messages Bulk Deleted";
replyEmbed.Title = $"{Constants.CROSS_MARK_EMOJI} Messages Bulk Deleted";
replyEmbed.Description = "Multiple messages have been deleted at once.";
replyEmbed.WithColor(Constants.VeryBadColor);

Expand Down Expand Up @@ -420,7 +420,7 @@ public async Task OnUserUnbanned(SocketUser unbannedUser, SocketGuild sourceGuil
{
EmbedBuilder replyEmbed = new EmbedBuilder();

replyEmbed.Title = "\u2705 User Unbanned";
replyEmbed.Title = $"{Constants.WHITE_CHECKMARK_EMOJI} User Unbanned";
replyEmbed.Description = "A user has been unbanned from the server.";
replyEmbed.WithColor(Constants.GoodColor);

Expand Down

0 comments on commit 90ccc57

Please sign in to comment.