fix(bot): display new Discord usernames correctly

This commit is contained in:
Iris System 2023-06-28 13:55:21 +12:00
parent 11d70666d0
commit a0fa03599b
3 changed files with 3 additions and 2 deletions

View File

@ -23,6 +23,7 @@ public record User
public ulong Id { get; init; }
public string Username { get; init; }
public string Discriminator { get; init; }
public string GlobalName { get; init; }
public string? Avatar { get; init; }
public bool Bot { get; init; }
public bool? System { get; init; }

View File

@ -386,7 +386,7 @@ public class ProxyService
content.Append($"*[(click to see attachment)]({jumpLink})*");
}
var username = nickname ?? repliedTo.Author.Username;
var username = nickname ?? repliedTo.Author.GlobalName ?? repliedTo.Author.Username;
var avatarUrl = avatar != null
? $"https://cdn.discordapp.com/guilds/{trigger.GuildId}/users/{repliedTo.Author.Id}/avatars/{avatar}.png"
: $"https://cdn.discordapp.com/avatars/{repliedTo.Author.Id}/{repliedTo.Author.Avatar}.png";

View File

@ -35,7 +35,7 @@ public static class DiscordUtils
private static readonly Regex UNBROKEN_LINK_REGEX = new("<?(https?:\\/\\/[^\\s<]+[^<.,:;\"')\\]\\s])>?");
public static string NameAndMention(this User user) =>
$"{user.Username}#{user.Discriminator} ({user.Mention()})";
$"{user.Username}{(user.Discriminator == "0" ? "" : $"#{user.Discriminator}")} ({user.Mention()})";
public static Instant SnowflakeToInstant(ulong snowflake) =>
Instant.FromUtc(2015, 1, 1, 0, 0, 0) + Duration.FromMilliseconds(snowflake >> 22);