add channel permission update logging
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 41s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 41s
This commit is contained in:
parent
a0e0b82f40
commit
dbe6fb4762
@ -27,6 +27,7 @@ import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent;
|
|||||||
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateBoostTimeEvent;
|
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateBoostTimeEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateNicknameEvent;
|
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateNicknameEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateTimeOutEvent;
|
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateTimeOutEvent;
|
||||||
|
import net.dv8tion.jda.api.events.guild.override.GenericPermissionOverrideEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.voice.GenericGuildVoiceEvent;
|
import net.dv8tion.jda.api.events.guild.voice.GenericGuildVoiceEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||||
@ -136,6 +137,9 @@ public interface EventListener {
|
|||||||
default void onChannelUpdateName(@NonNull BatGuild guild, @NonNull ChannelUpdateNameEvent event) {
|
default void onChannelUpdateName(@NonNull BatGuild guild, @NonNull ChannelUpdateNameEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default void onPermissionOverride(@NonNull BatGuild guild, @NonNull GenericPermissionOverrideEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
default void onShutdown() {
|
default void onShutdown() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ public enum LogType {
|
|||||||
VOICE_CHANNEL_JOIN(LogCategory.CHANNEL),
|
VOICE_CHANNEL_JOIN(LogCategory.CHANNEL),
|
||||||
VOICE_CHANNEL_LEAVE(LogCategory.CHANNEL),
|
VOICE_CHANNEL_LEAVE(LogCategory.CHANNEL),
|
||||||
CHANNEL_UPDATE_NAME(LogCategory.CHANNEL),
|
CHANNEL_UPDATE_NAME(LogCategory.CHANNEL),
|
||||||
|
CHANNEL_PERMISSIONS_UPDATED(LogCategory.CHANNEL),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guild Events
|
* Guild Events
|
||||||
|
@ -13,6 +13,7 @@ import cc.fascinated.bat.service.UserService;
|
|||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import net.dv8tion.jda.api.Permission;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||||
@ -22,6 +23,7 @@ import net.dv8tion.jda.api.entities.channel.unions.ChannelUnion;
|
|||||||
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent;
|
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent;
|
||||||
import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent;
|
import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent;
|
||||||
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNameEvent;
|
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNameEvent;
|
||||||
|
import net.dv8tion.jda.api.events.guild.override.GenericPermissionOverrideEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.voice.GenericGuildVoiceEvent;
|
import net.dv8tion.jda.api.events.guild.voice.GenericGuildVoiceEvent;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
@ -135,6 +137,42 @@ public class ChannelListener implements EventListener {
|
|||||||
logFeature.sendLog(guild, LogType.VOICE_CHANNEL_LEAVE, EmbedUtils.errorEmbed().setDescription(description).build());
|
logFeature.sendLog(guild, LogType.VOICE_CHANNEL_LEAVE, EmbedUtils.errorEmbed().setDescription(description).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPermissionOverride(@NonNull BatGuild guild, @NonNull GenericPermissionOverrideEvent event) {
|
||||||
|
log.info("Channel permissions updated for channel \"{}\" in guild \"{}\"", event.getChannel().getName(), guild.getName());
|
||||||
|
|
||||||
|
StringBuilder allowedPermissions = new StringBuilder();
|
||||||
|
for (Permission permission : event.getPermissionOverride().getAllowed()) {
|
||||||
|
allowedPermissions.append("`").append(permission.getName()).append("`, ");
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder deniedPermissions = new StringBuilder();
|
||||||
|
for (Permission permission : event.getPermissionOverride().getDenied()) {
|
||||||
|
deniedPermissions.append("`").append(permission.getName()).append("`, ");
|
||||||
|
}
|
||||||
|
|
||||||
|
String target = event.getPermissionOverride().isRoleOverride() ? event.getPermissionOverride().getRole().getAsMention()
|
||||||
|
: event.getPermissionOverride().getMember().getAsMention();
|
||||||
|
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Channel permissions updated")
|
||||||
|
.appendLine("Channel: %s".formatted(event.getChannel().getAsMention()), true)
|
||||||
|
.appendLine("%s: %s".formatted(
|
||||||
|
event.getPermissionOverride().isRoleOverride() ? "Role" : "Member",
|
||||||
|
target
|
||||||
|
), true);
|
||||||
|
|
||||||
|
if (!allowedPermissions.isEmpty()) {
|
||||||
|
description.appendLine("Allowed Permissions: %s".formatted(allowedPermissions.toString().isEmpty() ? "None"
|
||||||
|
: allowedPermissions.substring(0, allowedPermissions.length() - 2)), true);
|
||||||
|
}
|
||||||
|
if (!deniedPermissions.isEmpty()) {
|
||||||
|
description.appendLine("Denied Permissions: %s".formatted(deniedPermissions.toString().isEmpty() ? "None"
|
||||||
|
: deniedPermissions.substring(0, deniedPermissions.length() - 2)), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
logFeature.sendLog(guild, LogType.CHANNEL_PERMISSIONS_UPDATED, EmbedUtils.successEmbed()
|
||||||
|
.setDescription(description.build()).build());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the channel type
|
* Formats the channel type
|
||||||
*
|
*
|
||||||
|
@ -24,6 +24,7 @@ import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent;
|
|||||||
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateBoostTimeEvent;
|
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateBoostTimeEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateNicknameEvent;
|
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateNicknameEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateTimeOutEvent;
|
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateTimeOutEvent;
|
||||||
|
import net.dv8tion.jda.api.events.guild.override.GenericPermissionOverrideEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
|
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||||
@ -391,4 +392,13 @@ public class EventService extends ListenerAdapter {
|
|||||||
listener.onChannelUpdateName(guild, event);
|
listener.onChannelUpdateName(guild, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGenericPermissionOverride(@NotNull GenericPermissionOverrideEvent event) {
|
||||||
|
BatGuild guild = guildService.getGuild(event.getGuild().getId());
|
||||||
|
|
||||||
|
for (EventListener listener : LISTENERS) {
|
||||||
|
listener.onPermissionOverride(guild, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user