switch voice channel log
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m15s

This commit is contained in:
Lee 2024-07-05 21:38:21 +01:00
parent fdd36d4385
commit a7af4108c6
3 changed files with 15 additions and 1 deletions

@ -58,7 +58,7 @@ public class LogFeature extends Feature {
if (content == null) { if (content == null) {
return "No content"; return "No content";
} }
if (content.contains("`")) { // Workaround for markdown formatting if (content.contains("`")) { // Workaround for Markdown formatting
content = content.replace("`", "'"); content = content.replace("`", "'");
} }
// More than 512 characters or is more than 4 lines // More than 512 characters or is more than 4 lines

@ -42,6 +42,7 @@ public enum LogType {
CHANNEL_DELETE(LogCategory.CHANNEL), CHANNEL_DELETE(LogCategory.CHANNEL),
VOICE_CHANNEL_JOIN(LogCategory.CHANNEL), VOICE_CHANNEL_JOIN(LogCategory.CHANNEL),
VOICE_CHANNEL_LEAVE(LogCategory.CHANNEL), VOICE_CHANNEL_LEAVE(LogCategory.CHANNEL),
VOICE_CHANNEL_SWITCH(LogCategory.CHANNEL),
CHANNEL_CONFIGURATION(LogCategory.CHANNEL), CHANNEL_CONFIGURATION(LogCategory.CHANNEL),
THREAD_ARCHIVE(LogCategory.CHANNEL), THREAD_ARCHIVE(LogCategory.CHANNEL),

@ -108,6 +108,7 @@ public class ChannelListener implements EventListener {
@Override @Override
public void onGuildVoiceUpdate(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GenericGuildVoiceEvent event) { public void onGuildVoiceUpdate(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GenericGuildVoiceEvent event) {
AudioChannelUnion channel = event.getVoiceState().getChannel(); AudioChannelUnion channel = event.getVoiceState().getChannel();
VoiceChannel oldChannel = lastVoiceChannel.get(user);
if (channel != null) { if (channel != null) {
VoiceChannel voiceChannel = channel.asVoiceChannel(); VoiceChannel voiceChannel = channel.asVoiceChannel();
lastVoiceChannel.put(user, voiceChannel); lastVoiceChannel.put(user, voiceChannel);
@ -120,6 +121,18 @@ public class ChannelListener implements EventListener {
if (!joined) { if (!joined) {
lastVoiceChannel.remove(user); lastVoiceChannel.remove(user);
} }
// User switched channels
if (oldChannel != null && !oldChannel.equals(voiceChannel)) {
log.info("User \"{}\" switched from voice channel \"{}\" to \"{}\" in guild \"{}\"", user.getName(), oldChannel.getName(), voiceChannel.getName(), guild.getName());
String switchDescription = new EmbedDescriptionBuilder("Member Switched Voice Channel")
.appendLine("User: %s".formatted(user.getDiscordUser().getAsMention()), true)
.appendLine("Channel: %s -> %s".formatted(oldChannel.getAsMention(), voiceChannel.getAsMention()), true)
.build();
logFeature.sendLog(guild, LogType.VOICE_CHANNEL_SWITCH, EmbedUtils.successEmbed().setDescription(switchDescription).build());
return;
}
log.info("User \"{}\" {} voice channel \"{}\" in guild \"{}\"", user.getName(), joined ? "joined" : "left", voiceChannel.getName(), guild.getName()); log.info("User \"{}\" {} voice channel \"{}\" in guild \"{}\"", user.getName(), joined ? "joined" : "left", voiceChannel.getName(), guild.getName());
String description = new EmbedDescriptionBuilder("Member %s Voice Channel".formatted(joined ? "Joined" : "Left")) String description = new EmbedDescriptionBuilder("Member %s Voice Channel".formatted(joined ? "Joined" : "Left"))
.appendLine("User: %s".formatted(user.getDiscordUser().getAsMention()), true) .appendLine("User: %s".formatted(user.getDiscordUser().getAsMention()), true)