Username fixes

This commit is contained in:
Vankka 2023-06-18 14:14:04 +03:00
parent 3d6c7f72de
commit 8de37ce767
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
7 changed files with 25 additions and 12 deletions

View File

@ -56,6 +56,14 @@ public interface DiscordUser extends JDAEntity<User>, Snowflake, Mentionable {
@NotNull
String getUsername();
/**
* Gets the effective display name of the Discord user.
* @return the user's effective display name
*/
@Placeholder("user_effective_name")
@NotNull
String getEffectiveName();
/**
* Gets the Discord user's discriminator.
* @return the user's discriminator
@ -85,7 +93,7 @@ public interface DiscordUser extends JDAEntity<User>, Snowflake, Mentionable {
* Gets the Discord user's username followed by a {@code #} and their discriminator.
* @return the Discord user's username and discriminator in the following format {@code Username#1234}
*/
@Placeholder("user_tag")
@Deprecated
default String getAsTag() {
return getUsername() + "#" + getDiscriminator();
}

View File

@ -94,18 +94,18 @@ public interface DiscordGuildMember extends JDAEntity<Member>, Mentionable {
* Gets the effective name of this Discord server member.
* @return the Discord server member's effective name
*/
@Placeholder("user_effective_name")
@Placeholder("user_effective_server_name")
@NotNull
default String getEffectiveName() {
default String getEffectiveServerName() {
String nickname = getNickname();
return nickname != null ? nickname : getUser().getUsername();
return nickname != null ? nickname : getUser().getEffectiveName();
}
/**
* Gets the avatar url that is active for this user in this server.
* @return the user's avatar url in this server
*/
@Placeholder("user_effective_avatar_url")
@Placeholder("user_effective_server_avatar_url")
@NotNull
String getEffectiveServerAvatarUrl();

View File

@ -136,7 +136,7 @@ public class DebugCommand extends CombinedCommand {
String key = new String(KEY_ENCODER.encode(paste.decryptionKey()), StandardCharsets.UTF_8);
String url = String.format(URL_FORMAT, paste.id(), key);
execution.send(new Text(url));
execution.send(new Text(url)); // TODO: fix in-game click
return null;
} catch (Throwable e) {
return e;

View File

@ -35,11 +35,11 @@ public class DiscordToMinecraftChatConfig {
@Comment("The Discord to Minecraft message format for regular users and bots")
@Untranslated(Untranslated.Type.VALUE)
public String format = "[&#5865F2Discord&r] [hover:show_text:Tag: %user_tag%&r\nRoles: %user_roles:', '|text:'&7&oNone'%]%user_color%%user_effective_name%&r » %message%%message_attachments%";
public String format = "[&#5865F2Discord&r] [hover:show_text:Tag: %user_tag%&r\nRoles: %user_roles:', '|text:'&7&oNone'%]%user_color%%user_effective_server_name%&r » %message%%message_attachments%";
@Comment("The Discord to Minecraft message format for webhook messages (if enabled)")
@Untranslated(Untranslated.Type.VALUE)
public String webhookFormat = "[&#5865F2Discord&r] [hover:show_text:Webhook message]%user_name%&r » %message%%message_attachments%";
public String webhookFormat = "[&#5865F2Discord&r] [hover:show_text:Webhook message]%user_effective_name%&r » %message%%message_attachments%";
@Comment("Attachment format")
@Untranslated(Untranslated.Type.VALUE)
@ -61,7 +61,7 @@ public class DiscordToMinecraftChatConfig {
public Format role = new Format("&#5865f2@%role_name%", "&#5865f2@deleted-role");
public Format channel = new Format("[hover:show_text:Click to go to channel][click:open_url:%channel_jump_url%]&#5865f2#%channel_name%", "&#5865f2#deleted-channel");
public Format user = new Format("[hover:show_text:Tag: %user_tag%&r\nRoles: %user_roles:', '|text:'&7&oNone'%]&#5865f2@%user_effective_name|user_name%", "&#5865f2@Unknown user");
public Format user = new Format("[hover:show_text:Username: @%user_name%&r\nRoles: %user_roles:', '|text:'&7&oNone'%]&#5865f2@%user_effective_server_name|user_effective_name%", "&#5865f2@Unknown user");
public String messageUrl = "[hover:show_text:Click to go to message][click:open_url:%jump_url%]&#5865f2#%channel_name% > ...";

View File

@ -33,10 +33,10 @@ public class MirroringConfig {
@Comment("The format of the username of mirrored messages\n"
+ "It's recommended to include some special character if in-game messages use webhooks,\n"
+ "in order to prevent Discord users and in-game players with the same name being grouped together")
public String usernameFormat = "%user_effective_name% \uD83D\uDD03";
public String usernameFormat = "%user_effective_server_name|user_effective_name% \uD83D\uDD03";
@Comment("Content to append to the beginning of a message if the message is replying to another")
public String replyFormat = "[In reply to %user_effective_name|user_name%](%message_jump_url%)\n";
public String replyFormat = "[In reply to %user_effective_server_name|user_effective_name%](%message_jump_url%)\n";
@Comment("Attachment related options")
public AttachmentConfig attachments = new AttachmentConfig();

View File

@ -61,6 +61,11 @@ public class DiscordUserImpl implements DiscordUser {
return user.getName();
}
@Override
public @NotNull String getEffectiveName() {
return user.getEffectiveName();
}
@Override
public @NotNull String getDiscriminator() {
return user.getDiscriminator();

View File

@ -638,7 +638,7 @@ public class JDAConnectionManager implements DiscordConnectionManager {
discordSRV.logger().error("| server requiring 2FA for moderation actions");
if (user != null) {
discordSRV.logger().error("|");
discordSRV.logger().error("| The Discord bot's owner is " + user.getAsTag() + " (" + user.getId() + ")");
discordSRV.logger().error("| The Discord bot's owner is " + user.getUsername() + " (" + user.getId() + ")");
}
discordSRV.logger().error("|");
discordSRV.logger().error("| You can view instructions for enabling 2FA here:");