diff --git a/.gitea/workflows/production.yml b/.gitea/workflows/production.yml
new file mode 100644
index 0000000..a52fc21
--- /dev/null
+++ b/.gitea/workflows/production.yml
@@ -0,0 +1,55 @@
+# This defines the name of the workflow as it will appear in the "Actions" tab of the Gitea repository.
+name: Production deployment
+
+on:
+ push:
+ branches:
+ - master
+
+env:
+ SSH_SERVER: "192.168.1.37"
+ DOCKER_IMAGE_NAME: "jdrbot"
+
+jobs:
+ build:
+ name: Build
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Check out repo's default branch
+ uses: actions/checkout@v3
+ - name: Install Docker
+ run: curl -fsSL https://get.docker.com | sh
+ - name: Docker build
+ run: |
+ echo ${{ secrets.DOCKER_TOKEN }} | docker login gitea.skydust.fr -u ${{ secrets.DOCKER_USER }} --password-stdin
+ docker build . -t gitea.skydust.fr/skydust/${{ env.DOCKER_IMAGE_NAME }}
+ docker tag gitea.skydust.fr/skydust/${{ env.DOCKER_IMAGE_NAME }} gitea.skydust.fr/skydust/${{ env.DOCKER_IMAGE_NAME }}:latest
+ - name: Docker push
+ run: docker push gitea.skydust.fr/skydust/${{ env.DOCKER_IMAGE_NAME }}:latest
+
+ deploy:
+ name: Deploying
+ runs-on: ubuntu-latest
+ needs: build
+
+ steps:
+ - name: Check out repo's default branch
+ uses: actions/checkout@v3
+ - name: Setup the ssh key
+ run: |
+ mkdir ~/.ssh
+ echo "${{ secrets.SSH_KEY }}" > ~/.ssh/ssh_key
+ ssh-keyscan -t rsa ${{ env.SSH_SERVER }} >> ~/.ssh/known_hosts
+ chmod 700 -R ~/.ssh
+ - name: Deploying
+ run: |
+ ssh -i ~/.ssh/ssh_key ${{ secrets.SSH_USER }}@${{ env.SSH_SERVER }} << EOF
+ echo ${{ secrets.DOCKER_TOKEN }} | docker login gitea.skydust.fr -u ${{ secrets.DOCKER_USER }} --password-stdin
+ PREVIOUS_IMAGE=\$(docker inspect ${{ env.DOCKER_IMAGE_NAME }} --format "{{.Image}}")
+ docker stop ${{ env.DOCKER_IMAGE_NAME }} || true
+ docker rm ${{ env.DOCKER_IMAGE_NAME }} || true
+ docker image rm \${PREVIOUS_IMAGE} || true
+ docker pull gitea.skydust.fr/skydust/${{ env.DOCKER_IMAGE_NAME }}:latest
+ docker run --restart=always -d --name="${{ env.DOCKER_IMAGE_NAME }}" gitea.skydust.fr/skydust/${{ env.DOCKER_IMAGE_NAME }}:latest
+ EOF
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index a06bb62..e5eead4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
# ---> Java
+.idea
+
# Compiled class file
*.class
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 26d3352..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
deleted file mode 100644
index fb7f4a8..0000000
--- a/.idea/compiler.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
deleted file mode 100644
index 611e7c8..0000000
--- a/.idea/gradle.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
deleted file mode 100644
index 8cc70bd..0000000
--- a/.idea/jarRepositories.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries-with-intellij-classes.xml b/.idea/libraries-with-intellij-classes.xml
deleted file mode 100644
index 9fa3156..0000000
--- a/.idea/libraries-with-intellij-classes.xml
+++ /dev/null
@@ -1,65 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 62269df..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/JdrBot.iml b/.idea/modules/JdrBot.iml
deleted file mode 100644
index cc815a6..0000000
--- a/.idea/modules/JdrBot.iml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/.idea/thriftCompiler.xml b/.idea/thriftCompiler.xml
deleted file mode 100644
index 7bc123c..0000000
--- a/.idea/thriftCompiler.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
deleted file mode 100644
index e96534f..0000000
--- a/.idea/uiDesigner.xml
+++ /dev/null
@@ -1,124 +0,0 @@
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..641bf75
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,14 @@
+FROM openjdk:18-ea-jdk-slim-bullseye AS builder
+WORKDIR /app
+COPY . /app
+RUN ./gradlew shadowJar
+
+FROM openjdk:18-ea-slim-bullseye AS runner
+LABEL authors="skydust"
+WORKDIR /app
+
+COPY --from=builder /app/build/libs/JdrBot-all.jar /app/JdrBot.jar
+COPY Songs /app/Songs
+COPY start.sh /app
+
+CMD ["/bin/bash","./start.sh"]
\ No newline at end of file
diff --git a/README.md b/README.md
index 6b14374..6e9e0c7 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,7 @@
# JdrBot
-Jdr botto
\ No newline at end of file
+Jdr botto
+
+To update gradlew:
+- Find every plugins and upgrade them
+- Run `gradle wrapper --gradle-version 8.3`
\ No newline at end of file
diff --git a/Songs/One Folder/Violin 2.mp3 b/Songs/One Folder/Violin 2.mp3
new file mode 100644
index 0000000..a0e7736
Binary files /dev/null and b/Songs/One Folder/Violin 2.mp3 differ
diff --git a/Songs/One Folder/Violin.mp3 b/Songs/One Folder/Violin.mp3
new file mode 100644
index 0000000..a0e7736
Binary files /dev/null and b/Songs/One Folder/Violin.mp3 differ
diff --git a/Songs/Two Folder/Violin.mp3 b/Songs/Two Folder/Violin.mp3
new file mode 100644
index 0000000..a0e7736
Binary files /dev/null and b/Songs/Two Folder/Violin.mp3 differ
diff --git a/Songs/Two Folder/Woo/Violin.mp3 b/Songs/Two Folder/Woo/Violin.mp3
new file mode 100644
index 0000000..a0e7736
Binary files /dev/null and b/Songs/Two Folder/Woo/Violin.mp3 differ
diff --git a/Songs/Violin 2 copie 2.mp3 b/Songs/Violin 2 copie 2.mp3
new file mode 100644
index 0000000..a0e7736
Binary files /dev/null and b/Songs/Violin 2 copie 2.mp3 differ
diff --git a/build.gradle b/build.gradle
index 74a8281..367701a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -14,32 +14,29 @@ plugins {
id 'application'
// Shadow plugin to make uberJars
- id 'com.github.johnrengelman.shadow' version '7.1.0'
+ id 'com.github.johnrengelman.shadow' version '8.1.1'
}
repositories {
mavenCentral()
- maven {
- url 'https://m2.dv8tion.net/releases'
- }
-
maven {
url 'https://jitpack.io'
}
}
dependencies {
- implementation 'com.google.guava:guava:31.1-jre'
- implementation 'com.github.oshi:oshi-core:6.1.6'
- implementation 'com.github.oshi:oshi-json:3.13.6'
- implementation 'org.slf4j:slf4j-simple:2.0.0-alpha0'
implementation 'net.lingala.zip4j:zip4j:2.10.0'
implementation 'club.minnced:opus-java:1.1.1'
implementation 'ws.schild:jave-all-deps:3.3.1'
+ implementation 'com.google.guava:guava:31.1-jre'
+ implementation 'com.github.oshi:oshi-core:6.1.6'
+ implementation 'com.github.oshi:oshi-json:3.13.6'
+ implementation 'org.slf4j:slf4j-simple:2.0.9'
implementation 'org.apache.commons:commons-lang3:3.12.0'
- implementation 'com.sedmelluq:lavaplayer:1.3.78'
- implementation 'com.github.DV8FromTheWorld:JDA:5.0.0-alpha.12'
+ implementation 'dev.arbjerg:lavaplayer:2.0.1'
+ implementation 'net.dv8tion:JDA:5.0.0-beta.13'
+ implementation 'org.reflections:reflections:0.10.2'
}
application {
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index e708b1c..7f93135 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index ffed3a2..ac72c34 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
+networkTimeout=10000
+validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index 4f906e0..0adc8e1 100755
--- a/gradlew
+++ b/gradlew
@@ -1,7 +1,7 @@
-#!/usr/bin/env sh
+#!/bin/sh
#
-# Copyright 2015 the original author or authors.
+# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,67 +17,99 @@
#
##############################################################################
-##
-## Gradle start up script for UN*X
-##
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# 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/.
+#
##############################################################################
# Attempt to set APP_HOME
+
# Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`"/$link"
- fi
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
-APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$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"'
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# 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"
+MAX_FD=maximum
warn () {
echo "$*"
-}
+} >&2
die () {
echo
echo "$*"
echo
exit 1
-}
+} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
-case "`uname`" in
- CYGWIN* )
- cygwin=true
- ;;
- Darwin* )
- darwin=true
- ;;
- MINGW* )
- msys=true
- ;;
- NONSTOP* )
- nonstop=true
- ;;
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
@@ -87,9 +119,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
- JAVACMD="$JAVA_HOME/jre/sh/java"
+ JAVACMD=$JAVA_HOME/jre/sh/java
else
- JAVACMD="$JAVA_HOME/bin/java"
+ JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@@ -98,88 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the
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.
+ JAVACMD=java
+ 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" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
- MAX_FD_LIMIT=`ulimit -H -n`
- if [ $? -eq 0 ] ; then
- if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
- MAX_FD="$MAX_FD_LIMIT"
- fi
- ulimit -n $MAX_FD
- if [ $? -ne 0 ] ; then
- warn "Could not set maximum file descriptor limit: $MAX_FD"
- fi
- else
- warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
- fi
-fi
-
-# For Darwin, add options to specify how the application appears in the dock
-if $darwin; then
- GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
-fi
-
-# For Cygwin or MSYS, switch paths to Windows format before running java
-if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
- APP_HOME=`cygpath --path --mixed "$APP_HOME"`
- CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
-
- JAVACMD=`cygpath --unix "$JAVACMD"`
-
- # We build the pattern for arguments to be converted via cygpath
- ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
- SEP=""
- for dir in $ROOTDIRSRAW ; do
- ROOTDIRS="$ROOTDIRS$SEP$dir"
- SEP="|"
- done
- OURCYGPATTERN="(^($ROOTDIRS))"
- # Add a user-defined pattern to the cygpath arguments
- if [ "$GRADLE_CYGPATTERN" != "" ] ; then
- OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
- fi
- # Now convert the arguments - kludge to limit ourselves to /bin/sh
- i=0
- for arg in "$@" ; do
- CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
- CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
-
- if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
- eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
- else
- eval `echo args$i`="\"$arg\""
- fi
- i=`expr $i + 1`
- done
- case $i in
- 0) set -- ;;
- 1) set -- "$args0" ;;
- 2) set -- "$args0" "$args1" ;;
- 3) set -- "$args0" "$args1" "$args2" ;;
- 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+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=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=SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
-# Escape application args
-save () {
- for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
- echo " "
-}
-APP_ARGS=`save "$@"`
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
-# Collect all arguments for the java command, following the shell quoting and substitution rules
-eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# 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, 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.
+
+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.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
index ac1b06f..6689b85 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -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
@@ -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%
@@ -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.
@@ -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
diff --git a/src/main/java/.idea/workspace.xml b/src/main/java/.idea/workspace.xml
deleted file mode 100644
index 9b1009f..0000000
--- a/src/main/java/.idea/workspace.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1616004344851
-
-
- 1616004344851
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/main/java/fr/Skydust/JdrBot/JdrBot.java b/src/main/java/fr/Skydust/JdrBot/JdrBot.java
index d60437d..6157512 100755
--- a/src/main/java/fr/Skydust/JdrBot/JdrBot.java
+++ b/src/main/java/fr/Skydust/JdrBot/JdrBot.java
@@ -1,25 +1,24 @@
package fr.Skydust.JdrBot;
+import java.lang.reflect.InvocationTargetException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import java.util.Timer;
-import javax.security.auth.login.LoginException;
-import fr.Skydust.JdrBot.cmds.*;
-import fr.Skydust.JdrBot.cmds.playmusic.*;
-import fr.Skydust.JdrBot.cmds.record.CancelRecord;
-import fr.Skydust.JdrBot.cmds.record.Record;
-import fr.Skydust.JdrBot.cmds.record.StopRecord;
-import fr.Skydust.JdrBot.stock.Command;
-import fr.Skydust.JdrBot.utils.HeartbeatTask;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
+import fr.Skydust.JdrBot.tasks.HeartbeatTask;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
+import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
+import org.reflections.Reflections;
public class JdrBot {
- public static String Version = "3.1";
+ public static String Version = "4.0";
public static JDA jda;
public static LocalDateTime basedate;
@@ -29,7 +28,7 @@ public class JdrBot {
public static boolean debugMode = false;
- public static void main(String args[]) {
+ public static void main(String[] args) {
for (int i=0;i();
- registerCommand(new Aide());
- registerCommand(new Etat());
- registerCommand(new Roll());
- registerCommand(new Record());
- registerCommand(new StopRecord());
- registerCommand(new CancelRecord());
- registerCommand(new Emote());
- registerCommand(new PlayMusic());
- registerCommand(new StopMusic());
- registerCommand(new FLoad());
- registerCommand(new FLoadLoop());
+ registerCommands();
jda.addEventListener(new JdrBotListener());
- } catch (LoginException e) {
- System.out.println("The login token is wrong");
} catch (Exception e) {
e.printStackTrace();
}
}
- public static void registerCommand(Command cmd) {
- commandList.add(cmd);
+ /**
+ * Finds every class annotated with CommandSpec and registers them as a command.
+ */
+ public static void registerCommands() {
+ commandList = new ArrayList();
+
+ Reflections reflections = new Reflections("fr.Skydust.JdrBot.cmds");
+ Set> annotated = reflections.getTypesAnnotatedWith(CommandSpec.class);
+
+ for (Class> command: annotated) {
+ try {
+ Command cmd = (Command) command.getDeclaredConstructor().newInstance();
+ commandList.add(cmd);
+
+ System.out.println("Registered command "+ cmd.cmdName);
+ } catch (InstantiationException | NoSuchMethodException | InvocationTargetException |
+ IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
}
diff --git a/src/main/java/fr/Skydust/JdrBot/JdrBotListener.java b/src/main/java/fr/Skydust/JdrBot/JdrBotListener.java
index d61ffdd..6b05da2 100755
--- a/src/main/java/fr/Skydust/JdrBot/JdrBotListener.java
+++ b/src/main/java/fr/Skydust/JdrBot/JdrBotListener.java
@@ -1,19 +1,17 @@
package fr.Skydust.JdrBot;
-import java.util.Random;
-
+import fr.Skydust.JdrBot.bases.command.Command;
import fr.Skydust.JdrBot.cmds.LastTimeOnline;
import fr.Skydust.JdrBot.cmds.playmusic.StopMusic;
import fr.Skydust.JdrBot.menu.MenuSystem;
-import fr.Skydust.JdrBot.stock.Command;
-import fr.Skydust.JdrBot.utils.HeartbeatTask;
+import fr.Skydust.JdrBot.tasks.HeartbeatTask;
import net.dv8tion.jda.api.events.GatewayPingEvent;
-import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent;
-import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent;
+import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateOnlineStatusEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
+import org.jetbrains.annotations.NotNull;
public class JdrBotListener extends ListenerAdapter {
@Override
@@ -38,24 +36,21 @@ public class JdrBotListener extends ListenerAdapter {
/* LastTimeOnline listener */
@Override
- public void onUserUpdateOnlineStatus(UserUpdateOnlineStatusEvent e) {
+ public void onUserUpdateOnlineStatus(@NotNull UserUpdateOnlineStatusEvent e) {
LastTimeOnline.onUserUpdateOnlineStatus(e);
}
+
/* Empty voice channel listener */
@Override
- public void onGuildVoiceMove(GuildVoiceMoveEvent e) {
- StopMusic.onGuildVoiceMove(e);
- }
- @Override
- public void onGuildVoiceLeave(GuildVoiceLeaveEvent e) {
- StopMusic.onGuildVoiceLeave(e);
+ public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent e) {
+ StopMusic.onGuildVoiceUpdate(e);
}
/* Menu system listener */
@Override
- public void onMessageReactionAdd(MessageReactionAddEvent e) { MenuSystem.onMessageReactionAdd(e); }
+ public void onMessageReactionAdd(@NotNull MessageReactionAddEvent e) { MenuSystem.onMessageReactionAdd(e); }
/* Heartbeat command listener */
@Override
- public void onGatewayPing(GatewayPingEvent e) { HeartbeatTask.HeartbeatUpdateEvent(e); }
+ public void onGatewayPing(@NotNull GatewayPingEvent e) { HeartbeatTask.HeartbeatUpdateEvent(e); }
public boolean isACommand(String message, String cmd) {
return message.matches("^("+ JdrBot.startcmdchar +")("+ cmd +")( .*|)$");
diff --git a/src/main/java/fr/Skydust/JdrBot/audio/handler/JdrBotARH.java b/src/main/java/fr/Skydust/JdrBot/audio/handler/JdrBotARH.java
index ce6bcca..f5646a9 100755
--- a/src/main/java/fr/Skydust/JdrBot/audio/handler/JdrBotARH.java
+++ b/src/main/java/fr/Skydust/JdrBot/audio/handler/JdrBotARH.java
@@ -1,12 +1,10 @@
package fr.Skydust.JdrBot.audio.handler;
-import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
-import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
-import fr.Skydust.JdrBot.cmds.record.Record;
import fr.Skydust.JdrBot.stock.RecordState;
import net.dv8tion.jda.api.audio.AudioReceiveHandler;
import net.dv8tion.jda.api.audio.CombinedAudio;
import net.dv8tion.jda.api.audio.UserAudio;
+import org.jetbrains.annotations.NotNull;
public class JdrBotARH implements AudioReceiveHandler {
private final RecordState recordState;
@@ -20,21 +18,10 @@ public class JdrBotARH implements AudioReceiveHandler {
return true;
}
- @Override
- public boolean canReceiveUser() {
- return false;
- }
-
- @Override
- public void handleCombinedAudio(CombinedAudio arg0) {
+ @Override
+ public void handleCombinedAudio(@NotNull CombinedAudio combinedAudio) {
if(recordState.isRecording) {
- recordState.addBytes(arg0.getAudioData(1.0));
+ recordState.addBytes(combinedAudio.getAudioData(1.0));
}
}
-
- @Override
- public void handleUserAudio(UserAudio arg0) {
-
- }
-
}
diff --git a/src/main/java/fr/Skydust/JdrBot/bases/command/Command.java b/src/main/java/fr/Skydust/JdrBot/bases/command/Command.java
new file mode 100755
index 0000000..c188858
--- /dev/null
+++ b/src/main/java/fr/Skydust/JdrBot/bases/command/Command.java
@@ -0,0 +1,33 @@
+package fr.Skydust.JdrBot.bases.command;
+
+import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
+
+public abstract class Command {
+ public String cmdName;
+ public String cmdDesc;
+ public String cmdUsage = "";
+ public boolean hidden = false;
+
+ public Command() {
+ if (!getClass().isAnnotationPresent(CommandSpec.class)) {
+ throw new WrongCommandSpecException("The command spec was not declared ! (@CommandSpec)");
+ }
+
+ CommandSpec specs = getClass().getAnnotation(CommandSpec.class);
+ if (specs.name().isEmpty()) {
+ throw new WrongCommandSpecException("The command name is invalid.");
+ }
+
+ cmdName = specs.name();
+ cmdDesc = specs.description();
+ cmdUsage = specs.usage();
+
+ if (getClass().isAnnotationPresent(HideCommand.class)) {
+ hidden = true;
+ }
+ }
+
+ public abstract void call(MessageReceivedEvent e);
+}
+
+
diff --git a/src/main/java/fr/Skydust/JdrBot/bases/command/CommandSpec.java b/src/main/java/fr/Skydust/JdrBot/bases/command/CommandSpec.java
new file mode 100644
index 0000000..6ebbabe
--- /dev/null
+++ b/src/main/java/fr/Skydust/JdrBot/bases/command/CommandSpec.java
@@ -0,0 +1,17 @@
+package fr.Skydust.JdrBot.bases.command;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface CommandSpec {
+ String name() default "";
+
+ String description() default "Empty description";
+
+ String usage() default "";
+}
+
diff --git a/src/main/java/fr/Skydust/JdrBot/bases/command/HideCommand.java b/src/main/java/fr/Skydust/JdrBot/bases/command/HideCommand.java
new file mode 100644
index 0000000..a0dc310
--- /dev/null
+++ b/src/main/java/fr/Skydust/JdrBot/bases/command/HideCommand.java
@@ -0,0 +1,11 @@
+package fr.Skydust.JdrBot.bases.command;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface HideCommand {
+}
diff --git a/src/main/java/fr/Skydust/JdrBot/bases/command/WrongCommandSpecException.java b/src/main/java/fr/Skydust/JdrBot/bases/command/WrongCommandSpecException.java
new file mode 100644
index 0000000..f1a2ed1
--- /dev/null
+++ b/src/main/java/fr/Skydust/JdrBot/bases/command/WrongCommandSpecException.java
@@ -0,0 +1,7 @@
+package fr.Skydust.JdrBot.bases.command;
+
+public class WrongCommandSpecException extends RuntimeException {
+ public WrongCommandSpecException(String errorMessage) {
+ super(errorMessage);
+ }
+}
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/AddSong.java b/src/main/java/fr/Skydust/JdrBot/cmds/AddSong.java
index 85da530..3356914 100644
--- a/src/main/java/fr/Skydust/JdrBot/cmds/AddSong.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/AddSong.java
@@ -1,15 +1,17 @@
package fr.Skydust.JdrBot.cmds;
-import fr.Skydust.JdrBot.stock.Command;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
+import fr.Skydust.JdrBot.bases.command.HideCommand;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
+@HideCommand // While its not ready
+@CommandSpec(
+ name = "addsong",
+ usage = "[Chemin] [URL]",
+ description = "(Admin) Ajoute une musique au jukebox"
+)
public class AddSong extends Command {
- public AddSong() {
- SetName("addsong");
- SetUsage("[Chemin] [URL]");
- SetDesc("(Admin) Ajoute une musique au jukebox");
- }
-
@Override
public void call(MessageReceivedEvent e) {
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/Aide.java b/src/main/java/fr/Skydust/JdrBot/cmds/Aide.java
index e0fc2cb..e4e28c4 100755
--- a/src/main/java/fr/Skydust/JdrBot/cmds/Aide.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/Aide.java
@@ -1,21 +1,21 @@
package fr.Skydust.JdrBot.cmds;
import fr.Skydust.JdrBot.JdrBot;
-import fr.Skydust.JdrBot.stock.Command;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
import net.dv8tion.jda.api.EmbedBuilder;
-import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
+import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import java.awt.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
+@CommandSpec(
+ name = "aide",
+ description = "Pour avoir de l'aide !"
+)
public class Aide extends Command {
- public Aide() {
- SetName("aide");
- SetDesc("Pour avoir de l'aide !");
- }
-
@Override
public void call(MessageReceivedEvent e) {
StringBuilder sb = new StringBuilder();
@@ -24,11 +24,14 @@ public class Aide extends Command {
{
Command cmd = JdrBot.commandList.get(i);
if(!cmd.hidden) {
- sb.append("`"+cmd.cmdName + ((cmd.cmdUsage.equals("")) ? "" : " "+cmd.cmdUsage) +"` - *"+cmd.cmdDesc+"*"+ ((i != JdrBot.commandList.size()-1) ? "\n" : ""));
+ sb.append("`"+cmd.cmdName
+ + ((cmd.cmdUsage.isEmpty()) ? "" : " "+cmd.cmdUsage)
+ +"` - *"+cmd.cmdDesc+"*"
+ + ((i != JdrBot.commandList.size()-1) ? "\n" : ""));
}
}
- e.getChannel().sendMessage(new MessageBuilder().setEmbeds(new EmbedBuilder()
+ e.getChannel().sendMessage(new MessageCreateBuilder().setEmbeds(new EmbedBuilder()
.setDescription(sb.toString())
.setTitle("Aide", null)
.setFooter("Fait le " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy 'a' HH:mm:ss")), e.getJDA().getSelfUser().getAvatarUrl())
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/Emote.java b/src/main/java/fr/Skydust/JdrBot/cmds/Emote.java
index ecb4f6a..d543073 100755
--- a/src/main/java/fr/Skydust/JdrBot/cmds/Emote.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/Emote.java
@@ -2,15 +2,18 @@ package fr.Skydust.JdrBot.cmds;
import java.util.Arrays;
-import fr.Skydust.JdrBot.stock.Command;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
+import fr.Skydust.JdrBot.bases.command.HideCommand;
+import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
+@HideCommand
+@CommandSpec(
+ name = "emote",
+ description = "Donne les informations techniques d'une emote"
+)
public class Emote extends Command {
- public Emote() {
- SetName("emote");
- SetDesc("Donne les informations techniques d'une emote");
- }
-
@Override
public void call(MessageReceivedEvent e) {
String[] args = Arrays.copyOfRange(e.getMessage().getContentRaw().split(" "), 1, e.getMessage().getContentRaw().split(" ").length);
@@ -19,7 +22,7 @@ public class Emote extends Command {
if(str.matches("<:.*:\\d+>"))
{
String id = str.replaceAll("<:.*:(\\d+)>", "$1");
- net.dv8tion.jda.api.entities.Emote emote = e.getJDA().getEmoteById(id);
+ RichCustomEmoji emote = e.getJDA().getEmojiById(id);
if(emote==null)
{
e.getChannel().sendMessage("Unknown emote:\n"
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/Etat.java b/src/main/java/fr/Skydust/JdrBot/cmds/Etat.java
index b7f8c71..7c787ce 100755
--- a/src/main/java/fr/Skydust/JdrBot/cmds/Etat.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/Etat.java
@@ -10,23 +10,24 @@ import java.util.Arrays;
import com.sedmelluq.discord.lavaplayer.tools.PlayerLibrary;
import fr.Skydust.JdrBot.JdrBot;
-import fr.Skydust.JdrBot.stock.Command;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
+import fr.Skydust.JdrBot.utils.DurationUtils;
import fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDAInfo;
-import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
+import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import oshi.SystemInfo;
import oshi.hardware.HardwareAbstractionLayer;
+@CommandSpec(
+ name = "status",
+ description = "Donne le status du bot et du serveur"
+)
public class Etat extends Command {
private static final DecimalFormat df = new DecimalFormat("###.##");
- public Etat() {
- SetName("status");
- SetDesc("Donne le status du bot et du serveur");
- }
-
@Override
public void call(MessageReceivedEvent e) {
SystemInfo si = new SystemInfo();
@@ -37,7 +38,7 @@ public class Etat extends Command {
LocalDateTime currentDate = LocalDateTime.now();
Duration difference = Duration.between(JdrBot.basedate, currentDate);
- e.getChannel().sendMessage(new MessageBuilder().setEmbeds(new EmbedBuilder()
+ e.getChannel().sendMessage(new MessageCreateBuilder().setEmbeds(new EmbedBuilder()
.setAuthor("Etat de "+ e.getGuild().getSelfMember().getEffectiveName())
.addBlankField(false)
.addField("CPU","-----", false)
@@ -53,7 +54,7 @@ public class Etat extends Command {
.addBlankField(false)
.addField("Servers",e.getJDA().getGuilds().size()+"",true)
.addField("Versions", "JdrBot: "+ JdrBot.Version +" - JDA: "+ JDAInfo.VERSION +" - Lavaplayer: "+ PlayerLibrary.VERSION, true)
- .addField("Uptime", Utils.formatDuration(difference), true)
+ .addField("Uptime", DurationUtils.formatDuration(difference), true)
.setFooter("*Fait le "+ currentDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy à HH:mm:ss")) +"*", e.getJDA().getSelfUser().getAvatarUrl())
.setColor(Color.BLUE)
.build()).build()).queue();
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/LastTimeOnline.java b/src/main/java/fr/Skydust/JdrBot/cmds/LastTimeOnline.java
index dfad147..804813c 100755
--- a/src/main/java/fr/Skydust/JdrBot/cmds/LastTimeOnline.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/LastTimeOnline.java
@@ -4,25 +4,25 @@ import java.time.Duration;
import java.time.LocalDateTime;
import java.util.HashMap;
-import fr.Skydust.JdrBot.stock.Command;
-import fr.Skydust.JdrBot.utils.Utils;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
+import fr.Skydust.JdrBot.utils.DurationUtils;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateOnlineStatusEvent;
+@CommandSpec(
+ name = "lasttimeonline|lto",
+ usage = "[Mention]",
+ description = "Dit depuis combien de temps un utilisateur est en ligne/hors-ligne"
+)
public class LastTimeOnline extends Command {
static HashMap AllUsers = new HashMap<>();
- public LastTimeOnline() {
- SetName("lasttimeonline|lto");
- SetDesc("Dit depuis combien de temps un utilisateur est en ligne/hors-ligne");
- SetUsage("[Mention]");
- }
-
@Override
public void call(MessageReceivedEvent e) {
- if(e.getMessage().getMentions().getUsers().size() < 1) {
+ if(e.getMessage().getMentions().getUsers().isEmpty()) {
e.getChannel().sendMessage("Vous n'avez pas mentionne d'utilisateur !").queue();
return;
}
@@ -41,7 +41,7 @@ public class LastTimeOnline extends Command {
} else {
sb.append(u.getAsMention()+" est en ligne depuis ");
}
- sb.append(Utils.formatDurationSmooth(Duration.between(UserDate, LocalDateTime.now())));
+ sb.append(DurationUtils.formatDurationSmooth(Duration.between(UserDate, LocalDateTime.now())));
e.getChannel().sendMessage(sb.toString()).queue();
}
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/Roll.java b/src/main/java/fr/Skydust/JdrBot/cmds/Roll.java
index 1e375a6..327eab7 100755
--- a/src/main/java/fr/Skydust/JdrBot/cmds/Roll.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/Roll.java
@@ -2,19 +2,19 @@ package fr.Skydust.JdrBot.cmds;
import java.util.*;
-import fr.Skydust.JdrBot.stock.Command;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
import fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
+@CommandSpec(
+ name = "r|roll",
+ usage = "[NombreDés]d[NombreFaces] OU [NombreFaces]",
+ description = "Lance un dé"
+)
public class Roll extends Command {
static Random r = new Random();
- public Roll() {
- SetName("r|roll");
- SetDesc("Lance un dé");
- SetUsage("[NombreDés]d[NombreFaces] OU [NombreFaces]");
- }
-
public void call(MessageReceivedEvent e) {
if (e.getMessage().getContentRaw().split(" ").length != 1)
{
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/FLoad.java b/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/FLoad.java
index 58344e6..9db3cc8 100755
--- a/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/FLoad.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/FLoad.java
@@ -1,21 +1,23 @@
package fr.Skydust.JdrBot.cmds.playmusic;
-import fr.Skydust.JdrBot.stock.Command;
-import fr.Skydust.JdrBot.utils.MessageType;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
+import fr.Skydust.JdrBot.bases.command.HideCommand;
+import fr.Skydust.JdrBot.enums.MessageType;
import fr.Skydust.JdrBot.utils.Utils;
+import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
+@HideCommand
+@CommandSpec(
+ name = "fload",
+ description = "/!\\ Commande test /!\\ Permet de charger une musique de force",
+ usage = "[URL/Recherche]"
+)
public class FLoad extends Command {
- public FLoad() {
- SetName("fload");
- SetDesc("/!\\ Commande test /!\\ Permet de charger une musique de force");
- SetUsage("[URL/Recherche]");
- Hide();
- }
-
@Override
public void call(MessageReceivedEvent e) {
if(e.getMember().getVoiceState().getChannel() != null) {
@@ -24,7 +26,7 @@ public class FLoad extends Command {
e.getGuild().getAudioManager().openAudioConnection(e.getMember().getVoiceState().getChannel());
//ytsearch:query
- PlayMusic.loadAndPlay(e.getGuild(), e.getChannel(), args, false, false);
+ PlayMusic.loadAndPlay(e.getGuild(), (TextChannel) e.getChannel(), args, false, false);
Utils.sendMessage(e.getChannel(), MessageType.NORMAL, "Forçage du lancement de "+args);
} else {
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/FLoadLoop.java b/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/FLoadLoop.java
index a6be0b2..da69500 100755
--- a/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/FLoadLoop.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/FLoadLoop.java
@@ -1,21 +1,23 @@
package fr.Skydust.JdrBot.cmds.playmusic;
-import fr.Skydust.JdrBot.stock.Command;
-import fr.Skydust.JdrBot.utils.MessageType;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
+import fr.Skydust.JdrBot.bases.command.HideCommand;
+import fr.Skydust.JdrBot.enums.MessageType;
import fr.Skydust.JdrBot.utils.Utils;
+import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
+@HideCommand
+@CommandSpec(
+ name = "floadloop",
+ description = "/!\\ Commande test /!\\ Permet de charger une musique de force",
+ usage = "[URL/Recherche]"
+)
public class FLoadLoop extends Command {
- public FLoadLoop() {
- SetName("floadloop");
- SetDesc("/!\\ Commande test /!\\ Permet de charger une musique de force");
- SetUsage("[URL/Recherche]");
- Hide();
- }
-
@Override
public void call(MessageReceivedEvent e) {
if(e.getMember().getVoiceState().getChannel() != null) {
@@ -26,7 +28,7 @@ public class FLoadLoop extends Command {
if(!args.matches(".*(https?)://.*")) {
args = "ytsearch:"+args;
}
- PlayMusic.loadAndPlay(e.getGuild(), e.getChannel(), StringUtils.join(args," "), true, false);
+ PlayMusic.loadAndPlay(e.getGuild(), (TextChannel) e.getChannel(), StringUtils.join(args," "), true, false);
} else {
Utils.sendMessage(e.getChannel(), MessageType.ERROR, "Vous n'êtes dans un salon vocal");
}
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/PlayMusic.java b/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/PlayMusic.java
index 9482c8d..506e2a0 100755
--- a/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/PlayMusic.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/PlayMusic.java
@@ -3,11 +3,12 @@ package fr.Skydust.JdrBot.cmds.playmusic;
import java.util.HashMap;
import java.util.Map;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
import fr.Skydust.JdrBot.jukebox.JukeboxSystem;
-import fr.Skydust.JdrBot.stock.Command;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
-import net.dv8tion.jda.api.entities.MessageChannel;
+import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
@@ -20,6 +21,10 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import fr.Skydust.JdrBot.audio.GuildMusicManager;
+@CommandSpec(
+ name = "playmusic|pm",
+ description = "(Admin) Demarre le jukebox"
+)
public class PlayMusic extends Command {
private static final AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
static Map musicManagers;
@@ -27,12 +32,11 @@ public class PlayMusic extends Command {
public static HashMap jukeboxSystems = new HashMap<>();
public PlayMusic() {
+ super();
+
musicManagers = new HashMap<>();
AudioSourceManagers.registerRemoteSources(playerManager);
AudioSourceManagers.registerLocalSource(playerManager);
-
- SetName("playmusic|pm");
- SetDesc("(Admin) Demarre le jukebox");
}
@Override
@@ -64,7 +68,7 @@ public class PlayMusic extends Command {
return jukeboxSystems.get(guild.getIdLong());
}
- public static void loadAndPlay(final Guild guild, final MessageChannel channel, final String trackUrl, boolean loop, boolean nomsg) {
+ public static void loadAndPlay(final Guild guild, final TextChannel channel, final String trackUrl, boolean loop, boolean nomsg) {
System.out.println(trackUrl);
GuildMusicManager musicManager = getGuildAudioPlayer(guild);
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/StopMusic.java b/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/StopMusic.java
index 1b72ccf..7665b4c 100755
--- a/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/StopMusic.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/playmusic/StopMusic.java
@@ -1,20 +1,19 @@
package fr.Skydust.JdrBot.cmds.playmusic;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
import fr.Skydust.JdrBot.cmds.record.Record;
import fr.Skydust.JdrBot.jukebox.JukeboxSystem;
-import fr.Skydust.JdrBot.stock.Command;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
-import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent;
-import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent;
+import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
+@CommandSpec(
+ name = "stopmusic|sm",
+ description = "(Admin) Arrete le jukebox et supprime son message"
+)
public class StopMusic extends Command {
- public StopMusic() {
- SetName("stopmusic|sm");
- SetDesc("(Admin) Arrete le jukebox et supprime son message");
- }
-
@Override
public void call(MessageReceivedEvent e) {
if(!e.getGuild().getAudioManager().isConnected() || !e.getMember().hasPermission(Permission.ADMINISTRATOR)) {
@@ -24,15 +23,12 @@ public class StopMusic extends Command {
stopMusic(e.getGuild());
}
- public static void onGuildVoiceLeave(GuildVoiceLeaveEvent e) {
- if(e.getGuild().getAudioManager().isConnected() && e.getChannelLeft().getIdLong() == e.getGuild().getAudioManager().getConnectedChannel().getIdLong() && e.getChannelLeft().getMembers().size() == 1) {
- stopMusic(e.getGuild());
- }
- }
- public static void onGuildVoiceMove(GuildVoiceMoveEvent e) {
- if(e.getGuild().getAudioManager().isConnected() && e.getChannelLeft().getIdLong() == e.getGuild().getAudioManager().getConnectedChannel().getIdLong() && e.getChannelLeft().getMembers().size() == 1) {
- stopMusic(e.getGuild());
+ public static void onGuildVoiceUpdate(GuildVoiceUpdateEvent e) {
+ if(e.getChannelLeft() != null) {
+ if (e.getGuild().getAudioManager().isConnected() && e.getChannelLeft().getIdLong() == e.getGuild().getAudioManager().getConnectedChannel().getIdLong() && e.getChannelLeft().getMembers().size() == 1) {
+ stopMusic(e.getGuild());
+ }
}
}
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/record/CancelRecord.java b/src/main/java/fr/Skydust/JdrBot/cmds/record/CancelRecord.java
index aae21ac..1968f30 100755
--- a/src/main/java/fr/Skydust/JdrBot/cmds/record/CancelRecord.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/record/CancelRecord.java
@@ -1,18 +1,18 @@
package fr.Skydust.JdrBot.cmds.record;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
import fr.Skydust.JdrBot.cmds.playmusic.PlayMusic;
-import fr.Skydust.JdrBot.stock.Command;
import fr.Skydust.JdrBot.stock.RecordState;
-import fr.Skydust.JdrBot.utils.MessageType;
+import fr.Skydust.JdrBot.enums.MessageType;
import fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
+@CommandSpec(
+ name = "crecord|cr",
+ description = "Annule l'enregistrement"
+)
public class CancelRecord extends Command {
- public CancelRecord() {
- SetName("crecord|cr");
- SetDesc("Annule l'enregistrement");
- }
-
@Override
public void call(MessageReceivedEvent e) {
RecordState rs = Record.getGuildRecordState(e.getGuild());
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/record/Record.java b/src/main/java/fr/Skydust/JdrBot/cmds/record/Record.java
index b22ed58..482f91f 100755
--- a/src/main/java/fr/Skydust/JdrBot/cmds/record/Record.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/record/Record.java
@@ -4,22 +4,22 @@ import java.util.Date;
import java.util.HashMap;
import fr.Skydust.JdrBot.audio.handler.JdrBotARH;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
import fr.Skydust.JdrBot.stock.RecordState;
-import fr.Skydust.JdrBot.stock.Command;
-import fr.Skydust.JdrBot.utils.MessageType;
+import fr.Skydust.JdrBot.enums.MessageType;
import fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
+@CommandSpec(
+ name = "record",
+ description = "(Admin) Enregistre le chat vocal"
+)
public class Record extends Command {
public static HashMap recordStates = new HashMap<>();
- public Record() {
- SetName("record");
- SetDesc("(Admin) Enregistre le chat vocal");
- }
-
@Override
public void call(MessageReceivedEvent e)
{
diff --git a/src/main/java/fr/Skydust/JdrBot/cmds/record/StopRecord.java b/src/main/java/fr/Skydust/JdrBot/cmds/record/StopRecord.java
index 255e629..6aedb23 100755
--- a/src/main/java/fr/Skydust/JdrBot/cmds/record/StopRecord.java
+++ b/src/main/java/fr/Skydust/JdrBot/cmds/record/StopRecord.java
@@ -1,18 +1,19 @@
package fr.Skydust.JdrBot.cmds.record;
+import fr.Skydust.JdrBot.bases.command.Command;
+import fr.Skydust.JdrBot.bases.command.CommandSpec;
import fr.Skydust.JdrBot.cmds.playmusic.PlayMusic;
-import fr.Skydust.JdrBot.stock.Command;
import fr.Skydust.JdrBot.stock.RecordState;
-import fr.Skydust.JdrBot.utils.MessageType;
+import fr.Skydust.JdrBot.enums.MessageType;
import fr.Skydust.JdrBot.utils.Utils;
+import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
+@CommandSpec(
+ name = "stoprecord|sr",
+ description = "Arrete et archive l'enregistrement"
+)
public class StopRecord extends Command {
- public StopRecord() {
- SetName("stoprecord|sr");
- SetDesc("Arrete l'enregistrement");
- }
-
@Override
public void call(MessageReceivedEvent e) {
RecordState rs = Record.getGuildRecordState(e.getGuild());
@@ -20,7 +21,7 @@ public class StopRecord extends Command {
if(PlayMusic.getGuildsJukebox(e.getGuild()) == null) {
e.getGuild().getAudioManager().closeAudioConnection();
}
- rs.endRecord(e.getGuild(), e.getChannel());
+ rs.endRecord(e.getGuild(), (TextChannel) e.getChannel());
} else {
Utils.sendMessage(e.getChannel(), MessageType.ERROR, "Il n'y a aucun enregistrement en cours");
}
diff --git a/src/main/java/fr/Skydust/JdrBot/utils/MessageType.java b/src/main/java/fr/Skydust/JdrBot/enums/MessageType.java
similarity index 60%
rename from src/main/java/fr/Skydust/JdrBot/utils/MessageType.java
rename to src/main/java/fr/Skydust/JdrBot/enums/MessageType.java
index aa0e14e..dfdb145 100644
--- a/src/main/java/fr/Skydust/JdrBot/utils/MessageType.java
+++ b/src/main/java/fr/Skydust/JdrBot/enums/MessageType.java
@@ -1,4 +1,4 @@
-package fr.Skydust.JdrBot.utils;
+package fr.Skydust.JdrBot.enums;
public enum MessageType {
ERROR,
diff --git a/src/main/java/fr/Skydust/JdrBot/jukebox/JukeboxSystem.java b/src/main/java/fr/Skydust/JdrBot/jukebox/JukeboxSystem.java
index 3a7988a..3eeba1a 100644
--- a/src/main/java/fr/Skydust/JdrBot/jukebox/JukeboxSystem.java
+++ b/src/main/java/fr/Skydust/JdrBot/jukebox/JukeboxSystem.java
@@ -3,9 +3,10 @@ package fr.Skydust.JdrBot.jukebox;
import fr.Skydust.JdrBot.cmds.playmusic.PlayMusic;
import fr.Skydust.JdrBot.menu.Menu;
import fr.Skydust.JdrBot.menu.MenuSystem;
-import fr.Skydust.JdrBot.utils.Utils;
+import fr.Skydust.JdrBot.utils.UnicodeEmotes;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
+import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.io.File;
import java.util.*;
@@ -42,7 +43,7 @@ public class JukeboxSystem {
// If it isn't the root folder, place the return button
if(isntInRootFolder()) {
- items.add(Utils.ReturnUnicode + " Retour");
+ items.add(UnicodeEmotes.ReturnUnicode + " Retour");
}
if(files != null) {
// Sort files by alphabetical order with directories first
@@ -59,9 +60,9 @@ public class JukeboxSystem {
StringBuilder sb = new StringBuilder();
if (file.isDirectory())
- sb.append(Utils.FolderUnicode);
+ sb.append(UnicodeEmotes.FolderUnicode);
else
- sb.append(Utils.SongUnicode);
+ sb.append(UnicodeEmotes.SongUnicode);
sb.append(" ");
sb.append(file.getName().replaceAll(".mp3", ""));
@@ -80,7 +81,7 @@ public class JukeboxSystem {
String str = items[itemId];
// Loop back to open a subfolder
- if (str.contains(Utils.FolderUnicode)) {
+ if (str.contains(UnicodeEmotes.FolderUnicode)) {
openFolder(currentFolder + "/" + getFileNameFromItem(str));
return;
}
@@ -95,25 +96,29 @@ public class JukeboxSystem {
}
// If not already playing
- if (str.contains(Utils.SongUnicode)) {
+ if (str.contains(UnicodeEmotes.SongUnicode)) {
if(!songPlayedPath.equals("")) {
String folder = songPlayedPath.substring(0, songPlayedPath.lastIndexOf("/"));
int previousSongItemID = Integer.parseInt(songPlayedPath.substring(songPlayedPath.lastIndexOf("/")+1));
Menu previousMenu = linkedPath.get(folder);
- previousMenu.items[previousSongItemID] = previousMenu.items[previousSongItemID].replace(Utils.PlayUnicode, Utils.SongUnicode);
+ previousMenu.items[previousSongItemID] =
+ previousMenu.items[previousSongItemID].replace(
+ UnicodeEmotes.PlayUnicode,
+ UnicodeEmotes.SongUnicode
+ );
}
- items[itemId] = items[itemId].replace(Utils.SongUnicode, Utils.PlayUnicode);
+ items[itemId] = items[itemId].replace(UnicodeEmotes.SongUnicode, UnicodeEmotes.PlayUnicode);
String songPath = currentFolder + "/" + getFileNameFromItem(str) + ".mp3";
- PlayMusic.loadAndPlay(msg.getGuild(), msg.getTextChannel(), songPath, true, true);
+ PlayMusic.loadAndPlay(msg.getGuild(), (TextChannel) msg.getChannel(), songPath, true, true);
// Format: Songs/Folder/SubFolder/2
songPlayedPath = currentFolder + "/" + itemId;
} else {
//If already playing, stop the song
- items[itemId] = items[itemId].replace(Utils.PlayUnicode, Utils.SongUnicode);
+ items[itemId] = items[itemId].replace(UnicodeEmotes.PlayUnicode, UnicodeEmotes.SongUnicode);
PlayMusic.getGuildAudioPlayer(member.getGuild()).scheduler.stop();
}
// Reload the current menu
@@ -125,7 +130,7 @@ public class JukeboxSystem {
// Reget the message to update it
Menu finalMenu = menu;
- jukeboxMessage.getTextChannel().retrieveMessageById(jukeboxMessage.getIdLong()).queue(msg -> {
+ jukeboxMessage.getChannel().retrieveMessageById(jukeboxMessage.getIdLong()).queue(msg -> {
MenuSystem.changeMenu(msg, finalMenu);
});
}
diff --git a/src/main/java/fr/Skydust/JdrBot/menu/Menu.java b/src/main/java/fr/Skydust/JdrBot/menu/Menu.java
index 38a8649..8d6166f 100644
--- a/src/main/java/fr/Skydust/JdrBot/menu/Menu.java
+++ b/src/main/java/fr/Skydust/JdrBot/menu/Menu.java
@@ -1,10 +1,11 @@
package fr.Skydust.JdrBot.menu;
-import fr.Skydust.JdrBot.utils.Utils;
+import fr.Skydust.JdrBot.utils.UnicodeEmotes;
import net.dv8tion.jda.api.EmbedBuilder;
-import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
+import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
+import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import java.awt.*;
@@ -25,17 +26,17 @@ public class Menu {
public void onButtonClicked(Member member, Message msg, int itemId) { }
/** Builds the menu message */
- public Message makeMessage() {
+ public MessageCreateData makeMessage() {
StringBuilder str = new StringBuilder();
int i = 0;
for (String s : items) {
- str.append(Utils.CharsUnicodeArray[i] +" "+ s +"\n");
+ str.append(UnicodeEmotes.CharsUnicodeArray[i] +" "+ s +"\n");
i++;
}
- return new MessageBuilder()
- .append(name)
+ return new MessageCreateBuilder()
+ .addContent(name)
.setEmbeds(
new EmbedBuilder()
.setThumbnail(thumbnail)
diff --git a/src/main/java/fr/Skydust/JdrBot/menu/MenuSystem.java b/src/main/java/fr/Skydust/JdrBot/menu/MenuSystem.java
index e841f3a..f6e2e6b 100644
--- a/src/main/java/fr/Skydust/JdrBot/menu/MenuSystem.java
+++ b/src/main/java/fr/Skydust/JdrBot/menu/MenuSystem.java
@@ -1,9 +1,11 @@
package fr.Skydust.JdrBot.menu;
-import fr.Skydust.JdrBot.utils.Utils;
+import fr.Skydust.JdrBot.utils.UnicodeEmotes;
import net.dv8tion.jda.api.entities.Message;
-import net.dv8tion.jda.api.entities.TextChannel;
+import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
+import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
+import net.dv8tion.jda.api.utils.messages.MessageEditData;
import java.util.HashMap;
@@ -13,7 +15,7 @@ public class MenuSystem {
/** Action Listening */
public static void onMessageReactionAdd(MessageReactionAddEvent e) {
if (e.getChannel() instanceof TextChannel) {
- if(e.getUser().isBot())
+ if(e.getUser() != null && e.getUser().isBot())
return;
e.getChannel().retrieveMessageById(e.getMessageId()).queue(msg -> {
@@ -26,14 +28,16 @@ public class MenuSystem {
// Check if the emote is valid and get id
int emoteId = 0;
- for(String s : Utils.CharsUnicodeArray){
- if(s.equals(e.getReaction().getReactionEmote().getEmoji().replace("(null)","").replace("RE:",""))) {
+ for(String emote : UnicodeEmotes.CharsUnicodeArray){
+ String cleanedUpEmote = UnicodeEmotes.cleanUpDiscordEmote(
+ e.getReaction().getEmoji().getAsReactionCode());
+ if(emote.equals(cleanedUpEmote)) {
break;
}
emoteId++;
}
// Do not proceed if not valid
- if(emoteId > Utils.CharsUnicodeArray.length) {
+ if(emoteId > UnicodeEmotes.CharsUnicodeArray.length) {
return;
}
@@ -50,7 +54,7 @@ public class MenuSystem {
System.out.println("Error: No menu on this message");
return;
}
- currentMessage.editMessage(newMenu.makeMessage()).queue();
+ currentMessage.editMessage(MessageEditData.fromCreateData(newMenu.makeMessage())).queue();
updateReactions(currentMessage, newMenu);
}
@@ -61,7 +65,7 @@ public class MenuSystem {
}
// Adds missing reactions
for (int i = msg.getReactions().size(); i < menu.items.length; i++) {
- msg.addReaction(Utils.CharsUnicodeArray[i]).queue();
+ msg.addReaction(Emoji.fromUnicode(UnicodeEmotes.CharsUnicodeArray[i])).queue();
}
}
@@ -73,7 +77,7 @@ public class MenuSystem {
return;
}
- currentMessage.editMessage(newMenu.makeMessage()).queue();
+ currentMessage.editMessage(MessageEditData.fromCreateData(newMenu.makeMessage())).queue();
updateReactions(currentMessage, newMenu);
menuHash.put(currentMessage, newMenu);
}
diff --git a/src/main/java/fr/Skydust/JdrBot/stock/Command.java b/src/main/java/fr/Skydust/JdrBot/stock/Command.java
deleted file mode 100755
index 340963b..0000000
--- a/src/main/java/fr/Skydust/JdrBot/stock/Command.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package fr.Skydust.JdrBot.stock;
-
-import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
-
-public abstract class Command {
- public String cmdName;
- public String cmdDesc;
- public String cmdUsage = "";
- public boolean hidden = false;
-
- public abstract void call(MessageReceivedEvent e);
-
- public void Hide() {
- hidden = true;
- }
-
- public void SetName(String name) {
- this.cmdName = name;
- }
-
- public void SetDesc(String desc) {
- this.cmdDesc = desc;
- }
-
- public void SetUsage(String usage) {
- this.cmdUsage = usage;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/fr/Skydust/JdrBot/stock/RecordState.java b/src/main/java/fr/Skydust/JdrBot/stock/RecordState.java
index b13d507..46f2b7c 100755
--- a/src/main/java/fr/Skydust/JdrBot/stock/RecordState.java
+++ b/src/main/java/fr/Skydust/JdrBot/stock/RecordState.java
@@ -5,16 +5,15 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import fr.Skydust.JdrBot.utils.MessageType;
+import fr.Skydust.JdrBot.enums.MessageType;
import fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.entities.Guild;
-import net.dv8tion.jda.api.entities.MessageChannel;
-import net.dv8tion.jda.api.entities.TextChannel;
+import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
+import net.dv8tion.jda.api.utils.FileUpload;
import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.model.enums.CompressionLevel;
import net.lingala.zip4j.model.enums.CompressionMethod;
-import org.apache.commons.codec.EncoderException;
import ws.schild.jave.Encoder;
import ws.schild.jave.MultimediaObject;
import ws.schild.jave.encode.AudioAttributes;
@@ -26,7 +25,6 @@ import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
public class RecordState {
- private static final int RECORDER_SAMPLERATE = 44100;
public boolean isRecording;
private ByteArrayOutputStream recordData;
public boolean isProcessing;
@@ -61,7 +59,7 @@ public class RecordState {
}
}
- public void endRecord(Guild g, MessageChannel tc) {
+ public void endRecord(Guild g, TextChannel tc) {
isRecording = false;
isProcessing = true;
@@ -86,7 +84,7 @@ public class RecordState {
}).start();
}
- public void processRecording(MessageChannel tc) throws IOException, IllegalArgumentException, EncoderException, ws.schild.jave.EncoderException {
+ public void processRecording(TextChannel tc) throws IOException, IllegalArgumentException, ws.schild.jave.EncoderException {
//BigEndian, 16 bit signed, 44100hz
String OriginalName = new Date().toString().replaceAll(":", "-");
@@ -130,12 +128,14 @@ public class RecordState {
tc.sendMessage("Envoi du fichier audio(Via plusieurs fichiers zip)...").queue();
for(Object file : zipFile.getSplitZipFiles()) {
File currentFile = new File(file+"");
- tc.sendFile(currentFile, "").queue(msg -> currentFile.delete());
+ FileUpload fileUpload = FileUpload.fromData(currentFile, currentFile.getName());
+ tc.sendFiles(fileUpload).queue(msg -> currentFile.delete());
}
} else {
tc.sendMessage("Envoi du fichier audio(Via un fichier zip)...").queue();
File currentFile = new File(zipFile.getSplitZipFiles().get(0)+"");
- tc.sendFile(currentFile, currentFile.getName()).queue(msg -> currentFile.delete());
+ FileUpload fileUpload = FileUpload.fromData(currentFile, currentFile.getName());
+ tc.sendFiles(fileUpload).queue(msg -> currentFile.delete());
}
}
diff --git a/src/main/java/fr/Skydust/JdrBot/utils/HeartbeatTask.java b/src/main/java/fr/Skydust/JdrBot/tasks/HeartbeatTask.java
similarity index 97%
rename from src/main/java/fr/Skydust/JdrBot/utils/HeartbeatTask.java
rename to src/main/java/fr/Skydust/JdrBot/tasks/HeartbeatTask.java
index 0932029..63ec98f 100644
--- a/src/main/java/fr/Skydust/JdrBot/utils/HeartbeatTask.java
+++ b/src/main/java/fr/Skydust/JdrBot/tasks/HeartbeatTask.java
@@ -1,4 +1,4 @@
-package fr.Skydust.JdrBot.utils;
+package fr.Skydust.JdrBot.tasks;
import fr.Skydust.JdrBot.JdrBot;
import net.dv8tion.jda.api.events.GatewayPingEvent;
diff --git a/src/main/java/fr/Skydust/JdrBot/utils/DurationUtils.java b/src/main/java/fr/Skydust/JdrBot/utils/DurationUtils.java
new file mode 100644
index 0000000..e122aca
--- /dev/null
+++ b/src/main/java/fr/Skydust/JdrBot/utils/DurationUtils.java
@@ -0,0 +1,30 @@
+package fr.Skydust.JdrBot.utils;
+
+import java.time.Duration;
+
+public class DurationUtils {
+
+ public static String formatDuration(Duration duration) {
+ long seconds = duration.getSeconds();
+ long absSeconds = Math.abs(seconds);
+ String positive = String.format(
+ "%d:%02d:%02d",
+ absSeconds / 3600,
+ (absSeconds % 3600) / 60,
+ absSeconds % 60);
+ return seconds < 0 ? "-" + positive : positive;
+ }
+
+ public static String formatDurationSmooth(Duration duration) {
+ long absSeconds = Math.abs(duration.getSeconds());
+
+ if((absSeconds/3600) == 0) {//Hours
+ if(((absSeconds%3600)/60) == 0)
+ {//Minutes
+ return String.format("%d secondes", absSeconds % 60);
+ }
+ return String.format("%d minutes", (absSeconds % 3600) / 60);
+ }
+ return String.format("%d heures", (absSeconds /3600));
+ }
+}
diff --git a/src/main/java/fr/Skydust/JdrBot/utils/UnicodeEmotes.java b/src/main/java/fr/Skydust/JdrBot/utils/UnicodeEmotes.java
new file mode 100644
index 0000000..72aa821
--- /dev/null
+++ b/src/main/java/fr/Skydust/JdrBot/utils/UnicodeEmotes.java
@@ -0,0 +1,19 @@
+package fr.Skydust.JdrBot.utils;
+
+public class UnicodeEmotes {
+ /*0to10*/
+ public static final String[] CharsUnicodeArray = {"\u0030\u20E3","\u0031\u20E3","\u0032\u20E3","\u0033\u20E3","\u0034\u20E3","\u0035\u20E3","\u0036\u20E3","\u0037\u20E3","\u0038\u20E3","\u0039\u20E3","\uD83D\uDD1F",
+ /*Alphabet*/ "\uD83C\uDDE6","\uD83C\uDDE7","\uD83C\uDDE8","\uD83C\uDDE9","\uD83C\uDDEA","\uD83C\uDDEB","\uD83C\uDDEC","\uD83C\uDDED","\uD83C\uDDEE","\uD83C\uDDEF","\uD83C\uDDF0","\uD83C\uDDF1","\uD83C\uDDF2","\uD83C\uDDF3","\uD83C\uDDF4","\uD83C\uDDF5","\uD83C\uDDF6","\uD83C\uDDF7","\uD83C\uDDF8","\uD83C\uDDF9","\uD83C\uDDFA","\uD83C\uDDFB","\uD83C\uDDFC","\uD83C\uDDFD","\uD83C\uDDFE","\uD83C\uDDFF"};
+
+ public static final String PlayUnicode = "\uD83D\uDD09";
+ public static final String SongUnicode = "\uD83C\uDFB5";
+ public static final String FolderUnicode = "\uD83D\uDCC1";
+ public static final String ReturnUnicode = "\uD83D\uDCC2";
+
+ public static final String ProgressBarForeground = "\uD83D\uDFE9";
+ public static final String ProgressBarBackground = "\u2B1C";
+
+ public static String cleanUpDiscordEmote(String discordReactionString) {
+ return discordReactionString.replace("(null)","").replace("RE:","");
+ }
+}
diff --git a/src/main/java/fr/Skydust/JdrBot/utils/Utils.java b/src/main/java/fr/Skydust/JdrBot/utils/Utils.java
index c3b974e..27ad2b7 100755
--- a/src/main/java/fr/Skydust/JdrBot/utils/Utils.java
+++ b/src/main/java/fr/Skydust/JdrBot/utils/Utils.java
@@ -1,59 +1,35 @@
package fr.Skydust.JdrBot.utils;
import fr.Skydust.JdrBot.JdrBot;
+import fr.Skydust.JdrBot.enums.MessageType;
import net.dv8tion.jda.api.EmbedBuilder;
-import net.dv8tion.jda.api.MessageBuilder;
-import net.dv8tion.jda.api.entities.MessageChannel;
-import net.dv8tion.jda.api.entities.TextChannel;
+import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
+import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import java.awt.*;
-import java.time.Duration;
public class Utils {
- /*0to10*/
- public static final String[] CharsUnicodeArray = {"\u0030\u20E3","\u0031\u20E3","\u0032\u20E3","\u0033\u20E3","\u0034\u20E3","\u0035\u20E3","\u0036\u20E3","\u0037\u20E3","\u0038\u20E3","\u0039\u20E3","\uD83D\uDD1F",
- /*Alphabet*/ "\uD83C\uDDE6","\uD83C\uDDE7","\uD83C\uDDE8","\uD83C\uDDE9","\uD83C\uDDEA","\uD83C\uDDEB","\uD83C\uDDEC","\uD83C\uDDED","\uD83C\uDDEE","\uD83C\uDDEF","\uD83C\uDDF0","\uD83C\uDDF1","\uD83C\uDDF2","\uD83C\uDDF3","\uD83C\uDDF4","\uD83C\uDDF5","\uD83C\uDDF6","\uD83C\uDDF7","\uD83C\uDDF8","\uD83C\uDDF9","\uD83C\uDDFA","\uD83C\uDDFB","\uD83C\uDDFC","\uD83C\uDDFD","\uD83C\uDDFE","\uD83C\uDDFF"};
-
- public static final String PlayUnicode = "\uD83D\uDD09";
- public static final String SongUnicode = "\uD83C\uDFB5";
- public static final String FolderUnicode = "\uD83D\uDCC1";
- public static final String ReturnUnicode = "\uD83D\uDCC2";
-
- public static final String ProgressBarForeground = "\uD83D\uDFE9";
- public static final String ProgressBarBackground = "\u2B1C";
-
- public static boolean IsInt(String info) {
+ /**
+ * Simple function to check if a string is parseable as an integer.
+ * @param str The string to try to parse.
+ * @return True is the string is parseable, false otherwise.
+ */
+ public static boolean IsInt(String str) {
try {
- Integer.parseInt(info);
+ Integer.parseInt(str);
return true;
} catch(Exception e) {
return false;
}
}
- public static String formatDuration(Duration duration) {
- long seconds = duration.getSeconds();
- long absSeconds = Math.abs(seconds);
- String positive = String.format(
- "%d:%02d:%02d",
- absSeconds / 3600,
- (absSeconds % 3600) / 60,
- absSeconds % 60);
- return seconds < 0 ? "-" + positive : positive;
- }
-
- public static String formatDurationSmooth(Duration duration) {
- long absSeconds = Math.abs(duration.getSeconds());
-
- if((absSeconds/3600) == 0) {//Hours
- if(((absSeconds%3600)/60) == 0)
- {//Minutes
- return String.format("%d secondes", absSeconds % 60);
- }
- return String.format("%d minutes", (absSeconds % 3600) / 60);
- }
- return String.format("%d heures", (absSeconds /3600));
- }
+
+ /**
+ * An utility function to send a message into a discord channel.
+ * @param channel The channel to send the message to.
+ * @param msgType The type of message to send.
+ * @param message The message.
+ */
public static void sendMessage(MessageChannel channel, MessageType msgType, String message) {
Color c = Color.GREEN;
String title = "Message";
@@ -63,7 +39,7 @@ public class Utils {
title = "Erreur";
}
- channel.sendMessage(new MessageBuilder().setEmbeds(new EmbedBuilder().
+ channel.sendMessage(new MessageCreateBuilder().setEmbeds(new EmbedBuilder().
setDescription(message)
.setTitle(title, null)
.setFooter("", JdrBot.jda.getSelfUser().getAvatarUrl())
diff --git a/start.sh b/start.sh
new file mode 100644
index 0000000..e70bd1f
--- /dev/null
+++ b/start.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+java -jar JdrBot.jar
\ No newline at end of file