mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-21 05:54:36 +00:00
Formatting fixes; add global name to export
This commit is contained in:
parent
5aaa860205
commit
0b3ae1ec0d
2 changed files with 14 additions and 9 deletions
|
@ -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(',');
|
||||
|
|
12
Common.cs
12
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}";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue