update log messages and add bitrate and topic change logs
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 42s

This commit is contained in:
Lee 2024-07-04 10:22:19 +01:00
parent 06ded19492
commit 626a9bd77d
6 changed files with 102 additions and 31 deletions

View File

@ -12,7 +12,9 @@ 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.ChannelUpdateBitrateEvent;
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNameEvent;
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateTopicEvent;
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;
@ -156,6 +158,12 @@ public interface EventListener {
default void onRoleUpdateName(@NonNull BatGuild guild, @NonNull RoleUpdateNameEvent event) {
}
default void onChannelUpdateTopic(@NonNull BatGuild guild, @NonNull ChannelUpdateTopicEvent event) {
}
default void onChannelUpdateBitrate(@NonNull BatGuild guild, @NonNull ChannelUpdateBitrateEvent event) {
}
default void onShutdown() {
}
}

View File

@ -42,8 +42,8 @@ public enum LogType {
CHANNEL_DELETE(LogCategory.CHANNEL),
VOICE_CHANNEL_JOIN(LogCategory.CHANNEL),
VOICE_CHANNEL_LEAVE(LogCategory.CHANNEL),
CHANNEL_UPDATE_NAME(LogCategory.CHANNEL),
CHANNEL_PERMISSIONS_UPDATED(LogCategory.CHANNEL),
CHANNEL_CONFIGURATION(LogCategory.CHANNEL),
/**
* Guild Events
@ -55,7 +55,7 @@ public enum LogType {
ROLE_PERMISSIONS_UPDATED(LogCategory.GUILD),
ROLE_CREATE(LogCategory.GUILD),
ROLE_DELETE(LogCategory.GUILD),
ROLE_NAME_UPDATED(LogCategory.GUILD);
ROLE_CONFIGURATION(LogCategory.GUILD);
/**
* The category of the log type

View File

@ -3,6 +3,7 @@ package cc.fascinated.bat.features.logging.listeners;
import cc.fascinated.bat.common.EmbedDescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.EnumUtils;
import cc.fascinated.bat.common.NumberFormatter;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.features.logging.LogFeature;
import cc.fascinated.bat.features.logging.LogType;
@ -22,7 +23,9 @@ 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.ChannelUpdateBitrateEvent;
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNameEvent;
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateTopicEvent;
import net.dv8tion.jda.api.events.guild.override.GenericPermissionOverrideEvent;
import net.dv8tion.jda.api.events.guild.voice.GenericGuildVoiceEvent;
import org.springframework.beans.factory.annotation.Autowired;
@ -31,6 +34,7 @@ import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* @author Fascinated (fascinated7)
@ -93,23 +97,6 @@ public class ChannelListener implements EventListener {
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 to {} in guild \"{}\"", type, event.getNewValue(), event.getOldValue(), guild.getName());
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("%s Name Updated".formatted(type));
if (channel.getType() == ChannelType.TEXT || channel.getType() == ChannelType.VOICE) {
description.appendLine("Channel: %s".formatted(event.getChannel().getAsMention()), true);
}
description.appendLine("Old Name: `%s`".formatted(event.getOldValue()), true);
description.appendLine("New Name: `%s`".formatted(event.getNewValue()), true);
logFeature.sendLog(guild, LogType.CHANNEL_UPDATE_NAME, EmbedUtils.successEmbed()
.setDescription(description
.build())
.build());
}
@Override
public void onGuildVoiceUpdate(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GenericGuildVoiceEvent event) {
AudioChannelUnion channel = event.getVoiceState().getChannel();
@ -173,6 +160,58 @@ public class ChannelListener implements EventListener {
.setDescription(description.build()).build());
}
@Override
public void onChannelUpdateTopic(@NonNull BatGuild guild, @NonNull ChannelUpdateTopicEvent event) {
String oldValue = event.getOldValue();
String newValue = event.getNewValue();
ChannelUnion channel = event.getChannel();
String type = formatChannelType(channel);
log.info("{} \"{}\" topic was updated to {} in guild \"{}\"", type, newValue, oldValue, guild.getName());
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("%s Topic Updated".formatted(type));
description.appendLine("Channel: %s".formatted(event.getChannel().getAsMention()), true);
description.appendLine("Topic: `%s` -> `%s`".formatted(oldValue, newValue), true);
logFeature.sendLog(guild, LogType.CHANNEL_CONFIGURATION, EmbedUtils.successEmbed()
.setDescription(description.build())
.build());
}
@Override
public void onChannelUpdateBitrate(@NonNull BatGuild guild, @NonNull ChannelUpdateBitrateEvent event) {
if (Objects.equals(event.getOldValue(), event.getNewValue()) || event.getOldValue() == null || event.getNewValue() == null) {
return;
}
VoiceChannel channel = event.getChannel().asVoiceChannel();
log.info("Voice channel \"{}\" bitrate was updated to {} in guild \"{}\"", channel.getName(), event.getNewValue(), guild.getName());
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Voice Channel Updated")
.appendLine("Channel: %s".formatted(channel.getAsMention()), true)
.appendLine("Bitrate: `%s` -> `%s`".formatted(NumberFormatter.format(event.getOldValue()),
NumberFormatter.format(event.getNewValue())), true);
logFeature.sendLog(guild, LogType.CHANNEL_CONFIGURATION, EmbedUtils.successEmbed()
.setDescription(description.build())
.build());
}
@Override
public void onChannelUpdateName(@NonNull BatGuild guild, @NonNull ChannelUpdateNameEvent event) {
String oldValue = event.getOldValue();
String newValue = event.getNewValue();
ChannelUnion channel = event.getChannel();
String type = formatChannelType(channel);
log.info("{} \"{}\" name was updated to {} in guild \"{}\"", type, newValue, oldValue, guild.getName());
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("%s Name Updated".formatted(type));
if (channel.getType() == ChannelType.TEXT || channel.getType() == ChannelType.VOICE) {
description.appendLine("Channel: %s".formatted(event.getChannel().getAsMention()), true);
}
description.appendLine("Name: `%s` -> `%s`".formatted(oldValue, newValue), true);
logFeature.sendLog(guild, LogType.CHANNEL_CONFIGURATION, EmbedUtils.successEmbed()
.setDescription(description
.build())
.build());
}
/**
* Formats the channel type
*

View File

@ -87,8 +87,7 @@ public class GuildListener implements EventListener {
logFeature.sendLog(guild, LogType.EMOJI_NAME_UPDATED, 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("Name: `%s` -> `%s`".formatted(oldName, newName), true)
.build())
.build());
}
@ -154,12 +153,13 @@ public class GuildListener implements EventListener {
@Override
public void onRoleUpdateName(@NonNull BatGuild guild, @NonNull RoleUpdateNameEvent event) {
log.info("Role \"{}\" was renamed to \"{}\" in guild \"{}\"", event.getOldName(), event.getNewName(), guild.getName());
logFeature.sendLog(guild, LogType.ROLE_NAME_UPDATED, EmbedUtils.successEmbed()
String oldName = event.getOldName();
String newName = event.getNewName();
log.info("Role \"{}\" was renamed to \"{}\" in guild \"{}\"", oldName, newName, guild.getName());
logFeature.sendLog(guild, LogType.ROLE_CONFIGURATION, EmbedUtils.successEmbed()
.setDescription(new EmbedDescriptionBuilder("Role Renamed")
.appendLine("Role: %s".formatted(event.getRole().getAsMention()), true)
.appendLine("Old Name: `%s`".formatted(event.getOldName()), true)
.appendLine("New Name: `%s`".formatted(event.getNewName()), true)
.appendLine("Name: `%s` -> `%s`".formatted(oldName, newName), true)
.build())
.build());
}

View File

@ -85,8 +85,10 @@ public class MemberListener implements EventListener {
logFeature.sendLog(guild, LogType.MEMBER_NICKNAME_UPDATE, EmbedUtils.genericEmbed()
.setDescription(new EmbedDescriptionBuilder("Member Nickname Updated")
.appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true)
.appendLine("Old Nickname: `%s`".formatted(oldName == null ? user.getName() : oldName), true)
.appendLine("New Nickname: `%s`".formatted(newName == null ? "Removed Nickname" : newName), true)
.appendLine("Nickname: `%s` -> `%s`".formatted(
oldName == null ? user.getName() : oldName,
newName == null ? user.getName() : newName
), true)
.build())
.build());
}
@ -106,8 +108,10 @@ public class MemberListener implements EventListener {
logFeature.sendLog(batGuild, LogType.MEMBER_GLOBAL_NAME_UPDATE, EmbedUtils.genericEmbed()
.setDescription(new EmbedDescriptionBuilder("Member Name Updated")
.appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true)
.appendLine("Old Name: `%s`".formatted(oldName == null ? user.getName() : oldName), true)
.appendLine("New Name: `%s`".formatted(newName == null ? "Removed Name" : newName), true)
.appendLine("Name: `%s` -> `%s`".formatted(
oldName == null ? user.getName() : oldName,
newName == null ? user.getName() : newName
), true)
.build())
.build());
}
@ -128,8 +132,7 @@ public class MemberListener implements EventListener {
logFeature.sendLog(batGuild, LogType.MEMBER_USERNAME_UPDATE, EmbedUtils.genericEmbed()
.setDescription(new EmbedDescriptionBuilder("Member Username Updated")
.appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true)
.appendLine("Old Username: `%s`".formatted(oldName), true)
.appendLine("New Username: `%s`".formatted(newName), true)
.appendLine("Username: `%s` -> `%s`".formatted(oldName, newName), true)
.build())
.build());
}

View File

@ -10,7 +10,10 @@ 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.ChannelUpdateBitrateEvent;
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNSFWEvent;
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNameEvent;
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateTopicEvent;
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;
@ -441,4 +444,22 @@ public class EventService extends ListenerAdapter {
listener.onRoleUpdateName(guild, event);
}
}
@Override
public void onChannelUpdateTopic(@NotNull ChannelUpdateTopicEvent event) {
BatGuild guild = guildService.getGuild(event.getGuild().getId());
for (EventListener listener : LISTENERS) {
listener.onChannelUpdateTopic(guild, event);
}
}
@Override
public void onChannelUpdateBitrate(@NotNull ChannelUpdateBitrateEvent event) {
BatGuild guild = guildService.getGuild(event.getGuild().getId());
for (EventListener listener : LISTENERS) {
listener.onChannelUpdateBitrate(guild, event);
}
}
}