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

Support new username format
This commit is contained in:
Noi 2023-09-10 14:12:49 -07:00 committed by GitHub
commit c2de69c236
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View file

@ -58,7 +58,7 @@ public class CommandsBase : InteractionModuleBase<ShardedInteractionContext> {
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);
@ -66,11 +66,19 @@ public class CommandsBase : InteractionModuleBase<ShardedInteractionContext> {
return result.ToString();
}
if (user.DiscriminatorValue == 0) {
var username = escapeFormattingCharacters(user.GlobalName ?? user.Username);
if (user.Nickname != null) {
return $"{escapeFormattingCharacters(user.Nickname)} ({username})";
}
return username;
} else {
var username = escapeFormattingCharacters(user.Username);
if (user.Nickname != null) {
return $"**{escapeFormattingCharacters(user.Nickname)}** ({username}#{user.Discriminator})";
return $"{escapeFormattingCharacters(user.Nickname)} ({username}#{user.Discriminator})";
}
return $"{username}#{user.Discriminator}";
}
return $"**{username}**#{user.Discriminator}";
}
/// <summary>

View file

@ -41,7 +41,8 @@ internal class WorldTime : IDisposable {
MessageCacheSize = 0, // disable message cache
GatewayIntents = GatewayIntents.Guilds | GatewayIntents.GuildMembers,
SuppressUnknownDispatchWarnings = true,
LogGatewayIntentWarnings = false
LogGatewayIntentWarnings = false,
FormatUsersInBidirectionalUnicode = false
};
_services = new ServiceCollection()
.AddSingleton(new DiscordShardedClient(clientConf))

View file

@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Discord.Net" Version="3.9.0" />
<PackageReference Include="Discord.Net" Version="3.12.0" />
<PackageReference Include="EFCore.NamingConventions" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">