impl channel create and delete logging
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 39s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 39s
This commit is contained in:
@ -8,8 +8,9 @@ import lombok.Getter;
|
||||
*/
|
||||
@AllArgsConstructor @Getter
|
||||
public enum LogCategory {
|
||||
MESSAGES("Messages"),
|
||||
MEMBER("Member");
|
||||
MESSAGE("Message"),
|
||||
MEMBER("Member"),
|
||||
CHANNEL("Channel");
|
||||
|
||||
/**
|
||||
* The name of the log category
|
||||
|
@ -14,8 +14,8 @@ public enum LogType {
|
||||
/**
|
||||
* Message Events
|
||||
*/
|
||||
MESSAGE_DELETE(LogCategory.MESSAGES, "Message Delete"),
|
||||
MESSAGE_EDIT(LogCategory.MESSAGES,"Message Edit"),
|
||||
MESSAGE_DELETE(LogCategory.MESSAGE, "Message Delete"),
|
||||
MESSAGE_EDIT(LogCategory.MESSAGE,"Message Edit"),
|
||||
|
||||
/**
|
||||
* Member Events
|
||||
@ -23,7 +23,13 @@ public enum LogType {
|
||||
MEMBER_JOIN(LogCategory.MEMBER, "Member Join"),
|
||||
MEMBER_LEAVE(LogCategory.MEMBER, "Member Leave"),
|
||||
MEMBER_NICKNAME_UPDATE(LogCategory.MEMBER, "Member Nickname Update"),
|
||||
MEMBER_ROLE_UPDATE(LogCategory.MEMBER, "Member Role Update");
|
||||
MEMBER_ROLE_UPDATE(LogCategory.MEMBER, "Member Role Update"),
|
||||
|
||||
/**
|
||||
* Channel Events
|
||||
*/
|
||||
CHANNEL_CREATE(LogCategory.CHANNEL, "Channel Create"),
|
||||
CHANNEL_DELETE(LogCategory.CHANNEL, "Channel Delete");
|
||||
|
||||
/**
|
||||
* The category of the log type
|
||||
|
@ -0,0 +1,55 @@
|
||||
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.event.EventListener;
|
||||
import cc.fascinated.bat.features.logging.LogFeature;
|
||||
import cc.fascinated.bat.features.logging.LogType;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
public class ChannelListener implements EventListener {
|
||||
private final LogFeature logFeature;
|
||||
|
||||
@Autowired
|
||||
public ChannelListener(@NonNull ApplicationContext context) {
|
||||
this.logFeature = context.getBean(LogFeature.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChannelCreate(@NonNull BatGuild guild, @NonNull ChannelCreateEvent event) {
|
||||
logFeature.sendLog(guild, LogType.CHANNEL_CREATE, EmbedUtils.successEmbed()
|
||||
.setDescription(new EmbedDescriptionBuilder("Channel Created")
|
||||
.appendLine("Channel: %s".formatted(event.getChannel().getAsMention()), true)
|
||||
.appendLine("Name: %s".formatted(event.getChannel().getName()), true)
|
||||
.appendLine("Type: %s".formatted(EnumUtils.getEnumName(event.getChannel().getType())), true)
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChannelDelete(@NonNull BatGuild guild, @NonNull ChannelDeleteEvent event) {
|
||||
ChannelUnion channel = event.getChannel();
|
||||
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Channel Deleted")
|
||||
.appendLine("Channel: %s".formatted(channel.getAsMention()), true)
|
||||
.appendLine("Name: %s".formatted(channel.getName()), true);
|
||||
if (channel.getType().isMessage()) {
|
||||
TextChannel textChannel = channel.asTextChannel();
|
||||
description.appendLine("Topic: %s".formatted(textChannel.getTopic()), true);
|
||||
}
|
||||
description.appendLine("Type: %s".formatted(EnumUtils.getEnumName(channel.getType())), true);
|
||||
logFeature.sendLog(guild, LogType.CHANNEL_DELETE, EmbedUtils.errorEmbed().setDescription(description.build()).build());
|
||||
}
|
||||
}
|
@ -51,6 +51,7 @@ public class MessageListener implements EventListener {
|
||||
.appendLine("Channel: %s".formatted(newMessage.getChannel().getAsMention()), true)
|
||||
.appendLine("Old Content: %s".formatted(logFeature.formatContent(oldMessage.getContent())), true)
|
||||
.appendLine("New Content: %s".formatted(logFeature.formatContent(newMessage.getContent())), true)
|
||||
.appendLine("*[Jump to Message](%s)*".formatted(newMessage.getMessageUrl()), false)
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
|
Reference in New Issue
Block a user