diff --git a/.env.example b/.env.example deleted file mode 100644 index b314844..0000000 --- a/.env.example +++ /dev/null @@ -1,12 +0,0 @@ -#Mandatory -TOKEN= -API_URL= -#Optional -TOTAL_SHARDS= -MIN_SHARD_ID= -MAX_SHARD_ID= -TWILIGHT_HTTP_PROXY_URL= -PORT= -MANAGEMENT_PORT= -GLOBAL_LOG_LEVEL= -APPLICATION_LOG_LEVEL= \ No newline at end of file diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index cd6cf73..e09bfd5 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -1,40 +1,4 @@ -_Last Updated : August 07, 2026_ - -# Table of Contents - -* [Overview](#overview) -* [LITE vs ORIGINAL](#difference-between-original-and-lite-editions) -* [Deployment](#deployment) -* [Sharding](#sharding) -* [Synchronizing Rate Limits](#synchronizing-rate-limits) -* [Health Checks](#health-checks-and-custom-port-configuration) -* [Native-Builds](#native-builds) - -# Overview - -This section will show you how to deploy the `ORIGINAL` version of the bot. - -To deploy the `LITE` edition check out [this](https://github.com/eggy03/PaperTrailBot-Lite) repository. - -# Difference between `ORIGINAL` and `LITE` editions - -The `ORIGINAL` edition is designed to support self-hosting, horizontal scaling, customizable sharding. This requires you -to deploy/lease one or many instances of the PaperTrail API, a Redis/Valkey service and a database service. Very soon I -realized that this creates a bit of maintenance overhead for users. - -This is where `LITE` edition was proposed. It is a fork of the `ORIGINAL` edition but is designed with greater -personalization and easier setup in mind. It does not require a separate API or database service, just a Redis/Valkey -instance, and allows for greater customization during setup, most of which comes with sane defaults as well. This makes -it easy to set it up and get it working. However, the `LITE` edition can log only for a single server and does not -support scaling or sharding. - -Other than the aforementioned differences, everything else is identical between the two editions. - -If you are self-hosting it, you will probably host it for your own server, and hence in most cases, `LITE` edition is -the recommended one. - -You should use the `ORIGINAL` edition only if you need capabilities that are not available in the `LITE` edition, -such as manual sharding or horizontal scaling. +_Last Updated : October 03, 2026_ # Deployment @@ -42,11 +6,7 @@ such as manual sharding or horizontal scaling. > > This guide assumes you already have a working PostgreSQL and Redis/Valkey instance or know how to set up one. -## Step 1: Setting up the API Service - -Follow this [guide](https://github.com/eggy03/PaperTrail-API-Quarkus?tab=readme-ov-file) - -## Step 2: Setting up the Bot In Discord +## Step 1: Create a bot in the Discord Dev Portal Log on to the [Discord Developer Portal](https://discord.com/developers/applications) and create an application. @@ -79,291 +39,82 @@ needed for it to work properly: Note down the `BOT TOKEN` since it will be shown only once and will be required in the later steps. -## Step 3: Deploying the Bot - -### 3.1: Get Required Secrets - -| Variable | Description | Default Value | Optional | -|-----------|-----------------------------------------------------------|------------------|----------| -| `TOKEN` | Discord application bot token (from the Developer Portal) | No Default Value | No | -| `API_URL` | Internal URL of the PaperTrail API | No Default Value | No | - -Example `.env` file: - -```dotenv -TOKEN="my-token" -API_URL="http://localhost:8080" -``` - -### 3.2: Deployment Options - -#### Option A : Deploy Using Pre-Built Docker Images - -The GitHub Container Registry for this repository -has pre-built docker images for both JVM and Native versions the bot which you can use. - -[Container Registry for JVM Edition](https://github.com/eggy03/PaperTrailBot/pkgs/container/papertrail-bot) - -[Container Registry for Native Edition](https://github.com/eggy03/PaperTrailBot/pkgs/container/papertrail-bot-native) - -You may choose either one. - -To know more about native builds, visit the [bottom](#native-builds) of this guide. - -```bash -# JVM -docker run -d --name papertrail-bot --env-file .env ghcr.io/eggy03/papertrail-bot:latest -``` - -```bash -# Native -docker run -d --name papertrail-bot-native --env-file .env ghcr.io/eggy03/papertrail-bot-native:latest -``` - -#### Option B : Building From Source With Docker - -```bash -git clone https://github.com/eggy03/PaperTrailBot.git -cd PaperTrailBot -``` - -```bash -# JVM -docker build -t papertrail-bot . -docker run -d --name papertrail-bot --env-file .env papertrail-bot -``` - -```bash -# Native -docker build -f Dockerfile.native -t papertrail-bot-native . -docker run -d --name papertrail-bot-native --env-file .env papertrail-bot-native -``` - -#### Option C : Building From Source Without Docker - -```bash -git clone https://github.com/eggy03/PaperTrailBot.git -cd PaperTrailBot -``` - -```bash -# JVM -./mvnw clean package -java -jar target/quarkus-app/quarkus-run.jar -``` - -```bash -# Native -./mvnw clean package -Dnative -``` - -The built application will be found in the `target` folder of the project. - -#### Option D : Cloud Deployment - -If your cloud supports building from Dockerfile, point the source towards `Dockerfile` (for JVM Build) -or `Dockerfile.native` (for Native Build), found in the project's root. - -If your cloud supports using pre-built docker images, you can find the image links in -the container registry. - -## Step 4: Testing your deployment - -Upon successful deployment of all the required services, including the bot, you can run the slash command -`/setup` in a server where the bot has been invited. The command will tell you how to configure your bot. - -# Sharding - -> [!NOTE] -> Sharding is required only when your bot reaches 2500 servers. - -Sharding splits your bot connection into multiple independent connections to the Discord gateway. -Each independent connection is called a shard. -Discord allows you to have up to 2500 guilds per shard but the recommended configuration is 1 shard per 1000 guilds. - -You will need the following additional environment variables for custom shard configuration. - -| Variable | Description | Default Value | Optional | -|----------------|-------------------------------------------------------------------------------|---------------|----------| -| `TOTAL_SHARDS` | Total number of shards used by the bot across all running processes/instances | 1 | Yes | -| `MIN_SHARD_ID` | The first shard ID handled by this specific bot instance | 0 | Yes | -| `MAX_SHARD_ID` | The last shard ID handled by this specific bot instance | 0 | Yes | - -Shard IDs start at 0. - -If `TOTAL_SHARDS=5`, the valid shard IDs are: - -``` -0 1 2 3 4 -``` - -Take a look at the following configuration examples to have a clearer picture of what values to put -for your use-case - -#### Example 1: Single Process / Small Bot (<2500 Guilds) - -If your bot is small or self-hosted for a limited number of servers (<2500), one shard is sufficient. -This is the default pre-applied configuration when you do not provide any manual shard info. - -```dotenv -TOTAL_SHARDS=1 -MIN_SHARD_ID=0 -MAX_SHARD_ID=0 -``` - -#### Example 2: Single Process / Medium Bot (2500 - 5000 Guilds) - -If your bot exceeds the 2500 guild limit for a single shard, you can increase the shard count while still running one -process: - -```dotenv -TOTAL_SHARDS=2 -MIN_SHARD_ID=0 -MAX_SHARD_ID=1 -``` - -Remember that each shard can only handle up to 2500 guilds so plan the total number shards accordingly - -#### Example 3: 2 Bot Processes / 25000 Guilds - -If you run your bot across multiple processes, you need to split the shards between them. - -Process/Instance 1: - -```dotenv -TOTAL_SHARDS=10 -MIN_SHARD_ID=0 -MAX_SHARD_ID=4 -``` - -Process/Instance 2: - -```dotenv -TOTAL_SHARDS=10 -MIN_SHARD_ID=5 -MAX_SHARD_ID=9 -``` - -Process 1 handles shards 0-4 and Process 2 handles 5-9. -Each process manages 5 shards, together covering all 10 shards. - -> [!IMPORTANT] -> Shard ID ranges must never overlap between running bot processes/instances. -> -> `TOTAL_SHARDS` count must be equal for all instances and must reflect the total shards used across all instances -> combined. - -# Synchronizing Rate Limits - -> [!NOTE] -> This section is required only if you have multiple instances of the bot running, like in Example 3 of Sharding. - -When you run multiple instances/process, the JDA in each process thinks that it has the sole responsibility -of handling Discord's API rate limits because the processes aren't aware of each other's existence. -This means, without some sort of communication or synchronization between the instances, you may exceed the rate limits -pretty early. - -It is possible to synchronize Discord's rate limits across multiple instances/processes -by using an external proxy such as the [Twilight HTTP Proxy](https://github.com/twilight-rs/http-proxy). -This proxy acts as a shared HTTP gateway that coordinates Discord API rate limits across multiple bot instances. - -This however, requires disabling the default rate limiter in JDA because the proxy will handle them globally. - -It is also worth noting that this feature is largely untested in PaperTrail. -Read more about this in the [Limitations](#limitations) section. - -### Running the Proxy - -To use the pre-built Docker images from -the [container registry](https://github.com/twilight-rs/http-proxy/pkgs/container/http-proxy), -run one of the following commands: - -```shell -$ docker run -itd -e DISCORD_TOKEN="my token" -p 3000:80 ghcr.io/twilight-rs/http-proxy -# Or with metrics enabled -$ docker run -itd -e DISCORD_TOKEN="my token" -p 3000:80 ghcr.io/twilight-rs/http-proxy:metrics - -``` - -This will set the discord token to `"my token"` and map the bound port to port `3000` on the host machine. - -### Bot Configuration - -Add the following environment variable to your bot: - -| Variable | Description | Default Value | Optional | -|---------------------------|----------------------------------------------------------------------------------------------------------------------------|---------------|----------| -| `TWILIGHT_HTTP_PROXY_URL` | Base URL for the HTTP proxy that will receive Discord API requests instead of discord.com (Example: http://localhost:3000) | Blank | Yes | - -When configured, all Discord API requests made by the bot will be routed through the proxy. - -### Limitations - -Twilight HTTP Proxy has its own global rate limiting feature and recommends clients to disable their per-instance -rate limit checks. That's because requests from all bot instances are centrally managed and throttled by the proxy -rather than by each client individually. - -For PaperTrail, this would mean replacing JDA's default `SequentialRestRateLimiter`, -which is an implementation of the `RestRateLimiter`, with a custom no-op implementation. -Such an implementation would effectively bypass JDA’s local rate-limit checks and defer all rate limiting to the proxy. -At the moment, PaperTrail does not provide such an implementation. - -This means that if you use a proxy for your bot clusters, you are effectively getting throttled at the proxy-level, as -well -as the instance-level. While this should not create functional conflicts, -it may lead to under-utilization of the rate limits provided by Discord and can reduce the overall throughput of your -bot cluster. - -# Health Checks and Custom Port Configuration - -### Health Checks - -Since v4, it is possible to get health information by probing any of the following health endpoints: - -| Endpoint | Description | -|---------------------|-------------------------------------------------------------------------------------------------------| -| `/q/health` | Aggregated health status containing all registered checks. | -| `/q/health/live` | Liveness probe. Verifies that the bot process is healthy and that all shards are operating normally. | -| `/q/health/ready` | Readiness probe. Verifies that all shards are fully connected to Discord and ready to receive events. | -| `/q/health/started` | Startup probe. Indicates whether the application has completed its startup sequence. | - -#### Liveness Check - -The liveness check reports **UP** when all shards belonging to this instance are in one of the following states: - -* `CONNECTED` -* `ATTEMPTING_TO_RECONNECT` -* `RECONNECT_QUEUED` -* `WAITING_TO_RECONNECT` - -#### Readiness Check - -The readiness check reports **UP** only when every shard belonging to this instance is fully `CONNECTED` to Discord. - -### Custom Port Configuration - -By, default PaperTrail runs on port 8080. If port 8080 is occupied by a different service, or you wish to -run the application on a different port, you can manually set the `PORT` environment variable. Same goes for -`MANAGEMENT_PORT` which will expose the health check endpoints. - -| Variable | Description | Default Value | Optional | -|-------------------|-------------------------------------------------------|---------------|----------| -| `PORT` | Port Number on which the instance of the bot will run | 8080 | Yes | -| `MANAGEMENT_PORT` | Port for Health Check Interface | 9000 | Yes | - -# Native Builds - -> [!CAUTION] -> Native builds are experimental - -Since `v4.1.3` it is possible to create and use native builds of the bot. Native builds are recommended -when you are hosting the bot in a very resource constrained environment, -and you need the bot to have faster startup times and low memory consumption. - -Native builds have a larger and resource incentive build time compared to standard JVM builds. - -Please note that native builds are experimental and I will try my best to improve support for it in upcoming versions. - -You may come across errors which require you to initialize classes during build time -or missing reflection config during runtime. -If you run across such errors, create an Issue in GitHub along with the build or runtime logs. +## Step 2: Deploying the API and the Bot + +### 2.1: Get Required Variables + +| Variable | Description/Format | Default Value | Optional | +|---------------|----------------------------------------------------------------------|------------------|----------| +| `DB_URL` | jdbc:postgresql://:/ | No Default Value | No | +| `DB_USERNAME` | Database Username | No Default Value | No | +| `DB_PASSWORD` | Database Password | No Default Value | No | +| `REDIS_URL` | rediss://:@: | No Default Value | No | +| `TOKEN` | Get from the dev portal | No Default Value | No | + +### 2.2: Deployment + +Use the following docker compose setup to deploy both the bot and the API + +```yaml +networks: + papertrail-network: + +services: + api: + container_name: papertrail-api + image: ghcr.io/eggy03/papertrail-api-native:latest + environment: + DB_URL: ${DB_URL} + DB_USERNAME: ${DB_USERNAME} + DB_PASSWORD: ${DB_PASSWORD} + REDIS_URL: ${REDIS_URL} + healthcheck: + test: [ "CMD", "curl", "-f", "http://localhost:9000/q/health" ] + interval: 10s + timeout: 5s + retries: 3 + + bot: + container_name: papertrail-bot + image: ghcr.io/eggy03/papertrail-bot-native:latest + depends_on: + api: + condition: service_healthy + environment: + TOKEN: ${TOKEN} + API_URL: http://papertrail-api:8080 + healthcheck: + test: [ "CMD", "curl", "-f", "http://localhost:9000/q/health" ] + interval: 10s + timeout: 5s + retries: 3 +``` + +If you want to build from source and then deploy individually, +you can point your builder to this [and the API] repository's +[Dockerfile](/Dockerfile) or [Dockerfile Native (GraalVM Native Image)](/Dockerfile.native). + +# Customization Options + +The following environment variables have defaults, but you can change them to allow for more customization: + +## Bot + +| Environment Variable | Description | Default Value | Optional | +|-------------------------------|------------------------------------------------------------|---------------------|-----------------| +| `APP_NAME` | Changes the application name used internally. | `PaperTrailBot` | Yes | +| `APP_ACTIVITY` | Changes the activity displayed by the bot in Discord. | `/help | latest version` | Yes | +| `APP_LOG_LEVEL` | Changes the application log level. | `INFO` | Yes | +| `PORT` | Changes the port used by the application. | `8080` | Yes | +| `MANAGEMENT_PORT` | Changes the management port used by Quarkus health checks. | `9000` | Yes | +| `EMBED_SUCCESS_COLOR_INT` | Changes the color of embeds for **creation events**. | `GREEN (712458)` | Yes | +| `EMBED_WARNING_COLOR_INT` | Changes the color of embeds for **update events**. | `YELLOW (16776960)` | Yes | +| `EMBED_DESTRUCTIVE_COLOR_INT` | Changes the color of embeds for **deletion events**. | `RED (16711680)` | Yes | + +## API + +| Environment Variable | Description | Default Value | Optional | +|----------------------|------------------------------------------------------------|---------------|----------| +| `LOG_LEVEL` | Changes the application log level. | `INFO` | Yes | +| `PORT` | Changes the port used by the application. | `8080` | Yes | +| `MANAGEMENT_PORT` | Changes the management port used by Quarkus health checks. | `9000` | Yes | \ No newline at end of file diff --git a/Dockerfile.native b/Dockerfile.native index 351f6db..e24e79f 100644 --- a/Dockerfile.native +++ b/Dockerfile.native @@ -19,7 +19,7 @@ COPY src ./src RUN ./mvnw -B -e clean package -DskipTests -Dnative # ---------- Stage 2: Minimal Runtime ---------- -FROM registry.access.redhat.com/ubi9/ubi-minimal:9.7 +FROM registry.access.redhat.com/ubi9/ubi-minimal:9.8 RUN microdnf install -y freetype fontconfig \ && microdnf clean all \ diff --git a/README.md b/README.md index fd86676..4ce81ac 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,11 @@ Integrations, Webhooks, Moderation Action, Unusual DMs, Raids and Unknown events # Repositories -| Repository | Description | -|--------------------------------------------------------------------|-------------------------------------------------------------| -| [PaperTrailBot](https://github.com/eggy03/PaperTrailBot) | Core bot application | -| [PaperTrailBot Lite](https://github.com/eggy03/PaperTrailBot-Lite) | Same bot application but designed for self-hosting | -| [PaperTrail SDK](https://github.com/eggy03/papertrail-sdk) | Java client library for interacting with the API | -| [PaperTrail API](https://github.com/eggy03/PaperTrail-API-Quarkus) | API used by the core bot application to store server config | +| Repository | Description | +|----------------------------------------------------------------------------|--------------------------------------------------------------| +| [PaperTrailBot](https://github.com/eggy03/PaperTrailBot) | Core bot application | +| [PaperTrail HTTP Client](https://github.com/eggy03/PaperTrail-HTTP-Client) | Synchronous Java client library for interacting with the API | +| [PaperTrail API](https://github.com/eggy03/PaperTrail-API-Quarkus) | API used by the bot to store server config | > [!IMPORTANT] > I've considered putting the project in maintenance mode since I believe it's mostly feature complete. @@ -52,17 +51,11 @@ A deployed instance is the easiest way to use this bot. Just invite it to your s Get it from here: https://discord.com/discovery/applications/1381658412550590475 -Run the `/setup` slash command to see instructions on how to configure the bot for your server. +Run the `/help` slash command to see instructions on how to configure the bot for your server. ### By Self Hosting It -For self-hosting, I'd recommend the [LITE](https://github.com/eggy03/PaperTrailBot-Lite) version of the bot. The `LITE` -version requires lesser services to set up and offers more granular customization. However, you can only use it for a -single server. - -If you do not wish to use the `LITE` version, you can self-host the `ORIGINAL` version by reading the -guide [here](/DEPLOYMENT.md). -The guide also mentions the difference between the `LITE` and the `ORIGINAL` versions. +Read the deployment guide [here](/DEPLOYMENT.md) # License diff --git a/pom.xml b/pom.xml index e9cc8bf..47e11bd 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.github.eggy03 papertrailbot - 4.2.4 + 5.0.0 PaperTrail Bot A simple bot for logging all server and member actions quarkus @@ -18,12 +18,12 @@ quarkus-bom io.quarkus.platform - 3.39.2 + 3.39.5 true - 6.6.0 - 3.0.3 + 6.7.0 + 4.0.0 3.20.0 33.7.1-jre 26.1.0 @@ -108,8 +108,8 @@ io.github.eggy03 - papertrail-sdk - ${papertrail.sdk.version} + papertrail-http-client + ${papertrail.http.client.version} diff --git a/src/main/java/io/github/eggy03/papertrail/bot/BootstrapService.java b/src/main/java/io/github/eggy03/papertrail/bot/BootstrapService.java index ddbca49..77fd21e 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/BootstrapService.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/BootstrapService.java @@ -1,6 +1,6 @@ package io.github.eggy03.papertrail.bot; -import io.github.eggy03.papertrail.bot.configuration.PaperTrailConfig; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.quarkus.runtime.Startup; import jakarta.annotation.PreDestroy; import jakarta.enterprise.context.ApplicationScoped; @@ -12,7 +12,6 @@ import net.dv8tion.jda.api.OnlineStatus; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.requests.GatewayIntent; -import net.dv8tion.jda.api.requests.RestConfig; import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder; import net.dv8tion.jda.api.sharding.ShardManager; import net.dv8tion.jda.api.utils.ChunkingFilter; @@ -24,13 +23,13 @@ @Startup public final class BootstrapService { - private final @NonNull PaperTrailConfig paperTrailConfig; + private final @NonNull PaperTrailEnvironment paperTrailEnvironment; private final @NonNull Instance listeners; private final @NonNull ShardManager shardManager; @Inject - public BootstrapService(@NonNull PaperTrailConfig paperTrailConfig, @NonNull Instance listeners) { - this.paperTrailConfig = paperTrailConfig; + public BootstrapService(@NonNull PaperTrailEnvironment paperTrailEnvironment, @NonNull Instance listeners) { + this.paperTrailEnvironment = paperTrailEnvironment; this.listeners = listeners; this.shardManager = constructShardManager(); } @@ -38,7 +37,7 @@ public BootstrapService(@NonNull PaperTrailConfig paperTrailConfig, @NonNull Ins @NonNull ShardManager constructShardManager() { - DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.createDefault(paperTrailConfig.discord().token()); + DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.createDefault(paperTrailEnvironment.discord().token()); builder.enableIntents(GatewayIntent.SCHEDULED_EVENTS, GatewayIntent.AUTO_MODERATION_EXECUTION, @@ -74,18 +73,6 @@ ShardManager constructShardManager() { builder.addEventListeners(listener); }); - // add shards - builder.setShardsTotal(paperTrailConfig.discord().shard().total()); - builder.setShards(paperTrailConfig.discord().shard().min(), paperTrailConfig.discord().shard().max()); - - // add custom twilight http proxy url if present - // note the current implementation only changes the proxy - // JDA's internal rate limit logic still applies on top of the proxy - // you need to provide a custom RestRateLimiter config - if (!paperTrailConfig.discord().twilightProxyUrl().isBlank()) { // don't use isEmpty cause default value is a whitespace - builder.setRestConfig(new RestConfig().setBaseUrl(paperTrailConfig.discord().twilightProxyUrl())); - } - // build shard manager and login return builder.build(); } @@ -99,9 +86,7 @@ ShardManager getShardManager() { @PreDestroy void shutdown() { - for (int i = paperTrailConfig.discord().shard().min(); i <= paperTrailConfig.discord().shard().max(); i++) { - log.info("Shutting Down Shard: {}", i); - shardManager.shutdown(i); - } + log.info("Shutting down all shards..."); + shardManager.shutdown(); } } diff --git a/src/main/java/io/github/eggy03/papertrail/bot/configuration/PaperTrailClientBeanProducer.java b/src/main/java/io/github/eggy03/papertrail/bot/configuration/PaperTrailClientBeanProducer.java new file mode 100644 index 0000000..8f7fdfe --- /dev/null +++ b/src/main/java/io/github/eggy03/papertrail/bot/configuration/PaperTrailClientBeanProducer.java @@ -0,0 +1,35 @@ +package io.github.eggy03.papertrail.bot.configuration; + +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.client.PaperTrailMessageClient; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; +import jakarta.inject.Inject; +import lombok.NonNull; +import org.jetbrains.annotations.Contract; +import retrofit2.Retrofit; + +@ApplicationScoped +public final class PaperTrailClientBeanProducer { + + private final @NonNull Retrofit retrofit; + + @Inject + public PaperTrailClientBeanProducer(@NonNull Retrofit retrofit) { + this.retrofit = retrofit; + } + + @Contract(" -> new") + @Produces + @ApplicationScoped + public @NonNull PaperTrailGuildClient paperTrailGuildClient() { + return new PaperTrailGuildClient(retrofit); + } + + @Contract(" -> new") + @Produces + @ApplicationScoped + public @NonNull PaperTrailMessageClient paperTrailMessageClient() { + return new PaperTrailMessageClient(retrofit); + } +} diff --git a/src/main/java/io/github/eggy03/papertrail/bot/configuration/PaperTrailSdkProducer.java b/src/main/java/io/github/eggy03/papertrail/bot/configuration/PaperTrailSdkProducer.java deleted file mode 100644 index 9a2e29c..0000000 --- a/src/main/java/io/github/eggy03/papertrail/bot/configuration/PaperTrailSdkProducer.java +++ /dev/null @@ -1,45 +0,0 @@ -package io.github.eggy03.papertrail.bot.configuration; - -import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.client.MessageLogContentClient; -import io.github.eggy03.papertrail.sdk.client.MessageLogRegistrationClient; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.enterprise.inject.Produces; -import jakarta.inject.Inject; -import lombok.NonNull; -import org.jetbrains.annotations.Contract; - -@ApplicationScoped -public final class PaperTrailSdkProducer { - - private final @NonNull String apiUrl; - private final @NonNull ObjectMapper objectMapper; - - @Inject - public PaperTrailSdkProducer(@NonNull PaperTrailConfig paperTrailConfig, @NonNull ObjectMapper objectMapper) { - this.apiUrl = paperTrailConfig.api().url(); - this.objectMapper = objectMapper; - } - - @Contract(" -> new") - @Produces - @ApplicationScoped - public @NonNull AuditLogRegistrationClient auditLogRegistrationClient() { - return new AuditLogRegistrationClient(apiUrl, objectMapper); - } - - @Contract(" -> new") - @Produces - @ApplicationScoped - public @NonNull MessageLogRegistrationClient messageLogRegistrationClient() { - return new MessageLogRegistrationClient(apiUrl, objectMapper); - } - - @Contract(" -> new") - @Produces - @ApplicationScoped - public @NonNull MessageLogContentClient messageLogContentClient() { - return new MessageLogContentClient(apiUrl, objectMapper); - } -} diff --git a/src/main/java/io/github/eggy03/papertrail/bot/configuration/RetrofitBeanProducer.java b/src/main/java/io/github/eggy03/papertrail/bot/configuration/RetrofitBeanProducer.java new file mode 100644 index 0000000..7476f91 --- /dev/null +++ b/src/main/java/io/github/eggy03/papertrail/bot/configuration/RetrofitBeanProducer.java @@ -0,0 +1,38 @@ +package io.github.eggy03.papertrail.bot.configuration; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; +import jakarta.inject.Inject; +import lombok.NonNull; +import okhttp3.OkHttpClient; +import org.jetbrains.annotations.Contract; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; + +import java.time.Duration; + +@ApplicationScoped +public final class RetrofitBeanProducer { + + private final @NonNull String apiUrl; + private final @NonNull ObjectMapper objectMapper; + + @Inject + public RetrofitBeanProducer(@NonNull PaperTrailEnvironment paperTrailEnvironment, @NonNull ObjectMapper objectMapper) { + this.apiUrl = paperTrailEnvironment.api().url(); + this.objectMapper = objectMapper; + } + + @Contract(" -> new") + @Produces + @ApplicationScoped + public @NonNull Retrofit retrofit() { + return new Retrofit.Builder() + .baseUrl(apiUrl) + .client(new OkHttpClient.Builder().callTimeout(Duration.ofSeconds(60)).readTimeout(Duration.ofSeconds(30)).writeTimeout(Duration.ofSeconds(30)).build()) + .addConverterFactory(JacksonConverterFactory.create(objectMapper)) + .build(); + } +} diff --git a/src/main/java/io/github/eggy03/papertrail/bot/configuration/PaperTrailConfig.java b/src/main/java/io/github/eggy03/papertrail/bot/environment/PaperTrailEnvironment.java similarity index 61% rename from src/main/java/io/github/eggy03/papertrail/bot/configuration/PaperTrailConfig.java rename to src/main/java/io/github/eggy03/papertrail/bot/environment/PaperTrailEnvironment.java index b6c1aa3..51a51a0 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/configuration/PaperTrailConfig.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/environment/PaperTrailEnvironment.java @@ -1,14 +1,15 @@ -package io.github.eggy03.papertrail.bot.configuration; +package io.github.eggy03.papertrail.bot.environment; import io.smallrye.config.ConfigMapping; import io.smallrye.config.WithName; import lombok.NonNull; @ConfigMapping(prefix = "papertrail") -public interface PaperTrailConfig { +public interface PaperTrailEnvironment { General general(); + EmbedColor embedColor(); Discord discord(); API api(); @@ -23,35 +24,33 @@ interface General { @NonNull String appVersion(); + @WithName("app.activity") + @NonNull + String appActivity(); + @WithName("github.issue.link") @NonNull String githubIssueLink(); } - interface Discord { - - @WithName("token") - @NonNull - String token(); - - @WithName("twilight.http.proxy.url") - @NonNull - String twilightProxyUrl(); + interface EmbedColor { - Shard shard(); + @WithName("success.color.integer") + int successColor(); - interface Shard { + @WithName("warning.color.integer") + int warningColor(); - @WithName("min") - int min(); + @WithName("destructive.color.integer") + int destructiveColor(); + } - @WithName("max") - int max(); + interface Discord { - @WithName("total") - int total(); - } + @WithName("token") + @NonNull + String token(); } interface API { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/AuditLogSetupCommandListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/ConfigCommandListener.java similarity index 52% rename from src/main/java/io/github/eggy03/papertrail/bot/listeners/command/AuditLogSetupCommandListener.java rename to src/main/java/io/github/eggy03/papertrail/bot/listeners/command/ConfigCommandListener.java index 27f386b..c8a39bc 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/AuditLogSetupCommandListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/ConfigCommandListener.java @@ -1,24 +1,23 @@ package io.github.eggy03.papertrail.bot.listeners.command; import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; -import io.github.eggy03.papertrail.bot.service.handlers.command.AuditLogSetupCommandHandler; +import io.github.eggy03.papertrail.bot.service.handlers.command.ConfigCommandHandler; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import java.util.concurrent.ThreadFactory; -@Singleton -public final class AuditLogSetupCommandListener extends ListenerAdapter { +@ApplicationScoped +public final class ConfigCommandListener extends ListenerAdapter { - private final @NonNull AuditLogSetupCommandHandler handler; - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; + private final @NonNull ConfigCommandHandler handler; + private final @NonNull ThreadFactory virtualThreadFactory; @Inject - public AuditLogSetupCommandListener(@NonNull AuditLogSetupCommandHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { + public ConfigCommandListener(@NonNull ConfigCommandHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { this.handler = handler; this.virtualThreadFactory = virtualThreadFactory; } @@ -26,16 +25,16 @@ public AuditLogSetupCommandListener(@NonNull AuditLogSetupCommandHandler handler @Override public void onSlashCommandInteraction(@NonNull SlashCommandInteractionEvent event) { - if (!event.getName().equals("auditlog") || event.getSubcommandName() == null) { + if (!event.getName().equals("config")) { return; } virtualThreadFactory.newThread(() -> { switch (event.getSubcommandName()) { - case "set" -> handler.setAuditLogging(event); - case "view" -> handler.viewAuditLoggingChannel(event); - case "remove" -> handler.unsetAuditLogging(event); - default -> { + case "save" -> handler.saveGuild(event); + case "view" -> handler.viewGuild(event); + case "update" -> handler.updateGuild(event); + case null, default -> { // do nothing } } diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/DebugCommandListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/DebugCommandListener.java index 52df670..2303e19 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/DebugCommandListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/DebugCommandListener.java @@ -2,8 +2,8 @@ import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; import io.github.eggy03.papertrail.bot.service.handlers.command.DebugCommandHandler; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.Guild; @@ -14,12 +14,11 @@ import java.util.concurrent.ThreadFactory; @Slf4j -@Singleton +@ApplicationScoped public final class DebugCommandListener extends ListenerAdapter { private final @NonNull DebugCommandHandler handler; - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; + private final @NonNull ThreadFactory virtualThreadFactory; @Inject public DebugCommandListener(@NonNull DebugCommandHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/BotSetupInstructionCommandListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/HelpCommandListener.java similarity index 59% rename from src/main/java/io/github/eggy03/papertrail/bot/listeners/command/BotSetupInstructionCommandListener.java rename to src/main/java/io/github/eggy03/papertrail/bot/listeners/command/HelpCommandListener.java index 075c3a0..c5d90f3 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/BotSetupInstructionCommandListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/HelpCommandListener.java @@ -1,24 +1,23 @@ package io.github.eggy03.papertrail.bot.listeners.command; import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; -import io.github.eggy03.papertrail.bot.service.handlers.command.BotSetupInstructionCommandHandler; +import io.github.eggy03.papertrail.bot.service.handlers.command.HelpCommandHandler; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import java.util.concurrent.ThreadFactory; -@Singleton -public final class BotSetupInstructionCommandListener extends ListenerAdapter { +@ApplicationScoped +public final class HelpCommandListener extends ListenerAdapter { - private final @NonNull BotSetupInstructionCommandHandler handler; - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; + private final @NonNull HelpCommandHandler handler; + private final @NonNull ThreadFactory virtualThreadFactory; @Inject - public BotSetupInstructionCommandListener(@NonNull BotSetupInstructionCommandHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { + public HelpCommandListener(@NonNull HelpCommandHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { this.handler = handler; this.virtualThreadFactory = virtualThreadFactory; } @@ -26,7 +25,7 @@ public BotSetupInstructionCommandListener(@NonNull BotSetupInstructionCommandHan @Override public void onSlashCommandInteraction(@NonNull SlashCommandInteractionEvent event) { - if (event.getName().equals("setup")) { + if (event.getName().equals("help")) { virtualThreadFactory .newThread(() -> handler.sendInstructions(event)) diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/MessageLogSetupCommandListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/MessageLogSetupCommandListener.java deleted file mode 100644 index 945f443..0000000 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/MessageLogSetupCommandListener.java +++ /dev/null @@ -1,46 +0,0 @@ -package io.github.eggy03.papertrail.bot.listeners.command; - -import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; -import io.github.eggy03.papertrail.bot.service.handlers.command.MessageLogSetupCommandHandler; -import jakarta.inject.Inject; -import jakarta.inject.Singleton; -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import net.dv8tion.jda.api.hooks.ListenerAdapter; - -import java.util.concurrent.ThreadFactory; - -@Slf4j -@Singleton -public final class MessageLogSetupCommandListener extends ListenerAdapter { - - private final @NonNull MessageLogSetupCommandHandler handler; - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; - - @Inject - public MessageLogSetupCommandListener(@NonNull MessageLogSetupCommandHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { - this.handler = handler; - this.virtualThreadFactory = virtualThreadFactory; - } - - @Override - public void onSlashCommandInteraction(@NonNull SlashCommandInteractionEvent event) { - - if (!event.getName().equals("messagelog") || event.getSubcommandName() == null) { - return; - } - - virtualThreadFactory.newThread(() -> { - switch (event.getSubcommandName()) { - case "set" -> handler.setMessageLogging(event); - case "view" -> handler.viewMessageLoggingChannel(event); - case "remove" -> handler.unsetMessageLogging(event); - default -> { - // skip - } - } - }).start(); - } -} diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/ServerStatCommandListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/ServerStatCommandListener.java index bc3cafb..e543681 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/ServerStatCommandListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/command/ServerStatCommandListener.java @@ -2,8 +2,8 @@ import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; import io.github.eggy03.papertrail.bot.service.handlers.command.ServerStatCommandHandler; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.Guild; @@ -12,13 +12,12 @@ import java.util.concurrent.ThreadFactory; -@Singleton +@ApplicationScoped @Slf4j public final class ServerStatCommandListener extends ListenerAdapter { private final @NonNull ServerStatCommandHandler handler; - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; + private final @NonNull ThreadFactory virtualThreadFactory; @Inject public ServerStatCommandListener(@NonNull ServerStatCommandHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildBoostEventListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildBoostEventListener.java index 553299f..db617c7 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildBoostEventListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildBoostEventListener.java @@ -2,8 +2,8 @@ import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; import io.github.eggy03.papertrail.bot.service.handlers.guild.GuildBoostEventHandler; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateBoostTimeEvent; @@ -13,13 +13,12 @@ import java.util.concurrent.ThreadFactory; -@Singleton +@ApplicationScoped @Slf4j public final class GuildBoostEventListener extends ListenerAdapter { private final @NonNull GuildBoostEventHandler handler; - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; + private final @NonNull ThreadFactory virtualThreadFactory; @Inject public GuildBoostEventListener(@NonNull GuildBoostEventHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildMemberEventListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildMemberEventListener.java index f52ea41..20a39de 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildMemberEventListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildMemberEventListener.java @@ -2,8 +2,8 @@ import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; import io.github.eggy03.papertrail.bot.service.handlers.guild.GuildMemberEventHandler; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; @@ -14,13 +14,12 @@ // this event is not properly logged in the audit logs, hence the usage of JDA's listener is preferred // this event is logged in the same channel where the audit log events are logged -@Singleton +@ApplicationScoped @Slf4j public final class GuildMemberEventListener extends ListenerAdapter { private final @NonNull GuildMemberEventHandler handler; - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; + private final @NonNull ThreadFactory virtualThreadFactory; @Inject public GuildMemberEventListener(@NonNull GuildMemberEventHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildPollEventListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildPollEventListener.java index e3154c5..f7b58fc 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildPollEventListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildPollEventListener.java @@ -2,8 +2,8 @@ import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; import io.github.eggy03.papertrail.bot.service.handlers.guild.GuildPollEventHandler; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -12,13 +12,12 @@ import java.util.concurrent.ThreadFactory; // guild poll events are mapped to audit log table -@Singleton +@ApplicationScoped @Slf4j public final class GuildPollEventListener extends ListenerAdapter { private final @NonNull GuildPollEventHandler handler; - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; + private final @NonNull ThreadFactory virtualThreadFactory; @Inject public GuildPollEventListener(@NonNull GuildPollEventHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildSecurityIncidentEventListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildSecurityIncidentEventListener.java index 28a235b..f7a2a4e 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildSecurityIncidentEventListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildSecurityIncidentEventListener.java @@ -2,8 +2,8 @@ import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; import io.github.eggy03.papertrail.bot.service.handlers.guild.GuildSecurityIncidentEventHandler; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.events.guild.update.GuildUpdateSecurityIncidentActionsEvent; @@ -12,13 +12,12 @@ import java.util.concurrent.ThreadFactory; -@Singleton +@ApplicationScoped @Slf4j public final class GuildSecurityIncidentEventListener extends ListenerAdapter { private final @NonNull GuildSecurityIncidentEventHandler handler; - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; + private final @NonNull ThreadFactory virtualThreadFactory; @Inject public GuildSecurityIncidentEventListener(@NonNull GuildSecurityIncidentEventHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildVoiceEventListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildVoiceEventListener.java index 77a5d65..6197371 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildVoiceEventListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/GuildVoiceEventListener.java @@ -2,8 +2,8 @@ import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; import io.github.eggy03.papertrail.bot.service.handlers.guild.GuildVoiceEventHandler; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; @@ -13,13 +13,12 @@ // this event is not properly logged in the audit logs, hence the usage of JDA's listener is preferred // this event is logged in the same channel where the audit log events are logged -@Singleton +@ApplicationScoped @Slf4j public final class GuildVoiceEventListener extends ListenerAdapter { private final @NonNull GuildVoiceEventHandler handler; - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; + private final @NonNull ThreadFactory virtualThreadFactory; @Inject public GuildVoiceEventListener(@NonNull GuildVoiceEventHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/auditlog/GuildAuditLogEntryEventListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/auditlog/GuildAuditLogEntryEventListener.java index 35b0b30..58821ce 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/auditlog/GuildAuditLogEntryEventListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/auditlog/GuildAuditLogEntryEventListener.java @@ -2,9 +2,9 @@ import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; import io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog.AbstractGuildAuditLogEntryCreateEventActionTypeHandler; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; @@ -30,12 +30,11 @@ *

