Skip to content

Commit

Permalink
Upgrade Java to 19
Browse files Browse the repository at this point in the history
Also:
- fix .dockerignore using the old groovy gradle scripts
- replace pattern matching switch with IFs
- make the "cancel" buttons delete their respective message
- Dockerfile: remove "--link" argument from the COPY statements
- Dockerfile: switch WORKDIR and COPY commands
- CommandButtonUtils: remove "getDeleteButton"
  • Loading branch information
SIMULATAN committed Dec 27, 2022
1 parent f0ef80d commit e595008
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*

!build.gradle
!settings.gradle
!build.gradle.kts
!settings.gradle.kts
!src/
!gradlew
!gradle/
!gradle/
4 changes: 2 additions & 2 deletions .github/workflows/buildandeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "17"
java-version: "19"
- name: Build project
uses: gradle/gradle-build-action@v2
with:
Expand All @@ -77,4 +77,4 @@ jobs:
with:
path: build/reports/jacoco/test/
name: Coverage Report
retention-days: 14
retention-days: 14
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Java JDK
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 17
java-version: 19

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
FROM gradle:7.5.1-jdk17-alpine AS build

COPY --chown=gradle:gradle . /bot
FROM gradle:7.6-jdk19-alpine AS build

WORKDIR /bot

COPY --chown=gradle:gradle . .

RUN gradle build downloadDependencies --no-daemon

FROM eclipse-temurin:17-jre-alpine AS run
FROM eclipse-temurin:19-jre-alpine AS run

WORKDIR /blackonionbot

# Copy the libraries to the container
COPY --link --from=build /bot/libraries/* ./
COPY --from=build /bot/libraries/* ./

# Copy the built application to the container
COPY --link --from=build /bot/build/libs/BlackOnion-Bot.jar ./bot.jar
COPY --from=build /bot/build/libs/BlackOnion-Bot.jar ./bot.jar

ENTRYPOINT [ "java", "-cp", "*", "com.github.black0nion.blackonionbot.Main" ]
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ dependencies {
testsImplementation("org.mockito:mockito-core:4.9.0")
}

tasks.withType<JavaCompile>().forEach { it.options.compilerArgs.add("--enable-preview") }

configurations { all { exclude(group = "org.slf4j", module = "slf4j-log4j12") } }

application { mainClass.set("com.github.black0nion.blackonionbot.Main") }
Expand All @@ -111,6 +109,8 @@ version = System.getenv("VERSION") ?: "dev"

tasks.named<Jar>("jar") { archiveVersion.set("") }

tasks.compileJava { options.release.set(19) }

tasks.test {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.GenericSelectMenuInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
Expand Down Expand Up @@ -222,6 +223,11 @@ public void onCommandAutoCompleteInteraction(@NotNull CommandAutoCompleteInterac

@Override
public void onButtonInteraction(@NotNull ButtonInteractionEvent event) {
if ("cancel".equals(event.getComponentId())) {
// don't delete the defer or it won't delete the message
event.deferEdit().flatMap(InteractionHook::deleteOriginal).queue();
return;
}
String key = event.getComponentId().split("\\|")[0];
if (commands.containsKey(key)) {
try {
Expand Down Expand Up @@ -309,11 +315,10 @@ public void onMessageContextInteraction(@NotNull MessageContextInteractionEvent

final C cmd = clazz.cast(command);

final AbstractCommandEvent<?, ?> cmde = switch (event) {
case SlashCommandInteractionEvent e1 -> new SlashCommandEvent((SlashCommand) cmd, e1, guild, member, author);
case MessageContextInteractionEvent e1 -> new MessageCommandEvent((MessageCommand) cmd, e1, guild, member, author);
default -> throw new IllegalArgumentException("Unexpected value: " + cmd);
};
AbstractCommandEvent<?, ?> cmde;
if (event instanceof SlashCommandInteractionEvent e1) cmde = new SlashCommandEvent((SlashCommand) cmd, e1, guild, member, author);
else if (event instanceof MessageContextInteractionEvent e1) cmde = new MessageCommandEvent((MessageCommand) cmd, e1, guild, member, author);
else throw new IllegalArgumentException("Unexpected value: " + cmd);

final boolean disabled = !guild.isCommandActivated(cmd);
if (disabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
import net.dv8tion.jda.api.interactions.components.buttons.Button;

public interface CommandButtonUtils extends CommandUtilsBase {
default Button getDeleteButton() {
return Button.danger("delete", Emoji.fromUnicode("U+F6AE"));
}

default Button getCancelButton() {
return Button.danger("cancel", Emoji.fromUnicode("U+2716"));
return Button.secondary("cancel", Emoji.fromUnicode("U+2716"));
}

default Button getConfirmButton() {
Expand Down

0 comments on commit e595008

Please sign in to comment.