Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update jda and curupira #84

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 'Check out repository'
uses: actions/checkout@v2

- name: 'Download latest JDK 17'
run: wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
uses: actions/checkout@v3

- name: 'Set up JDK'
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'jdkfile'
jdkFile: jdk-17_linux-x64_bin.tar.gz
distribution: 'temurin'
cache: 'gradle'

- name: 'Grant execute permission for gradlew'
run: chmod +x gradlew

- name: 'Build with Gradle'
run: ./gradlew build
run: ./gradlew build --no-daemon
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ replay_pid*
build/*

.gradle/*
.idea/*
.idea/*

*.db
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java'
id 'application'
id 'org.springframework.boot' version '2.7.0'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.github.johnrengelman.shadow' version '8.1.1'
}

group 'com.softwaii.capivara'
Expand Down Expand Up @@ -33,12 +33,12 @@ dependencies {
implementation 'com.h2database:h2:2.1.212'
implementation 'org.postgresql:postgresql:42.3.6'

implementation("net.dv8tion:JDA:5.0.0-alpha.15") {
implementation("net.dv8tion:JDA:5.0.0-beta.16") {
exclude module: 'opus-java'
}

implementation("com.github.Softawii:curupira:v0.2.10")
implementation("com.github.Softawii:curupira:v0.2.10:all")
implementation("com.github.Softawii:curupira:v0.3.0")
implementation("com.github.Softawii:curupira:v0.3.0:all")
implementation("com.github.minndevelopment:emoji-java:master-SNAPSHOT")
}

Expand All @@ -47,7 +47,7 @@ tasks.register('deploy') {
enabled = false
}
shadowJar {
archiveName("CapivaraBot.jar")
archiveFileName = "CapivaraBot.jar"
}
dependsOn 'shadowJar'
}
Expand All @@ -57,7 +57,7 @@ tasks.register('homolog') {
enabled = false
}
shadowJar {
archiveName("CapivaraBotHomolog.jar")
archiveFileName = "CapivaraBotHomolog.jar"
}
dependsOn 'shadowJar'
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
41 changes: 28 additions & 13 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,11 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,18 +198,28 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/softawii/capivara/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Main {

public static void main(String[] args) {
context = SpringApplication.run(Main.class, args);
JDA jda = context.getBean(JDA.class);
JDA jda = context.getBean(JDA.class);
BuildProperties buildProperties = context.getBean(BuildProperties.class);
jda.getPresence().setPresence(Activity.of(Activity.ActivityType.PLAYING, buildProperties.getVersion()), true);
LOGGER.info(buildProperties.getVersion() + " Bot is ready as " + jda.getSelfUser().getName());
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/softawii/capivara/config/SpringConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.security.auth.login.LoginException;
import javax.sql.DataSource;
import java.nio.file.Path;
import java.util.Properties;
Expand Down Expand Up @@ -74,7 +73,7 @@ public JDA jda(VoiceEvents voiceEvents) {
);
jda = builder.build();
jda.awaitReady();
} catch (LoginException | InterruptedException e) {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

Expand All @@ -91,11 +90,11 @@ public Curupira curupira(JDA jda) {

CapivaraExceptionHandler exceptionHandler = null;
String logChannelId = env.getProperty("log.channel.id");
String logDirectory = env.getProperty("log_directory");
String logDirectory = env.getProperty("log_directory");
if (logChannelId != null) {
Path logPath = null;
Path logPath = null;
if (logDirectory != null) {
logPath = Path.of(logDirectory);
logPath = Path.of(logDirectory);
}
exceptionHandler = new CapivaraExceptionHandler(logChannelId, logPath);
}
Expand Down
67 changes: 37 additions & 30 deletions src/main/java/com/softawii/capivara/core/DroneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.Category;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.Modal;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.interactions.components.text.TextInput;
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle;
import net.dv8tion.jda.api.interactions.modals.Modal;
import net.dv8tion.jda.api.requests.RestAction;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -30,7 +35,6 @@
import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -219,9 +223,9 @@ public void checkToDeleteTemporary(VoiceChannel channel, Member member, boolean

Message claimMessage;
if (textChannel != null) {
claimMessage = textChannel.sendMessageEmbeds(embed).setActionRows(ActionRow.of(claim)).complete();
claimMessage = textChannel.sendMessageEmbeds(embed).setActionRow(claim).complete();
} else {
claimMessage = channel.sendMessageEmbeds(embed).setActionRows(ActionRow.of(claim)).complete();
claimMessage = channel.sendMessageEmbeds(embed).setActionRow(claim).complete();
}

drone.setClaimMessage(claimMessage.getIdLong());
Expand Down Expand Up @@ -266,7 +270,7 @@ public void checkToCreateTemporary(VoiceChannel channel, Member member) {
RestAction<Void> actions = guild.moveVoiceMember(member, voice)
.and(voice.upsertPermissionOverride(member).grant(Permission.VOICE_CONNECT, Permission.VIEW_CHANNEL));

if(text != null) {
if (text != null) {
actions.and(text.upsertPermissionOverride(publicRole).deny(Permission.VIEW_CHANNEL))
.and(text.upsertPermissionOverride(member).grant(Permission.VIEW_CHANNEL))
.submit();
Expand Down Expand Up @@ -330,46 +334,49 @@ private void createControlPanel(VoiceChannel voiceChannel, GuildMessageChannel t
// region Buttons
// General Config

net.dv8tion.jda.api.interactions.components.buttons.Button config = net.dv8tion.jda.api.interactions.components.buttons.Button.primary(VoiceGroup.Dynamic.droneConfig, "🔧 Settings");
net.dv8tion.jda.api.interactions.components.buttons.Button visibility = net.dv8tion.jda.api.interactions.components.buttons.Button.secondary(VoiceGroup.Dynamic.droneHideShow, isVisible(voiceChannel) ? "👻 Hide" : "👀 Visible");
net.dv8tion.jda.api.interactions.components.buttons.Button connect = net.dv8tion.jda.api.interactions.components.buttons.Button.secondary(VoiceGroup.Dynamic.dronePublicPrivate, canConnect(voiceChannel) ? "📢 Public" : "🔒 Private");
net.dv8tion.jda.api.interactions.components.buttons.Button permanent = Button.danger(VoiceGroup.Dynamic.dronePermTemp, drone.isPermanent() ? "⏳ Temporary" : "✨ Permanent");

ActionRow general = ActionRow.of(config, visibility, connect, permanent);
Button config = Button.primary(VoiceGroup.Dynamic.droneConfig, "🔧 Settings");
Button visibility = Button.secondary(VoiceGroup.Dynamic.droneHideShow, isVisible(voiceChannel) ? "👻 Hide" : "👀 Visible");
Button connect = Button.secondary(VoiceGroup.Dynamic.dronePublicPrivate, canConnect(voiceChannel) ? "📢 Public" : "🔒 Private");
Button permanent = Button.danger(VoiceGroup.Dynamic.dronePermTemp, drone.isPermanent() ? "⏳ Temporary" : "✨ Permanent");
ActionRow general = ActionRow.of(config, visibility, connect, permanent);
// endregion

// Send the message
sendControlPanel(textChannel, drone, builder, java.util.List.of(general));
sendControlPanel(textChannel, drone, builder, general);
}

private void sendControlPanel(GuildMessageChannel channel, VoiceDrone drone, EmbedBuilder builder, java.util.List<ActionRow> actionRows) {
private void sendControlPanel(GuildMessageChannel channel, VoiceDrone drone, EmbedBuilder builder, ActionRow actionRow) {
// We already have a message, so we need to update it
if (drone.getControlPanel() != null) {
Member owner = channel.getGuild().getMemberById(drone.getOwnerId());
channel.editMessageById(drone.getControlPanel(), "Hello!")
.setEmbeds(builder.build())
.setActionRows(actionRows)
.setComponents(actionRow)
.queue(q -> { /* It's ok! */}, e -> {
LOGGER.error("Error updating control panel: {}", e.getMessage());
// If error, we need to create a new one
sendNewControlPanel(channel, drone, builder, actionRows);
});
LOGGER.error("Error updating control panel: {}", e.getMessage());
// If error, we need to create a new one
sendNewControlPanel(channel, drone, builder, actionRow);
});
} else {
sendNewControlPanel(channel, drone, builder, actionRows);
sendNewControlPanel(channel, drone, builder, actionRow);
}
}

