Skip to content

Commit bc4ecfe

Browse files
ankitsmt211Zabuzard
authored andcommitted
replace getAsTag() with getName() on user entity (#1016)
* replace getAsTag() with getName() on user entity * problematic changes in RemindRoutine related classes * addition to problematic changes * fixed failing tests --------- Co-authored-by: Zabuzard <[email protected]>
1 parent 74a4ad9 commit bc4ecfe

21 files changed

+34
-32
lines changed

application/src/main/java/org/togetherjava/tjbot/features/moderation/BanCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ private static RestAction<Message> handleAlreadyBanned(Guild.Ban ban, Interactio
7676
String reasonText =
7777
reason == null || reason.isBlank() ? "" : " (reason: %s)".formatted(reason);
7878

79-
String message = "The user '%s' is already banned%s.".formatted(ban.getUser().getAsTag(),
80-
reasonText);
79+
String message =
80+
"The user '%s' is already banned%s.".formatted(ban.getUser().getName(), reasonText);
8181
return hook.sendMessage(message).setEphemeral(true);
8282
}
8383

@@ -123,7 +123,7 @@ private static Optional<RestAction<Message>> handleNotAlreadyBannedResponse(
123123
}
124124
logger.warn(LogMarkers.SENSITIVE,
125125
"Something unexpected went wrong while trying to ban the user '{}'.",
126-
target.getAsTag(), alreadyBannedFailure);
126+
target.getName(), alreadyBannedFailure);
127127
return Optional.of(hook.sendMessage("Failed to ban the user due to an unexpected problem.")
128128
.setEphemeral(true));
129129
}
@@ -145,7 +145,7 @@ private AuditableRestAction<Void> banUser(User target, Member author,
145145
temporaryData == null ? "permanently" : "for " + temporaryData.duration();
146146
logger.info(LogMarkers.SENSITIVE,
147147
"'{}' ({}) banned the user '{}' ({}) {} from guild '{}' and deleted their message history of the last {} days, for reason '{}'.",
148-
author.getUser().getAsTag(), author.getId(), target.getAsTag(), target.getId(),
148+
author.getUser().getName(), author.getId(), target.getName(), target.getId(),
149149
durationMessage, guild.getName(), deleteHistoryDays, reason);
150150

151151
Instant expiresAt = temporaryData == null ? null : temporaryData.expiresAt();

application/src/main/java/org/togetherjava/tjbot/features/moderation/KickCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private AuditableRestAction<Void> kickUser(Member target, Member author, String
8181
Guild guild) {
8282
logger.info(LogMarkers.SENSITIVE,
8383
"'{}' ({}) kicked the user '{}' ({}) from guild '{}' for reason '{}'.",
84-
author.getUser().getAsTag(), author.getId(), target.getUser().getAsTag(),
84+
author.getUser().getName(), author.getId(), target.getUser().getName(),
8585
target.getId(), guild.getName(), reason);
8686

8787
actionsStore.addAction(guild.getIdLong(), author.getIdLong(), target.getIdLong(),

application/src/main/java/org/togetherjava/tjbot/features/moderation/ModerationUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static boolean handleReason(CharSequence reason, IReplyCallback event) {
8686
*/
8787
public static boolean handleCanInteractWithTarget(String actionVerb, Member bot, Member author,
8888
Member target, IReplyCallback event) {
89-
String targetTag = target.getUser().getAsTag();
89+
String targetTag = target.getUser().getName();
9090
if (!author.canInteract(target)) {
9191
event
9292
.reply("The user %s is too powerful for you to %s.".formatted(targetTag,
@@ -279,8 +279,8 @@ static boolean handleHasAuthorPermissions(String actionVerb, Permission permissi
279279
*/
280280
static MessageEmbed createActionResponse(User author, ModerationAction action, User target,
281281
@Nullable String extraMessage, @Nullable String reason) {
282-
String description = "%s **%s** (id: %s).".formatted(action.getVerb(), target.getAsTag(),
283-
target.getId());
282+
String description =
283+
"%s **%s** (id: %s).".formatted(action.getVerb(), target.getName(), target.getId());
284284
if (extraMessage != null && !extraMessage.isBlank()) {
285285
description += "\n" + extraMessage;
286286
}
@@ -290,7 +290,7 @@ static MessageEmbed createActionResponse(User author, ModerationAction action, U
290290

291291
String avatarOrDefaultUrl = author.getEffectiveAvatarUrl();
292292

293-
return new EmbedBuilder().setAuthor(author.getAsTag(), null, avatarOrDefaultUrl)
293+
return new EmbedBuilder().setAuthor(author.getName(), null, avatarOrDefaultUrl)
294294
.setDescription(description)
295295
.setTimestamp(Instant.now())
296296
.setColor(AMBIENT_COLOR)

application/src/main/java/org/togetherjava/tjbot/features/moderation/MuteCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private AuditableRestAction<Void> muteUser(Member target, Member author,
9999
temporaryData == null ? "permanently" : "for " + temporaryData.duration();
100100
logger.info(LogMarkers.SENSITIVE,
101101
"'{}' ({}) muted the user '{}' ({}) {} in guild '{}' for reason '{}'.",
102-
author.getUser().getAsTag(), author.getId(), target.getUser().getAsTag(),
102+
author.getUser().getName(), author.getId(), target.getUser().getName(),
103103
target.getId(), durationMessage, guild.getName(), reason);
104104

105105
Instant expiresAt = temporaryData == null ? null : temporaryData.expiresAt();

application/src/main/java/org/togetherjava/tjbot/features/moderation/NoteCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private void sendNote(User target, Member author, String content, ISnowflake gui
8383
private void storeNote(User target, Member author, String content, ISnowflake guild) {
8484
logger.info(LogMarkers.SENSITIVE,
8585
"'{}' ({}) wrote a note about the user '{}' ({}) with content '{}'.",
86-
author.getUser().getAsTag(), author.getId(), target.getAsTag(), target.getId(),
86+
author.getUser().getName(), author.getId(), target.getName(), target.getId(),
8787
content);
8888

8989
actionsStore.addAction(guild.getIdLong(), author.getIdLong(), target.getIdLong(),

application/src/main/java/org/togetherjava/tjbot/features/moderation/QuarantineCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private AuditableRestAction<Void> quarantineUser(Member target, Member author, S
8585
Guild guild) {
8686
logger.info(LogMarkers.SENSITIVE,
8787
"'{}' ({}) quarantined the user '{}' ({}) in guild '{}' for reason '{}'.",
88-
author.getUser().getAsTag(), author.getId(), target.getUser().getAsTag(),
88+
author.getUser().getName(), author.getId(), target.getUser().getName(),
8989
target.getId(), guild.getName(), reason);
9090

9191
actionsStore.addAction(guild.getIdLong(), author.getIdLong(), target.getIdLong(),

application/src/main/java/org/togetherjava/tjbot/features/moderation/RejoinModerationRoleListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private static void applyModerationRole(ModerationRole moderationRole, Member me
9797
Guild guild = member.getGuild();
9898
logger.info(LogMarkers.SENSITIVE,
9999
"Reapplied existing {} to user '{}' ({}) in guild '{}' after rejoining.",
100-
moderationRole.actionName, member.getUser().getAsTag(), member.getId(),
100+
moderationRole.actionName, member.getUser().getName(), member.getId(),
101101
guild.getName());
102102

103103
guild.addRoleToMember(member, moderationRole.guildToRole.apply(guild))

application/src/main/java/org/togetherjava/tjbot/features/moderation/UnbanCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private void unban(User target, Member author, String reason, Guild guild,
5353

5454
logger.info(LogMarkers.SENSITIVE,
5555
"'{}' ({}) unbanned the user '{}' ({}) from guild '{}' for reason '{}'.",
56-
author.getUser().getAsTag(), author.getId(), target.getAsTag(), target.getId(),
56+
author.getUser().getName(), author.getId(), target.getName(), target.getId(),
5757
guild.getName(), reason);
5858

5959
actionsStore.addAction(guild.getIdLong(), author.getIdLong(), target.getIdLong(),
@@ -62,7 +62,7 @@ private void unban(User target, Member author, String reason, Guild guild,
6262
}
6363

6464
private static void handleFailure(Throwable unbanFailure, User target, IReplyCallback event) {
65-
String targetTag = target.getAsTag();
65+
String targetTag = target.getName();
6666
if (unbanFailure instanceof ErrorResponseException errorResponseException) {
6767
if (errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) {
6868
event.reply("The specified user does not exist.").setEphemeral(true).queue();

application/src/main/java/org/togetherjava/tjbot/features/moderation/UnmuteCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private AuditableRestAction<Void> unmuteUser(Member target, Member author, Strin
8181
Guild guild) {
8282
logger.info(LogMarkers.SENSITIVE,
8383
"'{}' ({}) unmuted the user '{}' ({}) in guild '{}' for reason '{}'.",
84-
author.getUser().getAsTag(), author.getId(), target.getUser().getAsTag(),
84+
author.getUser().getName(), author.getId(), target.getUser().getName(),
8585
target.getId(), guild.getName(), reason);
8686

8787
actionsStore.addAction(guild.getIdLong(), author.getIdLong(), target.getIdLong(),

application/src/main/java/org/togetherjava/tjbot/features/moderation/UnquarantineCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private AuditableRestAction<Void> unquarantineUser(Member target, Member author,
8585
Guild guild) {
8686
logger.info(LogMarkers.SENSITIVE,
8787
"'{}' ({}) unquarantined the user '{}' ({}) in guild '{}' for reason '{}'.",
88-
author.getUser().getAsTag(), author.getId(), target.getUser().getAsTag(),
88+
author.getUser().getName(), author.getId(), target.getUser().getName(),
8989
target.getId(), guild.getName(), reason);
9090

9191
actionsStore.addAction(guild.getIdLong(), author.getIdLong(), target.getIdLong(),

0 commit comments

Comments
 (0)