I hate English. This fixes ordinal numbers in the birthday message using wrong suffix.

This commit is contained in:
Deukhoofd committed 2020-01-19 17:24:53 +01:00
1 parent e95b63c24b
commit a4b12c4b51
2 files changed
+21 -1

No files matched your search

+3 -1
View File
@@ -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());
+18
View File
@@ -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";
}
}
}
}