From a4b12c4b51f21b739b4fea638bfa989308f70348 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 19 Jan 2020 17:24:53 +0100 Subject: [PATCH] I hate English. This fixes ordinal numbers in the birthday message using wrong suffix. --- DeukBot4/Database/BirthdayHandler.cs | 4 +++- DeukBot4/Utilities/EnglishNumberParser.cs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/DeukBot4/Database/BirthdayHandler.cs b/DeukBot4/Database/BirthdayHandler.cs index 7cab51c..a22fb67 100644 --- a/DeukBot4/Database/BirthdayHandler.cs +++ b/DeukBot4/Database/BirthdayHandler.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using DeukBot4.MessageHandlers.CommandHandler; +using DeukBot4.Utilities; using StackExchange.Redis; namespace DeukBot4.Database @@ -140,7 +141,8 @@ namespace DeukBot4.Database var eb = EmbedFactory.GetStandardEmbedBuilder(); eb.Title = $":confetti_ball::confetti_ball: Happy Birthday! :confetti_ball::confetti_ball: "; var age = Years(birthday, today); - eb.Description = $"It's <@!{guildUser.Id}>'s {age}th birthday!! Have a good one!"; + string ageString = EnglishNumberParser.GetShortOrdinalNumber(age); + eb.Description = $"It's <@!{guildUser.Id}>'s {ageString} birthday!! Have a good one!"; eb.ThumbnailUrl = guildUser.GetAvatarUrl(); guild.SystemChannel.SendMessageAsync("", embed: eb.Build()); diff --git a/DeukBot4/Utilities/EnglishNumberParser.cs b/DeukBot4/Utilities/EnglishNumberParser.cs index 9f9d9fd..2f342ab 100644 --- a/DeukBot4/Utilities/EnglishNumberParser.cs +++ b/DeukBot4/Utilities/EnglishNumberParser.cs @@ -83,5 +83,23 @@ namespace DeukBot4.Utilities return null; } + + public static string GetShortOrdinalNumber(int number) + { + var tensDigit = number % 100 / 10; + if (tensDigit == 1) return $"{number}th"; + switch (number % 10) + { + case 1: + return $"{number}st"; + case 2: + return $"{number}nd"; + case 3: + return $"{number}rd"; + default: + return $"{number}th"; + } + + } } } \ No newline at end of file