mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-10-16 07:59:57 +00:00
Noi
5e4d030467
Fill it quicker when immediately needed, removing the need for a request list and all relating to it in the corresponding background service. Additionally, updated usings, style, nullables in all affected files.
34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using System.Text;
|
|
|
|
namespace BirthdayBot;
|
|
|
|
static class Common {
|
|
/// <summary>
|
|
/// Formats a user's name to a consistent, readable format which makes use of their nickname.
|
|
/// </summary>
|
|
public static string FormatName(SocketGuildUser member, bool ping) {
|
|
if (ping) return member.Mention;
|
|
|
|
static string escapeFormattingCharacters(string input) {
|
|
var result = new StringBuilder();
|
|
foreach (var c in input) {
|
|
if (c is '\\' or '_' or '~' or '*' or '@') {
|
|
result.Append('\\');
|
|
}
|
|
result.Append(c);
|
|
}
|
|
return result.ToString();
|
|
}
|
|
|
|
var username = escapeFormattingCharacters(member.Username);
|
|
if (member.Nickname != null) {
|
|
return $"**{escapeFormattingCharacters(member.Nickname)}** ({username}#{member.Discriminator})";
|
|
}
|
|
return $"**{username}**#{member.Discriminator}";
|
|
}
|
|
|
|
public static Dictionary<int, string> MonthNames { get; } = new() {
|
|
{ 1, "Jan" }, { 2, "Feb" }, { 3, "Mar" }, { 4, "Apr" }, { 5, "May" }, { 6, "Jun" },
|
|
{ 7, "Jul" }, { 8, "Aug" }, { 9, "Sep" }, { 10, "Oct" }, { 11, "Nov" }, { 12, "Dec" }
|
|
};
|
|
}
|