BirthdayBot/Common.cs
Noi 5e4d030467 Rework member cache downloading
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.
2021-11-22 13:40:08 -08:00

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