Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ MAX_SHARD_ID=<defaults-to-0>
TWILIGHT_HTTP_PROXY_URL=<defaults-to-blank>
PORT=<defaults-to-8080>
MANAGEMENT_PORT=<defaults-to-9000>
LOG_LEVEL=<defaults-to-info>
GLOBAL_LOG_LEVEL=<defaults-to-info>
APPLICATION_LOG_LEVEL=<defaults-to-info>
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2

updates:
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "weekly"

open-pull-requests-limit: 5

groups:
all-dependencies:
patterns:
- "*"
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.eggy03</groupId>
<artifactId>papertrailbot</artifactId>
<version>4.1.9</version>
<version>4.2.0</version>
<name>PaperTrail Bot</name>
<description>A simple bot for logging all server and member actions</description>
<packaging>quarkus</packaging>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.eggy03.papertrail.bot.listeners.auditlog;

import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory;
import io.github.eggy03.papertrail.bot.service.handlers.auditlog.AbstractGuildAuditLogEntryCreateEventActionTypeHandler;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
Expand All @@ -14,30 +15,30 @@
/**
* Listener responsible for receiving {@link GuildAuditLogEntryCreateEvent}
* events from JDA and delegating them to all registered
* {@link GuildAuditLogEntryCreateEventActionTypeHandler} CDI beans.
* {@link AbstractGuildAuditLogEntryCreateEventActionTypeHandler} CDI beans.
*
* <p>
* Event handlers are resolved dynamically using
* {@code Instance<GuildAuditLogEntryCreateEventActionTypeHandler>}, allowing multiple
* {@code Instance<AbstractGuildAuditLogEntryCreateEventActionTypeHandler>}, allowing multiple
* independent handler implementations to process the same audit log event.
* </p>
*
* <p>
* Each discovered handler instance will receive the event through
* {@link GuildAuditLogEntryCreateEventActionTypeHandler#handleActionType(GuildAuditLogEntryCreateEvent)}, where
* {@link AbstractGuildAuditLogEntryCreateEventActionTypeHandler#handleActionType(GuildAuditLogEntryCreateEvent)}, where
* it will process the event.
* </p>
*/
@Slf4j
@Singleton
public final class GuildAuditLogEntryEventListener extends ListenerAdapter {

private final @NonNull Instance<GuildAuditLogEntryCreateEventActionTypeHandler> handlerInstances;
private final @NonNull Instance<AbstractGuildAuditLogEntryCreateEventActionTypeHandler> handlerInstances;
private final @NonNull
@VirtualThreadFactory ThreadFactory virtualThreadFactory;

@Inject
public GuildAuditLogEntryEventListener(@NonNull Instance<GuildAuditLogEntryCreateEventActionTypeHandler> handlerInstances,
public GuildAuditLogEntryEventListener(@NonNull Instance<AbstractGuildAuditLogEntryCreateEventActionTypeHandler> handlerInstances,
@NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory
) {
this.handlerInstances = handlerInstances;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.eggy03.papertrail.bot.listeners.command;

import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory;
import io.github.eggy03.papertrail.bot.handlers.command.AuditLogSetupCommandHandler;
import io.github.eggy03.papertrail.bot.service.handlers.command.AuditLogSetupCommandHandler;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.eggy03.papertrail.bot.listeners.command;

import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory;
import io.github.eggy03.papertrail.bot.handlers.command.BotSetupInstructionCommandHandler;
import io.github.eggy03.papertrail.bot.service.handlers.command.BotSetupInstructionCommandHandler;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.eggy03.papertrail.bot.listeners.command;

import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory;
import io.github.eggy03.papertrail.bot.handlers.command.DebugCommandHandler;
import io.github.eggy03.papertrail.bot.service.handlers.command.DebugCommandHandler;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.eggy03.papertrail.bot.listeners.command;

import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory;
import io.github.eggy03.papertrail.bot.handlers.command.MessageLogSetupCommandHandler;
import io.github.eggy03.papertrail.bot.service.handlers.command.MessageLogSetupCommandHandler;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.eggy03.papertrail.bot.listeners.command;

import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory;
import io.github.eggy03.papertrail.bot.handlers.command.ServerStatCommandHandler;
import io.github.eggy03.papertrail.bot.service.handlers.command.ServerStatCommandHandler;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.eggy03.papertrail.bot.listeners.guild;

import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory;
import io.github.eggy03.papertrail.bot.handlers.guild.GuildBoostEventHandler;
import io.github.eggy03.papertrail.bot.service.handlers.guild.GuildBoostEventHandler;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.eggy03.papertrail.bot.listeners.guild;

import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory;
import io.github.eggy03.papertrail.bot.handlers.guild.GuildMemberEventHandler;
import io.github.eggy03.papertrail.bot.service.handlers.guild.GuildMemberEventHandler;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.eggy03.papertrail.bot.listeners.guild;

import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory;
import io.github.eggy03.papertrail.bot.handlers.guild.GuildPollEventHandler;
import io.github.eggy03.papertrail.bot.service.handlers.guild.GuildPollEventHandler;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.eggy03.papertrail.bot.listeners.guild;

import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory;
import io.github.eggy03.papertrail.bot.handlers.guild.GuildSecurityIncidentEventHandler;
import io.github.eggy03.papertrail.bot.service.handlers.guild.GuildSecurityIncidentEventHandler;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.eggy03.papertrail.bot.listeners.guild;

import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory;
import io.github.eggy03.papertrail.bot.handlers.guild.GuildVoiceEventHandler;
import io.github.eggy03.papertrail.bot.service.handlers.guild.GuildVoiceEventHandler;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.eggy03.papertrail.bot.listeners.message;

import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory;
import io.github.eggy03.papertrail.bot.handlers.message.GuildMessageEventHandler;
import io.github.eggy03.papertrail.bot.service.handlers.message.GuildMessageEventHandler;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.eggy03.papertrail.bot.service;

import jakarta.enterprise.context.ApplicationScoped;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.guild.GenericGuildEvent;
import net.dv8tion.jda.api.events.message.GenericMessageEvent;

@ApplicationScoped
@Slf4j
public final class EmbedCheckingService {

public void checkAndSend(@NonNull GenericGuildEvent event, @NonNull EmbedBuilder embedBuilder, @NonNull String channelIdToSendTo) {
if (!embedBuilder.isValidLength() || embedBuilder.isEmpty()) {
log.warn("Embed is empty or too long (current length: {}).", embedBuilder.length());
return;
}

TextChannel sendingChannel = event.getGuild().getTextChannelById(channelIdToSendTo);
if (sendingChannel != null && sendingChannel.canTalk()) {
sendingChannel.sendMessageEmbeds(embedBuilder.build()).queue();
}
}

public void checkAndSend(@NonNull GenericMessageEvent event, @NonNull EmbedBuilder embedBuilder, @NonNull String channelIdToSendTo) {
if (!embedBuilder.isValidLength() || embedBuilder.isEmpty()) {
log.warn("Embed containing message is empty or too long (current length: {}).", embedBuilder.length());
return;
}

TextChannel sendingChannel = event.getGuild().getTextChannelById(channelIdToSendTo);
if (sendingChannel != null && sendingChannel.canTalk()) {
sendingChannel.sendMessageEmbeds(embedBuilder.build()).queue();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.eggy03.papertrail.bot.listeners.auditlog;
package io.github.eggy03.papertrail.bot.service.handlers.auditlog;

import io.github.eggy03.papertrail.bot.listeners.auditlog.GuildAuditLogEntryEventListener;
import lombok.NonNull;
import net.dv8tion.jda.api.audit.ActionType;
import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent;
Expand Down Expand Up @@ -29,7 +30,7 @@
*
* <p>
* If multiple subclasses are registered as CDI beans and are iterated
* through {@code Instance<GuildAuditLogEntryCreateEventActionTypeHandler>}, each handler
* through {@code Instance<AbstractGuildAuditLogEntryCreateEventActionTypeHandler>}, each handler
* instance will independently receive and process the event.
* </p>
*
Expand All @@ -52,7 +53,7 @@
*
* <pre>{@code
* @ApplicationScoped
* public class MyHandler extends GuildAuditLogEntryCreateEventActionTypeHandler {
* public class MyHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler {
*
* @Override
* public void onBan(@NonNull GuildAuditLogEntryCreateEvent event) {
Expand All @@ -74,7 +75,7 @@
*
* <pre>{@code
* @Inject
* Instance<GuildAuditLogEntryCreateEventActionTypeHandler> eventHandlerInstance;
* Instance<AbstractGuildAuditLogEntryCreateEventActionTypeHandler> eventHandlerInstance;
*
* eventHandlerInstance.forEach(handler ->
* handler.handleActionType(event)
Expand All @@ -86,7 +87,7 @@
* {@link GuildAuditLogEntryEventListener}.
* </p>
*/
public abstract class GuildAuditLogEntryCreateEventActionTypeHandler {
public abstract class AbstractGuildAuditLogEntryCreateEventActionTypeHandler {

// handler methods for ActionType

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.eggy03.papertrail.bot.handlers.auditlog;
package io.github.eggy03.papertrail.bot.service.handlers.auditlog;

import io.github.eggy03.papertrail.bot.listeners.auditlog.GuildAuditLogEntryCreateEventActionTypeHandler;
import io.github.eggy03.papertrail.bot.service.EmbedCheckingService;
import io.github.eggy03.papertrail.bot.utils.BooleanUtils;
import io.github.eggy03.papertrail.bot.utils.auditlog.AutoModUtils;
import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient;
Expand All @@ -13,7 +13,6 @@
import net.dv8tion.jda.api.audit.AuditLogEntry;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.automod.AutoModRule;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent;
import net.dv8tion.jda.api.utils.MarkdownUtil;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -23,13 +22,15 @@
@ApplicationScoped
@Slf4j
@SuppressWarnings("java:S1192")
public final class AutoModActionTypeHandler extends GuildAuditLogEntryCreateEventActionTypeHandler {
public final class AutoModActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler {

private final @NonNull AuditLogRegistrationClient client;
private final @NonNull EmbedCheckingService embedCheckingService;

@Inject
public AutoModActionTypeHandler(@NonNull AuditLogRegistrationClient client) {
public AutoModActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) {
this.client = client;
this.embedCheckingService = embedCheckingService;
}

@NonNull
Expand All @@ -39,21 +40,9 @@ private String getRegisteredChannelId(@NonNull String guildId) {

}

private void performChecksThenBuildAndSendEmbed(@NonNull GuildAuditLogEntryCreateEvent event, @NonNull EmbedBuilder embedBuilder, @NonNull String channelIdToSendTo) {
if (!embedBuilder.isValidLength() || embedBuilder.isEmpty()) {
log.warn("Embed is empty or too long (current length: {}).", embedBuilder.length());
return;
}

TextChannel sendingChannel = event.getGuild().getTextChannelById(channelIdToSendTo);
if (sendingChannel != null && sendingChannel.canTalk()) {
sendingChannel.sendMessageEmbeds(embedBuilder.build()).queue();
}
}

@Override
public void onAutoModerationFlagToChannel(@NonNull GuildAuditLogEntryCreateEvent event) {

String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId());
if (channelIdToSendTo.isBlank()) return;

Expand All @@ -77,7 +66,7 @@ public void onAutoModerationFlagToChannel(@NonNull GuildAuditLogEntryCreateEvent
eb.setFooter("Audit Log Entry ID: " + ale.getId());
eb.setTimestamp(ale.getTimeCreated());

performChecksThenBuildAndSendEmbed(event, eb, channelIdToSendTo);
embedCheckingService.checkAndSend(event, eb, channelIdToSendTo);

}

Expand Down Expand Up @@ -107,7 +96,7 @@ public void onAutoModerationMemberTimeout(@NonNull GuildAuditLogEntryCreateEvent
eb.setFooter("Audit Log Entry ID: " + ale.getId());
eb.setTimestamp(ale.getTimeCreated());

performChecksThenBuildAndSendEmbed(event, eb, channelIdToSendTo);
embedCheckingService.checkAndSend(event, eb, channelIdToSendTo);
}

@Override
Expand Down Expand Up @@ -136,7 +125,7 @@ public void onAutoModerationRuleBlockMessage(@NonNull GuildAuditLogEntryCreateEv
eb.setFooter("Audit Log Entry ID: " + ale.getId());
eb.setTimestamp(ale.getTimeCreated());

performChecksThenBuildAndSendEmbed(event, eb, channelIdToSendTo);
embedCheckingService.checkAndSend(event, eb, channelIdToSendTo);

}

Expand Down Expand Up @@ -184,7 +173,7 @@ public void onAutoModerationRuleCreate(@NonNull GuildAuditLogEntryCreateEvent ev
eb.setFooter("Audit Log Entry ID: " + ale.getId());
eb.setTimestamp(ale.getTimeCreated());

performChecksThenBuildAndSendEmbed(event, eb, channelIdToSendTo);
embedCheckingService.checkAndSend(event, eb, channelIdToSendTo);
}

@Override
Expand Down Expand Up @@ -213,7 +202,7 @@ public void onAutoModerationRuleUpdate(@NonNull GuildAuditLogEntryCreateEvent ev
eb.setFooter("Audit Log Entry ID: " + ale.getId());
eb.setTimestamp(ale.getTimeCreated());

performChecksThenBuildAndSendEmbed(event, eb, channelIdToSendTo);
embedCheckingService.checkAndSend(event, eb, channelIdToSendTo);
}

@Override
Expand Down Expand Up @@ -245,6 +234,6 @@ public void onAutoModerationRuleDelete(@NonNull GuildAuditLogEntryCreateEvent ev
eb.setFooter("Audit Log Entry ID: " + ale.getId());
eb.setTimestamp(ale.getTimeCreated());

performChecksThenBuildAndSendEmbed(event, eb, channelIdToSendTo);
embedCheckingService.checkAndSend(event, eb, channelIdToSendTo);
}
}
Loading
Loading