*/ @Slf4j -@Singleton +@ApplicationScoped public final class GuildAuditLogEntryEventListener extends ListenerAdapter { private final @NonNull Instance handlerInstances; - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; + private final @NonNull ThreadFactory virtualThreadFactory; @Inject public GuildAuditLogEntryEventListener(@NonNull Instance handlerInstances, diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/message/GuildMessageEventListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/message/GuildMessageEventListener.java index 5b6069f..977c4d4 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/message/GuildMessageEventListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/guild/message/GuildMessageEventListener.java @@ -2,8 +2,8 @@ import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; import io.github.eggy03.papertrail.bot.service.handlers.guild.message.GuildMessageEventHandler; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import net.dv8tion.jda.api.events.message.MessageDeleteEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -12,12 +12,11 @@ import java.util.concurrent.ThreadFactory; -@Singleton +@ApplicationScoped public final class GuildMessageEventListener extends ListenerAdapter { private final @NonNull GuildMessageEventHandler handler; - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; + private final @NonNull ThreadFactory virtualThreadFactory; @Inject public GuildMessageEventListener(@NonNull GuildMessageEventHandler handler, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/misc/ActivityUpdateListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/misc/ActivityUpdateListener.java index 05a7968..de49ba2 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/misc/ActivityUpdateListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/misc/ActivityUpdateListener.java @@ -1,10 +1,8 @@ package io.github.eggy03.papertrail.bot.listeners.misc; -import io.github.eggy03.papertrail.bot.configuration.PaperTrailConfig; -import io.quarkus.runtime.ImageMode; -import io.quarkus.runtime.LaunchMode; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.Activity; @@ -14,24 +12,28 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.sharding.ShardManager; -@Singleton +@ApplicationScoped @Slf4j public final class ActivityUpdateListener extends ListenerAdapter { private final @NonNull ShardManager manager; - private final @NonNull PaperTrailConfig paperTrailConfig; + private final @NonNull PaperTrailEnvironment paperTrailEnvironment; @Inject - public ActivityUpdateListener(@NonNull ShardManager manager, @NonNull PaperTrailConfig paperTrailConfig) { + public ActivityUpdateListener(@NonNull ShardManager manager, @NonNull PaperTrailEnvironment paperTrailEnvironment) { this.manager = manager; - this.paperTrailConfig = paperTrailConfig; + this.paperTrailEnvironment = paperTrailEnvironment; } @Override public void onReady(@NonNull ReadyEvent event) { // update on cold start - manager.setActivity(Activity.customStatus( - "/setup | " + paperTrailConfig.general().appVersion() + " | " + getImageMode() + " | " + getLaunchMode()) - ); + + String customActivity = paperTrailEnvironment.general().appActivity(); + if (customActivity.isBlank()) { + manager.setActivity(Activity.customStatus("/help | v" + paperTrailEnvironment.general().appVersion())); + } else + manager.setActivity(Activity.customStatus(customActivity)); + } @Override @@ -43,21 +45,4 @@ public void onGuildJoin(@NonNull GuildJoinEvent event) { // update on guild join public void onGuildLeave(@NonNull GuildLeaveEvent event) { // update on guild leave log.info("Bot Removed From [Guild={}, ID={}]", event.getGuild().getName(), event.getGuild().getId()); } - - private @NonNull String getLaunchMode() { - return switch (LaunchMode.current()) { - case DEVELOPMENT -> "Dev"; - case NORMAL -> "Production"; - case RUN -> "Production w/ Dev Services"; - case TEST -> "Test"; - }; - } - - private @NonNull String getImageMode() { - return switch (ImageMode.current()) { - case JVM -> "JVM"; - case NATIVE_BUILD -> "Native Build Phase"; - case NATIVE_RUN -> "Native"; - }; - } } \ No newline at end of file diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/misc/SelfKickListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/misc/SelfKickListener.java index 1d7e827..cb1bf83 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/misc/SelfKickListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/misc/SelfKickListener.java @@ -1,10 +1,9 @@ package io.github.eggy03.papertrail.bot.listeners.misc; import io.github.eggy03.papertrail.bot.annotations.VirtualThreadFactory; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.client.MessageLogRegistrationClient; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.inject.Singleton; import lombok.NonNull; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.events.guild.GuildLeaveEvent; @@ -15,22 +14,17 @@ /* * This class will have methods that unregister the log channels from the database after the bot has been kicked */ -@Singleton +@ApplicationScoped public final class SelfKickListener extends ListenerAdapter { @NonNull - private final AuditLogRegistrationClient auditLogRegistrationClient; + private final PaperTrailGuildClient paperTrailGuildClient; - @NonNull - private final MessageLogRegistrationClient messageLogRegistrationClient; - - private final @NonNull - @VirtualThreadFactory ThreadFactory virtualThreadFactory; + private final @NonNull ThreadFactory virtualThreadFactory; @Inject - public SelfKickListener(@NonNull AuditLogRegistrationClient auditLogRegistrationClient, @NonNull MessageLogRegistrationClient messageLogRegistrationClient, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { - this.auditLogRegistrationClient = auditLogRegistrationClient; - this.messageLogRegistrationClient = messageLogRegistrationClient; + public SelfKickListener(@NonNull PaperTrailGuildClient paperTrailGuildClient, @NonNull @VirtualThreadFactory ThreadFactory virtualThreadFactory) { + this.paperTrailGuildClient = paperTrailGuildClient; this.virtualThreadFactory = virtualThreadFactory; } @@ -38,10 +32,9 @@ public SelfKickListener(@NonNull AuditLogRegistrationClient auditLogRegistration public void onGuildLeave(@NonNull GuildLeaveEvent event) { Guild leftGuild = event.getGuild(); - virtualThreadFactory.newThread(() -> { - auditLogRegistrationClient.deleteRegisteredGuild(leftGuild.getId()); - messageLogRegistrationClient.deleteRegisteredGuild(leftGuild.getId()); - }).start(); + virtualThreadFactory.newThread(() -> + paperTrailGuildClient.deleteGuild(leftGuild.getId()) + ).start(); } } diff --git a/src/main/java/io/github/eggy03/papertrail/bot/listeners/misc/SlashCommandRegistrationListener.java b/src/main/java/io/github/eggy03/papertrail/bot/listeners/misc/SlashCommandRegistrationListener.java index 938a511..6c99f47 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/listeners/misc/SlashCommandRegistrationListener.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/listeners/misc/SlashCommandRegistrationListener.java @@ -1,12 +1,13 @@ package io.github.eggy03.papertrail.bot.listeners.misc; -import jakarta.inject.Singleton; +import jakarta.enterprise.context.ApplicationScoped; import lombok.NonNull; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.events.session.ReadyEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.interactions.InteractionContextType; import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions; +import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; @@ -14,7 +15,7 @@ /* * Registers all the slash commands places throughout the code on startup */ -@Singleton +@ApplicationScoped public final class SlashCommandRegistrationListener extends ListenerAdapter { @Override @@ -24,29 +25,33 @@ public void onReady(@NonNull ReadyEvent event) { private void setAuditLogCommands(@NonNull JDA jda) { - CommandData auditLog = Commands - .slash("auditlog", "manage audit log options") + // main commands + CommandData config = Commands + .slash("config", "Configures the bot in your guild") .setContexts(InteractionContextType.GUILD) .setDefaultPermissions(DefaultMemberPermissions.DISABLED) - .addSubcommands(new SubcommandData("set", "set audit log channel here")) - .addSubcommands(new SubcommandData("view", "view audit log channel")) - .addSubcommands(new SubcommandData("remove", "unset audit log channel")); + .addSubcommands( + new SubcommandData("save", "Creates a configuration for your guild") + .addOption(OptionType.CHANNEL, "guild_event_channel", "Set channel for guild events", false) + .addOption(OptionType.CHANNEL, "member_event_channel", "Set channel for member events", false) + .addOption(OptionType.CHANNEL, "message_event_channel", "Set channel for message events", false), - CommandData messageLog = Commands - .slash("messagelog", "manage message log options") - .setContexts(InteractionContextType.GUILD) - .setDefaultPermissions(DefaultMemberPermissions.DISABLED) - .addSubcommands(new SubcommandData("set", "set message log channel here")) - .addSubcommands(new SubcommandData("view", "view message log channel")) - .addSubcommands(new SubcommandData("remove", "unset message log channel")); + new SubcommandData("view", "Shows the current configuration for your guild"), + + new SubcommandData("update", "Updates the current configuration") + .addOption(OptionType.CHANNEL, "guild_event_channel", "Set channel for guild events", false) + .addOption(OptionType.CHANNEL, "member_event_channel", "Set channel for member events", false) + .addOption(OptionType.CHANNEL, "message_event_channel", "Set channel for message events", false) + ); + // general commands CommandData serverStats = Commands .slash("stats", "Provides Server Statistics") .setContexts(InteractionContextType.GUILD) .setDefaultPermissions(DefaultMemberPermissions.ENABLED); - CommandData setup = Commands - .slash("setup", "Provides a guide on setting up the bot") + CommandData help = Commands + .slash("help", "Provides a guide on setting up the bot") .setContexts(InteractionContextType.GUILD) .setDefaultPermissions(DefaultMemberPermissions.ENABLED); @@ -56,7 +61,7 @@ private void setAuditLogCommands(@NonNull JDA jda) { .setDefaultPermissions(DefaultMemberPermissions.ENABLED); jda.updateCommands() - .addCommands(auditLog, messageLog, serverStats, setup, debug) + .addCommands(config, serverStats, help, debug) .queue(); } } diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/AuditLogSetupCommandHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/AuditLogSetupCommandHandler.java deleted file mode 100644 index f408073..0000000 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/AuditLogSetupCommandHandler.java +++ /dev/null @@ -1,119 +0,0 @@ -package io.github.eggy03.papertrail.bot.service.handlers.command; - -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import net.dv8tion.jda.api.utils.MarkdownUtil; - -import java.awt.Color; -import java.util.Optional; - -@ApplicationScoped -@Slf4j -public final class AuditLogSetupCommandHandler { - - private final @NonNull AuditLogRegistrationClient client; - - @Inject - public AuditLogSetupCommandHandler(@NonNull AuditLogRegistrationClient client) { - this.client = client; - } - - public void setAuditLogging(@NonNull SlashCommandInteractionEvent event) { - - Guild callerGuild = event.getGuild(); - GuildChannel callerChannel = event.getChannel().asTextChannel(); - if (callerGuild == null) { - log.warn("An audit log set command may have been called outside of a guild. This should not happen."); - return; - } - - // acknowledge this interaction before calling the API - event.deferReply().queue(); - - // Call the API to register the guild and the channel - boolean success = client.registerGuild(callerGuild.getId(), callerChannel.getId()); - - EmbedBuilder eb = new EmbedBuilder(); - eb.setTitle("Audit Log Registration Process"); - - if (success) { - eb.setColor(Color.GREEN); - eb.addField(MarkdownUtil.underline("Registration Success"), MarkdownUtil.codeblock("All audit log info will be logged here"), false); - } else { - eb.setColor(Color.YELLOW); - eb.addField(MarkdownUtil.underline("Registration Failure"), MarkdownUtil.codeblock("Channel could not be registered. Check if a channel in this guild is already registered for logging."), false); - } - - event.getHook().editOriginalEmbeds(eb.build()).queue(); - } - - public void viewAuditLoggingChannel(@NonNull SlashCommandInteractionEvent event) { - - Guild callerGuild = event.getGuild(); - if (callerGuild == null) { - log.warn("An audit log view command may have been called outside of a guild. This should not happen."); - return; - } - - // acknowledge this interaction before calling the API - event.deferReply().queue(); - - // Call the API to retrieve the registered channel - Optional response = client.getRegisteredGuild(callerGuild.getId()); - - EmbedBuilder eb = new EmbedBuilder(); - eb.setTitle("View Existing Audit Log Configuration"); - - // if there is no channel_id for the given guild_id returned by the API, then inform - // the user of the same, else link the channel that has been registered - response.ifPresentOrElse(success -> { - String registeredChannelId = success.getChannelId(); - GuildChannel registeredChannel = event.getJDA().getGuildChannelById(registeredChannelId); - String registeredChannelName = registeredChannel != null ? registeredChannel.getName() : registeredChannelId; - - eb.setColor(Color.CYAN); - eb.addField(MarkdownUtil.underline("Success"), MarkdownUtil.codeblock(registeredChannelName + " is found to be registered as the audit log channel"), false); - }, () -> { - eb.setColor(Color.YELLOW); - eb.addField(MarkdownUtil.underline("Warning"), MarkdownUtil.codeblock("No channel has been registered for audit logs"), false); - }); - - event.getHook().editOriginalEmbeds(eb.build()).queue(); - } - - public void unsetAuditLogging(@NonNull SlashCommandInteractionEvent event) { - - Guild callerGuild = event.getGuild(); - if (callerGuild == null) { - log.warn("An audit log unset command may have been called outside of a guild. This should not happen."); - return; - } - - // acknowledge this interaction before calling the API - event.deferReply().queue(); - - // Call the API to unregister guild - boolean success = client.deleteRegisteredGuild(callerGuild.getId()); - - EmbedBuilder eb = new EmbedBuilder(); - eb.setTitle("Audit Log Removal Process"); - - if (success) { - eb.setColor(Color.GREEN); - eb.addField(MarkdownUtil.underline("Removal Success"), MarkdownUtil.codeblock("Channel successfully unset"), false); - } else { - eb.setColor(Color.YELLOW); - eb.addField(MarkdownUtil.underline("Removal Failure"), MarkdownUtil.codeblock("Channel could not be unset. This may be because no channel has been registered in this guild yet."), false); - } - - event.getHook().editOriginalEmbeds(eb.build()).queue(); - } -} diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/BotSetupInstructionCommandHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/BotSetupInstructionCommandHandler.java deleted file mode 100644 index f690669..0000000 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/BotSetupInstructionCommandHandler.java +++ /dev/null @@ -1,78 +0,0 @@ -package io.github.eggy03.papertrail.bot.service.handlers.command; - -import io.github.eggy03.papertrail.bot.configuration.PaperTrailConfig; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; -import lombok.NonNull; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.MessageEmbed; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; - -import java.awt.Color; -import java.time.Instant; - -@ApplicationScoped -public final class BotSetupInstructionCommandHandler { - - private final @NonNull PaperTrailConfig paperTrailConfig; - - @Inject - public BotSetupInstructionCommandHandler(@NonNull PaperTrailConfig paperTrailConfig) { - this.paperTrailConfig = paperTrailConfig; - } - - public void sendInstructions(@NonNull SlashCommandInteractionEvent event) { - - EmbedBuilder eb = new EmbedBuilder(); - eb.setTitle("🛠️ Setup Guide for " + paperTrailConfig.general().appName()); - eb.setDescription("Follow the instructions below to set up the bot in your server."); - eb.setColor(Color.decode("#38e8bc")); - - eb.addField("1️⃣ Set Audit Log Channel", - "Use `/auditlog set` to **register this channel** for receiving audit log events.", - false); - - eb.addField("2️⃣ View Audit Log Channel", - "Use `/auditlog view` to **see which channel** is currently receiving audit logs.", - false); - - eb.addField("3️⃣ Remove Audit Log Channel", - "Use `/auditlog remove` to **stop logging** events and remove the registered channel.", - false); - - eb.addField("🔒 Permissions", - "These three commands require the **Administrator** permission.", - false); - - eb.addBlankField(false); - - eb.addField("4️⃣ Set Message Log Channel", - "Use `/messagelog set` to **register this channel** for receiving message logs.", - false); - - eb.addField("5️⃣ View Message Log Channel", - "Use `/messagelog view` to **see which channel** is currently receiving message logs.", - false); - - eb.addField("6️⃣ Remove Message Log Channel", - "Use `/messagelog remove` to **stop logging** messages and remove the registered channel.", - false); - - eb.addField("🔒 Permissions", - "These three commands require the **Administrator** permission.", - false); - - eb.addBlankField(false); - - eb.addField("7️⃣ View Server Stats", - "Use `/stats` to **view useful server information**, including member count, channel count, and more.", - false); - - eb.addField("📬 Need help?", "Create an issue on [GitHub](" + paperTrailConfig.general().githubIssueLink() + ")", false); - eb.setFooter(paperTrailConfig.general().appName() + " " + paperTrailConfig.general().appVersion()); - eb.setTimestamp(Instant.now()); - - MessageEmbed mb = eb.build(); - event.replyEmbeds(mb).queue(); - } -} diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/ConfigCommandHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/ConfigCommandHandler.java new file mode 100644 index 0000000..1236520 --- /dev/null +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/ConfigCommandHandler.java @@ -0,0 +1,170 @@ +package io.github.eggy03.papertrail.bot.service.handlers.command; + +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; +import net.dv8tion.jda.api.utils.MarkdownUtil; + +import java.util.Optional; + +@ApplicationScoped +@Slf4j +@SuppressWarnings("java:S1192") +public final class ConfigCommandHandler { + + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; + + @Inject + public ConfigCommandHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment) { + this.client = client; + this.environment = environment; + } + + public void saveGuild(@NonNull SlashCommandInteractionEvent event) { + + Guild callerGuild = event.getGuild(); + if (callerGuild == null) { + log.warn("An audit log set command may have been called outside of a guild. This should not happen."); + return; + } + + // acknowledge this interaction before calling the API + event.deferReply().queue(); + + OptionMapping guildEventChannelOption = event.getOption("guild_event_channel"); + OptionMapping memberEventChannelOption = event.getOption("member_event_channel"); + OptionMapping messageEventChannelOption = event.getOption("message_event_channel"); + + String guildEventChannelId = guildEventChannelOption == null ? null : guildEventChannelOption.getAsChannel().getId(); + String memberEventChannelId = memberEventChannelOption == null ? null : memberEventChannelOption.getAsChannel().getId(); + String messageEventChannelId = messageEventChannelOption == null ? null : messageEventChannelOption.getAsChannel().getId(); + + // Call the API to register the guild and the channel + boolean success = client.saveGuild(callerGuild.getId(), guildEventChannelId, memberEventChannelId, messageEventChannelId); + + EmbedBuilder eb = new EmbedBuilder(); + eb.setTitle("Bot Setup Process"); + + if (success) { + eb.setColor(environment.embedColor().successColor()); + eb.addField(MarkdownUtil.underline("Setup Success"), MarkdownUtil.codeblock("Events will be logged in your set channels"), false); + } else { + eb.setColor(environment.embedColor().warningColor()); + eb.addField(MarkdownUtil.underline("Setup Failure"), MarkdownUtil.codeblock("Channels could not be registered. This could be due to an existing configuration. You must also provide at least one channel during setup."), false); + } + + event.getHook().editOriginalEmbeds(eb.build()).queue(); + } + + public void viewGuild(@NonNull SlashCommandInteractionEvent event) { + + Guild callerGuild = event.getGuild(); + if (callerGuild == null) { + log.warn("An audit log view command may have been called outside of a guild. This should not happen."); + return; + } + + // acknowledge this interaction before calling the API + event.deferReply().queue(); + + // Call the API to retrieve the registered channel + Optional response = client.getGuild(callerGuild.getId()); + + EmbedBuilder eb = new EmbedBuilder(); + eb.setTitle("View Existing Configuration"); + + // if no guild object returned by the API, then inform + // the user that no channel has been registered, else resolve the channels + response.ifPresentOrElse(success -> { + + String guildEventChannelId = success.guildEventChannelId(); + String memberEventChannelId = success.memberEventChannelId(); + String messageEventChannelId = success.messageEventChannelId(); + + GuildChannel guildEventChannel = guildEventChannelId == null ? null : event.getJDA().getGuildChannelById(guildEventChannelId); + GuildChannel memberEventChannel = memberEventChannelId == null ? null : event.getJDA().getGuildChannelById(memberEventChannelId); + GuildChannel messageEventChannel = messageEventChannelId == null ? null : event.getJDA().getGuildChannelById(messageEventChannelId); + + String guildEventChannelJumpUrl = guildEventChannel == null ? "Not Available" : guildEventChannel.getJumpUrl(); + String memberEventChannelJumpUrl = memberEventChannel == null ? "Not Available" : memberEventChannel.getJumpUrl(); + String messageEventChannelJumpUrl = messageEventChannel == null ? "Not Available" : messageEventChannel.getJumpUrl(); + + eb.setColor(environment.embedColor().successColor()); + eb.addField(MarkdownUtil.underline("Guild Event Channel"), guildEventChannelJumpUrl, false); + eb.addField(MarkdownUtil.underline("Member Event Channel"), memberEventChannelJumpUrl, false); + eb.addField(MarkdownUtil.underline("Message Event Channel"), messageEventChannelJumpUrl, false); + }, () -> { + eb.setColor(environment.embedColor().warningColor()); + eb.addField(MarkdownUtil.underline("Warning"), MarkdownUtil.codeblock("No Configuration Found"), false); + }); + + event.getHook().editOriginalEmbeds(eb.build()).queue(); + } + + public void updateGuild(@NonNull SlashCommandInteractionEvent event) { + + Guild callerGuild = event.getGuild(); + if (callerGuild == null) { + log.warn("An audit log unset command may have been called outside of a guild. This should not happen."); + return; + } + + // acknowledge this interaction before calling the API + event.deferReply().queue(); + + OptionMapping guildEventChannelOption = event.getOption("guild_event_channel"); + OptionMapping memberEventChannelOption = event.getOption("member_event_channel"); + OptionMapping messageEventChannelOption = event.getOption("message_event_channel"); + + // if all the options are null, unregister the guild + if (guildEventChannelOption == null && memberEventChannelOption == null && messageEventChannelOption == null) { + boolean success = client.deleteGuild(callerGuild.getId()); + + EmbedBuilder eb = new EmbedBuilder(); + eb.setTitle("Delete Existing Configuration"); + + if (success) { + eb.setColor(environment.embedColor().destructiveColor()); + eb.addField(MarkdownUtil.underline("Deletion Success"), MarkdownUtil.codeblock("Configuration Deleted"), false); + } else { + eb.setColor(environment.embedColor().warningColor()); + eb.addField(MarkdownUtil.underline("Deletion Failure"), MarkdownUtil.codeblock("No Configuration Found."), false); + } + + event.getHook().editOriginalEmbeds(eb.build()).queue(); + return; + } + + // else update guild + String guildEventChannelId = guildEventChannelOption == null ? null : guildEventChannelOption.getAsChannel().getId(); + String memberEventChannelId = memberEventChannelOption == null ? null : memberEventChannelOption.getAsChannel().getId(); + String messageEventChannelId = messageEventChannelOption == null ? null : messageEventChannelOption.getAsChannel().getId(); + + // Call the API to update channel + boolean success = client.updateGuild(callerGuild.getId(), guildEventChannelId, memberEventChannelId, messageEventChannelId); + + EmbedBuilder eb = new EmbedBuilder(); + eb.setTitle("Update Existing Configuration"); + + if (success) { + eb.setColor(environment.embedColor().successColor()); + eb.addField(MarkdownUtil.underline("Update Success"), MarkdownUtil.codeblock("Configuration Has Been Updated"), false); + } else { + eb.setColor(environment.embedColor().warningColor()); + eb.addField(MarkdownUtil.underline("Update Failure"), MarkdownUtil.codeblock("No Configuration Found."), false); + } + + event.getHook().editOriginalEmbeds(eb.build()).queue(); + + } +} diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/DebugCommandHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/DebugCommandHandler.java index 6953b01..b6d0b69 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/DebugCommandHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/DebugCommandHandler.java @@ -1,10 +1,8 @@ package io.github.eggy03.papertrail.bot.service.handlers.command; -import io.github.eggy03.papertrail.bot.configuration.PaperTrailConfig; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.utils.BooleanUtils; import io.github.eggy03.papertrail.bot.utils.PermissionUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.client.MessageLogRegistrationClient; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -24,15 +22,11 @@ @ApplicationScoped public final class DebugCommandHandler { - private final @NonNull AuditLogRegistrationClient auditLogRegistrationClient; - private final @NonNull MessageLogRegistrationClient messageLogRegistrationClient; - private final @NonNull PaperTrailConfig paperTrailConfig; + private final @NonNull PaperTrailEnvironment paperTrailEnvironment; @Inject - public DebugCommandHandler(@NonNull AuditLogRegistrationClient auditLogRegistrationClient, @NonNull MessageLogRegistrationClient messageLogRegistrationClient, @NonNull PaperTrailConfig paperTrailConfig) { - this.auditLogRegistrationClient = auditLogRegistrationClient; - this.messageLogRegistrationClient = messageLogRegistrationClient; - this.paperTrailConfig = paperTrailConfig; + public DebugCommandHandler(@NonNull PaperTrailEnvironment paperTrailEnvironment) { + this.paperTrailEnvironment = paperTrailEnvironment; } public void sendDebugInfo(@NonNull SlashCommandInteractionEvent event, @NonNull Guild guild, @NonNull Member member) { @@ -51,10 +45,10 @@ public void sendDebugInfo(@NonNull SlashCommandInteractionEvent event, @NonNull eb.addField(MarkdownUtil.underline("Server Info"), MarkdownUtil.quoteBlock(getServerInfo(guild, channel)), true); eb.addField(MarkdownUtil.underline("User Info"), MarkdownUtil.quoteBlock(getCallerInfo(member)), true); + eb.addBlankField(true); eb.addField(MarkdownUtil.underline("Bot Info"), MarkdownUtil.quoteBlock(getBotInfo(event)), true); - eb.addField(MarkdownUtil.underline("Configuration Info"), MarkdownUtil.quoteBlock(getConfigurationInfo(guild)), true); - eb.setFooter(paperTrailConfig.general().appName() + " " + paperTrailConfig.general().appVersion()); + eb.setFooter(paperTrailEnvironment.general().appName() + " " + paperTrailEnvironment.general().appVersion()); eb.setTimestamp(Instant.now()); event.getHook().editOriginalEmbeds(eb.build()).queue(); @@ -124,28 +118,4 @@ private String getBotInfo(@NonNull SlashCommandInteractionEvent event) { return "Current Shard ID: " + shardInfo.getShardId() + "\n" + "Total Shards: " + shardInfo.getShardTotal(); } - - @NonNull - private String getConfigurationInfo(@NonNull Guild guild) { - - StringBuilder sb = new StringBuilder(); - - auditLogRegistrationClient.getRegisteredGuild(guild.getId()).ifPresentOrElse(entity -> { - GuildChannel channel = guild.getGuildChannelById(entity.getChannelId()); - if (channel != null) - sb.append("Registered Audit Log Channel: ").append(MarkdownUtil.underline(channel.getName())).append("\n"); - else - sb.append("Registered Audit Log Channel: ").append(MarkdownUtil.underline("Registered Channel Unresolvable")).append("\n"); - }, () -> sb.append(MarkdownUtil.underline("No Channel Registered For Audit Logging")).append("\n")); - - messageLogRegistrationClient.getRegisteredGuild(guild.getId()).ifPresentOrElse(entity -> { - GuildChannel channel = guild.getGuildChannelById(entity.getChannelId()); - if (channel != null) - sb.append("Registered Message Log Channel: ").append(MarkdownUtil.underline(channel.getName())); - else - sb.append("Registered Message Log Channel: ").append(MarkdownUtil.underline("Registered Channel Unresolvable")); - }, () -> sb.append(MarkdownUtil.underline("No Channel Registered For Message Logging"))); - - return sb.toString(); - } } diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/HelpCommandHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/HelpCommandHandler.java new file mode 100644 index 0000000..71dc360 --- /dev/null +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/HelpCommandHandler.java @@ -0,0 +1,103 @@ +package io.github.eggy03.papertrail.bot.service.handlers.command; + +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import lombok.NonNull; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.MessageEmbed; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.utils.MarkdownUtil; + +import java.awt.Color; +import java.time.Instant; + +@ApplicationScoped +public final class HelpCommandHandler { + + private final @NonNull PaperTrailEnvironment paperTrailEnvironment; + + @Inject + public HelpCommandHandler(@NonNull PaperTrailEnvironment paperTrailEnvironment) { + this.paperTrailEnvironment = paperTrailEnvironment; + } + + public void sendInstructions(@NonNull SlashCommandInteractionEvent event) { + + EmbedBuilder eb = new EmbedBuilder(); + + eb.setTitle("Setup Guide for " + paperTrailEnvironment.general().appName()); + eb.setColor(Color.WHITE); + + eb.addField( + MarkdownUtil.underline("1. Initial Setup"), + "Use `/config save [guild_event_channel] [member_event_channel] [message_event_chanel]` to save your server configuration. You can provide one or more event channels during setup.", + false + ); + + eb.addField( + MarkdownUtil.quote("Guild Events"), + MarkdownUtil.quoteBlock("The `guild_event_channel` receives events related to the server itself."), + false + ); + + eb.addField( + MarkdownUtil.quote("Member Events"), + MarkdownUtil.quoteBlock("The `member_event_channel` receives events related to server members."), + false + ); + + eb.addField( + MarkdownUtil.quote("Message Events"), + MarkdownUtil.quoteBlock("The `message_event_channel` receives message-related events and message logs."), + false + ); + + eb.addField( + MarkdownUtil.underline("2. View Configuration"), + "Use `/config view` to see the channels currently configured ", + false + ); + + eb.addField( + MarkdownUtil.underline("3. Update Configuration"), + "Use `/config update [guild_event_channel] [member_event_channel] [message_event_chanel]` to **update** your event channel configuration. " + + "Any channel option that is not provided will be **cleared** and set to no channel.", + false + ); + + eb.addField( + MarkdownUtil.underline("4. Remove Configuration"), + "Use `/config update` without providing any event channels to " + + "**remove the existing server configuration**.", + false + ); + + eb.addField( + MarkdownUtil.quote("Permissions"), + MarkdownUtil.quoteBlock("Only users with the ADMINISTRATOR permission can use the `/config` command."), + false + ); + + eb.addBlankField(false); + + eb.addField( + MarkdownUtil.underline("5. View Server Stats"), + "Use `/stats` to view useful server information.", + false + ); + + eb.addField( + MarkdownUtil.underline("6. View Debug Information"), + "Use `/debug` to view useful information about the bot. This information may help troubleshoot issues related to the bot.", + false + ); + + eb.addField("Need help?", "Create an issue on [GitHub](" + paperTrailEnvironment.general().githubIssueLink() + ")", false); + eb.setFooter(paperTrailEnvironment.general().appName() + " " + paperTrailEnvironment.general().appVersion()); + eb.setTimestamp(Instant.now()); + + MessageEmbed mb = eb.build(); + event.replyEmbeds(mb).queue(); + } +} diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/MessageLogSetupCommandHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/MessageLogSetupCommandHandler.java deleted file mode 100644 index 95cb097..0000000 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/MessageLogSetupCommandHandler.java +++ /dev/null @@ -1,119 +0,0 @@ -package io.github.eggy03.papertrail.bot.service.handlers.command; - -import io.github.eggy03.papertrail.sdk.client.MessageLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.MessageLogRegistrationEntity; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import net.dv8tion.jda.api.utils.MarkdownUtil; - -import java.awt.Color; -import java.util.Optional; - -@ApplicationScoped -@Slf4j -public final class MessageLogSetupCommandHandler { - - private final @NonNull MessageLogRegistrationClient client; - - @Inject - public MessageLogSetupCommandHandler(@NonNull MessageLogRegistrationClient client) { - this.client = client; - } - - public void setMessageLogging(@NonNull SlashCommandInteractionEvent event) { - - Guild callerGuild = event.getGuild(); - GuildChannel callerChannel = event.getChannel().asTextChannel(); - if (callerGuild == null) { - log.warn("A message log set command may have been called outside of a guild. This should not happen."); - return; - } - - // acknowledge this interaction before calling the API - event.deferReply().queue(); - - // Call the API to register guild for message logging - boolean success = client.registerGuild(callerGuild.getId(), callerChannel.getId()); - - EmbedBuilder eb = new EmbedBuilder(); - eb.setTitle("Message Log Registration Process"); - - if (success) { - eb.setColor(Color.GREEN); - eb.addField(MarkdownUtil.underline("Registration Success"), MarkdownUtil.codeblock("All edited and deleted messages will be logged here"), false); - } else { - eb.setColor(Color.YELLOW); - eb.addField(MarkdownUtil.underline("Registration Failure"), MarkdownUtil.codeblock("Channel could not be registered. Check if a channel in this guild is already registered for logging."), false); - - } - - event.getHook().editOriginalEmbeds(eb.build()).queue(); - } - - public void viewMessageLoggingChannel(@NonNull SlashCommandInteractionEvent event) { - - Guild callerGuild = event.getGuild(); - if (callerGuild == null) { - log.warn("A message log view command may have been called outside of a guild. This should not happen."); - return; - } - - // acknowledge this interaction before calling the API - event.deferReply().queue(); - - // Call the API to check for registered guild - Optional response = client.getRegisteredGuild(callerGuild.getId()); - - EmbedBuilder eb = new EmbedBuilder(); - eb.setTitle("View Existing Message Log Configuration"); - - response.ifPresentOrElse(success -> { - - String registeredChannelId = success.getChannelId(); - GuildChannel registeredChannel = event.getJDA().getGuildChannelById(registeredChannelId); - String registeredChannelName = registeredChannel != null ? registeredChannel.getName() : registeredChannelId; - - eb.setColor(Color.CYAN); - eb.addField(MarkdownUtil.underline("Success"), MarkdownUtil.codeblock(registeredChannelName + " is found to be registered as the message log channel"), false); - }, () -> { - eb.setColor(Color.YELLOW); - eb.addField(MarkdownUtil.underline("Warning"), MarkdownUtil.codeblock("No channel has been registered for message logs"), false); - }); - - event.getHook().editOriginalEmbeds(eb.build()).queue(); - } - - public void unsetMessageLogging(@NonNull SlashCommandInteractionEvent event) { - - Guild callerGuild = event.getGuild(); - if (callerGuild == null) { - log.warn("A message log unset command may have been called outside of a guild. This should not happen."); - return; - } - - // acknowledge this interaction before calling the API - event.deferReply().queue(); - - // Call the API to unregister guild - boolean success = client.deleteRegisteredGuild(callerGuild.getId()); - - EmbedBuilder eb = new EmbedBuilder(); - eb.setTitle("Message Log Removal Process"); - - if (success) { - eb.setColor(Color.GREEN); - eb.addField(MarkdownUtil.underline("Removal Success"), MarkdownUtil.codeblock("Channel successfully unset"), false); - } else { - eb.setColor(Color.YELLOW); - eb.addField(MarkdownUtil.underline("Removal Failure"), MarkdownUtil.codeblock("Channel could not be unset. This may be because no channel has been registered in this guild yet."), false); - } - - event.getHook().editOriginalEmbeds(eb.build()).queue(); - } -} diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/ServerStatCommandHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/ServerStatCommandHandler.java index f16c2f4..816a37c 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/ServerStatCommandHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/ServerStatCommandHandler.java @@ -25,7 +25,7 @@ public void sendServerStats(@NonNull SlashCommandInteractionEvent event, @NonNul eb.setTitle("Server Statistics"); eb.setDescription("Statistics For: " + guild.getName()); eb.setThumbnail(guild.getIconUrl()); - eb.setColor(Color.PINK); + eb.setColor(Color.WHITE); eb.addField(MarkdownUtil.underline("Guild Owner"), MarkdownUtil.quoteBlock(getGuildOwner(guild)), false); eb.addField(MarkdownUtil.underline("Guild Created On"), MarkdownUtil.quoteBlock(getGuildCreationDate(guild)), false); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildBoostEventHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildBoostEventHandler.java index d0e5c26..2a0fd99 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildBoostEventHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildBoostEventHandler.java @@ -1,8 +1,9 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -14,9 +15,8 @@ import net.dv8tion.jda.api.events.guild.update.GuildUpdateBoostCountEvent; import net.dv8tion.jda.api.events.guild.update.GuildUpdateBoostTierEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; +import org.jspecify.annotations.Nullable; -import java.awt.Color; import java.time.Instant; import java.time.OffsetDateTime; @@ -24,25 +24,28 @@ @Slf4j public final class GuildBoostEventHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public GuildBoostEventHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public GuildBoostEventHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } public void handleUpdateBoostTier(@NonNull GuildUpdateBoostTierEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; Guild guild = event.getGuild(); @@ -50,7 +53,7 @@ public void handleUpdateBoostTier(@NonNull GuildUpdateBoostTierEvent event) { eb.setTitle("Audit Log Entry | Server Boost Tier Update"); eb.setDescription(MarkdownUtil.quoteBlock("Guild Boost Tier Updated\nTarget Guild: " + guild.getName())); eb.setThumbnail(guild.getIconUrl()); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); Guild.BoostTier oldBoostTier = event.getOldBoostTier(); Guild.BoostTier newBoostTier = event.getNewBoostTier(); @@ -76,7 +79,7 @@ public void handleUpdateBoostTier(@NonNull GuildUpdateBoostTierEvent event) { public void handleUpdateBoostCount(@NonNull GuildUpdateBoostCountEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; Guild guild = event.getGuild(); @@ -84,7 +87,7 @@ public void handleUpdateBoostCount(@NonNull GuildUpdateBoostCountEvent event) { eb.setTitle("Audit Log Entry | Server Boost Event"); eb.setDescription(MarkdownUtil.quoteBlock("Guild Boost Count Updated\nTarget Guild: " + guild.getName())); eb.setThumbnail(guild.getIconUrl()); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); eb.addField(MarkdownUtil.underline("Old Boost Count"), "╰┈➤" + event.getOldBoostCount(), false); eb.addField(MarkdownUtil.underline("New Boost Count"), "╰┈➤" + event.getNewBoostCount(), false); @@ -97,7 +100,7 @@ public void handleUpdateBoostCount(@NonNull GuildUpdateBoostCountEvent event) { public void handleMemberUpdateBoostTime(@NonNull GuildMemberUpdateBoostTimeEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; Member member = event.getMember(); Guild guild = event.getGuild(); @@ -112,10 +115,10 @@ public void handleMemberUpdateBoostTime(@NonNull GuildMemberUpdateBoostTimeEvent if (newBoostTime != null) { eb.setDescription(MarkdownUtil.quoteBlock("Booster Gained: " + mentionableMember + "\nTarget Server: " + guild.getName())); - eb.setColor(Color.PINK); + eb.setColor(environment.embedColor().successColor()); } else { eb.setDescription(MarkdownUtil.quoteBlock("Booster Lost: " + mentionableMember + "\nTarget Server: " + guild.getName())); - eb.setColor(Color.GRAY); + eb.setColor(environment.embedColor().destructiveColor()); } eb.setFooter(guild.getName()); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildMemberEventHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildMemberEventHandler.java index 4b905c9..b74a59a 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildMemberEventHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildMemberEventHandler.java @@ -1,10 +1,11 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.BooleanUtils; import io.github.eggy03.papertrail.bot.utils.DurationUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -17,34 +18,36 @@ import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; import net.dv8tion.jda.api.utils.TimeFormat; -import org.apache.commons.lang3.StringUtils; +import org.jspecify.annotations.Nullable; -import java.awt.Color; import java.time.Instant; @ApplicationScoped @Slf4j public final class GuildMemberEventHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public GuildMemberEventHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public GuildMemberEventHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::memberEventChannelId) + .orElse(null); } public void handleGuildMemberJoin(@NonNull GuildMemberJoinEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; Guild guild = event.getGuild(); User user = event.getUser(); @@ -53,7 +56,7 @@ public void handleGuildMemberJoin(@NonNull GuildMemberJoinEvent event) { eb.setTitle("Audit Log Entry | Member Join Event"); eb.setDescription(MarkdownUtil.quoteBlock("Member Joined: " + user.getName() + "\nGuild: " + guild.getName())); eb.setThumbnail(user.getEffectiveAvatarUrl()); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); eb.addField(MarkdownUtil.underline("Member Name"), "╰┈➤" + user.getName(), false); eb.addField(MarkdownUtil.underline("Member Mention"), "╰┈➤" + user.getAsMention(), false); @@ -69,7 +72,7 @@ public void handleGuildMemberJoin(@NonNull GuildMemberJoinEvent event) { public void handleGuildMemberRemove(@NonNull GuildMemberRemoveEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; Guild guild = event.getGuild(); User user = event.getUser(); @@ -78,7 +81,7 @@ public void handleGuildMemberRemove(@NonNull GuildMemberRemoveEvent event) { eb.setTitle("Audit Log Entry | Member Leave Event"); eb.setDescription(MarkdownUtil.quoteBlock("Member Left: " + user.getName() + "\nGuild: " + guild.getName())); eb.setThumbnail(user.getEffectiveAvatarUrl()); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); eb.addField(MarkdownUtil.underline("Member Name"), "╰┈➤" + user.getName(), false); eb.addField(MarkdownUtil.underline("Member ID"), "╰┈➤" + user.getId(), false); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildPollEventHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildPollEventHandler.java index c09f806..8d7f102 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildPollEventHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildPollEventHandler.java @@ -1,9 +1,10 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.BooleanUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -13,28 +14,30 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; import net.dv8tion.jda.api.utils.TimeFormat; -import org.apache.commons.lang3.StringUtils; +import org.jspecify.annotations.Nullable; -import java.awt.Color; import java.time.Instant; @ApplicationScoped @Slf4j public final class GuildPollEventHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public GuildPollEventHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public GuildPollEventHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -45,11 +48,11 @@ public void handlePollCreationEvent(@NonNull MessageReceivedEvent event) { return; String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Poll Creation Event"); - eb.setColor(Color.PINK); + eb.setColor(environment.embedColor().successColor()); eb.setDescription(MarkdownUtil.quoteBlock("Poll Created By: " + event.getAuthor().getAsMention() + "\nTarget Channel: " + event.getChannel().getAsMention())); eb.addField(MarkdownUtil.underline("Question"), messagePoll.getQuestion().getText(), false); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildSecurityIncidentEventHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildSecurityIncidentEventHandler.java index b3cb66b..0502159 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildSecurityIncidentEventHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildSecurityIncidentEventHandler.java @@ -1,9 +1,10 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.DurationUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -14,9 +15,8 @@ import net.dv8tion.jda.api.events.guild.update.GuildUpdateSecurityIncidentActionsEvent; import net.dv8tion.jda.api.events.guild.update.GuildUpdateSecurityIncidentDetectionsEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; +import org.jspecify.annotations.Nullable; -import java.awt.Color; import java.time.Instant; import java.time.OffsetDateTime; @@ -24,25 +24,28 @@ @Slf4j public final class GuildSecurityIncidentEventHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public GuildSecurityIncidentEventHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public GuildSecurityIncidentEventHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } public void handleGuildUpdateSecurityIncidentDetections(@NonNull GuildUpdateSecurityIncidentDetectionsEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; SecurityIncidentDetections oldSID = event.getOldSecurityIncidentDetections(); SecurityIncidentDetections newSID = event.getNewSecurityIncidentDetections(); @@ -57,7 +60,7 @@ public void handleGuildUpdateSecurityIncidentDetections(@NonNull GuildUpdateSecu EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Security Incident Resolved"); eb.setDescription(MarkdownUtil.quoteBlock("Incident Type: DM Spam\nStatus: Resolved")); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); eb.addField(MarkdownUtil.underline("DM Spam Started At"), DurationUtils.isoToLocalTimeCounter(oldDMSpamDetectedAt), false); eb.setFooter(event.getGuild().getName()); eb.setTimestamp(Instant.now()); @@ -69,7 +72,7 @@ public void handleGuildUpdateSecurityIncidentDetections(@NonNull GuildUpdateSecu EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Security Incident Detected"); eb.setDescription(MarkdownUtil.quoteBlock("Incident Type: DM Spam\nStatus: Detected")); - eb.setColor(Color.ORANGE); + eb.setColor(environment.embedColor().warningColor()); eb.addField(MarkdownUtil.underline("DM Spam Detected At"), DurationUtils.isoToLocalTimeCounter(newDMSpamDetectedAt), false); eb.setFooter(event.getGuild().getName()); eb.setTimestamp(Instant.now()); @@ -81,7 +84,7 @@ public void handleGuildUpdateSecurityIncidentDetections(@NonNull GuildUpdateSecu EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Security Incident Resolved"); eb.setDescription(MarkdownUtil.quoteBlock("Incident Type: RAID\nStatus: Resolved")); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); eb.addField(MarkdownUtil.underline("Raid Was Detected At"), DurationUtils.isoToLocalTimeCounter(oldRaidDetectedAt), false); eb.setFooter(event.getGuild().getName()); eb.setTimestamp(Instant.now()); @@ -93,7 +96,7 @@ public void handleGuildUpdateSecurityIncidentDetections(@NonNull GuildUpdateSecu EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Security Incident Detected"); eb.setDescription(MarkdownUtil.quoteBlock("Incident Type: RAID\nStatus: Detected")); - eb.setColor(Color.ORANGE); + eb.setColor(environment.embedColor().warningColor()); eb.addField(MarkdownUtil.underline("Raid Detected At"), DurationUtils.isoToLocalTimeCounter(newRaidDetectedAt), false); eb.setFooter(event.getGuild().getName()); eb.setTimestamp(Instant.now()); @@ -104,7 +107,7 @@ public void handleGuildUpdateSecurityIncidentDetections(@NonNull GuildUpdateSecu public void handleGuildUpdateSecurityIncidentActions(@NonNull GuildUpdateSecurityIncidentActionsEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; SecurityIncidentActions oldSIA = event.getOldSecurityIncidentActions(); SecurityIncidentActions newSIA = event.getNewSecurityIncidentActions(); @@ -119,7 +122,7 @@ public void handleGuildUpdateSecurityIncidentActions(@NonNull GuildUpdateSecurit EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Security Action Disabled"); eb.setDescription(MarkdownUtil.quoteBlock("Action Type: DM Pause\nStatus: Disabled")); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); eb.addField(MarkdownUtil.underline("DMs Were Paused Until"), DurationUtils.isoToLocalTimeCounter(oldDMDisabledUntil), false); eb.setFooter(event.getGuild().getName()); eb.setTimestamp(Instant.now()); @@ -131,7 +134,7 @@ public void handleGuildUpdateSecurityIncidentActions(@NonNull GuildUpdateSecurit EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Security Action Enabled"); eb.setDescription(MarkdownUtil.quoteBlock("Action Type: DM Pause\nStatus: Enabled")); - eb.setColor(Color.ORANGE); + eb.setColor(environment.embedColor().warningColor()); eb.addField(MarkdownUtil.underline("DMs Paused Until"), DurationUtils.isoToLocalTimeCounter(newDMDisabledUntil), false); eb.setFooter(event.getGuild().getName()); eb.setTimestamp(Instant.now()); @@ -143,7 +146,7 @@ public void handleGuildUpdateSecurityIncidentActions(@NonNull GuildUpdateSecurit EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Security Action Disabled"); eb.setDescription(MarkdownUtil.quoteBlock("Action Type: Invite Pause\nStatus: Disabled")); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); eb.addField(MarkdownUtil.underline("Invites Were Paused Until"), DurationUtils.isoToLocalTimeCounter(oldInvitesPausedUntil), false); eb.setFooter(event.getGuild().getName()); eb.setTimestamp(Instant.now()); @@ -155,7 +158,7 @@ public void handleGuildUpdateSecurityIncidentActions(@NonNull GuildUpdateSecurit EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Security Action Enabled"); eb.setDescription(MarkdownUtil.quoteBlock("Action Type: Invite Pause\nStatus: Enabled")); - eb.setColor(Color.ORANGE); + eb.setColor(environment.embedColor().warningColor()); eb.addField(MarkdownUtil.underline("Invites Paused Until"), DurationUtils.isoToLocalTimeCounter(newInvitesPausedUntil), false); eb.setFooter(event.getGuild().getName()); eb.setTimestamp(Instant.now()); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildVoiceEventHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildVoiceEventHandler.java index 6c54cd6..f206e82 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildVoiceEventHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/GuildVoiceEventHandler.java @@ -1,8 +1,9 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -12,35 +13,36 @@ import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; +import org.jspecify.annotations.Nullable; -import java.awt.Color; import java.time.Instant; @ApplicationScoped @Slf4j public final class GuildVoiceEventHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public GuildVoiceEventHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public GuildVoiceEventHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull - private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + private @Nullable String getRegisteredChannelId(@NonNull String guildId) { + return client.getGuild(guildId) + .map(PaperTrailGuild::memberEventChannelId) + .orElse(null); } - + public void handleVoiceUpdateEvent(@NonNull GuildVoiceUpdateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; Member member = event.getMember(); AudioChannel left = event.getOldValue(); // can be null if user joined for first time @@ -52,7 +54,7 @@ public void handleVoiceUpdateEvent(@NonNull GuildVoiceUpdateEvent event) { if (left == null && joined != null) { // User has joined a vc eb.setDescription("A Member Has Joined A Voice Channel"); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); eb.addField( MarkdownUtil.underline("Connection Event Metadata"), MarkdownUtil.quoteBlock("Connected Member: " + member.getAsMention() + "\nJoined Channel: " + joined.getAsMention()), @@ -63,7 +65,7 @@ public void handleVoiceUpdateEvent(@NonNull GuildVoiceUpdateEvent event) { if (left != null && joined != null) { // Moved from one channel to another eb.setDescription("A Member Has Switched Voice Channels"); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); eb.addField( MarkdownUtil.underline("Switch Event Metadata"), MarkdownUtil.quoteBlock("Switched Member: " + member.getAsMention() + "\nLeft Channel: " + left.getAsMention() + "\nJoined Channel: " + joined.getAsMention()), @@ -73,7 +75,7 @@ public void handleVoiceUpdateEvent(@NonNull GuildVoiceUpdateEvent event) { if (left != null && joined == null) { // User disconnected voluntarily (or was disconnected by a moderator) eb.setDescription("A Member Has Left A Voice Channel"); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); eb.addField( MarkdownUtil.underline("Disconnection Event Metadata"), MarkdownUtil.quoteBlock("Disconnected Member: " + member.getAsMention() + "\nLeft Channel: " + left.getAsMention()), diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/AutoModActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/AutoModActionTypeHandler.java index 1532736..789fa5b 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/AutoModActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/AutoModActionTypeHandler.java @@ -1,10 +1,11 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; 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; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -15,36 +16,37 @@ import net.dv8tion.jda.api.entities.automod.AutoModRule; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class AutoModActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public AutoModActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public AutoModActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @Override public void onAutoModerationFlagToChannel(@NonNull GuildAuditLogEntryCreateEvent event) { - + String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -55,7 +57,7 @@ public void onAutoModerationFlagToChannel(@NonNull GuildAuditLogEntryCreateEvent String targetMention = (targetUser != null ? targetUser.getAsMention() : ale.getTargetId()); eb.setDescription(MarkdownUtil.quoteBlock("Event: AutoMod Message Flag\nTarget Member: " + targetMention)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); eb.addField( MarkdownUtil.underline("Additional Info"), @@ -74,7 +76,7 @@ public void onAutoModerationFlagToChannel(@NonNull GuildAuditLogEntryCreateEvent public void onAutoModerationMemberTimeout(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -85,7 +87,7 @@ public void onAutoModerationMemberTimeout(@NonNull GuildAuditLogEntryCreateEvent String targetMention = (targetUser != null ? targetUser.getAsMention() : ale.getTargetId()); eb.setDescription(MarkdownUtil.quoteBlock("Event: AutoMod Member Timeout\nTarget Member: " + targetMention)); - eb.setColor(Color.MAGENTA); + eb.setColor(environment.embedColor().warningColor()); eb.addField( MarkdownUtil.underline("Additional Info"), @@ -103,7 +105,7 @@ public void onAutoModerationMemberTimeout(@NonNull GuildAuditLogEntryCreateEvent public void onAutoModerationRuleBlockMessage(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -114,7 +116,7 @@ public void onAutoModerationRuleBlockMessage(@NonNull GuildAuditLogEntryCreateEv String targetMention = (targetUser != null ? targetUser.getAsMention() : ale.getTargetId()); eb.setDescription(MarkdownUtil.quoteBlock("Event: AutoMod Message Block\nTarget Member: " + targetMention)); - eb.setColor(Color.ORANGE); + eb.setColor(environment.embedColor().warningColor()); eb.addField( MarkdownUtil.underline("Additional Info"), @@ -133,7 +135,7 @@ public void onAutoModerationRuleBlockMessage(@NonNull GuildAuditLogEntryCreateEv public void onAutoModerationRuleCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -144,7 +146,7 @@ public void onAutoModerationRuleCreate(@NonNull GuildAuditLogEntryCreateEvent ev String mentionableExecutor = (executor != null ? executor.getAsMention() : ale.getUserId()); eb.setDescription(MarkdownUtil.quoteBlock("Rule Created By: " + mentionableExecutor + "\nRule Created For: AutoMod")); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -180,7 +182,7 @@ public void onAutoModerationRuleCreate(@NonNull GuildAuditLogEntryCreateEvent ev public void onAutoModerationRuleUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -191,7 +193,7 @@ public void onAutoModerationRuleUpdate(@NonNull GuildAuditLogEntryCreateEvent ev String mentionableExecutor = (executor != null ? executor.getAsMention() : ale.getUserId()); eb.setDescription(MarkdownUtil.quoteBlock("Rule Updated By: " + mentionableExecutor + "\nRule Updated For: AutoMod")); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); // add name of the rule which got updated AutoModRule rule = ale.getGuild().retrieveAutoModRuleById(ale.getTargetId()).complete(); @@ -209,7 +211,7 @@ public void onAutoModerationRuleUpdate(@NonNull GuildAuditLogEntryCreateEvent ev public void onAutoModerationRuleDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -220,7 +222,7 @@ public void onAutoModerationRuleDelete(@NonNull GuildAuditLogEntryCreateEvent ev String mentionableExecutor = (executor != null ? executor.getAsMention() : ale.getUserId()); eb.setDescription(MarkdownUtil.quoteBlock("Rule Deleted By: " + mentionableExecutor + "\nRule Deleted For: AutoMod")); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -241,7 +243,7 @@ public void onAutoModerationRuleDelete(@NonNull GuildAuditLogEntryCreateEvent ev public void onAutoModerationQuarantineUser(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -252,7 +254,7 @@ public void onAutoModerationQuarantineUser(@NonNull GuildAuditLogEntryCreateEven String mentionableTarget = (targetMember != null ? targetMember.getAsMention() : ale.getTargetId()); eb.setDescription(MarkdownUtil.quoteBlock("Quarantined User: " + mentionableTarget)); - eb.setColor(Color.ORANGE); + eb.setColor(environment.embedColor().warningColor()); eb.addField("INFO", "PaperTrail is still learning about this event", false); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ChannelActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ChannelActionTypeHandler.java index faea722..7cc763c 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ChannelActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ChannelActionTypeHandler.java @@ -1,11 +1,12 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.BooleanUtils; import io.github.eggy03.papertrail.bot.utils.DurationUtils; import io.github.eggy03.papertrail.bot.utils.auditlog.ChannelUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -16,28 +17,29 @@ import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class ChannelActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public ChannelActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public ChannelActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -45,7 +47,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onChannelCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -59,7 +61,7 @@ public void onChannelCreate(@NonNull GuildAuditLogEntryCreateEvent event) { eb.setTitle("Audit Log Entry | Channel Create Event"); eb.setDescription(MarkdownUtil.quoteBlock("Channel Created By: " + mentionableExecutor + "\nTarget Channel: " + targetChannelMention)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -109,7 +111,7 @@ public void onChannelCreate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onChannelUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -123,7 +125,7 @@ public void onChannelUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { eb.setTitle("Audit Log Entry | Channel Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Channel Updated By: " + mentionableExecutor + "\nTarget Channel: " + targetChannelMention)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -222,7 +224,7 @@ public void onChannelUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onChannelDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -233,7 +235,7 @@ public void onChannelDelete(@NonNull GuildAuditLogEntryCreateEvent event) { eb.setTitle("Audit Log Entry | Channel Delete Event"); eb.setDescription(MarkdownUtil.quoteBlock("Channel Deleted By: " + mentionableExecutor + "\nTarget Channel ID: " + ale.getTargetId())); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ChannelOverrideActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ChannelOverrideActionTypeHandler.java index f60f843..cab1c30 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ChannelOverrideActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ChannelOverrideActionTypeHandler.java @@ -1,9 +1,10 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.auditlog.ChannelUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -16,28 +17,29 @@ import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class ChannelOverrideActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public ChannelOverrideActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public ChannelOverrideActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -45,7 +47,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onChannelOverrideCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -58,7 +60,7 @@ public void onChannelOverrideCreate(@NonNull GuildAuditLogEntryCreateEvent event EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Channel Override Create"); eb.setDescription(MarkdownUtil.quoteBlock("Override Created By: " + mentionableExecutor + "\nTarget Channel: " + targetChannelMention)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -96,7 +98,7 @@ public void onChannelOverrideCreate(@NonNull GuildAuditLogEntryCreateEvent event @Override public void onChannelOverrideUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -109,7 +111,7 @@ public void onChannelOverrideUpdate(@NonNull GuildAuditLogEntryCreateEvent event EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Channel Override Update"); eb.setDescription(MarkdownUtil.quoteBlock("Override Updated By: " + mentionableExecutor + "\nTarget Channel: " + targetChannelMention)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); eb.addField(MarkdownUtil.underline("Override Type"), "╰┈➤" + ChannelUtils.resolveChannelOverrideTargetType(ale.getOptionByName("type")), false); eb.addField(MarkdownUtil.underline("Permissions Overridden For"), "╰┈➤" + getTargetRoleOrMember(ale, event), false); @@ -143,7 +145,7 @@ public void onChannelOverrideUpdate(@NonNull GuildAuditLogEntryCreateEvent event @Override public void onChannelOverrideDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -157,7 +159,7 @@ public void onChannelOverrideDelete(@NonNull GuildAuditLogEntryCreateEvent event eb.setTitle("Audit Log Entry | Channel Override Delete"); eb.setDescription(MarkdownUtil.quoteBlock("Override Deleted By: " + mentionableExecutor + "\nTarget Channel: " + targetChannelMention)); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/EmojiActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/EmojiActionTypeHandler.java index 797a2fc..a257ed7 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/EmojiActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/EmojiActionTypeHandler.java @@ -1,8 +1,9 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -12,28 +13,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class EmojiActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public EmojiActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public EmojiActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -41,7 +43,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onEmojiCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -51,7 +53,7 @@ public void onEmojiCreate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Emoji Create Event"); eb.setDescription(MarkdownUtil.quoteBlock("Emoji Created By: " + mentionableExecutor)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -76,7 +78,7 @@ public void onEmojiCreate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onEmojiUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -87,7 +89,7 @@ public void onEmojiUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Emoji Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Emoji Updated By: " + mentionableExecutor)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -112,7 +114,7 @@ public void onEmojiUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onEmojiDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -122,7 +124,7 @@ public void onEmojiDelete(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Emoji Delete Event"); eb.setDescription(MarkdownUtil.quoteBlock("Emoji Deleted By: " + mentionableExecutor)); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/GuildUpdateActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/GuildUpdateActionTypeHandler.java index 9bebbff..ef3e8a6 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/GuildUpdateActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/GuildUpdateActionTypeHandler.java @@ -1,11 +1,12 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.BooleanUtils; import io.github.eggy03.papertrail.bot.utils.DurationUtils; import io.github.eggy03.papertrail.bot.utils.auditlog.GuildUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -15,28 +16,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class GuildUpdateActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public GuildUpdateActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public GuildUpdateActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -44,7 +46,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onGuildUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -54,7 +56,7 @@ public void onGuildUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Guild Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Guild Settings Updated By: " + mentionableExecutor + "\nTarget Guild: " + event.getGuild().getName())); - eb.setColor(Color.MAGENTA); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -150,7 +152,7 @@ public void onGuildUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onGuildProfileUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -160,7 +162,7 @@ public void onGuildProfileUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Guild Profile Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Guild Profile Updated By: " + mentionableExecutor + "\nTarget Guild: " + event.getGuild().getName())); - eb.setColor(Color.PINK); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().keySet().forEach(key -> { switch (key) { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/HomeSettingsActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/HomeSettingsActionTypeHandler.java index 210a557..18956b7 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/HomeSettingsActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/HomeSettingsActionTypeHandler.java @@ -1,8 +1,9 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -12,28 +13,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class HomeSettingsActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public HomeSettingsActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public HomeSettingsActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -41,7 +43,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onHomeSettingsCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -51,7 +53,7 @@ public void onHomeSettingsCreate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Server Guide Create Event"); eb.setDescription(MarkdownUtil.quoteBlock("Server Guide Created By: " + mentionableExecutor)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); eb.addField( MarkdownUtil.underline("More Info"), @@ -68,7 +70,7 @@ public void onHomeSettingsCreate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onHomeSettingsUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -78,7 +80,7 @@ public void onHomeSettingsUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Server Guide Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Server Guide Updated By: " + mentionableExecutor)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().keySet().forEach(key -> { switch (key) { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/IntegrationActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/IntegrationActionTypeHandler.java index deb19d8..5f1af25 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/IntegrationActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/IntegrationActionTypeHandler.java @@ -1,8 +1,9 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -12,28 +13,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class IntegrationActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public IntegrationActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public IntegrationActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -41,7 +43,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onIntegrationCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -51,7 +53,7 @@ public void onIntegrationCreate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Integration Create Event"); eb.setDescription(MarkdownUtil.quoteBlock("Integration Created By: " + mentionableExecutor)); - eb.setColor(Color.PINK); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -81,13 +83,13 @@ public void onIntegrationUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { log.warn("Integration Update Event Detected. Implement this sometime later\n{}", event.getEntry().getChanges()); String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Integration Update Event"); - eb.setColor(Color.LIGHT_GRAY); + eb.setColor(environment.embedColor().warningColor()); String implementationNotice = "We do not have sufficient data to log the changes in an INTEGRATION_UPDATE Event." .concat(" A proper implementation might happen in future releases if such an event is fired consistently."); @@ -103,7 +105,7 @@ public void onIntegrationUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onIntegrationDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -113,7 +115,7 @@ public void onIntegrationDelete(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Integration Delete Event"); eb.setDescription(MarkdownUtil.quoteBlock("Integration Deleted By: " + mentionableExecutor)); - eb.setColor(Color.MAGENTA); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -139,7 +141,7 @@ public void onIntegrationDelete(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onApplicationCommandPrivilegesUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -149,7 +151,7 @@ public void onApplicationCommandPrivilegesUpdate(@NonNull GuildAuditLogEntryCrea EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Application Command Privilege Update"); eb.setDescription(MarkdownUtil.quoteBlock("Application Command Privilege Updated By: " + mentionableExecutor)); - eb.setColor(Color.PINK); + eb.setColor(environment.embedColor().warningColor()); eb.addField(MarkdownUtil.underline("More Info"), MarkdownUtil.codeblock("To know more about what changes were made, visit the Integrations section"), false); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/InviteActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/InviteActionTypeHandler.java index a337115..9c44397 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/InviteActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/InviteActionTypeHandler.java @@ -1,11 +1,12 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.BooleanUtils; import io.github.eggy03.papertrail.bot.utils.DurationUtils; import io.github.eggy03.papertrail.bot.utils.auditlog.InviteUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -15,28 +16,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class InviteActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public InviteActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public InviteActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -44,7 +46,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onInviteCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -55,7 +57,7 @@ public void onInviteCreate(@NonNull GuildAuditLogEntryCreateEvent event) { eb.setTitle("Audit Log Entry | Invite Create Event"); eb.setDescription(MarkdownUtil.quoteBlock("Invite Created By: " + mentionableExecutor)); - eb.setColor(Color.CYAN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -106,13 +108,13 @@ public void onInviteUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { log.warn("Invite Update Event Detected. Implement this sometime later\n{}", event.getEntry().getChanges()); String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Invite Update Event"); - eb.setColor(Color.LIGHT_GRAY); + eb.setColor(environment.embedColor().warningColor()); String implementationNotice = "We do not have sufficient data to log the changes in an INVITE_UPDATE Event" .concat(" because invites seem to be immutable at the moment, which causes this event to not be fired.") @@ -129,7 +131,7 @@ public void onInviteUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onInviteDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -140,7 +142,7 @@ public void onInviteDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String mentionableExecutor = (executor != null ? executor.getAsMention() : ale.getUserId()); eb.setDescription(MarkdownUtil.quoteBlock("Invite Deleted By: " + mentionableExecutor)); - eb.setColor(Color.BLUE); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/MemberUpdateActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/MemberUpdateActionTypeHandler.java index f11a3e5..88db81f 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/MemberUpdateActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/MemberUpdateActionTypeHandler.java @@ -1,11 +1,12 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.BooleanUtils; import io.github.eggy03.papertrail.bot.utils.DurationUtils; import io.github.eggy03.papertrail.bot.utils.auditlog.MemberUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -15,28 +16,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class MemberUpdateActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public MemberUpdateActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public MemberUpdateActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::memberEventChannelId) + .orElse(null); } @@ -44,7 +46,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onMemberUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -57,7 +59,7 @@ public void onMemberUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Member Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Executor: " + mentionableExecutor + "\nTarget: " + mentionableTargetUser)); - eb.setColor(Color.CYAN); + eb.setColor(environment.embedColor().warningColor()); if (targetUser != null) eb.setThumbnail(targetUser.getEffectiveAvatarUrl()); @@ -70,10 +72,10 @@ public void onMemberUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { case "communication_disabled_until" -> { if (newValue == null) { - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); eb.addField(MarkdownUtil.underline("Timeout Lifted"), "╰┈➤ Timeout has been removed", false); } else { - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); eb.addField(MarkdownUtil.underline("Timeout Received"), "╰┈➤ Member has received a timeout", false); eb.addField(MarkdownUtil.underline("Timeout Ends On"), "╰┈➤" + DurationUtils.isoToLocalTimeCounter(newValue), false); eb.addField(MarkdownUtil.underline("Timeout Reason"), "╰┈➤" + (ale.getReason() != null ? ale.getReason() : "No Reason Provided"), false); @@ -107,7 +109,7 @@ public void onMemberUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onMemberRoleUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -120,7 +122,7 @@ public void onMemberRoleUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Member Role Update"); eb.setDescription(MarkdownUtil.quoteBlock("Executor: " + mentionableExecutor + "\nTarget: " + mentionableTargetUser)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); if (targetUser != null) eb.setThumbnail(targetUser.getEffectiveAvatarUrl()); @@ -155,7 +157,7 @@ public void onMemberRoleUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { public void onMemberVoiceKick(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -165,7 +167,7 @@ public void onMemberVoiceKick(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Member Voice Kick Event"); eb.setDescription(MarkdownUtil.quoteBlock("Member Kicked From a Voice Channel\n By: " + mentionableExecutor)); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().warningColor()); eb.setFooter("Audit Log Entry ID: " + ale.getId()); eb.setTimestamp(ale.getTimeCreated()); @@ -178,7 +180,7 @@ public void onMemberVoiceKick(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onMemberVoiceMove(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -188,7 +190,7 @@ public void onMemberVoiceMove(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Member Voice Move Event"); eb.setDescription(MarkdownUtil.quoteBlock("Member Moved To A Different Voice Channel\n By: " + mentionableExecutor)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); eb.setFooter("Audit Log Entry ID: " + ale.getId()); eb.setTimestamp(ale.getTimeCreated()); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/MessageActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/MessageActionTypeHandler.java index 1571534..6e6f3c8 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/MessageActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/MessageActionTypeHandler.java @@ -1,8 +1,9 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -12,28 +13,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class MessageActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public MessageActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public MessageActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::messageEventChannelId) + .orElse(null); } @@ -53,7 +55,7 @@ public void onMessageUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onMessageDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -63,7 +65,7 @@ public void onMessageDelete(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Message Delete Event"); eb.setDescription(MarkdownUtil.quoteBlock("Executor: " + mentionableExecutor)); - eb.setColor(Color.LIGHT_GRAY); + eb.setColor(environment.embedColor().destructiveColor()); eb.setFooter("Audit Log Entry ID: " + ale.getId()); eb.setTimestamp(ale.getTimeCreated()); @@ -74,7 +76,7 @@ public void onMessageDelete(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onMessageBulkDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -84,7 +86,7 @@ public void onMessageBulkDelete(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Bulk Message Delete Event"); eb.setDescription(MarkdownUtil.quoteBlock("Executor: " + mentionableExecutor)); - eb.setColor(Color.LIGHT_GRAY); + eb.setColor(environment.embedColor().destructiveColor()); eb.setFooter("Audit Log Entry ID: " + ale.getId()); eb.setTimestamp(ale.getTimeCreated()); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/MessagePinActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/MessagePinActionTypeHandler.java index 9388528..c6737c3 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/MessagePinActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/MessagePinActionTypeHandler.java @@ -1,9 +1,10 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.auditlog.MessageUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -13,28 +14,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class MessagePinActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public MessagePinActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public MessagePinActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -42,7 +44,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onMessagePin(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -56,7 +58,7 @@ public void onMessagePin(@NonNull GuildAuditLogEntryCreateEvent event) { String mentionableTarget = (target != null ? target.getAsMention() : ale.getTargetId()); eb.setDescription(MarkdownUtil.quoteBlock("Message Pinned By: " + mentionableExecutor + "\nMessage Author: " + mentionableTarget)); - eb.setColor(Color.PINK); + eb.setColor(environment.embedColor().successColor()); eb.addField( MarkdownUtil.underline("Pinned Message Jump URL"), @@ -73,7 +75,7 @@ public void onMessagePin(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onMessageUnpin(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -87,7 +89,7 @@ public void onMessageUnpin(@NonNull GuildAuditLogEntryCreateEvent event) { String mentionableTarget = (target != null ? target.getAsMention() : ale.getTargetId()); eb.setDescription(MarkdownUtil.quoteBlock("Message Un-Pinned By: " + mentionableExecutor + "\nMessage Author: " + mentionableTarget)); - eb.setColor(Color.MAGENTA); + eb.setColor(environment.embedColor().warningColor()); eb.addField( MarkdownUtil.underline("Un-Pinned Message Jump URL"), diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ModActionActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ModActionActionTypeHandler.java index 937b934..f856f58 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ModActionActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ModActionActionTypeHandler.java @@ -1,8 +1,9 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -12,28 +13,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class ModActionActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public ModActionActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public ModActionActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::memberEventChannelId) + .orElse(null); } @@ -41,7 +43,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onKick(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -57,7 +59,7 @@ public void onKick(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Kick Event"); eb.setDescription(MarkdownUtil.quoteBlock("A Member Has Been Kicked By: " + mentionableModerator)); - eb.setColor(Color.ORANGE); + eb.setColor(environment.embedColor().warningColor()); eb.addField(MarkdownUtil.underline("Kicked Member"), "╰┈➤" + mentionableKickedUser, false); eb.addField(MarkdownUtil.underline("Reason"), "╰┈➤" + reasonForKick, false); @@ -73,7 +75,7 @@ public void onKick(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onBan(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -89,7 +91,7 @@ public void onBan(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Ban Event"); eb.setDescription(MarkdownUtil.quoteBlock("A Member Has Been Banned By: " + mentionableModerator)); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); eb.addField(MarkdownUtil.underline("Banned Member"), "╰┈➤" + mentionableBannedUser, false); eb.addField(MarkdownUtil.underline("Ban Reason"), "╰┈➤" + reasonForBan, false); @@ -104,7 +106,7 @@ public void onBan(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onUnban(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -118,7 +120,7 @@ public void onUnban(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Member Unban Event"); eb.setDescription(MarkdownUtil.quoteBlock("A Member Has Been Un-Banned By: " + mentionableModerator)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); eb.addField(MarkdownUtil.underline("Un-banned User"), "╰┈➤" + mentionableUnbannedUser, false); @@ -132,7 +134,7 @@ public void onUnban(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onBotAdd(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -145,7 +147,7 @@ public void onBotAdd(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Bot Add Event"); eb.setDescription(MarkdownUtil.quoteBlock("Bot Added By: " + mentionableExecutor + "\nBot ID: " + ale.getTargetId())); - eb.setColor(Color.CYAN); + eb.setColor(environment.embedColor().successColor()); eb.addField(MarkdownUtil.underline("Bot Added"), "╰┈➤" + mentionableTarget, false); @@ -161,13 +163,13 @@ public void onPrune(@NonNull GuildAuditLogEntryCreateEvent event) { log.warn("Prune Event Detected\n{}", event.getEntry().getChanges()); String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Prune Event"); - eb.setColor(Color.LIGHT_GRAY); + eb.setColor(environment.embedColor().warningColor()); String implementationNotice = "We do not have sufficient payload data to log the changes in a PRUNE Event." .concat(" A proper implementation might happen in future releases"); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/OnboardingActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/OnboardingActionTypeHandler.java index 5c6a182..42233c5 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/OnboardingActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/OnboardingActionTypeHandler.java @@ -1,10 +1,11 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.BooleanUtils; import io.github.eggy03.papertrail.bot.utils.auditlog.OnboardingUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -15,28 +16,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class OnboardingActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public OnboardingActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public OnboardingActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -46,13 +48,13 @@ public void onOnboardingCreate(@NonNull GuildAuditLogEntryCreateEvent event) { log.warn("Onboarding Create Event Detected. Implement this sometime later\n{}", event.getEntry().getChanges()); String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Onboarding Create Event"); - eb.setColor(Color.LIGHT_GRAY); + eb.setColor(environment.embedColor().successColor()); String implementationNotice = "We do not have sufficient data to log the changes in an ONBOARDING_CREATE Event." .concat(" That is because, even for Onboarding creations, ONBOARDING_UPDATE is fired instead.") @@ -69,7 +71,7 @@ public void onOnboardingCreate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onOnboardingUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -82,7 +84,7 @@ public void onOnboardingUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { Guild guild = event.getGuild(); eb.setDescription(MarkdownUtil.quoteBlock("Onboarding Settings Updated By: " + mentionableExecutor)); - eb.setColor(Color.MAGENTA); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/OnboardingPromptActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/OnboardingPromptActionTypeHandler.java index cfd324c..384de9e 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/OnboardingPromptActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/OnboardingPromptActionTypeHandler.java @@ -1,9 +1,10 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.BooleanUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -13,28 +14,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class OnboardingPromptActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public OnboardingPromptActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public OnboardingPromptActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -42,7 +44,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onOnboardingPromptCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -53,7 +55,7 @@ public void onOnboardingPromptCreate(@NonNull GuildAuditLogEntryCreateEvent even String mentionableExecutor = (executor != null ? executor.getAsMention() : ale.getTargetId()); eb.setDescription(MarkdownUtil.quoteBlock("Onboarding Prompt Created By: " + mentionableExecutor)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -96,7 +98,7 @@ public void onOnboardingPromptCreate(@NonNull GuildAuditLogEntryCreateEvent even @Override public void onOnboardingPromptUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -107,7 +109,7 @@ public void onOnboardingPromptUpdate(@NonNull GuildAuditLogEntryCreateEvent even String mentionableExecutor = (executor != null ? executor.getAsMention() : ale.getTargetId()); eb.setDescription(MarkdownUtil.quoteBlock("Onboarding Prompt Updated By: " + mentionableExecutor)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -158,7 +160,7 @@ public void onOnboardingPromptUpdate(@NonNull GuildAuditLogEntryCreateEvent even @Override public void onOnboardingPromptDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -169,7 +171,7 @@ public void onOnboardingPromptDelete(@NonNull GuildAuditLogEntryCreateEvent even String mentionableExecutor = (executor != null ? executor.getAsMention() : ale.getTargetId()); eb.setDescription(MarkdownUtil.quoteBlock("Onboarding Prompt Deleted By: " + mentionableExecutor)); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/RoleActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/RoleActionTypeHandler.java index 1291576..736aecc 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/RoleActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/RoleActionTypeHandler.java @@ -1,10 +1,11 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.BooleanUtils; import io.github.eggy03.papertrail.bot.utils.auditlog.RoleUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -15,28 +16,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class RoleActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public RoleActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public RoleActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -44,7 +46,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onRoleCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -57,7 +59,7 @@ public void onRoleCreate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Role Create Event"); eb.setDescription(MarkdownUtil.quoteBlock("Role Created By: " + mentionableExecutor + "\nTarget Role: " + mentionableTargetRole)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -75,7 +77,7 @@ public void onRoleCreate(@NonNull GuildAuditLogEntryCreateEvent event) { * and delegates them to ROLE_UPDATE event */ } - case "icon_hash" -> { + case "icon_hash", "unicode_emoji" -> { // ignore } @@ -95,7 +97,7 @@ public void onRoleCreate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onRoleUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -108,7 +110,7 @@ public void onRoleUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Role Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Role Updated By: " + mentionableExecutor + "\nTarget Role: " + mentionableTargetRole)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -173,7 +175,7 @@ public void onRoleUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onRoleDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -183,7 +185,7 @@ public void onRoleDelete(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Role Delete Event"); eb.setDescription(MarkdownUtil.quoteBlock("Role Deleted By: " + mentionableExecutor + "\nTarget Role ID: " + ale.getTargetId())); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -208,7 +210,7 @@ public void onRoleDelete(@NonNull GuildAuditLogEntryCreateEvent event) { case "colors" -> eb.addField(MarkdownUtil.underline("Gradient Color System"), RoleUtils.formatGradientToHex(oldValue), false); - case "icon_hash" -> { + case "icon_hash", "unicode_emoji" -> { // ignore } diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ScheduledEventActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ScheduledEventActionTypeHandler.java index a2ab041..e98b969 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ScheduledEventActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ScheduledEventActionTypeHandler.java @@ -1,9 +1,10 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.auditlog.ScheduledEventUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -13,28 +14,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class ScheduledEventActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public ScheduledEventActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public ScheduledEventActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -42,7 +44,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onScheduledEventCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -52,7 +54,7 @@ public void onScheduledEventCreate(@NonNull GuildAuditLogEntryCreateEvent event) EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Scheduled Event Create Event"); eb.setDescription(MarkdownUtil.quoteBlock("Scheduled Event Created By: " + mentionableExecutor)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -90,7 +92,7 @@ public void onScheduledEventCreate(@NonNull GuildAuditLogEntryCreateEvent event) @Override public void onScheduledEventUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -100,7 +102,7 @@ public void onScheduledEventUpdate(@NonNull GuildAuditLogEntryCreateEvent event) EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Scheduled Event Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Scheduled Event Updated By: " + mentionableExecutor)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -170,7 +172,7 @@ public void onScheduledEventUpdate(@NonNull GuildAuditLogEntryCreateEvent event) @Override public void onScheduledEventDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -180,7 +182,7 @@ public void onScheduledEventDelete(@NonNull GuildAuditLogEntryCreateEvent event) EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Scheduled Event Delete Event"); eb.setDescription(MarkdownUtil.quoteBlock("Scheduled Event Deleted By: " + mentionableExecutor)); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/SoundboardActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/SoundboardActionTypeHandler.java index 7a1307f..e51a2bd 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/SoundboardActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/SoundboardActionTypeHandler.java @@ -1,9 +1,10 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.auditlog.SoundboardUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -13,28 +14,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class SoundboardActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public SoundboardActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public SoundboardActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -42,7 +44,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onSoundboardSoundCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -52,7 +54,7 @@ public void onSoundboardSoundCreate(@NonNull GuildAuditLogEntryCreateEvent event EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Soundboard Sound Create Event"); eb.setDescription(MarkdownUtil.quoteBlock("Sound Item Added By: " + mentionableExecutor)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -89,7 +91,7 @@ public void onSoundboardSoundCreate(@NonNull GuildAuditLogEntryCreateEvent event @Override public void onSoundboardSoundUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -99,7 +101,7 @@ public void onSoundboardSoundUpdate(@NonNull GuildAuditLogEntryCreateEvent event EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Soundboard Sound Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Sound Item Updated By: " + mentionableExecutor)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -145,7 +147,7 @@ public void onSoundboardSoundUpdate(@NonNull GuildAuditLogEntryCreateEvent event @Override public void onSoundboardSoundDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -155,7 +157,7 @@ public void onSoundboardSoundDelete(@NonNull GuildAuditLogEntryCreateEvent event EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Soundboard Sound Delete Event"); eb.setDescription(MarkdownUtil.quoteBlock("Sound Item Deleted By: " + mentionableExecutor)); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/StageInstanceActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/StageInstanceActionTypeHandler.java index 81f3df8..f339c87 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/StageInstanceActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/StageInstanceActionTypeHandler.java @@ -1,9 +1,10 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.auditlog.StageUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -13,28 +14,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class StageInstanceActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public StageInstanceActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public StageInstanceActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -42,7 +44,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onStageInstanceCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -52,7 +54,7 @@ public void onStageInstanceCreate(@NonNull GuildAuditLogEntryCreateEvent event) EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Stage Instance Create Event"); eb.setDescription(MarkdownUtil.quoteBlock("Stage Instance Created By: " + mentionableExecutor)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -80,7 +82,7 @@ public void onStageInstanceCreate(@NonNull GuildAuditLogEntryCreateEvent event) @Override public void onStageInstanceUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -90,7 +92,7 @@ public void onStageInstanceUpdate(@NonNull GuildAuditLogEntryCreateEvent event) EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Stage Instance Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Stage Instance Updated By: " + mentionableExecutor)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -124,7 +126,7 @@ public void onStageInstanceUpdate(@NonNull GuildAuditLogEntryCreateEvent event) @Override public void onStageInstanceDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -134,7 +136,7 @@ public void onStageInstanceDelete(@NonNull GuildAuditLogEntryCreateEvent event) EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Stage Instance Delete Event"); eb.setDescription(MarkdownUtil.quoteBlock("Stage Instance Deleted By: " + mentionableExecutor)); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/StickerActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/StickerActionTypeHandler.java index e93f169..415c57c 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/StickerActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/StickerActionTypeHandler.java @@ -1,9 +1,10 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.auditlog.StickerUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -14,28 +15,29 @@ import net.dv8tion.jda.api.entities.sticker.GuildSticker; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class StickerActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public StickerActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public StickerActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -43,7 +45,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onStickerCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -56,7 +58,7 @@ public void onStickerCreate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Sticker Create Event"); eb.setDescription(MarkdownUtil.quoteBlock("Sticker Created By: " + mentionableExecutor + "\nCreated Sticker: " + mentionableSticker)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -91,7 +93,7 @@ public void onStickerCreate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onStickerUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -104,7 +106,7 @@ public void onStickerUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Sticker Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Sticker Updated By: " + mentionableExecutor + "\nUpdated Sticker: " + mentionableSticker)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -145,7 +147,7 @@ public void onStickerUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onStickerDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -158,7 +160,7 @@ public void onStickerDelete(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Sticker Delete Event"); eb.setDescription(MarkdownUtil.quoteBlock("Sticker Deleted By: " + mentionableExecutor + "\nDeleted Sticker ID: " + mentionableSticker)); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ThreadActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ThreadActionTypeHandler.java index ecf4510..516373d 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ThreadActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ThreadActionTypeHandler.java @@ -1,12 +1,13 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.BooleanUtils; import io.github.eggy03.papertrail.bot.utils.DurationUtils; import io.github.eggy03.papertrail.bot.utils.auditlog.ChannelUtils; import io.github.eggy03.papertrail.bot.utils.auditlog.ThreadUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -17,28 +18,29 @@ import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class ThreadActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public ThreadActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public ThreadActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -46,7 +48,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onThreadCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -59,7 +61,7 @@ public void onThreadCreate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Thread Create Event"); eb.setDescription(MarkdownUtil.quoteBlock("Thread Created By: " + mentionableExecutor + "\nTarget Thread: " + mentionableTargetThread)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -106,7 +108,7 @@ public void onThreadCreate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onThreadUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -119,7 +121,7 @@ public void onThreadUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Thread Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Thread Updated By: " + mentionableExecutor + "\nTarget Thread: " + mentionableTargetThread)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().forEach((changeKey, changeValue) -> { @@ -184,7 +186,7 @@ public void onThreadUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onThreadDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -194,7 +196,7 @@ public void onThreadDelete(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Thread Delete Event"); eb.setDescription(MarkdownUtil.quoteBlock("Thread Deleted By: " + mentionableExecutor + "\nTarget Thread ID: " + ale.getTargetId())); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/UnknownActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/UnknownActionTypeHandler.java index 67428a2..32e9028 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/UnknownActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/UnknownActionTypeHandler.java @@ -1,8 +1,9 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -12,9 +13,7 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; // for events not defined by JDA @ApplicationScoped @@ -22,19 +21,22 @@ @SuppressWarnings("java:S1192") public final class UnknownActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public UnknownActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public UnknownActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -43,7 +45,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { public void onUnknownActionType(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -53,7 +55,7 @@ public void onUnknownActionType(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Generic Event"); eb.setDescription(MarkdownUtil.quoteBlock("Executor: " + mentionableExecutor)); - eb.setColor(Color.LIGHT_GRAY); + eb.setColor(environment.embedColor().warningColor()); eb.addField(MarkdownUtil.underline("Action Type"), MarkdownUtil.codeblock(ale.getType().toString()), true); eb.addField(MarkdownUtil.underline("Target Type"), MarkdownUtil.codeblock(ale.getTargetType().toString()), true); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/VoiceChannelStatusActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/VoiceChannelStatusActionTypeHandler.java index 96f21de..97804fb 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/VoiceChannelStatusActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/VoiceChannelStatusActionTypeHandler.java @@ -1,8 +1,9 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -13,28 +14,29 @@ import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class VoiceChannelStatusActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public VoiceChannelStatusActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public VoiceChannelStatusActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -42,7 +44,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onVoiceChannelStatusUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -56,7 +58,7 @@ public void onVoiceChannelStatusUpdate(@NonNull GuildAuditLogEntryCreateEvent ev eb.setTitle("Audit Log Entry | Voice Channel Status Update"); eb.setDescription("A voice channel status has been updated"); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); eb.addField( MarkdownUtil.underline("Details"), @@ -77,7 +79,7 @@ public void onVoiceChannelStatusUpdate(@NonNull GuildAuditLogEntryCreateEvent ev @Override public void onVoiceChannelStatusDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -91,9 +93,9 @@ public void onVoiceChannelStatusDelete(@NonNull GuildAuditLogEntryCreateEvent ev eb.setTitle("Audit Log Entry | Voice Channel Status Delete"); eb.setDescription("A voice channel status has been reset"); - eb.setColor(Color.ORANGE); + eb.setColor(environment.embedColor().destructiveColor()); - // status deletes dont contain the deleted status content + // status deletes don't contain the deleted status content eb.addField( MarkdownUtil.underline("Details"), MarkdownUtil.quoteBlock("Status Reset By: " + mentionableExecutor + "\n" + "Target Channel: " + mentionableTargetChannel), diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/WebhookActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/WebhookActionTypeHandler.java index 53b7700..12fadcc 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/WebhookActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/WebhookActionTypeHandler.java @@ -1,10 +1,11 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.auditlog; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; import io.github.eggy03.papertrail.bot.utils.auditlog.GuildUtils; import io.github.eggy03.papertrail.bot.utils.auditlog.WebhookUtils; -import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -14,28 +15,29 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; - -import java.awt.Color; +import org.jspecify.annotations.Nullable; @ApplicationScoped @Slf4j @SuppressWarnings("java:S1192") public final class WebhookActionTypeHandler extends AbstractGuildAuditLogEntryCreateEventActionTypeHandler { - private final @NonNull AuditLogRegistrationClient client; + private final @NonNull PaperTrailGuildClient client; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public WebhookActionTypeHandler(@NonNull AuditLogRegistrationClient client, @NonNull EmbedCheckingService embedCheckingService) { + public WebhookActionTypeHandler(@NonNull PaperTrailGuildClient client, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { this.client = client; + this.environment = environment; this.embedCheckingService = embedCheckingService; } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return client.getRegisteredGuild(guildId) - .map(AuditLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return client.getGuild(guildId) + .map(PaperTrailGuild::guildEventChannelId) + .orElse(null); } @@ -43,7 +45,7 @@ private String getRegisteredChannelId(@NonNull String guildId) { @Override public void onWebhookCreate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -53,7 +55,7 @@ public void onWebhookCreate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Webhook Create Event"); eb.setDescription(MarkdownUtil.quoteBlock("Webhook Created By: " + mentionableExecutor)); - eb.setColor(Color.GREEN); + eb.setColor(environment.embedColor().successColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -86,7 +88,7 @@ public void onWebhookCreate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onWebhookUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -96,7 +98,7 @@ public void onWebhookUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Webhook Update Event"); eb.setDescription(MarkdownUtil.quoteBlock("Webhook Updated By: " + mentionableExecutor)); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); @@ -143,7 +145,7 @@ public void onWebhookUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { @Override public void onWebhookDelete(@NonNull GuildAuditLogEntryCreateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) return; + if (channelIdToSendTo == null) return; AuditLogEntry ale = event.getEntry(); @@ -153,7 +155,7 @@ public void onWebhookDelete(@NonNull GuildAuditLogEntryCreateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Audit Log Entry | Webhook Remove Event"); eb.setDescription(MarkdownUtil.quoteBlock("Webhook Removed By: " + mentionableExecutor)); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); ale.getChanges().forEach((changeKey, changeValue) -> { Object oldValue = changeValue.getOldValue(); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/message/GuildMessageEventHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/message/GuildMessageEventHandler.java index 33a62bd..c66ea84 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/message/GuildMessageEventHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/message/GuildMessageEventHandler.java @@ -1,11 +1,12 @@ package io.github.eggy03.papertrail.bot.service.handlers.guild.message; import com.google.common.base.Splitter; +import io.github.eggy03.papertrail.bot.environment.PaperTrailEnvironment; import io.github.eggy03.papertrail.bot.service.EmbedCheckingService; -import io.github.eggy03.papertrail.sdk.client.MessageLogContentClient; -import io.github.eggy03.papertrail.sdk.client.MessageLogRegistrationClient; -import io.github.eggy03.papertrail.sdk.entity.MessageLogContentEntity; -import io.github.eggy03.papertrail.sdk.entity.MessageLogRegistrationEntity; +import io.github.eggy03.papertrail.http.client.PaperTrailGuildClient; +import io.github.eggy03.papertrail.http.client.PaperTrailMessageClient; +import io.github.eggy03.papertrail.http.entity.PaperTrailGuild; +import io.github.eggy03.papertrail.http.entity.PaperTrailMessage; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import lombok.NonNull; @@ -16,9 +17,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageUpdateEvent; import net.dv8tion.jda.api.utils.MarkdownUtil; -import org.apache.commons.lang3.StringUtils; +import org.jspecify.annotations.Nullable; -import java.awt.Color; import java.time.Instant; import java.util.List; import java.util.Optional; @@ -27,52 +27,53 @@ @Slf4j public final class GuildMessageEventHandler { - private final @NonNull MessageLogRegistrationClient registrationClient; - private final @NonNull MessageLogContentClient contentClient; + private final @NonNull PaperTrailGuildClient paperTrailGuildClient; + private final @NonNull PaperTrailMessageClient paperTrailMessageClient; + private final @NonNull PaperTrailEnvironment environment; private final @NonNull EmbedCheckingService embedCheckingService; @Inject - public GuildMessageEventHandler(@NonNull MessageLogRegistrationClient registrationClient, @NonNull MessageLogContentClient contentClient, @NonNull EmbedCheckingService embedCheckingService) { - this.registrationClient = registrationClient; - this.contentClient = contentClient; + public GuildMessageEventHandler(@NonNull PaperTrailGuildClient paperTrailGuildClient, @NonNull PaperTrailMessageClient paperTrailMessageClient, @NonNull PaperTrailEnvironment environment, @NonNull EmbedCheckingService embedCheckingService) { + this.paperTrailGuildClient = paperTrailGuildClient; + this.paperTrailMessageClient = paperTrailMessageClient; + this.environment = environment; this.embedCheckingService = embedCheckingService; } private boolean isGuildRegistered(@NonNull String guildId) { - return registrationClient.getRegisteredGuild(guildId).isPresent(); + return paperTrailGuildClient.getGuild(guildId).isPresent(); } - @NonNull + @Nullable private String getRegisteredChannelId(@NonNull String guildId) { - return registrationClient.getRegisteredGuild(guildId) - .map(MessageLogRegistrationEntity::getChannelId).orElse(StringUtils.EMPTY); + return paperTrailGuildClient.getGuild(guildId) + .map(PaperTrailGuild::messageEventChannelId) + .orElse(null); } public void handleMessageReceivedEvent(@NonNull MessageReceivedEvent event) { - if (!isGuildRegistered(event.getGuild().getId())) - return; + if (!isGuildRegistered(event.getGuild().getId())) return; String messageId = event.getMessageId(); String messageContent = event.getMessage().getContentDisplay(); String authorId = event.getAuthor().getId(); - contentClient.logMessage(messageId, messageContent, authorId); + paperTrailMessageClient.saveMessage(messageId, messageContent, authorId); } public void handleMessageUpdateEvent(@NonNull MessageUpdateEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) - return; + if (channelIdToSendTo == null) return; // fetch the old message object from the API - Optional oldMessageContentOptional = contentClient.retrieveMessage(event.getMessageId()); + Optional oldMessageContentOptional = paperTrailMessageClient.getMessage(event.getMessageId()); if (oldMessageContentOptional.isEmpty()) return; - MessageLogContentEntity oldMessageContentEntity = oldMessageContentOptional.get(); + PaperTrailMessage oldMessageContentEntity = oldMessageContentOptional.get(); // Fetch the old message - String oldMessage = oldMessageContentEntity.getMessageContent(); + String oldMessage = oldMessageContentEntity.messageContent(); // fetch the updated message and its author from the event String updatedMessage = event.getMessage().getContentDisplay(); String updatedMessageAuthor = event.getAuthor().getAsMention(); @@ -90,7 +91,7 @@ public void handleMessageUpdateEvent(@NonNull MessageUpdateEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Message Edit Event"); eb.setDescription(MarkdownUtil.quoteBlock("Author: " + updatedMessageAuthor + "\n" + "Channel: " + event.getChannel().getAsMention())); - eb.setColor(Color.YELLOW); + eb.setColor(environment.embedColor().warningColor()); oldMessageSplits.forEach(split -> eb.addField(MarkdownUtil.underline("Old Message"), MarkdownUtil.codeblock(split), false)); updatedMessageSplits.forEach(split -> eb.addField(MarkdownUtil.underline("New Message"), MarkdownUtil.codeblock(split), false)); @@ -99,25 +100,23 @@ public void handleMessageUpdateEvent(@NonNull MessageUpdateEvent event) { eb.setTimestamp(Instant.now()); // update the database with the new message - contentClient.updateMessage(event.getMessageId(), updatedMessage, event.getAuthor().getId()); + paperTrailMessageClient.updateMessage(event.getMessageId(), updatedMessage, event.getAuthor().getId()); embedCheckingService.checkAndSend(event, eb, channelIdToSendTo); } public void handleMessageDeleteEvent(@NonNull MessageDeleteEvent event) { String channelIdToSendTo = getRegisteredChannelId(event.getGuild().getId()); - if (channelIdToSendTo.isBlank()) - return; + if (channelIdToSendTo == null) return; // fetch the message object from the API which was just deleted - Optional deletedMessageContentOptional = contentClient.retrieveMessage(event.getMessageId()); - if (deletedMessageContentOptional.isEmpty()) - return; + Optional deletedMessageContentOptional = paperTrailMessageClient.getMessage(event.getMessageId()); + if (deletedMessageContentOptional.isEmpty()) return; - MessageLogContentEntity deletedMessageContentEntity = deletedMessageContentOptional.get(); + PaperTrailMessage deletedMessageContentEntity = deletedMessageContentOptional.get(); // Fetch the deleted message and it's author id - String deletedMessage = deletedMessageContentEntity.getMessageContent(); - String deletedMessageAuthorId = deletedMessageContentEntity.getAuthorId(); + String deletedMessage = deletedMessageContentEntity.messageContent(); + String deletedMessageAuthorId = deletedMessageContentEntity.authorId(); User author = event.getJDA().getUserById(deletedMessageAuthorId); String mentionableAuthor = (author != null ? author.getAsMention() : deletedMessageAuthorId); @@ -128,7 +127,7 @@ public void handleMessageDeleteEvent(@NonNull MessageDeleteEvent event) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Message Delete Event"); eb.setDescription(MarkdownUtil.quoteBlock("Author: " + mentionableAuthor + "\n" + "Channel: " + event.getChannel().getAsMention())); - eb.setColor(Color.RED); + eb.setColor(environment.embedColor().destructiveColor()); deletedMessageSplits.forEach(split -> eb.addField(MarkdownUtil.underline("Deleted Message"), MarkdownUtil.codeblock(split), false)); @@ -136,7 +135,7 @@ public void handleMessageDeleteEvent(@NonNull MessageDeleteEvent event) { eb.setTimestamp(Instant.now()); // delete the message from the database - contentClient.deleteMessage(event.getMessageId()); + paperTrailMessageClient.deleteMessage(event.getMessageId()); embedCheckingService.checkAndSend(event, eb, channelIdToSendTo); } diff --git a/src/main/resources/META-INF/native-image/io/github/eggy03/papertrailbot/reachability-metadata.json b/src/main/resources/META-INF/native-image/io/github/eggy03/papertrailbot/reachability-metadata.json index e12f938..3c0c79f 100644 --- a/src/main/resources/META-INF/native-image/io/github/eggy03/papertrailbot/reachability-metadata.json +++ b/src/main/resources/META-INF/native-image/io/github/eggy03/papertrailbot/reachability-metadata.json @@ -1,34 +1,19 @@ { "reflection": [ { - "type": "io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient" + "type": "io.github.eggy03.papertrail.http.client.PaperTrailGuildClient" }, { - "type": "io.github.eggy03.papertrail.sdk.client.MessageLogContentClient" + "type": "io.github.eggy03.papertrail.http.client.PaperTrailMessageClient" }, { - "type": "io.github.eggy03.papertrail.sdk.client.MessageLogRegistrationClient" - }, - { - "type": "io.github.eggy03.papertrail.sdk.entity.AuditLogRegistrationEntity", - "allDeclaredConstructors": true, - "allDeclaredFields": true, - "allDeclaredMethods": true - }, - { - "type": "io.github.eggy03.papertrail.sdk.entity.MessageLogContentEntity", - "allDeclaredConstructors": true, - "allDeclaredFields": true, - "allDeclaredMethods": true - }, - { - "type": "io.github.eggy03.papertrail.sdk.entity.MessageLogRegistrationEntity", + "type": "io.github.eggy03.papertrail.http.entity.PaperTrailGuild", "allDeclaredConstructors": true, "allDeclaredFields": true, "allDeclaredMethods": true }, { - "type": "io.github.eggy03.papertrail.sdk.entity.ErrorEntity", + "type": "io.github.eggy03.papertrail.http.entity.PaperTrailMessage", "allDeclaredConstructors": true, "allDeclaredFields": true, "allDeclaredMethods": true @@ -36,21 +21,14 @@ { "type": { "proxy": [ - "io.github.eggy03.papertrail.sdk.service.AuditLogRegistrationService" - ] - } - }, - { - "type": { - "proxy": [ - "io.github.eggy03.papertrail.sdk.service.MessageLogRegistrationService" + "io.github.eggy03.papertrail.http.service.PaperTrailGuildService" ] } }, { "type": { "proxy": [ - "io.github.eggy03.papertrail.sdk.service.MessageLogContentService" + "io.github.eggy03.papertrail.http.service.PaperTrailMessageService" ] } }, diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 050f7b6..f3f4962 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,7 @@ # General -papertrail.general.app.name=PaperTrail +papertrail.general.app.name=${APP_NAME:PaperTrailBot} papertrail.general.app.version=${quarkus.application.version:N/A} +papertrail.general.app.activity=${APP_ACTIVITY: } papertrail.general.github.issue.link=https://github.com/eggy03/PaperTrailBot/issues # Token @@ -8,15 +9,10 @@ papertrail.discord.token=${TOKEN} # PaperTrail API URL papertrail.api.url=${API_URL} - -# Shard Config -papertrail.discord.shard.min=${MIN_SHARD_ID:0} -papertrail.discord.shard.max=${MAX_SHARD_ID:0} -papertrail.discord.shard.total=${TOTAL_SHARDS:1} - -# Twilight HTTP Proxy URL -# default value is a whitespace -papertrail.discord.twilight.http.proxy.url=${TWILIGHT_HTTP_PROXY_URL: } +# Embed Color Config +papertrail.embed-color.success.color.integer=${EMBED_SUCCESS_COLOR_INT:712458} +papertrail.embed-color.warning.color.integer=${EMBED_WARNING_COLOR_INT:16776960} +papertrail.embed-color.destructive.color.integer=${EMBED_DESTRUCTIVE_COLOR_INT:16711680} #Port quarkus.http.port=${PORT:8080} @@ -25,7 +21,7 @@ quarkus.management.port=${MANAGEMENT_PORT:9000} # Logging Level quarkus.log.level=${GLOBAL_LOG_LEVEL:INFO} -quarkus.log.category."io.github.eggy03.papertrail.bot".level=${APPLICATION_LOG_LEVEL:INFO} +quarkus.log.category."io.github.eggy03.papertrail".level=${APP_LOG_LEVEL:INFO} # Analytics quarkus.analytics.disabled=true