From 4148f6e05fc98e1d52de7fc846904f46d6726cf5 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 4 Jul 2024 06:41:17 +0100 Subject: [PATCH] check if the member is still boosting and update log set messages --- .../logging/command/SetSubCommand.java | 5 +- .../logging/listeners/MemberListener.java | 53 ++++++++++++------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/features/logging/command/SetSubCommand.java b/src/main/java/cc/fascinated/bat/features/logging/command/SetSubCommand.java index d592c3d..336a9cc 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/command/SetSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/logging/command/SetSubCommand.java @@ -51,7 +51,7 @@ public class SetSubCommand extends BatSubCommand { profile.setLogChannel(logType, targetChannel); } EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Log Channel"); - description.appendLine("Successfully set the log channel for all log types to %s".formatted(targetChannel.getAsMention()), false); + description.appendLine("Successfully set the log channel for %s log events to %s".formatted(LogType.values().length, targetChannel.getAsMention()), false); description.emptyLine(); description.appendLine("*To view the current log channels, use `/logs list`*", false); event.replyEmbeds(EmbedUtils.successEmbed().setDescription(description.build()).build()).queue(); @@ -63,7 +63,8 @@ public class SetSubCommand extends BatSubCommand { if (logCategory != null) { List category = LogType.getLogTypesByCategory(type); EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Log Channel"); - description.appendLine("Successfully set the log channel for the `%s` category to %s".formatted( + description.appendLine("Successfully set the log channel for %s %s log events to %s".formatted( + category.size(), logCategory.getName(), targetChannel.getAsMention() ), false); 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 fc38f2b..68fb446 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 @@ -49,7 +49,7 @@ public class MemberListener implements EventListener { @Override public void onGuildMemberJoin(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildMemberJoinEvent event) { - if (user.getDiscordUser().isBot()) return; + if (user.getDiscordUser().isBot()) log.info("User \"{}\" joined the guild \"{}\"", user.getName(), guild.getDiscordGuild().getName()); logFeature.sendLog(guild, LogType.MEMBER_JOIN, EmbedUtils.successEmbed() @@ -77,7 +77,9 @@ 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; + 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() @@ -91,7 +93,9 @@ public class MemberListener implements EventListener { @Override public void onUserUpdateGlobalName(@NonNull BatUser user, String oldName, String newName, @NonNull UserUpdateGlobalNameEvent event) { - if (user.getDiscordUser().isBot()) return; + if (user.getDiscordUser().isBot()) { + return; + } log.info("User \"{}\" changed their global name from \"{}\" to \"{}\"", user.getName(), oldName, newName); for (Guild guild : DiscordService.JDA.getGuilds()) { @@ -111,7 +115,9 @@ public class MemberListener implements EventListener { @Override public void onUserUpdateName(@NonNull BatUser user, String oldName, String newName, @NonNull UserUpdateNameEvent event) { - if (user.getDiscordUser().isBot()) return; + if (user.getDiscordUser().isBot()) { + return; + } log.info("User \"{}\" changed their username from \"{}\" to \"{}\"", user.getName(), oldName, newName); for (Guild guild : DiscordService.JDA.getGuilds()) { @@ -131,7 +137,9 @@ public class MemberListener implements EventListener { @Override public void onUserUpdateAvatar(@NonNull BatUser user, String oldAvatarUrl, String newAvatarUrl, @NonNull UserUpdateAvatarEvent event) { - if (user.getDiscordUser().isBot()) return; + if (user.getDiscordUser().isBot()) { + return; + } log.info("User \"{}\" changed their avatar to \"{}\"", user.getName(), newAvatarUrl); for (Guild guild : DiscordService.JDA.getGuilds()) { @@ -151,7 +159,9 @@ 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; + 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(); @@ -170,7 +180,9 @@ 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; + 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(); @@ -189,7 +201,9 @@ public class MemberListener implements EventListener { @Override public void onGuildMemberBan(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildBanEvent event) { - if (user.getDiscordUser().isBot()) return; + 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() @@ -201,7 +215,9 @@ public class MemberListener implements EventListener { @Override public void onGuildMemberUnban(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildUnbanEvent event) { - if (user.getDiscordUser().isBot()) return; + 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() @@ -230,17 +246,14 @@ public class MemberListener implements EventListener { @Override public void onGuildMemberBoostAdd(@NonNull BatGuild guild, @NonNull BatUser user, OffsetDateTime oldBoostTime, @NonNull OffsetDateTime newBoostTime, @NonNull GuildMemberUpdateBoostTimeEvent event) { - if (user.getDiscordUser().isBot()) return; + if (user.getDiscordUser().isBot()) { + return; + } log.info("User \"{}\" boosted the guild \"{}\" until \"{}\"", user.getName(), guild.getDiscordGuild().getName(), newBoostTime); - oldBoostTime = oldBoostTime == null ? OffsetDateTime.now() : oldBoostTime; - long boostAmount = ChronoUnit.MONTHS.between(oldBoostTime, newBoostTime); - long seconds = newBoostTime.toInstant().getEpochSecond(); 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 End: ".formatted(seconds), true) .build()) .build()); } @@ -248,15 +261,17 @@ public class MemberListener implements EventListener { @Override public void onGuildMemberBoostRemove(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull OffsetDateTime oldBoostTime, OffsetDateTime newBoostTime, @NonNull GuildMemberUpdateBoostTimeEvent event) { - if (user.getDiscordUser().isBot()) return; + if (user.getDiscordUser().isBot()) { + return; + } + if (event.getMember().isBoosting()) { // A boost was removed, but the user is still boosting + return; + } log.info("User \"{}\" boost expired in the guild \"{}\"", user.getName(), guild.getDiscordGuild().getName()); - newBoostTime = newBoostTime == null ? OffsetDateTime.now() : newBoostTime; - long boostAmount = ChronoUnit.MONTHS.between(newBoostTime, oldBoostTime); 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) .build()) .build()); }