Skip to content

Commit

Permalink
Release 1.15.0 (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs authored Jan 18, 2024
2 parents 1fd6c0e + 4d0ae9d commit 1693487
Show file tree
Hide file tree
Showing 26 changed files with 331 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.11
- run: pip install pipenv && pipenv install && pipenv run mkdocs gh-deploy --force
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
- run: pip install pipenv && pipenv install && pipenv run mkdocs build
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "de.chojo"
version = "1.14.0"
version = "1.15.0"

repositories {
maven("https://eldonexus.de/repository/maven-public")
Expand All @@ -25,12 +25,12 @@ 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")
}

// database
implementation("org.postgresql", "postgresql", "42.7.0")
implementation("org.postgresql", "postgresql", "42.7.1")
implementation(libs.bundles.sadu)

// Logging
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -15,15 +15,15 @@ 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")
library("slf4j-api", "org.slf4j:slf4j-api:2.0.9")
version("log4j", "2.22.1")
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")
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.24.0")
plugin("shadow", "com.github.johnrengelman.shadow").version("8.1.1")

}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/de/chojo/repbot/actions/messages/log/MessageLog.java
Original file line number Diff line number Diff line change
@@ -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<Message> {
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();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<User> {
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();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<User> {
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();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
5 changes: 3 additions & 2 deletions src/main/java/de/chojo/repbot/commands/bot/handler/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -147,8 +148,8 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont

var pages = new ListPageBag<>(embeds) {
@Override
public CompletableFuture<MessageEmbed> buildPage() {
return CompletableFuture.completedFuture(currentElement());
public CompletableFuture<MessageEditData> buildPage() {
return CompletableFuture.completedFuture(MessageEditData.fromEmbeds(currentElement()));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,11 +49,11 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont

context.registerPage(new ListPageBag<>(links) {
@Override
public CompletableFuture<MessageEmbed> buildPage() {
return CompletableFuture.completedFuture(new EmbedBuilder()
public CompletableFuture<MessageEditData> buildPage() {
return CompletableFuture.completedFuture(MessageEditData.fromEmbeds(new EmbedBuilder()
.setImage(currentElement())
.setAuthor("Open in Browser", currentElement(), event.getJDA().getSelfUser().getAvatarUrl())
.build());
.build()));
}
});
}
Expand Down
31 changes: 28 additions & 3 deletions src/main/java/de/chojo/repbot/commands/log/handler/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 extends BaseAnalyzer implements SlashHandler {
private final Guilds guilds;
Expand All @@ -27,4 +26,30 @@ public Analyzer(Guilds guilds) {
public void onSlashCommand(SlashCommandInteractionEvent event, EventContext context) {
onSlashCommand(event, context, guilds.guild(event.getGuild()).reputation());
}

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();
}
}
11 changes: 9 additions & 2 deletions src/main/java/de/chojo/repbot/commands/log/handler/Donated.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<MessageEmbed> buildPage() {
public CompletableFuture<MessageEditData> buildPage() {
return CompletableFuture.supplyAsync(() -> userLogEmbed(context, user, "command.log.donated.message.log",
mapUserLogEntry(context, logAccess.page(current()), ReputationLogEntry::receiverId)));
}

@Override
public CompletableFuture<MessageEmbed> buildEmptyPage() {
public CompletableFuture<MessageEditData> buildEmptyPage() {
return CompletableFuture.completedFuture(userLogEmbed(context, user, "command.log.donated.message.log",
mapUserLogEntry(context, Collections.emptyList(), ReputationLogEntry::receiverId)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> log) {
static MessageEditData userLogEmbed(EventContext context, Member user, String title, List<String> 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());
}

public static void buildFields(List<String> entries, LocalizedEmbedBuilder embedBuilder) {
Expand Down
Loading

0 comments on commit 1693487

Please sign in to comment.