Merge pull request #53 from NoiTheCat/dev/new-usernames

New username system support
This commit is contained in:
Noi 2023-11-14 17:40:16 -08:00 committed by GitHub
commit 9d32b6c8c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 11 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
writer.Write($"● {Common.MonthNames[item.BirthMonth]}-{item.BirthDay:00}: ");
writer.Write(item.UserId);
writer.Write(" " + user.Username + "#" + user.Discriminator);
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,16 +69,19 @@ 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.Username + "#" + user.Discriminator));
writer.Write(csvEscape(user.Username));
if (user.DiscriminatorValue != 0) writer.Write($"#{user.Discriminator}");
writer.Write(',');
if (user.Nickname != null) writer.Write(user.Nickname);
if (user.GlobalName != null) writer.Write(csvEscape(user.GlobalName));
writer.Write(',');
if (user.Nickname != null) writer.Write(csvEscape(user.Nickname));
writer.Write(',');
writer.Write($"{Common.MonthNames[item.BirthMonth]}-{item.BirthDay:00}");
writer.Write(',');

View file

@ -22,7 +22,7 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Discord.Net" Version="3.10.0" />
<PackageReference Include="Discord.Net" Version="3.12.0" />
<PackageReference Include="EFCore.NamingConventions" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>

View file

@ -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,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})";
if (member.DiscriminatorValue == 0) {
var username = escapeFormattingCharacters(member.GlobalName ?? member.Username);
if (member.Nickname != null) {
return $"{escapeFormattingCharacters(member.Nickname)} ({username})";
}
return username;
} else {
var username = escapeFormattingCharacters(member.Username);
if (member.Nickname != null) {
return $"{escapeFormattingCharacters(member.Nickname)} ({username}#{member.Discriminator})";
}
return $"{username}#{member.Discriminator}";
}
return $"**{username}**#{member.Discriminator}";
}
public static Dictionary<int, string> MonthNames { get; } = new() {

View file

@ -76,7 +76,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))