From f62a022ed5f458e6e6e4b48bcefe5bf9cd590fe8 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 3 Jul 2024 16:51:36 +0100 Subject: [PATCH] logging messages --- .../logging/listeners/ChannelListener.java | 4 ++++ .../logging/listeners/MemberListener.java | 17 +++++++++++++++++ .../logging/listeners/MessageListener.java | 4 ++++ .../cc/fascinated/bat/service/UserService.java | 1 - 4 files changed, 25 insertions(+), 1 deletion(-) 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 9c1bb05..bce1d21 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 @@ -8,6 +8,7 @@ import cc.fascinated.bat.features.logging.LogFeature; import cc.fascinated.bat.features.logging.LogType; import cc.fascinated.bat.model.BatGuild; import lombok.NonNull; +import lombok.extern.log4j.Log4j2; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.unions.ChannelUnion; import net.dv8tion.jda.api.events.channel.ChannelCreateEvent; @@ -20,6 +21,7 @@ import org.springframework.stereotype.Component; * @author Fascinated (fascinated7) */ @Component +@Log4j2 public class ChannelListener implements EventListener { private final LogFeature logFeature; @@ -30,6 +32,7 @@ public class ChannelListener implements EventListener { @Override public void onChannelCreate(@NonNull BatGuild guild, @NonNull ChannelCreateEvent event) { + log.info("Channel {} was created in guild {}", event.getChannel().getName(), guild.getName()); logFeature.sendLog(guild, LogType.CHANNEL_CREATE, EmbedUtils.successEmbed() .setDescription(new EmbedDescriptionBuilder("%s Channel Created".formatted(EnumUtils.getEnumName(event.getChannel().getType()))) .appendLine("Channel: %s".formatted(event.getChannel().getAsMention()), true) @@ -40,6 +43,7 @@ public class ChannelListener implements EventListener { @Override public void onChannelDelete(@NonNull BatGuild guild, @NonNull ChannelDeleteEvent event) { + log.info("Channel {} was deleted in guild {}", event.getChannel().getName(), guild.getName()); ChannelUnion channel = event.getChannel(); EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("%s Channel Deleted".formatted(EnumUtils.getEnumName(channel.getType()))) .appendLine("Name: #%s".formatted(channel.getName()), true); 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 9877afc..fbfd20b 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 @@ -23,6 +23,8 @@ import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateTimeOutEv import net.dv8tion.jda.api.events.user.update.UserUpdateAvatarEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateGlobalNameEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateNameEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; @@ -35,6 +37,7 @@ import java.util.List; */ @Component public class MemberListener implements EventListener { + private static final Logger log = LoggerFactory.getLogger(MemberListener.class); private final LogFeature logFeature; private final GuildService guildService; @@ -47,6 +50,7 @@ public class MemberListener implements EventListener { @Override public void onGuildMemberJoin(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildMemberJoinEvent event) { if (user.getDiscordUser().isBot()) return; + log.info("User \"{}\" joined the guild \"{}\"", user.getName(), guild.getDiscordGuild().getName()); logFeature.sendLog(guild, LogType.MEMBER_JOIN, EmbedUtils.successEmbed() .setDescription(new EmbedDescriptionBuilder("Member Joined") @@ -61,6 +65,7 @@ public class MemberListener implements EventListener { @Override public void onGuildMemberLeave(@NonNull BatGuild guild, BatUser user, @NonNull GuildMemberRemoveEvent event) { if (user.getDiscordUser().isBot()) return; + log.info("User \"{}\" left the guild \"{}\"", user.getName(), guild.getDiscordGuild().getName()); logFeature.sendLog(guild, LogType.MEMBER_LEAVE, EmbedUtils.errorEmbed() .setDescription(new EmbedDescriptionBuilder("Member Left") @@ -73,6 +78,7 @@ public class MemberListener implements EventListener { @Override public void onGuildMemberUpdateNickname(@NonNull BatGuild guild, @NonNull BatUser user, String oldName, String newName, @NonNull GuildMemberUpdateNicknameEvent event) { if (user.getDiscordUser().isBot()) return; + log.info("User \"{}\" changed their nickname from \"{}\" to \"{}\" in the guild \"{}\"", user.getName(), oldName, newName, guild.getDiscordGuild().getName()); logFeature.sendLog(guild, LogType.MEMBER_NICKNAME_UPDATE, EmbedUtils.genericEmbed() .setDescription(new EmbedDescriptionBuilder("Member Nickname Updated") @@ -86,6 +92,8 @@ public class MemberListener implements EventListener { @Override public void onUserUpdateGlobalName(@NonNull BatUser user, String oldName, String newName, @NonNull UserUpdateGlobalNameEvent event) { if (user.getDiscordUser().isBot()) return; + log.info("User \"{}\" changed their global name from \"{}\" to \"{}\"", user.getName(), oldName, newName); + for (Guild guild : DiscordService.JDA.getGuilds()) { BatGuild batGuild = guildService.getGuild(guild.getId()); if (batGuild == null) continue; @@ -104,6 +112,8 @@ public class MemberListener implements EventListener { @Override public void onUserUpdateName(@NonNull BatUser user, String oldName, String newName, @NonNull UserUpdateNameEvent event) { if (user.getDiscordUser().isBot()) return; + log.info("User \"{}\" changed their username from \"{}\" to \"{}\"", user.getName(), oldName, newName); + for (Guild guild : DiscordService.JDA.getGuilds()) { BatGuild batGuild = guildService.getGuild(guild.getId()); if (batGuild == null) continue; @@ -122,6 +132,8 @@ public class MemberListener implements EventListener { @Override public void onUserUpdateAvatar(@NonNull BatUser user, String oldAvatarUrl, String newAvatarUrl, @NonNull UserUpdateAvatarEvent event) { if (user.getDiscordUser().isBot()) return; + log.info("User \"{}\" changed their avatar to \"{}\"", user.getName(), newAvatarUrl); + for (Guild guild : DiscordService.JDA.getGuilds()) { BatGuild batGuild = guildService.getGuild(guild.getId()); if (batGuild == null) continue; @@ -140,6 +152,7 @@ public class MemberListener implements EventListener { @Override public void onGuildMemberRoleAdd(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull List rolesAdded, @NonNull GuildMemberRoleAddEvent event) { if (user.getDiscordUser().isBot()) return; + log.info("User \"{}\" was given {} roles in the guild \"{}\"", user.getName(), rolesAdded.size(), guild.getDiscordGuild().getName()); StringBuilder roles = new StringBuilder(); for (Role role : rolesAdded) { @@ -158,6 +171,7 @@ public class MemberListener implements EventListener { @Override public void onGuildMemberRoleRemove(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull List rolesAdded, @NonNull GuildMemberRoleRemoveEvent event) { if (user.getDiscordUser().isBot()) return; + log.info("User \"{}\" had {} roles removed in the guild \"{}\"", user.getName(), rolesAdded.size(), guild.getDiscordGuild().getName()); StringBuilder roles = new StringBuilder(); for (Role role : rolesAdded) { @@ -176,6 +190,7 @@ public class MemberListener implements EventListener { @Override public void onGuildMemberBan(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildBanEvent event) { if (user.getDiscordUser().isBot()) return; + log.info("User \"{}\" was banned from the guild \"{}\"", user.getName(), guild.getDiscordGuild().getName()); logFeature.sendLog(guild, LogType.MEMBER_BAN, EmbedUtils.errorEmbed() .setDescription(new EmbedDescriptionBuilder("Member Banned") @@ -187,6 +202,7 @@ public class MemberListener implements EventListener { @Override public void onGuildMemberUnban(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildUnbanEvent event) { if (user.getDiscordUser().isBot()) return; + log.info("User \"{}\" was unbanned from the guild \"{}\"", user.getName(), guild.getDiscordGuild().getName()); logFeature.sendLog(guild, LogType.MEMBER_UNBAN, EmbedUtils.successEmbed() .setDescription(new EmbedDescriptionBuilder("Member Unbanned") @@ -199,6 +215,7 @@ public class MemberListener implements EventListener { public void onGuildMemberTimeout(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildMemberUpdateTimeOutEvent event) { OffsetDateTime timeoutEnd = event.getNewTimeOutEnd(); if (user.getDiscordUser().isBot() || timeoutEnd == null) return; + log.info("User \"{}\" was timed out until \"{}\"", user.getName(), timeoutEnd); long seconds = timeoutEnd.toInstant().getEpochSecond(); logFeature.sendLog(guild, LogType.MEMBER_TIMEOUT, EmbedUtils.errorEmbed() diff --git a/src/main/java/cc/fascinated/bat/features/logging/listeners/MessageListener.java b/src/main/java/cc/fascinated/bat/features/logging/listeners/MessageListener.java index b8cdbe4..f305282 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/listeners/MessageListener.java +++ b/src/main/java/cc/fascinated/bat/features/logging/listeners/MessageListener.java @@ -9,6 +9,7 @@ import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatUser; import cc.fascinated.bat.model.DiscordMessage; import lombok.NonNull; +import lombok.extern.log4j.Log4j2; import net.dv8tion.jda.api.events.message.MessageDeleteEvent; import net.dv8tion.jda.api.events.message.MessageUpdateEvent; import org.springframework.beans.factory.annotation.Autowired; @@ -19,6 +20,7 @@ import org.springframework.stereotype.Component; * @author Fascinated (fascinated7) */ @Component +@Log4j2 public class MessageListener implements EventListener { private final LogFeature logFeature; @@ -30,6 +32,7 @@ public class MessageListener implements EventListener { @Override public void onGuildMessageDelete(@NonNull BatGuild guild, BatUser user, DiscordMessage message, @NonNull MessageDeleteEvent event) { if (user.getDiscordUser().isBot() || message.getAuthor().isBot()) return; + log.info("User {} deleted a message in guild {}", user.getDiscordUser().getGlobalName(), guild.getName()); logFeature.sendLog(guild, LogType.MESSAGE_DELETE, EmbedUtils.errorEmbed() .setDescription(new EmbedDescriptionBuilder("Message Deleted") @@ -44,6 +47,7 @@ public class MessageListener implements EventListener { public void onGuildMessageEdit(@NonNull BatGuild guild, @NonNull BatUser user, DiscordMessage oldMessage, @NonNull DiscordMessage newMessage, @NonNull MessageUpdateEvent event) { if (user.getDiscordUser().isBot() || newMessage.getAuthor().isBot() || oldMessage == null) return; + log.info("User {} edited a message in guild {}", user.getDiscordUser().getGlobalName(), guild.getName()); logFeature.sendLog(guild, LogType.MESSAGE_EDIT, EmbedUtils.genericEmbed() .setDescription(new EmbedDescriptionBuilder("Message Edited") diff --git a/src/main/java/cc/fascinated/bat/service/UserService.java b/src/main/java/cc/fascinated/bat/service/UserService.java index f31b61f..69331c6 100644 --- a/src/main/java/cc/fascinated/bat/service/UserService.java +++ b/src/main/java/cc/fascinated/bat/service/UserService.java @@ -92,7 +92,6 @@ public class UserService implements EventListener { @Override public void onUserUpdateGlobalName(@NonNull BatUser user, String oldName, String newName, @NonNull UserUpdateGlobalNameEvent event) { - log.info("User \"{}\" changed their name from \"{}\" to \"{}\"", user.getName(), oldName, newName); user.setGlobalName(newName); } }