From 22421f75177ab819f6003903e6ec56aba002d401 Mon Sep 17 00:00:00 2001 From: Noi Date: Mon, 4 Sep 2023 16:35:03 -0700 Subject: [PATCH 1/5] Update Discord.Net --- BirthdayBot.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BirthdayBot.csproj b/BirthdayBot.csproj index 67ff3f9..007546c 100644 --- a/BirthdayBot.csproj +++ b/BirthdayBot.csproj @@ -22,7 +22,7 @@ - + all From acb052bea3af39091510a28aae887bc6d8f8d816 Mon Sep 17 00:00:00 2001 From: Noi Date: Mon, 4 Sep 2023 16:58:45 -0700 Subject: [PATCH 2/5] Drop use of discriminator if none exists --- ApplicationCommands/ExportModule.cs | 6 +++--- Common.cs | 16 ++++++++++++---- ShardManager.cs | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ApplicationCommands/ExportModule.cs b/ApplicationCommands/ExportModule.cs index 77ca85b..0672307 100644 --- a/ApplicationCommands/ExportModule.cs +++ b/ApplicationCommands/ExportModule.cs @@ -40,7 +40,7 @@ public class ExportModule : BotModuleBase { if (user == null) continue; // User disappeared in the instant between getting list and processing writer.Write($"● {Common.MonthNames[item.BirthMonth]}-{item.BirthDay:00}: "); writer.Write(item.UserId); - writer.Write(" " + user.Username + "#" + user.Discriminator); + writer.Write(" " + user.ToString()); if (user.Nickname != null) writer.Write(" - Nickname: " + user.Nickname); if (item.TimeZone != null) writer.Write(" | Time zone: " + item.TimeZone); writer.WriteLine(); @@ -74,9 +74,9 @@ public class ExportModule : BotModuleBase { if (user == null) continue; // User disappeared in the instant between getting list and processing writer.Write(item.UserId); writer.Write(','); - writer.Write(csvEscape(user.Username + "#" + user.Discriminator)); + writer.Write(csvEscape(user.ToString())); writer.Write(','); - if (user.Nickname != null) writer.Write(user.Nickname); + if (user.Nickname != null) writer.Write(csvEscape(user.Nickname)); writer.Write(','); writer.Write($"{Common.MonthNames[item.BirthMonth]}-{item.BirthDay:00}"); writer.Write(','); diff --git a/Common.cs b/Common.cs index f1d7bf3..e88791c 100644 --- a/Common.cs +++ b/Common.cs @@ -19,11 +19,19 @@ static class Common { return result.ToString(); } - var username = escapeFormattingCharacters(member.Username); - if (member.Nickname != null) { - return $"**{escapeFormattingCharacters(member.Nickname)}** ({username}#{member.Discriminator})"; + // We do a little bit of special formatting here to try to emphasize the username/nickname over the discriminator + if (member.DiscriminatorValue == 0) { + if (member.Nickname != null) { + return $"**{escapeFormattingCharacters(member.Nickname)}** ({member.Username})"; + } + return member.Username; + } else { + var username = escapeFormattingCharacters(member.Username); + if (member.Nickname != null) { + return $"**{escapeFormattingCharacters(member.Nickname)}** ({username}#{member.Discriminator})"; + } + return $"**{username}**" + (member.DiscriminatorValue == 0 ? $"#{member.Discriminator}" : ""); } - return $"**{username}**#{member.Discriminator}"; } public static Dictionary MonthNames { get; } = new() { diff --git a/ShardManager.cs b/ShardManager.cs index d742725..7a1e5e2 100644 --- a/ShardManager.cs +++ b/ShardManager.cs @@ -79,7 +79,8 @@ class ShardManager : IDisposable { DefaultRetryMode = RetryMode.Retry502 | RetryMode.RetryTimeouts, GatewayIntents = GatewayIntents.Guilds | GatewayIntents.GuildMembers, SuppressUnknownDispatchWarnings = true, - LogGatewayIntentWarnings = false + LogGatewayIntentWarnings = false, + FormatUsersInBidirectionalUnicode = false }; var services = new ServiceCollection() .AddSingleton(s => new ShardInstance(this, s)) From 9baf7016a2a4a2143a2014b352722c67c91f8a80 Mon Sep 17 00:00:00 2001 From: Noi Date: Sat, 9 Sep 2023 10:46:45 -0700 Subject: [PATCH 3/5] Use display name instead of username --- Common.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Common.cs b/Common.cs index e88791c..e66b509 100644 --- a/Common.cs +++ b/Common.cs @@ -22,9 +22,9 @@ static class Common { // We do a little bit of special formatting here to try to emphasize the username/nickname over the discriminator if (member.DiscriminatorValue == 0) { if (member.Nickname != null) { - return $"**{escapeFormattingCharacters(member.Nickname)}** ({member.Username})"; + return $"**{escapeFormattingCharacters(member.Nickname)}** ({escapeFormattingCharacters(member.ToString())})"; } - return member.Username; + return member.ToString(); } else { var username = escapeFormattingCharacters(member.Username); if (member.Nickname != null) { From 5aaa860205b2f952c7da4b6edd24383d8aa01a08 Mon Sep 17 00:00:00 2001 From: Noi Date: Sat, 9 Sep 2023 10:50:38 -0700 Subject: [PATCH 4/5] And escape special characters from display name... --- Common.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common.cs b/Common.cs index e66b509..a32b084 100644 --- a/Common.cs +++ b/Common.cs @@ -24,7 +24,7 @@ static class Common { if (member.Nickname != null) { return $"**{escapeFormattingCharacters(member.Nickname)}** ({escapeFormattingCharacters(member.ToString())})"; } - return member.ToString(); + return escapeFormattingCharacters(member.ToString()); } else { var username = escapeFormattingCharacters(member.Username); if (member.Nickname != null) { From 0b3ae1ec0d6362d8a60d3c407f22f519d3579530 Mon Sep 17 00:00:00 2001 From: Noi Date: Sun, 10 Sep 2023 22:13:51 -0700 Subject: [PATCH 5/5] Formatting fixes; add global name to export --- ApplicationCommands/ExportModule.cs | 11 ++++++++--- Common.cs | 12 ++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ApplicationCommands/ExportModule.cs b/ApplicationCommands/ExportModule.cs index 0672307..815ac4c 100644 --- a/ApplicationCommands/ExportModule.cs +++ b/ApplicationCommands/ExportModule.cs @@ -40,7 +40,9 @@ public class ExportModule : BotModuleBase { if (user == null) continue; // User disappeared in the instant between getting list and processing writer.Write($"● {Common.MonthNames[item.BirthMonth]}-{item.BirthDay:00}: "); writer.Write(item.UserId); - writer.Write(" " + user.ToString()); + writer.Write(" " + user.Username); + if (user.DiscriminatorValue != 0) writer.Write($"#{user.Discriminator}"); + if (user.GlobalName != null) writer.Write($" ({user.GlobalName})"); if (user.Nickname != null) writer.Write(" - Nickname: " + user.Nickname); if (item.TimeZone != null) writer.Write(" | Time zone: " + item.TimeZone); writer.WriteLine(); @@ -67,14 +69,17 @@ public class ExportModule : BotModuleBase { } // Conforming to RFC 4180; with header - writer.Write("UserId,Username,Nickname,MonthDayDisp,Month,Day,TimeZone"); + writer.Write("UserId,Username,DisplayName,Nickname,MonthDayDisp,Month,Day,TimeZone"); writer.Write("\r\n"); // crlf line break is specified by the standard foreach (var item in list) { var user = guild.GetUser(item.UserId); if (user == null) continue; // User disappeared in the instant between getting list and processing writer.Write(item.UserId); writer.Write(','); - writer.Write(csvEscape(user.ToString())); + writer.Write(csvEscape(user.Username)); + if (user.DiscriminatorValue != 0) writer.Write($"#{user.Discriminator}"); + writer.Write(','); + if (user.GlobalName != null) writer.Write(csvEscape(user.GlobalName)); writer.Write(','); if (user.Nickname != null) writer.Write(csvEscape(user.Nickname)); writer.Write(','); diff --git a/Common.cs b/Common.cs index a32b084..9096c98 100644 --- a/Common.cs +++ b/Common.cs @@ -11,7 +11,7 @@ static class Common { static string escapeFormattingCharacters(string input) { var result = new StringBuilder(); foreach (var c in input) { - if (c is '\\' or '_' or '~' or '*' or '@') { + if (c is '\\' or '_' or '~' or '*' or '@' or '`') { result.Append('\\'); } result.Append(c); @@ -19,18 +19,18 @@ static class Common { return result.ToString(); } - // We do a little bit of special formatting here to try to emphasize the username/nickname over the discriminator if (member.DiscriminatorValue == 0) { + var username = escapeFormattingCharacters(member.GlobalName ?? member.Username); if (member.Nickname != null) { - return $"**{escapeFormattingCharacters(member.Nickname)}** ({escapeFormattingCharacters(member.ToString())})"; + return $"{escapeFormattingCharacters(member.Nickname)} ({username})"; } - return escapeFormattingCharacters(member.ToString()); + return username; } else { var username = escapeFormattingCharacters(member.Username); if (member.Nickname != null) { - return $"**{escapeFormattingCharacters(member.Nickname)}** ({username}#{member.Discriminator})"; + return $"{escapeFormattingCharacters(member.Nickname)} ({username}#{member.Discriminator})"; } - return $"**{username}**" + (member.DiscriminatorValue == 0 ? $"#{member.Discriminator}" : ""); + return $"{username}#{member.Discriminator}"; } }