check if the member is still boosting and update log set messages

This commit is contained in:
Lee 2024-07-04 06:41:17 +01:00
parent 0120fa24ef
commit 4148f6e05f
2 changed files with 37 additions and 21 deletions

@ -51,7 +51,7 @@ public class SetSubCommand extends BatSubCommand {
profile.setLogChannel(logType, targetChannel); profile.setLogChannel(logType, targetChannel);
} }
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Log Channel"); 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.emptyLine();
description.appendLine("*To view the current log channels, use `/logs list`*", false); description.appendLine("*To view the current log channels, use `/logs list`*", false);
event.replyEmbeds(EmbedUtils.successEmbed().setDescription(description.build()).build()).queue(); event.replyEmbeds(EmbedUtils.successEmbed().setDescription(description.build()).build()).queue();
@ -63,7 +63,8 @@ public class SetSubCommand extends BatSubCommand {
if (logCategory != null) { if (logCategory != null) {
List<LogType> category = LogType.getLogTypesByCategory(type); List<LogType> category = LogType.getLogTypesByCategory(type);
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Log Channel"); 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(), logCategory.getName(),
targetChannel.getAsMention() targetChannel.getAsMention()
), false); ), false);

@ -49,7 +49,7 @@ public class MemberListener implements EventListener {
@Override @Override
public void onGuildMemberJoin(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildMemberJoinEvent event) { 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()); log.info("User \"{}\" joined the guild \"{}\"", user.getName(), guild.getDiscordGuild().getName());
logFeature.sendLog(guild, LogType.MEMBER_JOIN, EmbedUtils.successEmbed() logFeature.sendLog(guild, LogType.MEMBER_JOIN, EmbedUtils.successEmbed()
@ -77,7 +77,9 @@ public class MemberListener implements EventListener {
@Override @Override
public void onGuildMemberUpdateNickname(@NonNull BatGuild guild, @NonNull BatUser user, String oldName, String newName, @NonNull GuildMemberUpdateNicknameEvent event) { 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()); 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() logFeature.sendLog(guild, LogType.MEMBER_NICKNAME_UPDATE, EmbedUtils.genericEmbed()
@ -91,7 +93,9 @@ public class MemberListener implements EventListener {
@Override @Override
public void onUserUpdateGlobalName(@NonNull BatUser user, String oldName, String newName, @NonNull UserUpdateGlobalNameEvent event) { 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); log.info("User \"{}\" changed their global name from \"{}\" to \"{}\"", user.getName(), oldName, newName);
for (Guild guild : DiscordService.JDA.getGuilds()) { for (Guild guild : DiscordService.JDA.getGuilds()) {
@ -111,7 +115,9 @@ public class MemberListener implements EventListener {
@Override @Override
public void onUserUpdateName(@NonNull BatUser user, String oldName, String newName, @NonNull UserUpdateNameEvent event) { 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); log.info("User \"{}\" changed their username from \"{}\" to \"{}\"", user.getName(), oldName, newName);
for (Guild guild : DiscordService.JDA.getGuilds()) { for (Guild guild : DiscordService.JDA.getGuilds()) {
@ -131,7 +137,9 @@ public class MemberListener implements EventListener {
@Override @Override
public void onUserUpdateAvatar(@NonNull BatUser user, String oldAvatarUrl, String newAvatarUrl, @NonNull UserUpdateAvatarEvent event) { 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); log.info("User \"{}\" changed their avatar to \"{}\"", user.getName(), newAvatarUrl);
for (Guild guild : DiscordService.JDA.getGuilds()) { for (Guild guild : DiscordService.JDA.getGuilds()) {
@ -151,7 +159,9 @@ public class MemberListener implements EventListener {
@Override @Override
public void onGuildMemberRoleAdd(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull List<Role> rolesAdded, @NonNull GuildMemberRoleAddEvent event) { public void onGuildMemberRoleAdd(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull List<Role> 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()); log.info("User \"{}\" was given {} roles in the guild \"{}\"", user.getName(), rolesAdded.size(), guild.getDiscordGuild().getName());
StringBuilder roles = new StringBuilder(); StringBuilder roles = new StringBuilder();
@ -170,7 +180,9 @@ public class MemberListener implements EventListener {
@Override @Override
public void onGuildMemberRoleRemove(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull List<Role> rolesAdded, @NonNull GuildMemberRoleRemoveEvent event) { public void onGuildMemberRoleRemove(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull List<Role> 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()); log.info("User \"{}\" had {} roles removed in the guild \"{}\"", user.getName(), rolesAdded.size(), guild.getDiscordGuild().getName());
StringBuilder roles = new StringBuilder(); StringBuilder roles = new StringBuilder();
@ -189,7 +201,9 @@ public class MemberListener implements EventListener {
@Override @Override
public void onGuildMemberBan(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildBanEvent event) { 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()); log.info("User \"{}\" was banned from the guild \"{}\"", user.getName(), guild.getDiscordGuild().getName());
logFeature.sendLog(guild, LogType.MEMBER_BAN, EmbedUtils.errorEmbed() logFeature.sendLog(guild, LogType.MEMBER_BAN, EmbedUtils.errorEmbed()
@ -201,7 +215,9 @@ public class MemberListener implements EventListener {
@Override @Override
public void onGuildMemberUnban(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildUnbanEvent event) { 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()); log.info("User \"{}\" was unbanned from the guild \"{}\"", user.getName(), guild.getDiscordGuild().getName());
logFeature.sendLog(guild, LogType.MEMBER_UNBAN, EmbedUtils.successEmbed() logFeature.sendLog(guild, LogType.MEMBER_UNBAN, EmbedUtils.successEmbed()
@ -230,17 +246,14 @@ public class MemberListener implements EventListener {
@Override @Override
public void onGuildMemberBoostAdd(@NonNull BatGuild guild, @NonNull BatUser user, OffsetDateTime oldBoostTime, public void onGuildMemberBoostAdd(@NonNull BatGuild guild, @NonNull BatUser user, OffsetDateTime oldBoostTime,
@NonNull OffsetDateTime newBoostTime, @NonNull GuildMemberUpdateBoostTimeEvent event) { @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); 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() logFeature.sendLog(guild, LogType.MEMBER_BOOSTED, EmbedUtils.successEmbed()
.setDescription(new EmbedDescriptionBuilder("Member Boosted") .setDescription(new EmbedDescriptionBuilder("Member Boosted")
.appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true) .appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true)
.appendLine("Boost Months: `%s`".formatted(boostAmount), true)
.appendLine("Boost End: <t:%s>".formatted(seconds), true)
.build()) .build())
.build()); .build());
} }
@ -248,15 +261,17 @@ public class MemberListener implements EventListener {
@Override @Override
public void onGuildMemberBoostRemove(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull OffsetDateTime oldBoostTime, public void onGuildMemberBoostRemove(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull OffsetDateTime oldBoostTime,
OffsetDateTime newBoostTime, @NonNull GuildMemberUpdateBoostTimeEvent event) { 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()); 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() logFeature.sendLog(guild, LogType.MEMBER_BOOST_EXPIRE, EmbedUtils.errorEmbed()
.setDescription(new EmbedDescriptionBuilder("Member Boost Expired") .setDescription(new EmbedDescriptionBuilder("Member Boost Expired")
.appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true) .appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true)
.appendLine("Boosts Removed: `%s`".formatted(boostAmount), true)
.build()) .build())
.build()); .build());
} }