diff --git a/build.gradle.kts b/build.gradle.kts index e807fdffc..32efd9f7e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,8 +30,8 @@ dependencies { compileOnly("org.jetbrains:annotations:23.0.0") // DIH4JDA (Command Framework) & JDA - implementation("xyz.dynxsty:dih4jda:1.6.2") - implementation("net.dv8tion:JDA:5.0.0-beta.2") { + implementation("com.github.DynxstyGIT:DIH4JDA:120a15ad2e") + implementation("net.dv8tion:JDA:5.0.0-beta.12") { exclude(module = "opus-java") } diff --git a/src/main/java/net/javadiscord/javabot/SpringConfig.java b/src/main/java/net/javadiscord/javabot/SpringConfig.java index f9631b62f..7faf073af 100644 --- a/src/main/java/net/javadiscord/javabot/SpringConfig.java +++ b/src/main/java/net/javadiscord/javabot/SpringConfig.java @@ -14,7 +14,6 @@ import xyz.dynxsty.dih4jda.DIH4JDA; import xyz.dynxsty.dih4jda.DIH4JDABuilder; -import xyz.dynxsty.dih4jda.DIH4JDALogger; import xyz.dynxsty.dih4jda.exceptions.DIH4JDAException; import xyz.dynxsty.dih4jda.interactions.commands.application.RegistrationType; @@ -93,7 +92,8 @@ public JDA jda(BotConfig botConfig, ApplicationContext ctx) throws LoginExceptio public DIH4JDA initializeDIH4JDA(JDA jda) throws DIH4JDAException { DIH4JDA.setDefaultRegistrationType(RegistrationType.GLOBAL); return DIH4JDABuilder.setJDA(jda) - .disableLogging(DIH4JDALogger.Type.SMART_QUEUE_IGNORED) + .setGlobalSmartQueue(false) + .setGuildSmartQueue(false) .disableAutomaticCommandRegistration() .build(); } diff --git a/src/main/java/net/javadiscord/javabot/data/h2db/DbHelper.java b/src/main/java/net/javadiscord/javabot/data/h2db/DbHelper.java index f1119db95..85fd667b5 100644 --- a/src/main/java/net/javadiscord/javabot/data/h2db/DbHelper.java +++ b/src/main/java/net/javadiscord/javabot/data/h2db/DbHelper.java @@ -22,7 +22,6 @@ import java.sql.Statement; import java.util.Arrays; import java.util.List; -import java.util.concurrent.ExecutorService; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -38,8 +37,6 @@ public class DbHelper { @Getter private final DataSource dataSource; - private final ExecutorService asyncPool; - private final BotConfig botConfig; /** * Initializes the data source that'll be used throughout the bot to access diff --git a/src/main/java/net/javadiscord/javabot/data/h2db/commands/MessageCacheInfoSubcommand.java b/src/main/java/net/javadiscord/javabot/data/h2db/commands/MessageCacheInfoSubcommand.java index 29a018063..e4eccca98 100644 --- a/src/main/java/net/javadiscord/javabot/data/h2db/commands/MessageCacheInfoSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/data/h2db/commands/MessageCacheInfoSubcommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.data.h2db.commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; @@ -45,7 +46,7 @@ private MessageEmbed buildInfoEmbed(GuildConfig config, User author) { long messages = dbActions.count("SELECT count(*) FROM message_cache"); int maxMessages = config.getMessageCacheConfig().getMaxCachedMessages(); return new EmbedBuilder() - .setAuthor(author.getAsTag(), null, author.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(author), null, author.getEffectiveAvatarUrl()) .setTitle("Message Cache Info") .setColor(Responses.Type.DEFAULT.getColor()) .addField("Table Size", dbActions.getLogicalSize("message_cache") + " bytes", false) diff --git a/src/main/java/net/javadiscord/javabot/data/h2db/commands/QuickMigrateSubcommand.java b/src/main/java/net/javadiscord/javabot/data/h2db/commands/QuickMigrateSubcommand.java index cae4471c9..3022e6af3 100644 --- a/src/main/java/net/javadiscord/javabot/data/h2db/commands/QuickMigrateSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/data/h2db/commands/QuickMigrateSubcommand.java @@ -118,7 +118,7 @@ CREATE TABLE my_table ( .setRequired(true) .build(); return Modal.create("quick-migrate", "Quick Migrate") - .addActionRows(ActionRow.of(sqlInput), ActionRow.of(confirmInput)) + .addComponents(ActionRow.of(sqlInput), ActionRow.of(confirmInput)) .build(); } } diff --git a/src/main/java/net/javadiscord/javabot/data/h2db/message_cache/MessageCache.java b/src/main/java/net/javadiscord/javabot/data/h2db/message_cache/MessageCache.java index 6cedd05fb..91c4d59e9 100644 --- a/src/main/java/net/javadiscord/javabot/data/h2db/message_cache/MessageCache.java +++ b/src/main/java/net/javadiscord/javabot/data/h2db/message_cache/MessageCache.java @@ -28,6 +28,7 @@ import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; +import net.javadiscord.javabot.util.UserUtils; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -142,7 +143,7 @@ public void sendDeletedMessageToLog(Guild guild, MessageChannel channel, CachedM private EmbedBuilder buildMessageCacheEmbed(MessageChannel channel, User author, CachedMessage before) { long epoch = IdCalculatorCommand.getTimestampFromId(before.getMessageId()) / 1000; return new EmbedBuilder() - .setAuthor(author.getAsTag(), null, author.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(author), null, author.getEffectiveAvatarUrl()) .addField("Author", author.getAsMention(), true) .addField("Channel", channel.getAsMention(), true) .addField("Created at", String.format("", epoch), true) @@ -200,14 +201,14 @@ private InputStream buildDeletedMessageFile(User author, CachedMessage message) DateTimeFormatter formatter = TimeUtils.STANDARD_FORMATTER.withZone(ZoneOffset.UTC); Instant instant = Instant.ofEpochMilli(IdCalculatorCommand.getTimestampFromId(message.getMessageId())); String in = String.format(""" - Author: %s - ID: %s - Created at: %s + Author: %s + ID: %s + Created at: %s - --- Message Content --- + --- Message Content --- - %s - """, author.getAsTag(), message.getMessageId(), formatter.format(instant), message.getMessageContent()); + %s + """, UserUtils.getUserTag(author), message.getMessageId(), formatter.format(instant), message.getMessageContent()); return new ByteArrayInputStream(in.getBytes(StandardCharsets.UTF_8)); } @@ -215,18 +216,18 @@ private InputStream buildEditedMessageFile(User author, CachedMessage before, Me DateTimeFormatter formatter = TimeUtils.STANDARD_FORMATTER.withZone(ZoneOffset.UTC); Instant instant = Instant.ofEpochMilli(IdCalculatorCommand.getTimestampFromId(before.getMessageId())); String in = String.format(""" - Author: %s - ID: %s - Created at: %s + Author: %s + ID: %s + Created at: %s - --- Message Content (before) --- + --- Message Content (before) --- - %s + %s - --- Message Content (after) --- + --- Message Content (after) --- - %s - """, author.getAsTag(), before.getMessageId(), formatter.format(instant), before.getMessageContent(), after.getContentRaw()); + %s + """, UserUtils.getUserTag(author), before.getMessageId(), formatter.format(instant), before.getMessageContent(), after.getContentRaw()); return new ByteArrayInputStream(in.getBytes(StandardCharsets.UTF_8)); } } diff --git a/src/main/java/net/javadiscord/javabot/systems/help/HelpManager.java b/src/main/java/net/javadiscord/javabot/systems/help/HelpManager.java index 476c5be79..527e69581 100644 --- a/src/main/java/net/javadiscord/javabot/systems/help/HelpManager.java +++ b/src/main/java/net/javadiscord/javabot/systems/help/HelpManager.java @@ -29,6 +29,7 @@ import net.javadiscord.javabot.util.ExceptionLogger; import net.javadiscord.javabot.util.MessageActionUtils; import net.javadiscord.javabot.util.Responses; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -177,8 +178,8 @@ public void thankHelper(@NotNull Guild guild, ThreadChannel postThread, long hel ExceptionLogger.capture(e, getClass().getSimpleName()); botConfig.get(guild).getModerationConfig().getLogChannel().sendMessageFormat( "Could not record user %s thanking %s for help in post %s: %s", - postThread.getOwner().getUser().getAsTag(), - helper.getAsTag(), + UserUtils.getUserTag(postThread.getOwner().getUser()), + UserUtils.getUserTag(helper), postThread.getAsMention(), e.getMessage() ).queue(); diff --git a/src/main/java/net/javadiscord/javabot/systems/help/commands/HelpAccountSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/help/commands/HelpAccountSubcommand.java index 4506dba31..40ba68206 100644 --- a/src/main/java/net/javadiscord/javabot/systems/help/commands/HelpAccountSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/help/commands/HelpAccountSubcommand.java @@ -23,6 +23,7 @@ import net.javadiscord.javabot.util.Plotter; import net.javadiscord.javabot.util.Responses; import net.javadiscord.javabot.util.StringUtils; +import net.javadiscord.javabot.util.UserUtils; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; @@ -141,7 +142,7 @@ private FileUpload generatePlot(User user) { private @NotNull MessageEmbed buildHelpAccountEmbed(HelpAccount account, @NotNull User user, Guild guild, long totalThanks, long weekThanks, FileUpload upload) { EmbedBuilder eb = new EmbedBuilder() - .setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(user), null, user.getEffectiveAvatarUrl()) .setTitle("Help Account") .setThumbnail(user.getEffectiveAvatarUrl()) .setDescription("Here are some statistics about how you've helped others here.") diff --git a/src/main/java/net/javadiscord/javabot/systems/moderation/ModerationService.java b/src/main/java/net/javadiscord/javabot/systems/moderation/ModerationService.java index 0ce9ca757..6c1bd5d61 100644 --- a/src/main/java/net/javadiscord/javabot/systems/moderation/ModerationService.java +++ b/src/main/java/net/javadiscord/javabot/systems/moderation/ModerationService.java @@ -14,6 +14,7 @@ import net.javadiscord.javabot.systems.notification.NotificationService; import net.javadiscord.javabot.util.ExceptionLogger; import net.javadiscord.javabot.util.Responses; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; import org.springframework.dao.DataAccessException; @@ -291,12 +292,12 @@ public void kick(User user, String reason, Member kickedBy, MessageChannel chann private @NotNull EmbedBuilder buildModerationEmbed(@NotNull User user, @NotNull Member moderator, String reason) { return new EmbedBuilder() - .setAuthor(moderator.getUser().getAsTag(), null, moderator.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(moderator.getUser()), null, moderator.getEffectiveAvatarUrl()) .addField("Member", user.getAsMention(), true) .addField("Moderator", moderator.getAsMention(), true) .addField("Reason", reason, true) .setTimestamp(Instant.now()) - .setFooter(user.getAsTag(), user.getEffectiveAvatarUrl()); + .setFooter(UserUtils.getUserTag(user), user.getEffectiveAvatarUrl()); } private @NotNull MessageEmbed buildBanEmbed(User user, Member bannedBy, String reason) { @@ -315,7 +316,7 @@ public void kick(User user, String reason, Member kickedBy, MessageChannel chann private @NotNull MessageEmbed buildUnbanEmbed(long userId, String reason, @NotNull Member unbannedBy) { return new EmbedBuilder() - .setAuthor(unbannedBy.getUser().getAsTag(), null, unbannedBy.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(unbannedBy.getUser()), null, unbannedBy.getEffectiveAvatarUrl()) .setTitle("Ban Revoked") .setColor(Responses.Type.ERROR.getColor()) .addField("Moderator", unbannedBy.getAsMention(), true) @@ -335,18 +336,18 @@ public void kick(User user, String reason, Member kickedBy, MessageChannel chann private @NotNull MessageEmbed buildClearWarnsEmbed(@NotNull User user, @NotNull User clearedBy) { return new EmbedBuilder() - .setAuthor(clearedBy.getAsTag(), null, clearedBy.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(clearedBy), null, clearedBy.getEffectiveAvatarUrl()) .setTitle("Warns Cleared") .setColor(Responses.Type.WARN.getColor()) .setDescription("All warns have been cleared from " + user.getAsMention() + "'s record.") .setTimestamp(Instant.now()) - .setFooter(user.getAsTag(), user.getEffectiveAvatarUrl()) + .setFooter(UserUtils.getUserTag(user), user.getEffectiveAvatarUrl()) .build(); } private @NotNull MessageEmbed buildClearWarnsByIdEmbed(@NotNull Warn w, @NotNull User clearedBy) { return new EmbedBuilder() - .setAuthor(clearedBy.getAsTag(), null, clearedBy.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(clearedBy), null, clearedBy.getEffectiveAvatarUrl()) .setTitle("Warn Cleared") .setColor(Responses.Type.WARN.getColor()) .setDescription(String.format(""" diff --git a/src/main/java/net/javadiscord/javabot/systems/moderation/PruneCommand.java b/src/main/java/net/javadiscord/javabot/systems/moderation/PruneCommand.java index 7bb84e129..3fecab317 100644 --- a/src/main/java/net/javadiscord/javabot/systems/moderation/PruneCommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/moderation/PruneCommand.java @@ -10,6 +10,7 @@ import net.javadiscord.javabot.data.config.guild.ModerationConfig; import net.javadiscord.javabot.util.Checks; import net.javadiscord.javabot.util.Responses; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; import java.time.LocalDateTime; @@ -77,7 +78,7 @@ protected ReplyCallbackAction handleModerationCommand(@NotNull SlashCommandInter (before == null || member.getTimeJoined().isBefore(before)) && (after == null || member.getTimeJoined().isAfter(after)); if (shouldRemove) { - config.getLogChannel().sendMessage("Removing " + member.getUser().getAsTag() + " as part of prune.").queue(); + config.getLogChannel().sendMessage("Removing " + UserUtils.getUserTag(member.getUser()) + " as part of prune.").queue(); member.ban(delDays, TimeUnit.DAYS).reason(reason).queue(); } }); diff --git a/src/main/java/net/javadiscord/javabot/systems/moderation/PurgeCommand.java b/src/main/java/net/javadiscord/javabot/systems/moderation/PurgeCommand.java index 378de8b3d..defa17b6f 100644 --- a/src/main/java/net/javadiscord/javabot/systems/moderation/PurgeCommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/moderation/PurgeCommand.java @@ -16,6 +16,7 @@ import net.javadiscord.javabot.util.ExceptionLogger; import net.javadiscord.javabot.util.Responses; import net.javadiscord.javabot.util.TimeUtils; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; import javax.annotation.CheckReturnValue; @@ -74,7 +75,7 @@ protected ReplyCallbackAction handleModerationCommand(@NotNull SlashCommandInter StringBuilder sb = new StringBuilder(); sb.append(amount > 1 ? "Up to " + amount + " messages " : "1 message "); if (user != null) { - sb.append("by the user ").append(user.getAsTag()).append(' '); + sb.append("by the user ").append(UserUtils.getUserTag(user)).append(' '); } sb.append("will be removed").append(archive ? " and placed in an archive." : '.'); return Responses.info(event, "Purge Started", sb.toString()); @@ -198,12 +199,12 @@ private int removeMessages(List messages, @Nullable User user, @Nullabl */ private void archiveMessage(PrintWriter writer, Message message) { writer.printf( - "%s : Removing message %s by %s which was sent at %s\n--- Text ---\n%s\n--- End Text ---\n\n", - OffsetDateTime.now().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME), - message.getId(), - message.getAuthor().getAsTag(), - message.getTimeCreated().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME), - message.getContentRaw() + "%s : Removing message %s by %s which was sent at %s\n--- Text ---\n%s\n--- End Text ---\n\n", + OffsetDateTime.now().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME), + message.getId(), + UserUtils.getUserTag(message.getAuthor()), + message.getTimeCreated().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME), + message.getContentRaw() ); } } \ No newline at end of file diff --git a/src/main/java/net/javadiscord/javabot/systems/moderation/report/ReportManager.java b/src/main/java/net/javadiscord/javabot/systems/moderation/report/ReportManager.java index 7f226fe77..31421ad71 100644 --- a/src/main/java/net/javadiscord/javabot/systems/moderation/report/ReportManager.java +++ b/src/main/java/net/javadiscord/javabot/systems/moderation/report/ReportManager.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.moderation.report; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.util.ComponentIdBuilder; import xyz.dynxsty.dih4jda.interactions.components.ButtonHandler; import xyz.dynxsty.dih4jda.interactions.components.ModalHandler; @@ -56,7 +57,7 @@ public void handleButton(@NotNull ButtonInteractionEvent event, Button button) { return; } Responses.info(event.getHook(), "Report resolved", "Successfully resolved this report!").queue(); - event.getMessage().editMessageComponents(ActionRow.of(Button.secondary("report-resolved", "Resolved by " + event.getUser().getAsTag()).asDisabled())).queue(); + event.getMessage().editMessageComponents(ActionRow.of(Button.secondary("report-resolved", "Resolved by " + UserUtils.getUserTag(event.getUser())).asDisabled())).queue(); thread.sendMessage("This thread was resolved by " + event.getUser().getAsMention()).queue( success -> thread.getManager() .setName(String.format("[Resolved] %s", thread.getName())) @@ -86,9 +87,9 @@ protected Modal buildUserReportModal(@NotNull UserContextInteractionEvent event) TextInput messageInput = TextInput.create("reason", "Report Description", TextInputStyle.PARAGRAPH) .setMaxLength(MessageEmbed.VALUE_MAX_LENGTH) .build(); - String title = "Report " + event.getTarget().getAsTag(); + String title = "Report " + UserUtils.getUserTag(event.getTarget()); return Modal.create(ComponentIdBuilder.build("report", "user", event.getTarget().getId()), title.substring(0, Math.min(title.length(), Modal.MAX_TITLE_LENGTH))) - .addActionRows(ActionRow.of(messageInput)) + .addActionRow(messageInput) .build(); } @@ -103,13 +104,13 @@ protected Modal buildMessageReportModal(@NotNull MessageContextInteractionEvent String title = "Report message"; Member targetMember = event.getTarget().getMember(); if (targetMember != null) { - title += " from " + targetMember.getUser().getAsTag(); + title += " from " + UserUtils.getUserTag(targetMember.getUser()); } TextInput messageInput = TextInput.create("reason", "Report Description", TextInputStyle.PARAGRAPH) .setMaxLength(MessageEmbed.VALUE_MAX_LENGTH) .build(); return Modal.create(ComponentIdBuilder.build("report", "message", event.getTarget().getId()), title.substring(0, Math.min(title.length(), Modal.MAX_TITLE_LENGTH))) - .addActionRows(ActionRow.of(messageInput)) + .addActionRow(messageInput) .build(); } @@ -136,7 +137,7 @@ protected WebhookMessageCreateAction handleUserReport(InteractionHook h } reportChannel.sendMessageEmbeds(embed.build()) .queue(m -> this.createReportThread(m, target.getIdLong(), config.getModerationConfig())); - embed.setDescription("Successfully reported " + "`" + target.getAsTag() + "`!\nYour report has been send to our Moderators"); + embed.setDescription("Successfully reported " + "`" + UserUtils.getUserTag(target) + "`!\nYour report has been send to our Moderators"); hook.sendMessageEmbeds(embed.build()).queue(); }, failure -> { Responses.error(hook, "The user to report seems not to exist any more.").queue(); @@ -162,7 +163,7 @@ private void handleMessageReport(ModalInteractionEvent event, String messageId) WebhookUtil.mirrorMessageToWebhook(wh, target, target.getContentRaw(), thread.getIdLong(), null, null); }); })); - embed.setDescription("Successfully reported " + "`" + target.getAuthor().getAsTag() + "`!\nYour report has been send to our Moderators"); + embed.setDescription("Successfully reported " + "`" + UserUtils.getUserTag(target.getAuthor()) + "`!\nYour report has been send to our Moderators"); event.getHook().sendMessageEmbeds(embed.build()).queue(); }, failure -> { Responses.error(event.getHook(), "The author of the message to report seems not to exist any more.").queue(); @@ -201,7 +202,7 @@ private void createReportThread(Message message, long targetId, ModerationConfig private EmbedBuilder buildReportEmbed(User reported, User reportedBy, String reason, Channel channel) { return new EmbedBuilder() - .setAuthor(reported.getAsTag(), null, reported.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(reported), null, reported.getEffectiveAvatarUrl()) .setColor(Responses.Type.DEFAULT.getColor()) .addField("Member", reported.getAsMention(), true) .addField("Reported by", reportedBy.getAsMention(), true) @@ -209,7 +210,7 @@ private EmbedBuilder buildReportEmbed(User reported, User reportedBy, String rea .addField("Reported on", String.format("", Instant.now().getEpochSecond()), false) .addField("ID", String.format("``` %s ```", reported.getId()), true) .addField("Reason", String.format("``` %s ```", reason), false) - .setFooter(reportedBy.getAsTag(), reportedBy.getEffectiveAvatarUrl()) + .setFooter(UserUtils.getUserTag(reportedBy), reportedBy.getEffectiveAvatarUrl()) .setTimestamp(Instant.now()); } } diff --git a/src/main/java/net/javadiscord/javabot/systems/moderation/server_lock/ServerLockManager.java b/src/main/java/net/javadiscord/javabot/systems/moderation/server_lock/ServerLockManager.java index d92b31f59..9fe8f4b28 100644 --- a/src/main/java/net/javadiscord/javabot/systems/moderation/server_lock/ServerLockManager.java +++ b/src/main/java/net/javadiscord/javabot/systems/moderation/server_lock/ServerLockManager.java @@ -17,6 +17,7 @@ import net.javadiscord.javabot.data.config.guild.ServerLockConfig; import net.javadiscord.javabot.util.Responses; import net.javadiscord.javabot.util.TimeUtils; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -202,7 +203,11 @@ private void rejectUserDuringRaid(@NotNull GuildMemberJoinEvent event) { c.sendMessage(Constants.INVITE_URL).setEmbeds(buildServerLockEmbed(event.getGuild())).queue(msg -> event.getMember().kick().queue())); String diff = new TimeUtils().formatDurationToNow(event.getMember().getTimeCreated()); - notificationService.withGuild(event.getGuild()).sendToModerationLog(c -> c.sendMessageFormat("**%s** (%s old) tried to join this server.", event.getMember().getUser().getAsTag(), diff)); + notificationService.withGuild(event.getGuild()).sendToModerationLog(c -> c.sendMessageFormat( + "**%s** (%s old) tried to join this server.", + UserUtils.getUserTag(event.getMember().getUser()), + diff + )); } /** @@ -219,7 +224,11 @@ public void lockServer(Guild guild, @NotNull Collection potentialRaiders c.sendMessage(Constants.INVITE_URL).setEmbeds(buildServerLockEmbed(guild)).queue(msg -> { member.kick().queue( success -> {}, - error -> notificationService.withGuild(guild).sendToModerationLog(m -> m.sendMessageFormat("Could not kick member %s%n> `%s`", member.getUser().getAsTag(), error.getMessage()))); + error -> notificationService.withGuild(guild).sendToModerationLog(m -> m.sendMessageFormat( + "Could not kick member %s%n> `%s`", + UserUtils.getUserTag(member.getUser()), + error.getMessage() + ))); }); }); } @@ -227,10 +236,10 @@ public void lockServer(Guild guild, @NotNull Collection potentialRaiders String membersString = potentialRaiders.stream() .sorted(Comparator.comparing(Member::getTimeJoined).reversed()) .map(m -> String.format( - "- **%s** joined at `%s`, account is `%s` old.", - m.getUser().getAsTag(), - m.getTimeJoined().format(DateTimeFormatter.ofPattern("HH:mm:ss.SSSS")), - TimeUtils.formatDuration(Duration.between(m.getTimeCreated(), OffsetDateTime.now())) + "- **%s** joined at `%s`, account is `%s` old.", + UserUtils.getUserTag(m.getUser()), + m.getTimeJoined().format(DateTimeFormatter.ofPattern("HH:mm:ss.SSSS")), + TimeUtils.formatDuration(Duration.between(m.getTimeCreated(), OffsetDateTime.now())) )) .collect(Collectors.joining("\n")); diff --git a/src/main/java/net/javadiscord/javabot/systems/moderation/warn/DiscardAllWarnsSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/moderation/warn/DiscardAllWarnsSubcommand.java index 1642221c7..9ddace733 100644 --- a/src/main/java/net/javadiscord/javabot/systems/moderation/warn/DiscardAllWarnsSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/moderation/warn/DiscardAllWarnsSubcommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.moderation.warn; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -55,7 +56,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { } User target = userMapping.getAsUser(); new ModerationService(notificationService, botConfig, event.getInteraction(), warnRepository, asyncPool).discardAllWarns(target, event.getMember()); - Responses.success(event, "Warns Discarded", "Successfully discarded all warns from **%s**.", target.getAsTag()).queue(); + Responses.success(event, "Warns Discarded", "Successfully discarded all warns from **%s**.", UserUtils.getUserTag(target)).queue(); } } diff --git a/src/main/java/net/javadiscord/javabot/systems/moderation/warn/WarnExportSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/moderation/warn/WarnExportSubcommand.java index 8aa39ab15..6682bdf46 100644 --- a/src/main/java/net/javadiscord/javabot/systems/moderation/warn/WarnExportSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/moderation/warn/WarnExportSubcommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.moderation.warn; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.User; @@ -76,7 +77,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { PipedInputStream pis=new PipedInputStream(); try(PrintWriter pw=new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(new PipedOutputStream(pis)), StandardCharsets.UTF_8))){ event.replyEmbeds(new EmbedBuilder() - .setAuthor(target.getAsTag(), null, target.getAvatarUrl()) + .setAuthor(UserUtils.getUserTag(target), null, target.getAvatarUrl()) .setDescription("Export containing all warns of "+target.getAsMention()) .addField("Total number of warns", String.valueOf(warns.stream().count()), false) .addField("Total number of non-discarded warns (includes expired warns)", String.valueOf(warns.stream().filter(w->!w.isDiscarded()).count()), false) diff --git a/src/main/java/net/javadiscord/javabot/systems/moderation/warn/WarnsListCommand.java b/src/main/java/net/javadiscord/javabot/systems/moderation/warn/WarnsListCommand.java index 9bb6ad630..09c3ca7c8 100644 --- a/src/main/java/net/javadiscord/javabot/systems/moderation/warn/WarnsListCommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/moderation/warn/WarnsListCommand.java @@ -8,6 +8,7 @@ import javax.annotation.Nonnull; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; import org.springframework.dao.DataAccessException; @@ -60,7 +61,7 @@ public WarnsListCommand(BotConfig botConfig, ExecutorService asyncPool, WarnRepo */ protected static @NotNull MessageEmbed buildWarnsEmbed(@Nonnull List warns, @Nonnull User user) { EmbedBuilder builder = new EmbedBuilder() - .setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(user), null, user.getEffectiveAvatarUrl()) .setTitle("Recent Warns") .setDescription(String.format("%s has `%s` active warns with a total of `%s` severity.\n", user.getAsMention(), warns.size(), warns.stream().mapToInt(Warn::getSeverityWeight).sum())) diff --git a/src/main/java/net/javadiscord/javabot/systems/notification/QOTWGuildNotificationService.java b/src/main/java/net/javadiscord/javabot/systems/notification/QOTWGuildNotificationService.java index a248b3873..ef0869f05 100644 --- a/src/main/java/net/javadiscord/javabot/systems/notification/QOTWGuildNotificationService.java +++ b/src/main/java/net/javadiscord/javabot/systems/notification/QOTWGuildNotificationService.java @@ -11,6 +11,7 @@ import net.javadiscord.javabot.systems.qotw.model.QOTWSubmission; import net.javadiscord.javabot.systems.qotw.submissions.SubmissionStatus; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; import java.time.Instant; @@ -37,14 +38,14 @@ public class QOTWGuildNotificationService { public void sendSubmissionActionNotification(User reviewedBy, @NotNull QOTWSubmission submission, SubmissionStatus status) { submission.retrieveAuthor(author -> { notificationService.withGuild(guild).sendToModerationLog(c -> c.sendMessageEmbeds(buildSubmissionActionEmbed(author, submission.getThread(), reviewedBy, status))); - log.info("{} {} {}'s QOTW Submission", reviewedBy.getAsTag(), status.getVerb(), author.getAsTag()); + log.info("{} {} {}'s QOTW Submission", UserUtils.getUserTag(reviewedBy), status.getVerb(), UserUtils.getUserTag(author)); }); } private @NotNull MessageEmbed buildSubmissionActionEmbed(@NotNull User author, ThreadChannel thread, @NotNull User reviewedBy, @NotNull SubmissionStatus status) { EmbedBuilder builder = new EmbedBuilder() - .setAuthor(reviewedBy.getAsTag(), null, reviewedBy.getEffectiveAvatarUrl()) - .setTitle(String.format("%s %s %s's QOTW Submission", reviewedBy.getAsTag(), status.getVerb(), author.getAsTag())) + .setAuthor(UserUtils.getUserTag(reviewedBy), null, reviewedBy.getEffectiveAvatarUrl()) + .setTitle(String.format("%s %s %s's QOTW Submission", UserUtils.getUserTag(reviewedBy), status.getVerb(), UserUtils.getUserTag(author))) .setTimestamp(Instant.now()); if (thread != null) { builder.addField("Thread", thread.getAsMention(), true); diff --git a/src/main/java/net/javadiscord/javabot/systems/notification/QOTWNotificationService.java b/src/main/java/net/javadiscord/javabot/systems/notification/QOTWNotificationService.java index dfc880c82..48d8512a9 100644 --- a/src/main/java/net/javadiscord/javabot/systems/notification/QOTWNotificationService.java +++ b/src/main/java/net/javadiscord/javabot/systems/notification/QOTWNotificationService.java @@ -10,6 +10,7 @@ import net.javadiscord.javabot.systems.qotw.model.QOTWAccount; import net.javadiscord.javabot.systems.qotw.submissions.SubmissionStatus; import net.javadiscord.javabot.util.Responses; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; import org.springframework.dao.DataAccessException; @@ -70,7 +71,7 @@ public void sendSubmissionDeclinedEmbed(SubmissionStatus status) { private @NotNull EmbedBuilder buildQOTWNotificationEmbed() { return new EmbedBuilder() - .setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(user), null, user.getEffectiveAvatarUrl()) .setTitle("QOTW Notification") .setTimestamp(Instant.now()); } diff --git a/src/main/java/net/javadiscord/javabot/systems/notification/UserNotificationService.java b/src/main/java/net/javadiscord/javabot/systems/notification/UserNotificationService.java index 6e727e8bc..58de848eb 100644 --- a/src/main/java/net/javadiscord/javabot/systems/notification/UserNotificationService.java +++ b/src/main/java/net/javadiscord/javabot/systems/notification/UserNotificationService.java @@ -11,6 +11,7 @@ import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; import net.javadiscord.javabot.data.config.guild.ModerationConfig; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; import java.util.function.Function; @@ -34,7 +35,7 @@ public void sendDirectMessage(@NotNull Function {}, error -> { - log.error("Could not open PrivateChannel with user " + user.getAsTag(), error); + log.error("Could not open PrivateChannel with user " + UserUtils.getUserTag(user), error); if(config != null) { TextChannel container = config.getNotificationThreadChannel(); if(container != null) { diff --git a/src/main/java/net/javadiscord/javabot/systems/qotw/commands/qotw_points/ChangePointsSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/qotw/commands/qotw_points/ChangePointsSubcommand.java index 84596652a..31da24a08 100644 --- a/src/main/java/net/javadiscord/javabot/systems/qotw/commands/qotw_points/ChangePointsSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/qotw/commands/qotw_points/ChangePointsSubcommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.qotw.commands.qotw_points; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Member; @@ -90,7 +91,7 @@ private void sendNotifications(SlashCommandInteractionEvent event, Member member */ protected @NotNull EmbedBuilder createIncrementEmbedBuilder(User user, long points) { return new EmbedBuilder() - .setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(user), null, user.getEffectiveAvatarUrl()) .setTitle("QOTW Account changed") .setColor(Responses.Type.SUCCESS.getColor()) .addField("Total QOTW-Points", "```" + points + "```", true) diff --git a/src/main/java/net/javadiscord/javabot/systems/qotw/commands/questions_queue/AddQuestionSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/qotw/commands/questions_queue/AddQuestionSubcommand.java index 5b05eebe2..f47a31827 100644 --- a/src/main/java/net/javadiscord/javabot/systems/qotw/commands/questions_queue/AddQuestionSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/qotw/commands/questions_queue/AddQuestionSubcommand.java @@ -56,7 +56,7 @@ protected InteractionCallbackAction handleCommand(@NotNull SlashCommandIntera .build(); return Modal.create("qotw-add-question", "Create QOTW Question") - .addActionRows(ActionRow.of(questionField), ActionRow.of(priorityField)) + .addComponents(ActionRow.of(questionField), ActionRow.of(priorityField)) .build(); } diff --git a/src/main/java/net/javadiscord/javabot/systems/qotw/commands/questions_queue/ListQuestionsSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/qotw/commands/questions_queue/ListQuestionsSubcommand.java index 562f0fcf0..2c91a2143 100644 --- a/src/main/java/net/javadiscord/javabot/systems/qotw/commands/questions_queue/ListQuestionsSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/qotw/commands/questions_queue/ListQuestionsSubcommand.java @@ -10,6 +10,7 @@ import net.javadiscord.javabot.systems.qotw.dao.QuestionQueueRepository; import net.javadiscord.javabot.systems.qotw.model.QOTWQuestion; import net.javadiscord.javabot.util.Responses; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; import org.springframework.dao.DataAccessException; import org.springframework.transaction.annotation.Transactional; @@ -52,7 +53,7 @@ protected InteractionCallbackAction handleCommand(@NotNull SlashCommandIntera } List questions = questionQueueRepository.getQuestions(guildId, page, 10); EmbedBuilder embedBuilder = new EmbedBuilder() - .setAuthor(event.getUser().getAsTag(), null, event.getUser().getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(event.getUser()), null, event.getUser().getEffectiveAvatarUrl()) .setTitle("QOTW Questions Queue") .setColor(Responses.Type.DEFAULT.getColor()); if (questions.isEmpty()) { diff --git a/src/main/java/net/javadiscord/javabot/systems/qotw/submissions/SubmissionManager.java b/src/main/java/net/javadiscord/javabot/systems/qotw/submissions/SubmissionManager.java index a9d8c171c..ea999ac88 100644 --- a/src/main/java/net/javadiscord/javabot/systems/qotw/submissions/SubmissionManager.java +++ b/src/main/java/net/javadiscord/javabot/systems/qotw/submissions/SubmissionManager.java @@ -24,6 +24,7 @@ import net.javadiscord.javabot.systems.qotw.model.QOTWSubmission; import net.javadiscord.javabot.util.ExceptionLogger; import net.javadiscord.javabot.util.Responses; +import net.javadiscord.javabot.util.UserUtils; import net.javadiscord.javabot.util.WebhookUtil; import org.jetbrains.annotations.NotNull; import org.springframework.transaction.annotation.Transactional; @@ -88,9 +89,9 @@ public WebhookMessageCreateAction handleSubmission(@NotNull ButtonInteraction .queue(); } }); - }, e -> log.error("Could not create submission thread for member {}. ", member.getUser().getAsTag(), e) + }, e -> log.error("Could not create submission thread for member {}. ", UserUtils.getUserTag(member.getUser()), e) ); - log.info("Opened new Submission Thread for User {}", member.getUser().getAsTag()); + log.info("Opened new Submission Thread for User {}", UserUtils.getUserTag(member.getUser())); return Responses.success(event.getHook(), "Submission Thread created", "Successfully created a new private Thread for your submission."); } @@ -153,7 +154,7 @@ public void handleSelectReview(StringSelectInteractionEvent event, String thread reviewChannel.asThreadChannel().getManager().setArchived(true).queue(); } } - event.getHook().editOriginalComponents(ActionRow.of(Button.secondary("dummy", "%s by %s".formatted(status.getVerb(), event.getUser().getAsTag())).asDisabled())).queue(); + event.getHook().editOriginalComponents(ActionRow.of(Button.secondary("dummy", "%s by %s".formatted(status.getVerb(), UserUtils.getUserTag(event.getUser()))).asDisabled())).queue(); }); } @@ -245,7 +246,7 @@ private CompletableFuture> getMessagesByUser(@NotNull ThreadChanne private @NotNull MessageEmbed buildAuthorEmbed(@NotNull User user, boolean bestAnswer) { return new EmbedBuilder() - .setAuthor((bestAnswer ? "\u2B50 " : "") + "Submission from " + user.getAsTag(), null, user.getAvatarUrl()) + .setAuthor((bestAnswer ? "\u2B50 " : "") + "Submission from " + UserUtils.getUserTag(user), null, user.getAvatarUrl()) .setColor(bestAnswer ? Responses.Type.WARN.getColor() : Responses.Type.DEFAULT.getColor()) .build(); } @@ -253,7 +254,7 @@ private CompletableFuture> getMessagesByUser(@NotNull ThreadChanne private @NotNull MessageEmbed buildSubmissionThreadEmbed(@NotNull User createdBy, @NotNull QOTWQuestion question, @NotNull QOTWConfig config) { return new EmbedBuilder() .setColor(Responses.Type.DEFAULT.getColor()) - .setAuthor(createdBy.getAsTag(), null, createdBy.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(createdBy), null, createdBy.getEffectiveAvatarUrl()) .setTitle(String.format("Question of the Week #%s", question.getQuestionNumber())) .setDescription(String.format(""" %s diff --git a/src/main/java/net/javadiscord/javabot/systems/staff_commands/RedeployCommand.java b/src/main/java/net/javadiscord/javabot/systems/staff_commands/RedeployCommand.java index 4c0b6f1a1..bafb13e2d 100644 --- a/src/main/java/net/javadiscord/javabot/systems/staff_commands/RedeployCommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/staff_commands/RedeployCommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.staff_commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -46,7 +47,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { Responses.replyAdminOnly(event, botConfig.get(event.getGuild())).queue(); return; } - log.warn("Redeploying... Requested by: " + event.getUser().getAsTag()); + log.warn("Redeploying... Requested by: " + UserUtils.getUserTag(event.getUser())); event.reply("**Redeploying...** This may take some time.").queue(); messageCache.synchronize(); System.exit(0); diff --git a/src/main/java/net/javadiscord/javabot/systems/staff_commands/SayCommand.java b/src/main/java/net/javadiscord/javabot/systems/staff_commands/SayCommand.java index 35a18343a..fce307c90 100644 --- a/src/main/java/net/javadiscord/javabot/systems/staff_commands/SayCommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/staff_commands/SayCommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.staff_commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.Message; @@ -48,7 +49,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { return; } String text = textMapping.getAsString(); - log.info("Posted \"{}\" in \"#{}\" as requested by \"{}\"", text, event.getChannel().getName(), event.getUser().getAsTag()); + log.info("Posted \"{}\" in \"#{}\" as requested by \"{}\"", text, event.getChannel().getName(), UserUtils.getUserTag(event.getUser())); event.deferReply(true).queue(); event.getChannel().sendMessage(text) .setAllowedMentions(Set.of(Message.MentionType.EMOJI, Message.MentionType.CHANNEL)) diff --git a/src/main/java/net/javadiscord/javabot/systems/staff_commands/embeds/AddEmbedFieldSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/staff_commands/embeds/AddEmbedFieldSubcommand.java index 143cb9a13..d2186339a 100644 --- a/src/main/java/net/javadiscord/javabot/systems/staff_commands/embeds/AddEmbedFieldSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/staff_commands/embeds/AddEmbedFieldSubcommand.java @@ -106,7 +106,7 @@ public void handleModal(@NotNull ModalInteractionEvent event, @NotNull List sendStaffSubmission(@NotNull ModalIn member -> { User user = member.getUser(); MessageEmbed embed = new EmbedBuilder() - .setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl()) - .setTitle(String.format("%s applied for %s", user.getAsTag(), role.getName())) + .setAuthor(UserUtils.getUserTag(user), null, user.getEffectiveAvatarUrl()) + .setTitle(String.format("%s applied for %s", UserUtils.getUserTag(user), role.getName())) .setColor(Responses.Type.SUCCESS.getColor()) .addField("Real Name", nameOption.getAsString(), false) .addField("Age", ageOption.getAsString(), true) @@ -237,8 +238,8 @@ private WebhookMessageCreateAction sendStaffSubmission(@NotNull ModalIn member -> { User user = member.getUser(); EmbedBuilder embed = new EmbedBuilder() - .setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl()) - .setTitle(String.format("%s applied for %s", user.getAsTag(), config.getExpertRole().getName())) + .setAuthor(UserUtils.getUserTag(user), null, user.getEffectiveAvatarUrl()) + .setTitle(String.format("%s applied for %s", UserUtils.getUserTag(user), config.getExpertRole().getName())) .setColor(config.getExpertRole().getColor()) .addField("How much Java experience do you have?", experienceOption.getAsString(), false) .addField("Present us a fitting Java Project", projectInfoOption.getAsString(), false) diff --git a/src/main/java/net/javadiscord/javabot/systems/staff_commands/suggestions/AcceptSuggestionSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/staff_commands/suggestions/AcceptSuggestionSubcommand.java index 053dc230a..c2789b0cf 100644 --- a/src/main/java/net/javadiscord/javabot/systems/staff_commands/suggestions/AcceptSuggestionSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/staff_commands/suggestions/AcceptSuggestionSubcommand.java @@ -11,6 +11,7 @@ import net.dv8tion.jda.api.requests.restaction.WebhookMessageCreateAction; import net.javadiscord.javabot.data.config.GuildConfig; import net.javadiscord.javabot.util.Responses; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; /** @@ -46,7 +47,7 @@ protected WebhookMessageCreateAction handleSuggestionCommand(@NotNull S .setTitle("Suggestion Accepted") .setDescription(embed.getDescription()) .setTimestamp(embed.getTimestamp()) - .setFooter("Accepted by " + user.getAsTag()) + .setFooter("Accepted by " + UserUtils.getUserTag(user)) .build(); } } \ No newline at end of file diff --git a/src/main/java/net/javadiscord/javabot/systems/staff_commands/suggestions/DeclineSuggestionSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/staff_commands/suggestions/DeclineSuggestionSubcommand.java index 7d597140d..80bde59cd 100644 --- a/src/main/java/net/javadiscord/javabot/systems/staff_commands/suggestions/DeclineSuggestionSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/staff_commands/suggestions/DeclineSuggestionSubcommand.java @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.requests.restaction.WebhookMessageCreateAction; import net.javadiscord.javabot.data.config.GuildConfig; import net.javadiscord.javabot.util.Responses; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; /** @@ -48,7 +49,7 @@ protected WebhookMessageCreateAction handleSuggestionCommand(@NotNull S .setTitle("Suggestion Declined") .setDescription(embed.getDescription()) .setTimestamp(embed.getTimestamp()) - .setFooter("Declined by " + user.getAsTag()); + .setFooter("Declined by " + UserUtils.getUserTag(user)); if (reason != null) builder.addField("Reason", reason, false); return builder.build(); } diff --git a/src/main/java/net/javadiscord/javabot/systems/staff_commands/suggestions/OnHoldSuggestionSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/staff_commands/suggestions/OnHoldSuggestionSubcommand.java index 9f8335b3c..c518bc414 100644 --- a/src/main/java/net/javadiscord/javabot/systems/staff_commands/suggestions/OnHoldSuggestionSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/staff_commands/suggestions/OnHoldSuggestionSubcommand.java @@ -11,6 +11,7 @@ import net.dv8tion.jda.api.requests.restaction.WebhookMessageCreateAction; import net.javadiscord.javabot.data.config.GuildConfig; import net.javadiscord.javabot.util.Responses; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; /** @@ -47,7 +48,7 @@ protected WebhookMessageCreateAction handleSuggestionCommand(@NotNull S .setTitle("Suggestion On Hold") .setDescription(embed.getDescription()) .setTimestamp(embed.getTimestamp()) - .setFooter("Suggestion marked as On Hold by " + user.getAsTag()) + .setFooter("Suggestion marked as On Hold by " + UserUtils.getUserTag(user)) .build(); } } \ No newline at end of file diff --git a/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/CustomTagManager.java b/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/CustomTagManager.java index 830a21c64..113a9ee29 100644 --- a/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/CustomTagManager.java +++ b/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/CustomTagManager.java @@ -18,7 +18,6 @@ import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; -import javax.sql.DataSource; import java.sql.SQLException; import java.util.*; import java.util.stream.Collectors; @@ -37,7 +36,6 @@ public class CustomTagManager { LOADED_TAGS = new HashMap<>(); } - private final DataSource dataSource; private final CustomTagRepository customTagRepository; /** diff --git a/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/CreateCustomTagSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/CreateCustomTagSubcommand.java index 2fd67b512..d0ba94081 100644 --- a/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/CreateCustomTagSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/CreateCustomTagSubcommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.staff_commands.tags.commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.components.ModalHandler; import net.dv8tion.jda.api.EmbedBuilder; @@ -80,13 +81,13 @@ public InteractionCallbackAction handleCustomTagsSubcommand(@NotNull Slash .setRequired(true) .build(); return Modal.create("tag-create", "Create Custom Tag") - .addActionRows(ActionRow.of(nameField), ActionRow.of(responseField), ActionRow.of(replyField), ActionRow.of(embedField)) + .addComponents(ActionRow.of(nameField), ActionRow.of(responseField), ActionRow.of(replyField), ActionRow.of(embedField)) .build(); } private @NotNull MessageEmbed buildCreateCommandEmbed(@NotNull User createdBy, @NotNull CustomTag command) { return new EmbedBuilder() - .setAuthor(createdBy.getAsTag(), null, createdBy.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(createdBy), null, createdBy.getEffectiveAvatarUrl()) .setTitle("Custom Tag Created") .addField("Id", String.format("`%s`", command.getId()), true) .addField("Name", String.format("`%s`", command.getName()), true) diff --git a/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/DeleteCustomTagSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/DeleteCustomTagSubcommand.java index 973dda0cd..2bab40472 100644 --- a/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/DeleteCustomTagSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/DeleteCustomTagSubcommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.staff_commands.tags.commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.AutoCompletable; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Member; @@ -77,7 +78,7 @@ public ReplyCallbackAction handleCustomTagsSubcommand(@NotNull SlashCommandInter private @NotNull MessageEmbed buildDeleteCommandEmbed(@NotNull Member deletedBy, @NotNull CustomTag command) { return new EmbedBuilder() - .setAuthor(deletedBy.getUser().getAsTag(), null, deletedBy.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(deletedBy.getUser()), null, deletedBy.getEffectiveAvatarUrl()) .setTitle("Custom Tag Deleted") .addField("Id", String.format("`%s`", command.getId()), true) .addField("Name", String.format("`%s`", command.getName()), true) diff --git a/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/EditCustomTagSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/EditCustomTagSubcommand.java index 19ea1308b..c3773d77c 100644 --- a/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/EditCustomTagSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/EditCustomTagSubcommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.staff_commands.tags.commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.util.ComponentIdBuilder; import xyz.dynxsty.dih4jda.interactions.AutoCompletable; import xyz.dynxsty.dih4jda.interactions.components.ModalHandler; @@ -107,13 +108,13 @@ public InteractionCallbackAction handleCustomTagsSubcommand(@NotNull SlashCom .build(); return Modal.create(ComponentIdBuilder.build("tag-edit", tag.getName()), String.format("Edit \"%s\"", tag.getName().length() > 90 ? tag.getName().substring(0, 87) + "..." : tag.getName())) - .addActionRows(ActionRow.of(responseField), ActionRow.of(replyField), ActionRow.of(embedField)) + .addComponents(ActionRow.of(responseField), ActionRow.of(replyField), ActionRow.of(embedField)) .build(); } private @NotNull MessageEmbed buildEditTagEmbed(@NotNull Member createdBy, @NotNull CustomTag command) { return new EmbedBuilder() - .setAuthor(createdBy.getUser().getAsTag(), null, createdBy.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(createdBy.getUser()), null, createdBy.getEffectiveAvatarUrl()) .setTitle("Custom Tag Edited") .addField("Id", String.format("`%s`", command.getId()), true) .addField("Name", String.format("`%s`", command.getName()), true) diff --git a/src/main/java/net/javadiscord/javabot/systems/starboard/StarboardManager.java b/src/main/java/net/javadiscord/javabot/systems/starboard/StarboardManager.java index 542e3f8a3..938d5d365 100644 --- a/src/main/java/net/javadiscord/javabot/systems/starboard/StarboardManager.java +++ b/src/main/java/net/javadiscord/javabot/systems/starboard/StarboardManager.java @@ -22,6 +22,7 @@ import net.javadiscord.javabot.systems.starboard.model.StarboardEntry; import net.javadiscord.javabot.util.ExceptionLogger; import net.javadiscord.javabot.util.Responses; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; import org.springframework.dao.DataAccessException; @@ -221,7 +222,7 @@ private boolean removeMessageFromStarboard(long messageId, MessageChannel channe private @NotNull MessageEmbed buildStarboardEmbed(@NotNull Message message) { User author = message.getAuthor(); return new EmbedBuilder() - .setAuthor(author.getAsTag(), message.getJumpUrl(), author.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(author), message.getJumpUrl(), author.getEffectiveAvatarUrl()) .setColor(Responses.Type.DEFAULT.getColor()) .setDescription(message.getContentRaw()) .setFooter("#" + message.getChannel().getName()) diff --git a/src/main/java/net/javadiscord/javabot/systems/user_commands/AvatarCommand.java b/src/main/java/net/javadiscord/javabot/systems/user_commands/AvatarCommand.java index 0074d3f60..6da88a8f4 100644 --- a/src/main/java/net/javadiscord/javabot/systems/user_commands/AvatarCommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/user_commands/AvatarCommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.user_commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageEmbed; @@ -38,7 +39,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { private @NotNull MessageEmbed buildAvatarEmbed(@NotNull User createdBy) { return new EmbedBuilder() .setColor(Responses.Type.DEFAULT.getColor()) - .setAuthor(createdBy.getAsTag(), null, createdBy.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(createdBy), null, createdBy.getEffectiveAvatarUrl()) .setTitle("Avatar") .setImage(createdBy.getEffectiveAvatarUrl() + "?size=4096") .build(); diff --git a/src/main/java/net/javadiscord/javabot/systems/user_commands/BotInfoCommand.java b/src/main/java/net/javadiscord/javabot/systems/user_commands/BotInfoCommand.java index 3deb68232..2c34eedfc 100644 --- a/src/main/java/net/javadiscord/javabot/systems/user_commands/BotInfoCommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/user_commands/BotInfoCommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.user_commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDA; @@ -39,7 +40,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { return new EmbedBuilder() .setColor(Responses.Type.DEFAULT.getColor()) .setThumbnail(jda.getSelfUser().getEffectiveAvatarUrl()) - .setAuthor(jda.getSelfUser().getAsTag(), null, jda.getSelfUser().getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(jda.getSelfUser()), null, jda.getSelfUser().getEffectiveAvatarUrl()) .setTitle("Bot Information") .addField("OS", MarkdownUtil.codeblock(StringUtils.getOperatingSystem()), true) .addField("Uptime", MarkdownUtil.codeblock(StringUtils.formatUptime()), true) diff --git a/src/main/java/net/javadiscord/javabot/systems/user_commands/ChangeMyMindCommand.java b/src/main/java/net/javadiscord/javabot/systems/user_commands/ChangeMyMindCommand.java index f04b7899b..7ad10efea 100644 --- a/src/main/java/net/javadiscord/javabot/systems/user_commands/ChangeMyMindCommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/user_commands/ChangeMyMindCommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.user_commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.JsonNode; @@ -56,7 +57,7 @@ public void completed(HttpResponse hr) { try { String imageUrl = hr.getBody().getObject().getString("message"); event.getHook().sendMessageEmbeds(new EmbedBuilder() - .setAuthor(event.getUser().getAsTag(), imageUrl, event.getUser().getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(event.getUser()), imageUrl, event.getUser().getEffectiveAvatarUrl()) .setColor(Responses.Type.DEFAULT.getColor()) .setImage(imageUrl) .setTimestamp(Instant.now()) diff --git a/src/main/java/net/javadiscord/javabot/systems/user_commands/IdCalculatorCommand.java b/src/main/java/net/javadiscord/javabot/systems/user_commands/IdCalculatorCommand.java index 5cf637550..50753864c 100644 --- a/src/main/java/net/javadiscord/javabot/systems/user_commands/IdCalculatorCommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/user_commands/IdCalculatorCommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.user_commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageEmbed; @@ -50,7 +51,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { private @NotNull MessageEmbed buildIdCalcEmbed(@NotNull User author, long id, long unixTimestamp) { return new EmbedBuilder() - .setAuthor(author.getAsTag(), null, author.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(author), null, author.getEffectiveAvatarUrl()) .setTitle("ID Calculator") .setColor(Responses.Type.DEFAULT.getColor()) .addField("Snowflake Input", String.format(MarkdownUtil.codeblock("%s"), id), false) diff --git a/src/main/java/net/javadiscord/javabot/systems/user_commands/PollCommand.java b/src/main/java/net/javadiscord/javabot/systems/user_commands/PollCommand.java index 5c886cd2e..bbdee613d 100644 --- a/src/main/java/net/javadiscord/javabot/systems/user_commands/PollCommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/user_commands/PollCommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.user_commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.emoji.Emoji; @@ -52,7 +53,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { return; } EmbedBuilder embed = new EmbedBuilder() - .setAuthor(event.getUser().getAsTag(), null, event.getUser().getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(event.getUser()), null, event.getUser().getEffectiveAvatarUrl()) .setTitle(titleOption.getAsString()) .setColor(Responses.Type.DEFAULT.getColor()) .setTimestamp(Instant.now()); diff --git a/src/main/java/net/javadiscord/javabot/systems/user_commands/ProfileCommand.java b/src/main/java/net/javadiscord/javabot/systems/user_commands/ProfileCommand.java index dd70ae913..355fdedda 100644 --- a/src/main/java/net/javadiscord/javabot/systems/user_commands/ProfileCommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/user_commands/ProfileCommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.user_commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.*; @@ -86,7 +87,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { double helpXP = helpExperienceService.getOrCreateAccount(member.getIdLong()).getExperience(); EmbedBuilder embed = new EmbedBuilder() .setTitle("Profile") - .setAuthor(member.getUser().getAsTag(), null, member.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(member.getUser()), null, member.getEffectiveAvatarUrl()) .setDescription(getDescription(member)) .setColor(member.getColor()) .setThumbnail(member.getEffectiveAvatarUrl() + "?size=4096") diff --git a/src/main/java/net/javadiscord/javabot/systems/user_commands/leaderboard/ExperienceLeaderboardSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/user_commands/leaderboard/ExperienceLeaderboardSubcommand.java index 6e8acaa3c..65eeb659b 100644 --- a/src/main/java/net/javadiscord/javabot/systems/user_commands/leaderboard/ExperienceLeaderboardSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/user_commands/leaderboard/ExperienceLeaderboardSubcommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.user_commands.leaderboard; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.util.ComponentIdBuilder; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import xyz.dynxsty.dih4jda.interactions.components.ButtonHandler; @@ -90,7 +91,7 @@ public void handleButton(@NotNull ButtonInteractionEvent event, Button button) { Pair currentRole = account.getCurrentExperienceGoal(guild); User user = guild.getJDA().getUserById(account.getUserId()); builder.addField( - String.format("**%s.** %s", (accounts.indexOf(account) + 1) + (page - 1) * PAGE_SIZE, user == null ? account.getUserId() : user.getAsTag()), + String.format("**%s.** %s", (accounts.indexOf(account) + 1) + (page - 1) * PAGE_SIZE, user == null ? account.getUserId() : UserUtils.getUserTag(user)), String.format("%s`%.0f XP`\n", currentRole.first() != null ? currentRole.first().getAsMention() + ": " : "", account.getExperience()), false); }); diff --git a/src/main/java/net/javadiscord/javabot/systems/user_commands/leaderboard/QOTWLeaderboardSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/user_commands/leaderboard/QOTWLeaderboardSubcommand.java index b43029234..d54120106 100644 --- a/src/main/java/net/javadiscord/javabot/systems/user_commands/leaderboard/QOTWLeaderboardSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/user_commands/leaderboard/QOTWLeaderboardSubcommand.java @@ -14,6 +14,7 @@ import javax.imageio.ImageIO; +import net.javadiscord.javabot.util.UserUtils; import org.jetbrains.annotations.NotNull; import org.springframework.dao.DataAccessException; @@ -104,7 +105,7 @@ private MessageEmbed buildLeaderboardRankEmbed(Member member) { long points = pointsService.getPoints(member.getIdLong()); String pointsText = points == 1 ? "point" : "points"; return new EmbedBuilder() - .setAuthor(member.getUser().getAsTag(), null, member.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(member.getUser()), null, member.getEffectiveAvatarUrl()) .setTitle("Question of the Week Leaderboard") .setDescription(points == 0 ? "You are currently not ranked." : String.format("This month, you're in `%s` place with `%s` %s.", rank + rankSuffix, points, pointsText)) @@ -124,9 +125,9 @@ private MessageEmbed buildLeaderboardRankEmbed(Member member) { */ private void drawUserCard(@NotNull Graphics2D g2d, @NotNull Member member, QOTWPointsService service, int y, boolean left) throws IOException { BufferedImage card = ImageGenerationUtils.getResourceImage("assets/images/LeaderboardUserCard.png"); - int x = left ? MARGIN * 5 : WIDTH - (MARGIN * 5) - card.getWidth(); + int x = left ? MARGIN * 5 : WIDTH - MARGIN * 5 - card.getWidth(); g2d.drawImage(ImageGenerationUtils.getImageFromUrl(member.getEffectiveAvatarUrl() + "?size=4096"), x + 185, y + 43, 200, 200, null); - String displayName = member.getUser().getAsTag(); + String displayName = UserUtils.getUserTag(member.getUser()); // draw card g2d.drawImage(card, x, y, null); g2d.setColor(PRIMARY_COLOR); diff --git a/src/main/java/net/javadiscord/javabot/systems/user_preferences/commands/PreferencesListSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/user_preferences/commands/PreferencesListSubcommand.java index 7f1326b85..6586c255c 100644 --- a/src/main/java/net/javadiscord/javabot/systems/user_preferences/commands/PreferencesListSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/user_preferences/commands/PreferencesListSubcommand.java @@ -1,5 +1,6 @@ package net.javadiscord.javabot.systems.user_preferences.commands; +import net.javadiscord.javabot.util.UserUtils; import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageEmbed; @@ -35,7 +36,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { private @NotNull MessageEmbed buildPreferencesEmbed(UserPreferenceService service, @NotNull User user) { EmbedBuilder builder = new EmbedBuilder() - .setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl()) + .setAuthor(UserUtils.getUserTag(user), null, user.getEffectiveAvatarUrl()) .setTitle(user.getName() + "'s Preferences") .setColor(Responses.Type.INFO.getColor()); for (Preference p : Preference.values()) { diff --git a/src/main/java/net/javadiscord/javabot/util/InteractionUtils.java b/src/main/java/net/javadiscord/javabot/util/InteractionUtils.java index aa224a9a9..abb08eea4 100644 --- a/src/main/java/net/javadiscord/javabot/util/InteractionUtils.java +++ b/src/main/java/net/javadiscord/javabot/util/InteractionUtils.java @@ -111,7 +111,7 @@ private void kick(ModalInteraction interaction, @NotNull Guild guild, String mem guild.retrieveMemberById(memberId).queue( member -> { service.kick(member.getUser(), reason, interaction.getMember(), interaction.getMessageChannel(), false); - interaction.getMessage().editMessageComponents(ActionRow.of(Button.danger(interaction.getModalId(), "Kicked by "+interaction.getUser().getAsTag()).asDisabled())).queue(); + interaction.getMessage().editMessageComponents(ActionRow.of(Button.danger(interaction.getModalId(), "Kicked by " + UserUtils.getUserTag(interaction.getUser())).asDisabled())).queue(); }, error -> Responses.error(interaction.getHook(), "Could not find member: " + error.getMessage()).queue() ); } @@ -125,7 +125,7 @@ private void warn(ModalInteraction interaction, @NotNull Guild guild, String mem guild.retrieveMemberById(memberId).queue( member -> { service.warn(member.getUser(), severity, reason, interaction.getMember(), interaction.getMessageChannel(), false); - interaction.getHook().editOriginalComponents(ActionRow.of(Button.primary(interaction.getModalId(), "Warned by "+interaction.getUser().getAsTag()).asDisabled())).queue(); + interaction.getHook().editOriginalComponents(ActionRow.of(Button.primary(interaction.getModalId(), "Warned by " + UserUtils.getUserTag(interaction.getUser())).asDisabled())).queue(); }, error -> Responses.error(interaction.getHook(), "Could not find member: " + error.getMessage()).queue() ); } @@ -139,7 +139,7 @@ private void ban(ModalInteraction interaction, @NotNull Guild guild, String memb guild.getJDA().retrieveUserById(memberId).queue( user -> { service.ban(user, reason, interaction.getMember(), interaction.getMessageChannel(), false); - interaction.getMessage().editMessageComponents(ActionRow.of(Button.danger(interaction.getModalId(), "Banned by "+interaction.getUser().getAsTag()).asDisabled())).queue(); + interaction.getMessage().editMessageComponents(ActionRow.of(Button.danger(interaction.getModalId(), "Banned by " + UserUtils.getUserTag(interaction.getUser())).asDisabled())).queue(); }, error -> Responses.error(interaction.getHook(), "Could not find member: " + error.getMessage()).queue() ); } @@ -151,7 +151,7 @@ private void unban(ModalInteraction interaction, long memberId, String reason) { } ModerationService service = new ModerationService(notificationService, botConfig, interaction, warnRepository, asyncPool); service.unban(memberId, reason, interaction.getMember(), interaction.getMessageChannel(), false); - interaction.getMessage().editMessageComponents(ActionRow.of(Button.secondary(interaction.getModalId(), "Unbanned by "+interaction.getUser().getAsTag()).asDisabled())).queue(); + interaction.getMessage().editMessageComponents(ActionRow.of(Button.secondary(interaction.getModalId(), "Unbanned by " + UserUtils.getUserTag(interaction.getUser())).asDisabled())).queue(); } @Override diff --git a/src/main/java/net/javadiscord/javabot/util/UserUtils.java b/src/main/java/net/javadiscord/javabot/util/UserUtils.java new file mode 100644 index 000000000..7190db7d3 --- /dev/null +++ b/src/main/java/net/javadiscord/javabot/util/UserUtils.java @@ -0,0 +1,25 @@ +package net.javadiscord.javabot.util; + +import net.dv8tion.jda.api.entities.User; + +/** + * Utils regarding users. + */ +public class UserUtils { + /** + * Returns the tag of a discord user, in the format "[username]#[discriminator]", or just "[username]" if the new username system is used. + * + * @param user The {@link User} to get the tag of + * + * @return The formatted tag of the user + */ + public static String getUserTag(User user) { + String name = user.getName(); + String discrim = user.getDiscriminator(); + if ("0000".equals(discrim)) { + return name; + } else { + return name + "#" + discrim; + } + } +}