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

This commit is contained in:
Deukhoofd 2020-01-19 17:24:53 +01:00
parent e95b63c24b
commit a4b12c4b51
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 21 additions and 1 deletions

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());

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";
}
}
}
}