Formatting fixes; add global name to export

This commit is contained in:
Noi 2023-09-10 22:13:51 -07:00
parent 5aaa860205
commit 0b3ae1ec0d
2 changed files with 14 additions and 9 deletions

View file

@ -40,7 +40,9 @@ public class ExportModule : BotModuleBase {
if (user == null) continue; // User disappeared in the instant between getting list and processing 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($"● {Common.MonthNames[item.BirthMonth]}-{item.BirthDay:00}: ");
writer.Write(item.UserId); 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 (user.Nickname != null) writer.Write(" - Nickname: " + user.Nickname);
if (item.TimeZone != null) writer.Write(" | Time zone: " + item.TimeZone); if (item.TimeZone != null) writer.Write(" | Time zone: " + item.TimeZone);
writer.WriteLine(); writer.WriteLine();
@ -67,14 +69,17 @@ public class ExportModule : BotModuleBase {
} }
// Conforming to RFC 4180; with header // 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 writer.Write("\r\n"); // crlf line break is specified by the standard
foreach (var item in list) { foreach (var item in list) {
var user = guild.GetUser(item.UserId); var user = guild.GetUser(item.UserId);
if (user == null) continue; // User disappeared in the instant between getting list and processing if (user == null) continue; // User disappeared in the instant between getting list and processing
writer.Write(item.UserId); writer.Write(item.UserId);
writer.Write(','); 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(','); writer.Write(',');
if (user.Nickname != null) writer.Write(csvEscape(user.Nickname)); if (user.Nickname != null) writer.Write(csvEscape(user.Nickname));
writer.Write(','); writer.Write(',');

View file

@ -11,7 +11,7 @@ static class Common {
static string escapeFormattingCharacters(string input) { static string escapeFormattingCharacters(string input) {
var result = new StringBuilder(); var result = new StringBuilder();
foreach (var c in input) { foreach (var c in input) {
if (c is '\\' or '_' or '~' or '*' or '@') { if (c is '\\' or '_' or '~' or '*' or '@' or '`') {
result.Append('\\'); result.Append('\\');
} }
result.Append(c); result.Append(c);
@ -19,18 +19,18 @@ static class Common {
return result.ToString(); 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) { if (member.DiscriminatorValue == 0) {
var username = escapeFormattingCharacters(member.GlobalName ?? member.Username);
if (member.Nickname != null) { if (member.Nickname != null) {
return $"**{escapeFormattingCharacters(member.Nickname)}** ({escapeFormattingCharacters(member.ToString())})"; return $"{escapeFormattingCharacters(member.Nickname)} ({username})";
} }
return escapeFormattingCharacters(member.ToString()); return username;
} else { } else {
var username = escapeFormattingCharacters(member.Username); var username = escapeFormattingCharacters(member.Username);
if (member.Nickname != null) { 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}";
} }
} }