private void sendNewControlPanel(GuildMessageChannel channel, VoiceDrone drone, EmbedBuilder builder, List<ActionRow> actionRows) {
private void sendNewControlPanel(GuildMessageChannel channel, VoiceDrone drone, EmbedBuilder builder, ActionRow actionRow) {
Member owner = channel.getGuild().getMemberById(drone.getOwnerId());
channel.sendMessage("Hello!").setEmbeds(builder.build()).setActionRows(actionRows).queue(q -> {
drone.setControlPanel(q.getIdLong());
try {
voiceDroneService.update(drone);
} catch (KeyNotFoundException ex) {
// WTF????
throw new RuntimeException(ex);
}
}, ee -> LOGGER.error("Error creating control panel: {}", ee.getMessage()));
channel.sendMessage("Hello!")
.setEmbeds(builder.build())
.setComponents(actionRow)
.setSuppressedNotifications(true)
.queue(q -> {
drone.setControlPanel(q.getIdLong());
try {
voiceDroneService.update(drone);
} catch (KeyNotFoundException ex) {
// WTF????
throw new RuntimeException(ex);
}
}, ee -> LOGGER.error("Error creating control panel: {}", ee.getMessage()));
}

public void makePermanent(VoiceChannel channel, boolean permanent) throws KeyNotFoundException {
Expand All @@ -385,7 +392,7 @@ private String getDroneName(Member member, VoiceHive hive) {

Matcher menteMatcher = this.digdinRegex.matcher(username);

if(menteMatcher.find()) {
if (menteMatcher.find()) {
digdin = menteMatcher.group("nome");
}

Expand Down
Loading