From 772787a98eb932dc0855624b11524f107d634c11 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 4 Jul 2024 05:25:19 +0100 Subject: [PATCH] make log messages more consistent --- .../fascinated/bat/event/EventListener.java | 4 ++++ .../bat/features/logging/LogType.java | 1 + .../logging/listeners/ChannelListener.java | 21 ++++++++++++++++--- .../logging/listeners/GuildListener.java | 10 ++++----- .../logging/listeners/MemberListener.java | 8 +++---- .../fascinated/bat/service/EventService.java | 10 +++++++++ 6 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/event/EventListener.java b/src/main/java/cc/fascinated/bat/event/EventListener.java index 701047e..acd9c81 100644 --- a/src/main/java/cc/fascinated/bat/event/EventListener.java +++ b/src/main/java/cc/fascinated/bat/event/EventListener.java @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.channel.ChannelCreateEvent; import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent; +import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNameEvent; import net.dv8tion.jda.api.events.channel.update.GenericChannelUpdateEvent; import net.dv8tion.jda.api.events.emoji.EmojiAddedEvent; import net.dv8tion.jda.api.events.emoji.EmojiRemovedEvent; @@ -132,6 +133,9 @@ public interface EventListener { default void onEmojiRename(@NonNull BatGuild guild, @NonNull Emoji emoji, @NonNull String oldName, @NonNull String newName, @NonNull EmojiUpdateNameEvent event) { } + default void onChannelUpdateName(@NonNull BatGuild guild, @NonNull ChannelUpdateNameEvent event) { + } + default void onShutdown() { } } diff --git a/src/main/java/cc/fascinated/bat/features/logging/LogType.java b/src/main/java/cc/fascinated/bat/features/logging/LogType.java index c192f5c..8379ac1 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/LogType.java +++ b/src/main/java/cc/fascinated/bat/features/logging/LogType.java @@ -41,6 +41,7 @@ public enum LogType { CHANNEL_DELETE(LogCategory.CHANNEL), VOICE_CHANNEL_JOIN(LogCategory.CHANNEL), VOICE_CHANNEL_LEAVE(LogCategory.CHANNEL), + CHANNEL_UPDATE_NAME(LogCategory.CHANNEL), /** * Guild Events diff --git a/src/main/java/cc/fascinated/bat/features/logging/listeners/ChannelListener.java b/src/main/java/cc/fascinated/bat/features/logging/listeners/ChannelListener.java index d500efd..706c81a 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/listeners/ChannelListener.java +++ b/src/main/java/cc/fascinated/bat/features/logging/listeners/ChannelListener.java @@ -17,6 +17,7 @@ import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion; import net.dv8tion.jda.api.entities.channel.unions.ChannelUnion; import net.dv8tion.jda.api.events.channel.ChannelCreateEvent; import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent; +import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNameEvent; import net.dv8tion.jda.api.events.guild.voice.GenericGuildVoiceEvent; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -50,7 +51,7 @@ public class ChannelListener implements EventListener { logFeature.sendLog(guild, LogType.CHANNEL_CREATE, EmbedUtils.successEmbed() .setDescription(new EmbedDescriptionBuilder("%s Created".formatted(type)) .appendLine("%s: %s".formatted(type, event.getChannel().getAsMention()), true) - .appendLine("Name: %s".formatted(event.getChannel().getName()), true) + .appendLine("Name: `%s`".formatted(event.getChannel().getName()), true) .build()) .build()); } @@ -61,14 +62,28 @@ public class ChannelListener implements EventListener { String type = formatChannelType(channel); log.info("{} \"{}\" was deleted in guild \"{}\"", type, event.getChannel().getName(), guild.getName()); EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("%s Deleted".formatted(type)) - .appendLine("Name: #%s".formatted(channel.getName()), true); + .appendLine("Name: `#%s`".formatted(channel.getName()), true); if (channel instanceof TextChannel) { TextChannel textChannel = channel.asTextChannel(); - description.appendLine("Topic: %s".formatted(textChannel.getTopic() == null ? "No Topic" : textChannel.getTopic()), true); + description.appendLine("Topic: `%s`".formatted(textChannel.getTopic() == null ? "No Topic" : textChannel.getTopic()), true); } logFeature.sendLog(guild, LogType.CHANNEL_DELETE, EmbedUtils.errorEmbed().setDescription(description.build()).build()); } + @Override + public void onChannelUpdateName(@NonNull BatGuild guild, @NonNull ChannelUpdateNameEvent event) { + ChannelUnion channel = event.getChannel(); + String type = formatChannelType(channel); + log.info("{} \"{}\" name was updated in guild \"{}\"", type, event.getChannel().getName(), guild.getName()); + logFeature.sendLog(guild, LogType.CHANNEL_UPDATE_NAME, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("%s Name Updated".formatted(type)) + .appendLine("%s: %s".formatted(type, event.getChannel().getAsMention()), true) + .appendLine("Old Name: `%s`".formatted(event.getOldValue()), true) + .appendLine("New Name: `%s`".formatted(event.getNewValue()), true) + .build()) + .build()); + } + @Override public void onGuildVoiceUpdate(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GenericGuildVoiceEvent event) { AudioChannelUnion channel = event.getVoiceState().getChannel(); diff --git a/src/main/java/cc/fascinated/bat/features/logging/listeners/GuildListener.java b/src/main/java/cc/fascinated/bat/features/logging/listeners/GuildListener.java index 541417b..566d9c3 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/listeners/GuildListener.java +++ b/src/main/java/cc/fascinated/bat/features/logging/listeners/GuildListener.java @@ -44,7 +44,7 @@ public class GuildListener implements EventListener { .setDescription(new EmbedDescriptionBuilder("Invite Created") .appendLine("Invite: %s".formatted(expanded.getUrl()), true) .appendLine("Channel: %s".formatted(expanded.getChannel()), true) - .appendLine("Max Uses: %s".formatted(expanded.getMaxUses() == 0 ? "Infinite" : expanded.getMaxUses()), true) + .appendLine("Max Uses: `%s`".formatted(expanded.getMaxUses() == 0 ? "Infinite" : expanded.getMaxUses()), true) .appendLine("Creator: %s".formatted(expanded.getInviter() == null ? "Unknown" : expanded.getInviter().getAsMention()), true) .build()) .build())); @@ -57,7 +57,7 @@ public class GuildListener implements EventListener { logFeature.sendLog(guild, LogType.EMOJI_ADD, EmbedUtils.successEmbed() .setDescription(new EmbedDescriptionBuilder("Emoji Added") .appendLine("Emoji: %s".formatted(emoji.getFormatted()), true) - .appendLine("Name: %s".formatted(emoji.getName()), true) + .appendLine("Name: `%s`".formatted(emoji.getName()), true) .build()) .build()); } @@ -68,7 +68,7 @@ public class GuildListener implements EventListener { logFeature.sendLog(guild, LogType.EMOJI_REMOVE, EmbedUtils.successEmbed() .setDescription(new EmbedDescriptionBuilder("Emoji Removed") .appendLine("Emoji: %s".formatted(emoji.getFormatted()), true) - .appendLine("Name: %s".formatted(emoji.getName()), true) + .appendLine("Name: `%s`".formatted(emoji.getName()), true) .build()) .build()); } @@ -79,8 +79,8 @@ public class GuildListener implements EventListener { logFeature.sendLog(guild, LogType.EMOJI_RENAME, EmbedUtils.successEmbed() .setDescription(new EmbedDescriptionBuilder("Emoji Renamed") .appendLine("Emoji: %s".formatted(emoji.getFormatted()), true) - .appendLine("Old Name: %s".formatted(oldName), true) - .appendLine("New Name: %s".formatted(newName), true) + .appendLine("Old Name: `%s`".formatted(oldName), true) + .appendLine("New Name: `%s`".formatted(newName), true) .build()) .build()); } diff --git a/src/main/java/cc/fascinated/bat/features/logging/listeners/MemberListener.java b/src/main/java/cc/fascinated/bat/features/logging/listeners/MemberListener.java index 0556a7b..fc38f2b 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/listeners/MemberListener.java +++ b/src/main/java/cc/fascinated/bat/features/logging/listeners/MemberListener.java @@ -55,7 +55,7 @@ public class MemberListener implements EventListener { logFeature.sendLog(guild, LogType.MEMBER_JOIN, EmbedUtils.successEmbed() .setDescription(new EmbedDescriptionBuilder("Member Joined") .appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true) - .appendLine("Username: %s".formatted(user.getDiscordUser().getName()), true) + .appendLine("Username: `%s`".formatted(user.getDiscordUser().getName()), true) .appendLine("Joined Discord: ".formatted(user.getDiscordUser().getTimeCreated().toEpochSecond()), true) .build()) .setThumbnail(user.getDiscordUser().getEffectiveAvatarUrl()) @@ -70,7 +70,7 @@ public class MemberListener implements EventListener { logFeature.sendLog(guild, LogType.MEMBER_LEAVE, EmbedUtils.errorEmbed() .setDescription(new EmbedDescriptionBuilder("Member Left") .appendLine("Member: <@%s>".formatted(user.getId()), true) - .appendLine("Username: %s".formatted(user.getName()), true) + .appendLine("Username: `%s`".formatted(user.getName()), true) .build()) .build()); } @@ -239,7 +239,7 @@ public class MemberListener implements EventListener { logFeature.sendLog(guild, LogType.MEMBER_BOOSTED, EmbedUtils.successEmbed() .setDescription(new EmbedDescriptionBuilder("Member Boosted") .appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true) - .appendLine("Boost Months: %s".formatted(boostAmount), true) + .appendLine("Boost Months: `%s`".formatted(boostAmount), true) .appendLine("Boost End: ".formatted(seconds), true) .build()) .build()); @@ -256,7 +256,7 @@ public class MemberListener implements EventListener { logFeature.sendLog(guild, LogType.MEMBER_BOOST_EXPIRE, EmbedUtils.errorEmbed() .setDescription(new EmbedDescriptionBuilder("Member Boost Expired") .appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true) - .appendLine("Boosts Removed: %s".formatted(boostAmount), true) + .appendLine("Boosts Removed: `%s`".formatted(boostAmount), true) .build()) .build()); } diff --git a/src/main/java/cc/fascinated/bat/service/EventService.java b/src/main/java/cc/fascinated/bat/service/EventService.java index ef4ab21..7314ab9 100644 --- a/src/main/java/cc/fascinated/bat/service/EventService.java +++ b/src/main/java/cc/fascinated/bat/service/EventService.java @@ -10,6 +10,7 @@ import lombok.extern.log4j.Log4j2; import net.dv8tion.jda.api.entities.Invite; import net.dv8tion.jda.api.events.channel.ChannelCreateEvent; import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent; +import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNameEvent; import net.dv8tion.jda.api.events.emoji.EmojiAddedEvent; import net.dv8tion.jda.api.events.emoji.EmojiRemovedEvent; import net.dv8tion.jda.api.events.emoji.update.EmojiUpdateNameEvent; @@ -381,4 +382,13 @@ public class EventService extends ListenerAdapter { listener.onEmojiRename(guild, event.getEmoji(), event.getOldName(), event.getNewName(), event); } } + + @Override + public void onChannelUpdateName(@NotNull ChannelUpdateNameEvent event) { + BatGuild guild = guildService.getGuild(event.getGuild().getId()); + + for (EventListener listener : LISTENERS) { + listener.onChannelUpdateName(guild, event); + } + } }