Skip to content

Commit

Permalink
[REFACTOR] Upgrade to snapshot of jda-commands 4.0.0-beta.3 (#226)
Browse files Browse the repository at this point in the history
* upgrade to snapshot of jda-commands 4.0.0-beta.3

* make github ci use java 23
  • Loading branch information
SachsenspieltCoding authored Jan 7, 2025
1 parent ddeb039 commit ce1a058
Show file tree
Hide file tree
Showing 28 changed files with 168 additions and 158 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v1
- name: Set up JDK 23
uses: actions/setup-java@v4
with:
java-version: 21
java-version: 23
distribution: "temurin"
- name: Build with Maven
run: mvn -B package --file pom.xml
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ FROM redgate/flyway as flyway
WORKDIR /flyway


FROM maven:3.9.5-amazoncorretto-21-debian AS builder
FROM maven:3.9.9-eclipse-temurin-23 AS builder

WORKDIR /bot
COPY . .
RUN mvn clean package -DskipTests

FROM openjdk:21
FROM openjdk:23

COPY --from=flyway /flyway ./flyway
COPY src/main/resources/db/migration ./db/migration
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
<maven.compiler.source>23</maven.compiler.source>
</properties>

<build>
Expand Down Expand Up @@ -72,12 +72,12 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>5.0.2</version>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>com.github.Kaktushose</groupId>
<artifactId>jda-commands</artifactId>
<version>d1e7cb6229</version>
<version>737f90b697</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
Expand All @@ -97,12 +97,12 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.6</version>
<version>1.5.13</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.5.6</version>
<version>1.5.13</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class Bootstrapper {

private final static Logger log = LoggerFactory.getLogger(Bootstrapper.class);
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/com/github/kaktushose/nplaybot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import com.github.kaktushose.jda.commands.JDACommands;
import com.github.kaktushose.jda.commands.annotations.Produces;
import com.github.kaktushose.jda.commands.data.EmbedCache;
import com.github.kaktushose.jda.commands.embeds.JsonErrorMessageFactory;
import com.github.kaktushose.jda.commands.dependency.DefaultDependencyInjector;
import com.github.kaktushose.jda.commands.embeds.EmbedCache;
import com.github.kaktushose.jda.commands.embeds.error.JsonErrorMessageFactory;
import com.github.kaktushose.nplaybot.events.contest.ContestListener;
import com.github.kaktushose.nplaybot.karma.KarmaListener;
import com.github.kaktushose.nplaybot.permissions.CustomPermissionsProvider;
Expand Down Expand Up @@ -63,11 +64,15 @@ private Bot(long guildId, String token) throws InterruptedException, RuntimeExce
new MemberDatabaseSyncListener(database),
new LegacyCommandListener(embedCache)
);

jdaCommands = JDACommands.start(jda, Bot.class, "com.github.kaktushose.nplaybot");
jdaCommands.getDependencyInjector().registerProvider(this);
jdaCommands.getImplementationRegistry().setErrorMessageFactory(new JsonErrorMessageFactory(embedCache));
jdaCommands.getImplementationRegistry().setPermissionsProvider(new CustomPermissionsProvider(database));

var dependencyInjector = new DefaultDependencyInjector();
dependencyInjector.registerProvider(this);

jdaCommands = JDACommands.builder(jda, Bot.class, "com.github.kaktushose.nplaybot")
.dependencyInjector(dependencyInjector)
.errorMessageFactory(new JsonErrorMessageFactory(embedCache))
.permissionsProvider(new CustomPermissionsProvider(database))
.start();

jda.getPresence().setPresence(OnlineStatus.ONLINE, Activity.customStatus("Version 3.0.0"));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.kaktushose.nplaybot;

import com.github.kaktushose.jda.commands.data.EmbedCache;
import com.github.kaktushose.jda.commands.embeds.EmbedCache;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.github.kaktushose.jda.commands.annotations.interactions.Param;
import com.github.kaktushose.jda.commands.annotations.interactions.Permissions;
import com.github.kaktushose.jda.commands.annotations.interactions.SlashCommand;
import com.github.kaktushose.jda.commands.data.EmbedCache;
import com.github.kaktushose.jda.commands.dispatching.interactions.commands.CommandEvent;
import com.github.kaktushose.jda.commands.dispatching.events.interactions.CommandEvent;
import com.github.kaktushose.jda.commands.embeds.EmbedCache;
import com.github.kaktushose.nplaybot.Database;
import com.github.kaktushose.nplaybot.permissions.BotPermissions;
import net.dv8tion.jda.api.Permission;
Expand Down Expand Up @@ -42,7 +42,7 @@ public void onCollectEventStop(CommandEvent event) {
}

@SlashCommand(value = "events set collect-loot-chance", desc = "Legt die Wahrscheinlichkeit für zufällige Collect-Loot-Drops fest", isGuildOnly = true, enabledFor = Permission.BAN_MEMBERS)
public void onSetXpLootDropChance(CommandEvent event, @Param("Die Wahrscheinlichkeit in Prozent") @Min(1) @Max(100) double chance) {
public void onSetXpLootDropChance(CommandEvent event, @Param("Die Wahrscheinlichkeit in Prozent") @Min(1) @Max(100) Double chance) {
database.getCollectEventService().updateCollectLootChance(chance);
event.reply(embedCache.getEmbed("collectLootChanceUpdate").injectValue("chance", chance));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import com.github.kaktushose.jda.commands.annotations.Inject;
import com.github.kaktushose.jda.commands.annotations.interactions.*;
import com.github.kaktushose.jda.commands.data.EmbedCache;
import com.github.kaktushose.jda.commands.dispatching.interactions.commands.CommandEvent;
import com.github.kaktushose.jda.commands.dispatching.interactions.components.ComponentEvent;
import com.github.kaktushose.jda.commands.dispatching.interactions.modals.ModalEvent;
import com.github.kaktushose.jda.commands.dispatching.reply.Replyable;
import com.github.kaktushose.jda.commands.dispatching.events.interactions.ComponentEvent;
import com.github.kaktushose.jda.commands.dispatching.events.interactions.ModalEvent;
import com.github.kaktushose.jda.commands.embeds.EmbedCache;
import com.github.kaktushose.jda.commands.dispatching.events.interactions.CommandEvent;
import com.github.kaktushose.nplaybot.Database;
import com.github.kaktushose.nplaybot.items.ItemService;
import com.github.kaktushose.nplaybot.permissions.BotPermissions;
Expand Down Expand Up @@ -47,7 +46,7 @@ public class CollectRewardCommands {
public void onRewardCreate(CommandEvent event, @Param("Der interne Name dieser Belohnung") String name, @Param("Der Wert, ab wann die Belohnung vergeben werden soll") int threshold) {
this.name = name;
this.threshold = threshold;
event.withSelectMenus("onSelectType").reply(embedCache.getEmbed("rewardCreateSelectType").injectValue("name", name));
event.with().components("onSelectType").reply(embedCache.getEmbed("rewardCreateSelectType").injectValue("name", name));
}

@StringSelectMenu("Wähle eine Belohnungsart aus")
Expand All @@ -57,7 +56,7 @@ public void onRewardCreate(CommandEvent event, @Param("Der interne Name dieser B
public void onSelectType(ComponentEvent event, List<String> selection) {
rewardType = selection.get(0);
if (ROLE_REWARD.equals(rewardType)) {
event.withSelectMenus("onSelectRole").reply(embedCache.getEmbed("rewardCreateSelectRole").injectValue("name", name));
event.with().components("onSelectRole").reply(embedCache.getEmbed("rewardCreateSelectRole").injectValue("name", name));
} else if (XP_REWARD.equals(rewardType)) {
event.replyModal("onSelectXp");
} else if (ITEM_REWARD.equals(rewardType)) {
Expand All @@ -67,16 +66,15 @@ public void onSelectType(ComponentEvent event, List<String> selection) {
return;
}

var menu = event.getSelectMenu(
"CollectRewardCommands.onSelectItem",
net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu.class
).createCopy();
var menu = ((net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu) event.getSelectMenu("CollectRewardCommands.onSelectItem")).createCopy();
menu.getOptions().clear();
menu.setMaxValues(1);

items.forEach(it -> menu.addOption(it.name(), String.valueOf(it.itemId())));
event.getReplyContext().getBuilder().addActionRow(menu.build());
event.reply(embedCache.getEmbed("rewardCreateSelectItem").injectValue("name", name));
event.jdaEvent()
.replyEmbeds(embedCache.getEmbed("rewardCreateSelectItem").injectValue("name", name).toMessageEmbed())
.addActionRow(menu.build())
.queue();
} else {
throw new IllegalArgumentException(String.format("%s ist keine gültige Auswahl!", rewardType));
}
Expand All @@ -101,7 +99,7 @@ public void onSelectEmbed(ModalEvent event, @TextInput(value = "Das Embed im JSO
parseJson(embed).ifPresentOrElse(it -> {
this.embed = it;
finishSetup(event);
}, () -> event.withButtons("onRetryEmbedInput").reply(embedCache.getEmbed("rewardCreateInvalidEmbed").injectValue("name", name)));
}, () -> event.with().components("onRetryEmbedInput").reply(embedCache.getEmbed("rewardCreateInvalidEmbed").injectValue("name", name)));
}

@Button("neue Eingabe")
Expand All @@ -117,26 +115,26 @@ public void onSelectXp(ModalEvent event,
try {
xp = Integer.parseInt(amount);
} catch (NumberFormatException ignored) {
event.withButtons("onRetryXpInput").reply(embedCache.getEmbed("rewardCreateInvalidXp").injectValue("name", name));
event.with().components("onRetryXpInput").reply(embedCache.getEmbed("rewardCreateInvalidXp").injectValue("name", name));
return;
}
if (xp < 1) {
event.withButtons("onRetryXpInput").reply(embedCache.getEmbed("rewardCreateInvalidXp").injectValue("name", name));
event.with().components("onRetryXpInput").reply(embedCache.getEmbed("rewardCreateInvalidXp").injectValue("name", name));
return;
}
parseJson(embed).ifPresentOrElse(it -> {
this.embed = it;
this.xp = xp;
finishSetup(event);
}, () -> event.withButtons("onRetryXpInput").reply(embedCache.getEmbed("rewardCreateInvalidEmbed").injectValue("name", name)));
}, () -> event.with().components("onRetryXpInput").reply(embedCache.getEmbed("rewardCreateInvalidEmbed").injectValue("name", name)));
}

@Button("neue Eingabe")
public void onRetryXpInput(ComponentEvent event) {
event.replyModal("onSelectXp");
}

private void finishSetup(Replyable event) {
private void finishSetup(ModalEvent event) {
String reward;
if (role != null) {
reward = role.getAsMention();
Expand All @@ -145,7 +143,7 @@ private void finishSetup(Replyable event) {
} else {
reward = String.valueOf(xp);
}
event.withButtons("onConfirm", "onCancel").reply(embedCache.getEmbed("rewardCreateSummarize")
event.with().components("onConfirm", "onCancel").reply(embedCache.getEmbed("rewardCreateSummarize")
.injectValue("name", name)
.injectValue("type", rewardType)
.injectValue("threshold", threshold)
Expand Down Expand Up @@ -175,13 +173,15 @@ public void onRewardDelete(CommandEvent event) {
return;
}

var menu = ((net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu)
event.getJdaCommands().getSelectMenu("CollectRewardCommands.onRewardDeleteSelect")).createCopy();
var menu = ((net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu)
event.getSelectMenu("CollectRewardCommands.onRewardDeleteSelect")).createCopy();
menu.getOptions().clear();
menu.setMaxValues(SelectMenu.OPTIONS_MAX_AMOUNT);
rewards.forEach(it -> menu.addOption(it.name(), String.valueOf(it.rewardId())));
event.getReplyContext().getBuilder().addActionRow(menu.build());
event.reply(embedCache.getEmbed("rewardDeleteSelect"));
event.jdaEvent()
.replyEmbeds(embedCache.getEmbed("rewardDeleteSelect").toMessageEmbed())
.addActionRow(menu.build())
.queue();
}

@StringSelectMenu(value = "Wähle eine oder mehrere Belohnungen aus")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.github.kaktushose.jda.commands.annotations.interactions.Param;
import com.github.kaktushose.jda.commands.annotations.interactions.Permissions;
import com.github.kaktushose.jda.commands.annotations.interactions.SlashCommand;
import com.github.kaktushose.jda.commands.data.EmbedCache;
import com.github.kaktushose.jda.commands.dispatching.interactions.commands.CommandEvent;
import com.github.kaktushose.jda.commands.embeds.EmbedCache;
import com.github.kaktushose.jda.commands.dispatching.events.interactions.CommandEvent;
import com.github.kaktushose.nplaybot.Database;
import com.github.kaktushose.nplaybot.permissions.BotPermissions;
import net.dv8tion.jda.api.Permission;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.github.kaktushose.jda.commands.annotations.interactions.ContextCommand;
import com.github.kaktushose.jda.commands.annotations.interactions.Interaction;
import com.github.kaktushose.jda.commands.annotations.interactions.Permissions;
import com.github.kaktushose.jda.commands.data.EmbedCache;
import com.github.kaktushose.jda.commands.dispatching.interactions.commands.CommandEvent;
import com.github.kaktushose.jda.commands.embeds.EmbedCache;
import com.github.kaktushose.jda.commands.dispatching.events.interactions.CommandEvent;
import com.github.kaktushose.nplaybot.Database;
import com.github.kaktushose.nplaybot.permissions.BotPermissions;
import net.dv8tion.jda.api.Permission;
Expand All @@ -25,13 +25,13 @@ public class MemberExcludeCommand {
@Inject
private EmbedCache embedCache;

@ContextCommand(value = "Vom Contest ausschließen", type = Command.Type.MESSAGE, isGuildOnly = true, ephemeral = true, enabledFor = Permission.BAN_MEMBERS)
@ContextCommand(value = "Vom Contest ausschließen", type = Command.Type.MESSAGE, isGuildOnly = true, enabledFor = Permission.BAN_MEMBERS)
public void onRemoveContestPost(CommandEvent event, Message message) {
log.info("Excluding member {} from contest event", message.getAuthor());
database.getContestEventService().setVoteCount(message.getIdLong(), 0);
message.delete().queue();
event.getGuild().addRoleToMember(message.getAuthor(), message.getGuild().getRoleById(885530505192284210L)).queue();
event.reply(embedCache.getEmbed("memberExcluded"));
event.with().ephemeral(true).reply(embedCache.getEmbed("memberExcluded"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.github.kaktushose.jda.commands.annotations.interactions.Interaction;
import com.github.kaktushose.jda.commands.annotations.interactions.Permissions;
import com.github.kaktushose.jda.commands.annotations.interactions.SlashCommand;
import com.github.kaktushose.jda.commands.data.EmbedCache;
import com.github.kaktushose.jda.commands.dispatching.interactions.commands.CommandEvent;
import com.github.kaktushose.jda.commands.embeds.EmbedCache;
import com.github.kaktushose.jda.commands.dispatching.events.interactions.CommandEvent;
import com.github.kaktushose.nplaybot.permissions.BotPermissions;
import net.dv8tion.jda.api.Permission;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.github.kaktushose.jda.commands.annotations.Inject;
import com.github.kaktushose.jda.commands.annotations.interactions.*;
import com.github.kaktushose.jda.commands.data.EmbedCache;
import com.github.kaktushose.jda.commands.dispatching.interactions.commands.CommandEvent;
import com.github.kaktushose.jda.commands.dispatching.interactions.components.ComponentEvent;
import com.github.kaktushose.jda.commands.dispatching.events.interactions.ComponentEvent;
import com.github.kaktushose.jda.commands.embeds.EmbedCache;
import com.github.kaktushose.jda.commands.dispatching.events.interactions.CommandEvent;
import com.github.kaktushose.nplaybot.Database;
import com.github.kaktushose.nplaybot.permissions.BotPermissions;
import net.dv8tion.jda.api.Permission;
Expand Down Expand Up @@ -52,17 +52,16 @@ public void onItemAdd(CommandEvent event, Member target) {

this.target = target;

var menu = event.getSelectMenu(
"AddItemCommand.onItemAddSelect",
net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu.class
).createCopy();
var menu = ((net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu) event.getSelectMenu("AddItemCommand.onItemAddSelect")).createCopy();

menu.getOptions().clear();
menu.setMaxValues(1);

items.forEach(it -> menu.addOption(it.name(), String.valueOf(it.itemId())));
event.getReplyContext().getBuilder().addActionRow(menu.build());
event.reply(embedCache.getEmbed("itemAddSelect"));
event.jdaEvent()
.replyEmbeds(embedCache.getEmbed("itemAddSelect").toMessageEmbed())
.addActionRow(menu.build())
.queue();
}

@StringSelectMenu("Wähle ein Item aus")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.kaktushose.nplaybot.items;

import com.github.kaktushose.jda.commands.data.EmbedCache;
import com.github.kaktushose.jda.commands.embeds.EmbedCache;
import com.github.kaktushose.nplaybot.Bot;
import com.github.kaktushose.nplaybot.settings.SettingsService;
import net.dv8tion.jda.api.entities.Guild;
Expand Down
Loading

0 comments on commit ce1a058

Please sign in to comment.