From 18478338d0d6c2ea2d869ac5f6e9d4ee3d99473e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:00:38 +0000 Subject: [PATCH 01/11] Update plugin com.diffplug.spotless to v6.23.3 --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 505ac24ff..f3cbb108d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,7 +23,7 @@ dependencyResolutionManagement { bundle("log4j", listOf("slf4j-api", "log4j-core", "log4j-slf4j2", "log4j-jsontemplate")) // plugins - plugin("spotless", "com.diffplug.spotless").version("6.23.2") + plugin("spotless", "com.diffplug.spotless").version("6.23.3") plugin("shadow", "com.github.johnrengelman.shadow").version("8.1.1") } From 5fcc986505d20c3c003376825b18cf9a24d9fd1f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 6 Dec 2023 14:41:40 +0100 Subject: [PATCH 02/11] Update actions/setup-python action to v5 (#576) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/docs.yml | 2 +- .github/workflows/verify.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 4df3dd7c7..1c9b7c520 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: 3.x - run: pip install mkdocs-material diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 20c858d1b..7543992b9 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -48,7 +48,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: 3.x - run: pip install mkdocs-material From bddde27d4b197ff6a690ea2829b3bf3770f63d9f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:18:43 +0000 Subject: [PATCH 03/11] Update dependency org.postgresql:postgresql to v42.7.1 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index a2e2a8eb3..d19f346c1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,7 +30,7 @@ dependencies { } // database - implementation("org.postgresql", "postgresql", "42.7.0") + implementation("org.postgresql", "postgresql", "42.7.1") implementation(libs.bundles.sadu) // Logging From 266281e07edb1c223a72d0d31893dafa8e754c12 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Dec 2023 00:51:24 +0000 Subject: [PATCH 04/11] Update log4j to v2.22.1 --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index f3cbb108d..ca6dbe09b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,7 +15,7 @@ dependencyResolutionManagement { library("sadu-datasource", "de.chojo.sadu", "sadu-datasource").versionRef("sadu") bundle("sadu", listOf("sadu-queries", "sadu-updater", "sadu-postgresql", "sadu-datasource")) - version("log4j", "2.22.0") + version("log4j", "2.22.1") library("slf4j-api", "org.slf4j:slf4j-api:2.0.9") library("log4j-core", "org.apache.logging.log4j", "log4j-core").versionRef("log4j") library("log4j-slf4j2", "org.apache.logging.log4j", "log4j-slf4j2-impl").versionRef("log4j") From 7176088ac51d2b247c2ee3b58722955acf3af1db Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 29 Dec 2023 12:59:02 +0100 Subject: [PATCH 05/11] Update dependency org.slf4j:slf4j-api to v2.0.10 (#579) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index ca6dbe09b..8aa4b947d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -16,7 +16,7 @@ dependencyResolutionManagement { bundle("sadu", listOf("sadu-queries", "sadu-updater", "sadu-postgresql", "sadu-datasource")) version("log4j", "2.22.1") - library("slf4j-api", "org.slf4j:slf4j-api:2.0.9") + library("slf4j-api", "org.slf4j:slf4j-api:2.0.10") library("log4j-core", "org.apache.logging.log4j", "log4j-core").versionRef("log4j") library("log4j-slf4j2", "org.apache.logging.log4j", "log4j-slf4j2-impl").versionRef("log4j") library("log4j-jsontemplate","org.apache.logging.log4j", "log4j-layout-template-json").versionRef("log4j") From e83e37024a0e6a1b91b50524f07c502c16f5e52f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 5 Jan 2024 15:34:53 +0100 Subject: [PATCH 06/11] Update dependency org.knowm.xchart:xchart to v3.8.7 (#580) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d19f346c1..40dfd5a56 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,12 +39,12 @@ dependencies { exclude("org.apache.logging.log4j") } - implementation("org.knowm.xchart", "xchart", "3.8.6") + implementation("org.knowm.xchart", "xchart", "3.8.7") // unit testing testImplementation(platform("org.junit:junit-bom:5.10.1")) testImplementation("org.junit.jupiter", "junit-jupiter") - testImplementation("org.knowm.xchart", "xchart", "3.8.6") + testImplementation("org.knowm.xchart", "xchart", "3.8.7") } java { From 24364a323cd5eb34e06d971936c154e70e4ce9d6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 9 Jan 2024 13:47:07 +0100 Subject: [PATCH 07/11] Update dependency org.slf4j:slf4j-api to v2.0.11 (#581) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 8aa4b947d..162a9fbb3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -16,7 +16,7 @@ dependencyResolutionManagement { bundle("sadu", listOf("sadu-queries", "sadu-updater", "sadu-postgresql", "sadu-datasource")) version("log4j", "2.22.1") - library("slf4j-api", "org.slf4j:slf4j-api:2.0.10") + library("slf4j-api", "org.slf4j:slf4j-api:2.0.11") library("log4j-core", "org.apache.logging.log4j", "log4j-core").versionRef("log4j") library("log4j-slf4j2", "org.apache.logging.log4j", "log4j-slf4j2-impl").versionRef("log4j") library("log4j-jsontemplate","org.apache.logging.log4j", "log4j-layout-template-json").versionRef("log4j") From 331d31ceb7968b6006ae8e5303e361023af2b31d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 12 Jan 2024 19:06:34 +0000 Subject: [PATCH 08/11] Update plugin org.gradle.toolchains.foojay-resolver-convention to v0.8.0 --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 162a9fbb3..440d8b7a3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,7 @@ rootProject.name = "rep-bot" plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version("0.7.0") + id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0") } dependencyResolutionManagement { From 8bea97c7ac55537caefbe198b05079c051c292d5 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 02:13:16 +0000 Subject: [PATCH 09/11] Update plugin com.diffplug.spotless to v6.24.0 --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 440d8b7a3..db3b34e7b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,7 +23,7 @@ dependencyResolutionManagement { bundle("log4j", listOf("slf4j-api", "log4j-core", "log4j-slf4j2", "log4j-jsontemplate")) // plugins - plugin("spotless", "com.diffplug.spotless").version("6.23.3") + plugin("spotless", "com.diffplug.spotless").version("6.24.0") plugin("shadow", "com.github.johnrengelman.shadow").version("8.1.1") } From 1386e77e0eb91a4b881920ca760f81155f6284ac Mon Sep 17 00:00:00 2001 From: Lilly Tempest <46890129+rainbowdashlabs@users.noreply.github.com> Date: Thu, 18 Jan 2024 22:31:56 +0100 Subject: [PATCH 10/11] Feature: quick buttons (#585) --- build.gradle.kts | 2 +- .../actions/messages/log/MessageLog.java | 29 ++++ .../messages/log/handler/MessageAnalyzer.java | 25 ++++ .../user/donated/received/UserDonated.java | 28 ++++ .../received/handler/DonatedReputation.java | 27 ++++ .../actions/user/received/UserReceived.java | 28 ++++ .../received/handler/ReceivedReputation.java | 26 ++++ .../repbot/commands/bot/handler/Debug.java | 5 +- .../commands/bot/handler/system/Metrics.java | 7 +- .../repbot/commands/log/handler/Analyzer.java | 31 +++- .../repbot/commands/log/handler/Donated.java | 11 +- .../commands/log/handler/LogFormatter.java | 5 +- .../repbot/commands/log/handler/Received.java | 16 ++- .../repbot/commands/top/handler/Show.java | 13 +- src/main/java/de/chojo/repbot/core/Bot.java | 132 +++++++++--------- .../database/postgresql/1/patch_28.sql | 2 +- src/main/resources/locale.properties | 3 + src/main/resources/locale_de.properties | 3 + src/main/resources/locale_en_US.properties | 3 + src/main/resources/locale_es_ES.properties | 3 + src/main/resources/locale_fr.properties | 3 + src/main/resources/locale_pt_BR.properties | 3 + src/main/resources/locale_ru.properties | 3 + 23 files changed, 321 insertions(+), 87 deletions(-) create mode 100644 src/main/java/de/chojo/repbot/actions/messages/log/MessageLog.java create mode 100644 src/main/java/de/chojo/repbot/actions/messages/log/handler/MessageAnalyzer.java create mode 100644 src/main/java/de/chojo/repbot/actions/user/donated/received/UserDonated.java create mode 100644 src/main/java/de/chojo/repbot/actions/user/donated/received/handler/DonatedReputation.java create mode 100644 src/main/java/de/chojo/repbot/actions/user/received/UserReceived.java create mode 100644 src/main/java/de/chojo/repbot/actions/user/received/handler/ReceivedReputation.java diff --git a/build.gradle.kts b/build.gradle.kts index 40dfd5a56..904cd009b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,7 +25,7 @@ spotless { dependencies { //discord - implementation("de.chojo", "cjda-util", "2.8.6+beta.11") { + implementation("de.chojo", "cjda-util", "2.9.3+beta.19") { exclude(group = "club.minnced", module = "opus-java") } diff --git a/src/main/java/de/chojo/repbot/actions/messages/log/MessageLog.java b/src/main/java/de/chojo/repbot/actions/messages/log/MessageLog.java new file mode 100644 index 000000000..47929b21e --- /dev/null +++ b/src/main/java/de/chojo/repbot/actions/messages/log/MessageLog.java @@ -0,0 +1,29 @@ +/* + * SPDX-License-Identifier: AGPL-3.0-only + * + * Copyright (C) RainbowDashLabs and Contributor + */ +package de.chojo.repbot.actions.messages.log; + +import de.chojo.jdautil.interactions.message.Message; +import de.chojo.jdautil.interactions.message.provider.MessageProvider; +import de.chojo.repbot.actions.messages.log.handler.MessageAnalyzer; +import de.chojo.repbot.dao.provider.Guilds; +import net.dv8tion.jda.api.Permission; + +public class MessageLog implements MessageProvider { + private final Guilds guilds; + + public MessageLog(Guilds guilds) { + this.guilds = guilds; + } + + @Override + public Message message() { + return Message.of("Message Log") + .handler(new MessageAnalyzer(guilds)) + .setGuildOnly(true) + .withPermission(Permission.MESSAGE_MANAGE) + .build(); + } +} diff --git a/src/main/java/de/chojo/repbot/actions/messages/log/handler/MessageAnalyzer.java b/src/main/java/de/chojo/repbot/actions/messages/log/handler/MessageAnalyzer.java new file mode 100644 index 000000000..419c4685f --- /dev/null +++ b/src/main/java/de/chojo/repbot/actions/messages/log/handler/MessageAnalyzer.java @@ -0,0 +1,25 @@ +/* + * SPDX-License-Identifier: AGPL-3.0-only + * + * Copyright (C) RainbowDashLabs and Contributor + */ +package de.chojo.repbot.actions.messages.log.handler; + +import de.chojo.jdautil.interactions.message.MessageHandler; +import de.chojo.jdautil.wrapper.EventContext; +import de.chojo.repbot.commands.log.handler.Analyzer; +import de.chojo.repbot.dao.provider.Guilds; +import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent; + +public class MessageAnalyzer implements MessageHandler { + private final Guilds guilds; + + public MessageAnalyzer(Guilds guilds) { + this.guilds = guilds; + } + + @Override + public void onMessage(MessageContextInteractionEvent event, EventContext eventContext) { + Analyzer.sendAnalyzerLog(event, guilds, event.getTarget().getIdLong(), eventContext); + } +} diff --git a/src/main/java/de/chojo/repbot/actions/user/donated/received/UserDonated.java b/src/main/java/de/chojo/repbot/actions/user/donated/received/UserDonated.java new file mode 100644 index 000000000..2e9e61972 --- /dev/null +++ b/src/main/java/de/chojo/repbot/actions/user/donated/received/UserDonated.java @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: AGPL-3.0-only + * + * Copyright (C) RainbowDashLabs and Contributor + */ +package de.chojo.repbot.actions.user.donated.received; + +import de.chojo.jdautil.interactions.user.User; +import de.chojo.jdautil.interactions.user.provider.UserProvider; +import de.chojo.repbot.actions.user.donated.received.handler.DonatedReputation; +import de.chojo.repbot.dao.provider.Guilds; +import net.dv8tion.jda.api.Permission; + +public class UserDonated implements UserProvider { + private final Guilds guilds; + + public UserDonated(Guilds guilds) { + this.guilds = guilds; + } + + @Override + public User user() { + return User.of("Given Reputation").handler(new DonatedReputation(guilds)) + .setGuildOnly(true) + .withPermission(Permission.MESSAGE_MANAGE) + .build(); + } +} diff --git a/src/main/java/de/chojo/repbot/actions/user/donated/received/handler/DonatedReputation.java b/src/main/java/de/chojo/repbot/actions/user/donated/received/handler/DonatedReputation.java new file mode 100644 index 000000000..834002bea --- /dev/null +++ b/src/main/java/de/chojo/repbot/actions/user/donated/received/handler/DonatedReputation.java @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: AGPL-3.0-only + * + * Copyright (C) RainbowDashLabs and Contributor + */ +package de.chojo.repbot.actions.user.donated.received.handler; + +import de.chojo.jdautil.interactions.user.UserHandler; +import de.chojo.jdautil.wrapper.EventContext; +import de.chojo.repbot.commands.log.handler.Donated; +import de.chojo.repbot.commands.log.handler.Received; +import de.chojo.repbot.dao.provider.Guilds; +import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent; + +public class DonatedReputation implements UserHandler { + private final Guilds guilds; + + public DonatedReputation(Guilds guilds) { + this.guilds = guilds; + } + + + @Override + public void onUser(UserContextInteractionEvent event, EventContext eventContext) { + Donated.send(event, event.getTargetMember(), guilds, eventContext); + } +} diff --git a/src/main/java/de/chojo/repbot/actions/user/received/UserReceived.java b/src/main/java/de/chojo/repbot/actions/user/received/UserReceived.java new file mode 100644 index 000000000..22fe7ddf7 --- /dev/null +++ b/src/main/java/de/chojo/repbot/actions/user/received/UserReceived.java @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: AGPL-3.0-only + * + * Copyright (C) RainbowDashLabs and Contributor + */ +package de.chojo.repbot.actions.user.received; + +import de.chojo.jdautil.interactions.user.User; +import de.chojo.jdautil.interactions.user.provider.UserProvider; +import de.chojo.repbot.actions.user.received.handler.ReceivedReputation; +import de.chojo.repbot.dao.provider.Guilds; +import net.dv8tion.jda.api.Permission; + +public class UserReceived implements UserProvider { + private final Guilds guilds; + + public UserReceived(Guilds guilds) { + this.guilds = guilds; + } + + @Override + public User user() { + return User.of("Received Reputation").handler(new ReceivedReputation(guilds)) + .setGuildOnly(true) + .withPermission(Permission.MESSAGE_MANAGE) + .build(); + } +} diff --git a/src/main/java/de/chojo/repbot/actions/user/received/handler/ReceivedReputation.java b/src/main/java/de/chojo/repbot/actions/user/received/handler/ReceivedReputation.java new file mode 100644 index 000000000..a3c9daea0 --- /dev/null +++ b/src/main/java/de/chojo/repbot/actions/user/received/handler/ReceivedReputation.java @@ -0,0 +1,26 @@ +/* + * SPDX-License-Identifier: AGPL-3.0-only + * + * Copyright (C) RainbowDashLabs and Contributor + */ +package de.chojo.repbot.actions.user.received.handler; + +import de.chojo.jdautil.interactions.user.UserHandler; +import de.chojo.jdautil.wrapper.EventContext; +import de.chojo.repbot.commands.log.handler.Received; +import de.chojo.repbot.dao.provider.Guilds; +import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent; + +public class ReceivedReputation implements UserHandler { + private final Guilds guilds; + + public ReceivedReputation(Guilds guilds) { + this.guilds = guilds; + } + + + @Override + public void onUser(UserContextInteractionEvent event, EventContext eventContext) { + Received.send(event, event.getTargetMember(), guilds, eventContext); + } +} diff --git a/src/main/java/de/chojo/repbot/commands/bot/handler/Debug.java b/src/main/java/de/chojo/repbot/commands/bot/handler/Debug.java index b81948f75..4c61bca91 100644 --- a/src/main/java/de/chojo/repbot/commands/bot/handler/Debug.java +++ b/src/main/java/de/chojo/repbot/commands/bot/handler/Debug.java @@ -20,6 +20,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.utils.TimeFormat; +import net.dv8tion.jda.api.utils.messages.MessageEditData; import java.time.LocalDateTime; import java.time.OffsetDateTime; @@ -147,8 +148,8 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont var pages = new ListPageBag<>(embeds) { @Override - public CompletableFuture buildPage() { - return CompletableFuture.completedFuture(currentElement()); + public CompletableFuture buildPage() { + return CompletableFuture.completedFuture(MessageEditData.fromEmbeds(currentElement())); } }; diff --git a/src/main/java/de/chojo/repbot/commands/bot/handler/system/Metrics.java b/src/main/java/de/chojo/repbot/commands/bot/handler/system/Metrics.java index e9fa8e5c3..12f809938 100644 --- a/src/main/java/de/chojo/repbot/commands/bot/handler/system/Metrics.java +++ b/src/main/java/de/chojo/repbot/commands/bot/handler/system/Metrics.java @@ -12,6 +12,7 @@ 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.messages.MessageEditData; import java.util.ArrayList; import java.util.List; @@ -48,11 +49,11 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont context.registerPage(new ListPageBag<>(links) { @Override - public CompletableFuture buildPage() { - return CompletableFuture.completedFuture(new EmbedBuilder() + public CompletableFuture buildPage() { + return CompletableFuture.completedFuture(MessageEditData.fromEmbeds(new EmbedBuilder() .setImage(currentElement()) .setAuthor("Open in Browser", currentElement(), event.getJDA().getSelfUser().getAvatarUrl()) - .build()); + .build())); } }); } diff --git a/src/main/java/de/chojo/repbot/commands/log/handler/Analyzer.java b/src/main/java/de/chojo/repbot/commands/log/handler/Analyzer.java index c7de62fb6..d1b09b1c5 100644 --- a/src/main/java/de/chojo/repbot/commands/log/handler/Analyzer.java +++ b/src/main/java/de/chojo/repbot/commands/log/handler/Analyzer.java @@ -10,11 +10,10 @@ import de.chojo.jdautil.localization.util.Replacement; import de.chojo.jdautil.parsing.ValueParser; import de.chojo.jdautil.wrapper.EventContext; -import de.chojo.repbot.dao.access.guild.reputation.Reputation; import de.chojo.repbot.dao.provider.Guilds; +import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; - -import java.util.List; +import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; public class Analyzer implements SlashHandler { private final Guilds guilds; @@ -54,4 +53,30 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont event.replyEmbeds(embed).setEphemeral(true).queue(); } + + public static void sendAnalyzerLog(IReplyCallback callback, Guilds guilds, long messageId, EventContext context) { + var reputation = guilds.guild(callback.getGuild()).reputation(); + var resultEntry = reputation.analyzer() + .get(messageId); + + if (resultEntry.isEmpty()) { + callback.reply(context.localize("command.log.analyzer.notanalyzed")).setEphemeral(true).queue(); + return; + } + + var embed = resultEntry.get().embed(callback.getGuild(), context); + + var reputationLogEntries = reputation.log().messageLog(messageId, 10); + + var entries = LogFormatter.mapMessageLogEntry(context, reputationLogEntries); + + var builder = new LocalizedEmbedBuilder(context.guildLocalizer()) + .setTitle("command.log.message.message.log", Replacement.create("ID", messageId)); + + LogFormatter.buildFields(entries, builder); + + embed.add(builder.build()); + + callback.replyEmbeds(embed).setEphemeral(true).queue(); + } } diff --git a/src/main/java/de/chojo/repbot/commands/log/handler/Donated.java b/src/main/java/de/chojo/repbot/commands/log/handler/Donated.java index 28956da50..fac747eee 100644 --- a/src/main/java/de/chojo/repbot/commands/log/handler/Donated.java +++ b/src/main/java/de/chojo/repbot/commands/log/handler/Donated.java @@ -10,8 +10,11 @@ import de.chojo.jdautil.wrapper.EventContext; import de.chojo.repbot.dao.provider.Guilds; import de.chojo.repbot.dao.snapshots.ReputationLogEntry; +import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; +import net.dv8tion.jda.api.utils.messages.MessageEditData; import java.util.Collections; import java.util.concurrent.CompletableFuture; @@ -30,16 +33,20 @@ public Donated(Guilds guilds) { @Override public void onSlashCommand(SlashCommandInteractionEvent event, EventContext context) { var user = event.getOption("user").getAsMember(); + send(event, user, guilds, context); + } + + public static void send(IReplyCallback event, Member user, Guilds guilds, EventContext context) { var logAccess = guilds.guild(event.getGuild()).reputation().log().userDonatedLog(user.getUser(), PAGE_SIZE); context.registerPage(new PrivatePageBag(logAccess.pages(), event.getUser().getIdLong()) { @Override - public CompletableFuture buildPage() { + public CompletableFuture buildPage() { return CompletableFuture.supplyAsync(() -> userLogEmbed(context, user, "command.log.donated.message.log", mapUserLogEntry(context, logAccess.page(current()), ReputationLogEntry::receiverId))); } @Override - public CompletableFuture buildEmptyPage() { + public CompletableFuture buildEmptyPage() { return CompletableFuture.completedFuture(userLogEmbed(context, user, "command.log.donated.message.log", mapUserLogEntry(context, Collections.emptyList(), ReputationLogEntry::receiverId))); } diff --git a/src/main/java/de/chojo/repbot/commands/log/handler/LogFormatter.java b/src/main/java/de/chojo/repbot/commands/log/handler/LogFormatter.java index 744b15998..3cf224e21 100644 --- a/src/main/java/de/chojo/repbot/commands/log/handler/LogFormatter.java +++ b/src/main/java/de/chojo/repbot/commands/log/handler/LogFormatter.java @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.utils.messages.MessageEditData; import java.util.ArrayList; import java.util.Collections; @@ -66,11 +67,11 @@ static String createJumpLink(EventContext context, ReputationLogEntry log) { return String.format("**%s** %s", jump, refJump == null ? "" : "➜ **" + refJump + "**"); } - static MessageEmbed userLogEmbed(EventContext context, Member user, String title, List log) { + static MessageEditData userLogEmbed(EventContext context, Member user, String title, List log) { var builder = new LocalizedEmbedBuilder(context.guildLocalizer()) .setAuthor(title, null, user.getEffectiveAvatarUrl(), Replacement.create("USER", user.getEffectiveName())); buildFields(log, builder); - return builder.build(); + return MessageEditData.fromEmbeds(builder.build()); } static void buildFields(List entries, LocalizedEmbedBuilder embedBuilder) { diff --git a/src/main/java/de/chojo/repbot/commands/log/handler/Received.java b/src/main/java/de/chojo/repbot/commands/log/handler/Received.java index 12538d321..63c367507 100644 --- a/src/main/java/de/chojo/repbot/commands/log/handler/Received.java +++ b/src/main/java/de/chojo/repbot/commands/log/handler/Received.java @@ -10,8 +10,12 @@ import de.chojo.jdautil.wrapper.EventContext; import de.chojo.repbot.dao.provider.Guilds; import de.chojo.repbot.dao.snapshots.ReputationLogEntry; +import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.MessageEmbed; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; +import net.dv8tion.jda.api.utils.messages.MessageEditData; import java.util.Collections; import java.util.concurrent.CompletableFuture; @@ -30,16 +34,20 @@ public Received(Guilds guilds) { @Override public void onSlashCommand(SlashCommandInteractionEvent event, EventContext context) { var user = event.getOption("user").getAsMember(); - var logAccess = guilds.guild(event.getGuild()).reputation().log().getUserReceivedLog(user.getUser(), PAGE_SIZE); - context.registerPage(new PrivatePageBag(logAccess.pages(), event.getUser().getIdLong()) { + send(event,user, guilds, context); + } + + public static void send(IReplyCallback callback, Member user, Guilds guilds, EventContext context) { + var logAccess = guilds.guild(callback.getGuild()).reputation().log().getUserReceivedLog(user.getUser(), PAGE_SIZE); + context.registerPage(new PrivatePageBag(logAccess.pages(), callback.getUser().getIdLong()) { @Override - public CompletableFuture buildPage() { + public CompletableFuture buildPage() { return CompletableFuture.supplyAsync(() -> userLogEmbed(context, user, "command.log.received.message.log", mapUserLogEntry(context, logAccess.page(current()), ReputationLogEntry::donorId))); } @Override - public CompletableFuture buildEmptyPage() { + public CompletableFuture buildEmptyPage() { return CompletableFuture.completedFuture(userLogEmbed(context, user, "command.log.received.message.log", mapUserLogEntry(context, Collections.emptyList(), ReputationLogEntry::donorId))); } diff --git a/src/main/java/de/chojo/repbot/commands/top/handler/Show.java b/src/main/java/de/chojo/repbot/commands/top/handler/Show.java index d7bb5d993..48afc1c46 100644 --- a/src/main/java/de/chojo/repbot/commands/top/handler/Show.java +++ b/src/main/java/de/chojo/repbot/commands/top/handler/Show.java @@ -18,6 +18,7 @@ import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.utils.messages.MessageEditData; import java.awt.Color; import java.util.concurrent.CompletableFuture; @@ -54,7 +55,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont public static void registerPage(GuildRanking guildRanking, SlashCommandInteractionEvent event, EventContext context) { context.registerPage(new PageBag(guildRanking.pages()) { @Override - public CompletableFuture buildPage() { + public CompletableFuture buildPage() { return CompletableFuture.supplyAsync(() -> { var ranking = guildRanking.page(current()); @@ -62,17 +63,17 @@ public CompletableFuture buildPage() { var rankString = ranking.stream().map(rank -> rank.fancyString((int) maxRank)) .collect(Collectors.joining("\n")); - return createBaseBuilder(guildRanking, context, event.getGuild()) + return MessageEditData.fromEmbeds(createBaseBuilder(guildRanking, context, event.getGuild()) .setDescription(rankString) - .build(); + .build()); }); } @Override - public CompletableFuture buildEmptyPage() { - return CompletableFuture.completedFuture(createBaseBuilder(guildRanking, context, event.getGuild()) + public CompletableFuture buildEmptyPage() { + return CompletableFuture.completedFuture(MessageEditData.fromEmbeds(createBaseBuilder(guildRanking, context, event.getGuild()) .setDescription("*" + context.localize("command.top.message.empty") + "*") - .build()); + .build())); } }, true); } diff --git a/src/main/java/de/chojo/repbot/core/Bot.java b/src/main/java/de/chojo/repbot/core/Bot.java index 76581daf9..d50053214 100644 --- a/src/main/java/de/chojo/repbot/core/Bot.java +++ b/src/main/java/de/chojo/repbot/core/Bot.java @@ -7,6 +7,9 @@ import de.chojo.jdautil.interactions.dispatching.InteractionHub; import de.chojo.jdautil.localization.util.LocaleProvider; +import de.chojo.repbot.actions.messages.log.MessageLog; +import de.chojo.repbot.actions.user.donated.received.UserDonated; +import de.chojo.repbot.actions.user.received.UserReceived; import de.chojo.repbot.analyzer.ContextResolver; import de.chojo.repbot.analyzer.MessageAnalyzer; import de.chojo.repbot.commands.abuseprotection.AbuseProtection; @@ -42,10 +45,10 @@ import de.chojo.repbot.service.MetricService; import de.chojo.repbot.service.PresenceService; import de.chojo.repbot.service.RepBotCachePolicy; -import de.chojo.repbot.service.reputation.ReputationService; import de.chojo.repbot.service.RoleAssigner; import de.chojo.repbot.service.RoleUpdater; import de.chojo.repbot.service.SelfCleanupService; +import de.chojo.repbot.service.reputation.ReputationService; import de.chojo.repbot.statistic.Statistic; import de.chojo.repbot.util.LogNotify; import de.chojo.repbot.util.PermissionErrorHandler; @@ -61,7 +64,6 @@ import org.slf4j.Logger; import javax.security.auth.login.LoginException; - import java.util.Collections; import static org.slf4j.LoggerFactory.getLogger; @@ -139,25 +141,26 @@ private void initShardManager() throws LoginException { roles = new Roles(data.guilds(), new RoleAssigner(data.guilds(), localization.localizer())); repBotCachePolicy = new RepBotCachePolicy(scan, roles); - shardManager = DefaultShardManagerBuilder.createDefault(configuration.baseSettings().token()) - .enableIntents( - // Required to retrieve reputation emotes - GatewayIntent.GUILD_MESSAGE_REACTIONS, - // Required to scan for thankwords - GatewayIntent.GUILD_MESSAGES, GatewayIntent.MESSAGE_CONTENT, - // Required to resolve member without a direct mention - GatewayIntent.GUILD_MEMBERS, - // Required to cache voice states for member relationships - GatewayIntent.GUILD_VOICE_STATES) - .enableCache( - // Required for voice activity - CacheFlag.VOICE_STATE) - // we have our own shutdown hook - .setEnableShutdownHook(false) - .setMemberCachePolicy(repBotCachePolicy) - .setEventPool(threading.eventThreads()) - .setThreadFactory(Threading.createThreadFactory(threading.jdaGroup())) - .build(); + shardManager = DefaultShardManagerBuilder + .createDefault(configuration.baseSettings().token()) + .enableIntents( + // Required to retrieve reputation emotes + GatewayIntent.GUILD_MESSAGE_REACTIONS, + // Required to scan for thankwords + GatewayIntent.GUILD_MESSAGES, GatewayIntent.MESSAGE_CONTENT, + // Required to resolve member without a direct mention + GatewayIntent.GUILD_MEMBERS, + // Required to cache voice states for member relationships + GatewayIntent.GUILD_VOICE_STATES) + .enableCache( + // Required for voice activity + CacheFlag.VOICE_STATE) + // we have our own shutdown hook + .setEnableShutdownHook(false) + .setMemberCachePolicy(repBotCachePolicy) + .setEventPool(threading.eventThreads()) + .setThreadFactory(Threading.createThreadFactory(threading.jdaGroup())) + .build(); } private void initServices() { @@ -187,48 +190,51 @@ private void initInteractions() { var guilds = data.guilds(); InteractionHub.builder(shardManager) - .withConversationSystem() - .withCommands( - new Channel(guilds), - new Reputation(guilds, configuration, roleAssigner), - roles, - new RepSettings(guilds), - new Top(guilds), - Thankwords.of(messageAnalyzer, guilds), - scan, - new Locale(guilds), - new Invite(configuration), - Info.create(configuration), - new Log(guilds), - Setup.of(guilds, configuration), - new Gdpr(data.gdpr()), - new Prune(gdprService), - new Reactions(guilds), - new Dashboard(guilds), - new AbuseProtection(guilds), - new Debug(guilds), - new RepAdmin(guilds, configuration, roleAssigner), - new Messages(guilds), - new BotAdmin(guilds, configuration, statistic)) - .withLocalizer(localizer) - .cleanGuildCommands("true".equals(System.getProperty("bot.cleancommands", "false"))) - .testMode("true".equals(System.getProperty("bot.testmode", "false"))) - .withCommandErrorHandler((context, throwable) -> { - if (throwable instanceof InsufficientPermissionException) { - PermissionErrorHandler.handle((InsufficientPermissionException) throwable, shardManager, - localizer.context(LocaleProvider.guild(context.guild())), configuration); - return; - } - log.error(LogNotify.NOTIFY_ADMIN, "Command execution of {} failed\n{}", - context.interaction().meta().name(), context.args(), throwable); - }) - .withGuildCommandMapper(cmd -> Collections.singletonList(configuration.baseSettings().botGuild())) - .withDefaultMenuService() - .withPostCommandHook(result -> data.metrics().commands() - .logCommand(result.context().interaction().meta().name())) - .withPagination(builder -> builder.withLocalizer(localizer).previousText("pages.previous") - .nextText("pages.next")) - .build(); + .withConversationSystem() + .withCommands( + new Channel(guilds), + new Reputation(guilds, configuration, roleAssigner), + roles, + new RepSettings(guilds), + new Top(guilds), + Thankwords.of(messageAnalyzer, guilds), + scan, + new Locale(guilds), + new Invite(configuration), + Info.create(configuration), + new Log(guilds), + Setup.of(guilds, configuration), + new Gdpr(data.gdpr()), + new Prune(gdprService), + new Reactions(guilds), + new Dashboard(guilds), + new AbuseProtection(guilds), + new Debug(guilds), + new RepAdmin(guilds, configuration, roleAssigner), + new Messages(guilds), + new BotAdmin(guilds, configuration, statistic)) + .withMessages(new MessageLog(guilds)) + .withUsers(new UserReceived(guilds), + new UserDonated(guilds)) + .withLocalizer(localizer) + .cleanGuildCommands("true".equals(System.getProperty("bot.cleancommands", "false"))) + .testMode("true".equals(System.getProperty("bot.testmode", "false"))) + .withCommandErrorHandler((context, throwable) -> { + if (throwable instanceof InsufficientPermissionException) { + PermissionErrorHandler.handle((InsufficientPermissionException) throwable, shardManager, + localizer.context(LocaleProvider.guild(context.guild())), configuration); + return; + } + log.error(LogNotify.NOTIFY_ADMIN, "Command execution of {} failed\n{}", + context.interaction().meta().name(), context.args(), throwable); + }) + .withGuildCommandMapper(cmd -> Collections.singletonList(configuration.baseSettings().botGuild())) + .withDefaultMenuService() + .withPostCommandHook(result -> data.metrics().commands() + .logCommand(result.context().interaction().meta().name())) + .withPagination(builder -> builder.withLocalizer(localizer).previousText("pages.previous") + .nextText("pages.next")) + .build(); } private void initListener() { diff --git a/src/main/resources/database/postgresql/1/patch_28.sql b/src/main/resources/database/postgresql/1/patch_28.sql index ed6a0b010..a3f89e2f9 100644 --- a/src/main/resources/database/postgresql/1/patch_28.sql +++ b/src/main/resources/database/postgresql/1/patch_28.sql @@ -1,4 +1,4 @@ -CREATE OR REPLACE VIEW repbot.truncated_reputation_offset AS +CREATE OR REPLACE VIEW repbot_schema.truncated_reputation_offset AS SELECT l.guild_id, l.user_id, sum(l.amount)::BIGINT as amount FROM repbot_schema.reputation_offset l LEFT JOIN repbot_schema.guild_settings s ON l.guild_id = s.guild_id diff --git a/src/main/resources/locale.properties b/src/main/resources/locale.properties index 4f43cf5f9..aee6233e2 100644 --- a/src/main/resources/locale.properties +++ b/src/main/resources/locale.properties @@ -436,3 +436,6 @@ words.reputation= words.reputationOffset= words.role= words.unknown= +message.message_log.name= +user.received_reputation.name= +user.given_reputation.name= diff --git a/src/main/resources/locale_de.properties b/src/main/resources/locale_de.properties index 174689930..bf7f51c00 100644 --- a/src/main/resources/locale_de.properties +++ b/src/main/resources/locale_de.properties @@ -436,3 +436,6 @@ words.reputation=Reputation words.reputationOffset=Reputationsversatz words.role=Rolle words.unknown=Unbekannt +message.message_log.name=Nachricht Protokol +user.received_reputation.name=Erhaltene Reputation +user.given_reputation.name=Gegebene Reputation diff --git a/src/main/resources/locale_en_US.properties b/src/main/resources/locale_en_US.properties index 35b3660e7..095ed1b5d 100644 --- a/src/main/resources/locale_en_US.properties +++ b/src/main/resources/locale_en_US.properties @@ -436,3 +436,6 @@ words.reputation=Reputation words.reputationOffset=Reputation offset words.role=role words.unknown=Unknown +message.message_log.name=Message Log +user.received_reputation.name=Received Reputation +user.given_reputation.name=Given Reputation diff --git a/src/main/resources/locale_es_ES.properties b/src/main/resources/locale_es_ES.properties index 143655e4b..4c9937388 100644 --- a/src/main/resources/locale_es_ES.properties +++ b/src/main/resources/locale_es_ES.properties @@ -436,3 +436,6 @@ words.reputation=Reputación words.reputationOffset=Compensación de la reputación words.role=papel words.unknown=Desconocido +message.message_log.name=Protocolo de mensajes +user.received_reputation.name=Reputación mantenida +user.given_reputation.name=Reputación dada diff --git a/src/main/resources/locale_fr.properties b/src/main/resources/locale_fr.properties index 02573001d..099eeef2e 100644 --- a/src/main/resources/locale_fr.properties +++ b/src/main/resources/locale_fr.properties @@ -436,3 +436,6 @@ words.reputation=Réputation words.reputationOffset=Compensation de réputation words.role=Rôle words.unknown=Inconnu +message.message_log.name=Message Protocole +user.received_reputation.name=Réputation obtenue +user.given_reputation.name=Réputation donnée diff --git a/src/main/resources/locale_pt_BR.properties b/src/main/resources/locale_pt_BR.properties index 58e5ba68d..a31aebfbf 100644 --- a/src/main/resources/locale_pt_BR.properties +++ b/src/main/resources/locale_pt_BR.properties @@ -436,3 +436,6 @@ words.reputation=Reputação words.reputationOffset=Compensação da reputação words.role=papel words.unknown=Desconhecido +message.message_log.name=Protocolo de mensagens +user.received_reputation.name=Manutenção da reputação +user.given_reputation.name=Reputação perdoada diff --git a/src/main/resources/locale_ru.properties b/src/main/resources/locale_ru.properties index 61d328506..58c724e7c 100644 --- a/src/main/resources/locale_ru.properties +++ b/src/main/resources/locale_ru.properties @@ -436,3 +436,6 @@ words.reputation=Репутация words.reputationOffset=Зачет репутации words.role=Роль words.unknown=Неизвестно +message.message_log.name=Протокол сообщения +user.received_reputation.name=Поддержание репутации +user.given_reputation.name=Прощенная репутация From 8eb4da7008be0996f060a3f45c3be2cf6b081a03 Mon Sep 17 00:00:00 2001 From: Lilly Tempest <46890129+rainbowdashlabs@users.noreply.github.com> Date: Thu, 18 Jan 2024 22:32:40 +0100 Subject: [PATCH 11/11] Update build.gradle.kts --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 904cd009b..dfaa5889f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "de.chojo" -version = "1.14.0" +version = "1.15.0" repositories { maven("https://eldonexus.de/repository/maven-public")