Updated the jdrbot to be at the same standard as potatos #1

Merged
Skydust merged 1 commits from f/update-jdrbot-docker into dev 2023-09-09 21:10:45 +00:00
56 changed files with 631 additions and 737 deletions
Showing only changes of commit b98bb0a634 - Show all commits

View File

@@ -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

2
.gitignore vendored
View File

@@ -1,4 +1,6 @@
# ---> Java # ---> Java
.idea
# Compiled class file # Compiled class file
*.class *.class

3
.idea/.gitignore generated vendored
View File

@@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

6
.idea/compiler.xml generated
View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>

17
.idea/gradle.xml generated
View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

View File

@@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenRepo" />
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://m2.dv8tion.net/releases" />
</remote-repository>
<remote-repository>
<option name="id" value="maven2" />
<option name="name" value="maven2" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
</component>
</project>

View File

@@ -1,65 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="libraries-with-intellij-classes">
<option name="intellijApiContainingLibraries">
<list>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIU" />
<option name="groupId" value="com.jetbrains.intellij.idea" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIU" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIC" />
<option name="groupId" value="com.jetbrains.intellij.idea" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIC" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPY" />
<option name="groupId" value="com.jetbrains.intellij.pycharm" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPY" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPC" />
<option name="groupId" value="com.jetbrains.intellij.pycharm" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPC" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="clion" />
<option name="groupId" value="com.jetbrains.intellij.clion" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="clion" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="riderRD" />
<option name="groupId" value="com.jetbrains.intellij.rider" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="riderRD" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="goland" />
<option name="groupId" value="com.jetbrains.intellij.goland" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="goland" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
</list>
</option>
</component>
</project>

7
.idea/misc.xml generated
View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="JdrBot" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" type="JAVA_MODULE" version="4" />

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ThriftCompiler">
<compilers />
</component>
</project>

124
.idea/uiDesigner.xml generated
View File

@@ -1,124 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

6
.idea/vcs.xml generated
View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

14
Dockerfile Normal file
View File

@@ -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"]

View File

@@ -1,3 +1,7 @@
# JdrBot # JdrBot
Jdr botto Jdr botto
To update gradlew:
- Find every plugins and upgrade them
- Run `gradle wrapper --gradle-version 8.3`

Binary file not shown.

BIN
Songs/One Folder/Violin.mp3 Normal file

Binary file not shown.

BIN
Songs/Two Folder/Violin.mp3 Normal file

Binary file not shown.

Binary file not shown.

BIN
Songs/Violin 2 copie 2.mp3 Normal file

Binary file not shown.

View File

@@ -14,32 +14,29 @@ plugins {
id 'application' id 'application'
// Shadow plugin to make uberJars // Shadow plugin to make uberJars
id 'com.github.johnrengelman.shadow' version '7.1.0' id 'com.github.johnrengelman.shadow' version '8.1.1'
} }
repositories { repositories {
mavenCentral() mavenCentral()
maven {
url 'https://m2.dv8tion.net/releases'
}
maven { maven {
url 'https://jitpack.io' url 'https://jitpack.io'
} }
} }
dependencies { 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 'net.lingala.zip4j:zip4j:2.10.0'
implementation 'club.minnced:opus-java:1.1.1' implementation 'club.minnced:opus-java:1.1.1'
implementation 'ws.schild:jave-all-deps:3.3.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 'org.apache.commons:commons-lang3:3.12.0'
implementation 'com.sedmelluq:lavaplayer:1.3.78' implementation 'dev.arbjerg:lavaplayer:2.0.1'
implementation 'com.github.DV8FromTheWorld:JDA:5.0.0-alpha.12' implementation 'net.dv8tion:JDA:5.0.0-beta.13'
implementation 'org.reflections:reflections:0.10.2'
} }
application { application {

Binary file not shown.

View File

@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

294
gradlew vendored
View File

@@ -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"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with 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 # Attempt to set APP_HOME
# Resolve links: $0 may be a link # Resolve links: $0 may be a link
PRG="$0" app_path=$0
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do # Need this for daisy-chained symlinks.
ls=`ls -ld "$PRG"` while
link=`expr "$ls" : '.*-> \(.*\)$'` APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
if expr "$link" : '/.*' > /dev/null; then [ -h "$app_path" ]
PRG="$link" do
else ls=$( ls -ld "$app_path" )
PRG=`dirname "$PRG"`"/$link" link=${ls#*' -> '}
fi case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle" # This is normally unused
APP_BASE_NAME=`basename "$0"` # 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. # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum" MAX_FD=maximum
warn () { warn () {
echo "$*" echo "$*"
} } >&2
die () { die () {
echo echo
echo "$*" echo "$*"
echo echo
exit 1 exit 1
} } >&2
# OS specific support (must be 'true' or 'false'). # OS specific support (must be 'true' or 'false').
cygwin=false cygwin=false
msys=false msys=false
darwin=false darwin=false
nonstop=false nonstop=false
case "`uname`" in case "$( uname )" in #(
CYGWIN* ) CYGWIN* ) cygwin=true ;; #(
cygwin=true Darwin* ) darwin=true ;; #(
;; MSYS* | MINGW* ) msys=true ;; #(
Darwin* ) NONSTOP* ) nonstop=true ;;
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 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 [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables # IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java" JAVACMD=$JAVA_HOME/jre/sh/java
else else
JAVACMD="$JAVA_HOME/bin/java" JAVACMD=$JAVA_HOME/bin/java
fi fi
if [ ! -x "$JAVACMD" ] ; then if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 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." location of your Java installation."
fi fi
else else
JAVACMD="java" 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 Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." location of your Java installation."
fi
fi fi
# Increase the maximum file descriptors if we can. # Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
MAX_FD_LIMIT=`ulimit -H -n` case $MAX_FD in #(
if [ $? -eq 0 ] ; then max*)
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
MAX_FD="$MAX_FD_LIMIT" # shellcheck disable=SC3045
fi MAX_FD=$( ulimit -H -n ) ||
ulimit -n $MAX_FD warn "Could not query maximum file descriptor limit"
if [ $? -ne 0 ] ; then esac
warn "Could not set maximum file descriptor limit: $MAX_FD" case $MAX_FD in #(
fi '' | soft) :;; #(
else *)
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
fi # shellcheck disable=SC3045
fi ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
# 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" ;;
esac esac
fi fi
# Escape application args # Collect all arguments for the java command, stacking in reverse order:
save () { # * args from the command line
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done # * the main class name
echo " " # * -classpath
} # * -D...appname settings
APP_ARGS=`save "$@"` # * --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 # For Cygwin or MSYS, switch paths to Windows format before running java
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 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" "$@" exec "$JAVACMD" "$@"

15
gradlew.bat vendored
View File

@@ -14,7 +14,7 @@
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@if "%DEBUG%" == "" @echo off @if "%DEBUG%"=="" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@rem Gradle startup script for Windows @rem Gradle startup script for Windows
@@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=. if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute if %ERRORLEVEL% equ 0 goto execute
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 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 :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd if %ERRORLEVEL% equ 0 goto mainEnd
:fail :fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code! rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 set EXIT_CODE=%ERRORLEVEL%
exit /b 1 if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd :mainEnd
if "%OS%"=="Windows_NT" endlocal if "%OS%"=="Windows_NT" endlocal

View File

@@ -1,54 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="92be5a76-72cc-4791-b8e0-146745624e77" name="Default Changelist" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ExternalProjectsData">
<projectState path="$PROJECT_DIR$">
<ProjectState />
</projectState>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../../.." />
</component>
<component name="ProjectId" id="1ptZSIDZd86tmu17YY146ADRTUU" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="settings.editor.selected.configurable" value="Errors" />
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="92be5a76-72cc-4791-b8e0-146745624e77" name="Default Changelist" comment="" />
<created>1616004344851</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1616004344851</updated>
</task>
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
</project>

View File

@@ -1,25 +1,24 @@
package fr.Skydust.JdrBot; package fr.Skydust.JdrBot;
import java.lang.reflect.InvocationTargetException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.Timer; import java.util.Timer;
import javax.security.auth.login.LoginException;
import fr.Skydust.JdrBot.cmds.*; import fr.Skydust.JdrBot.bases.command.Command;
import fr.Skydust.JdrBot.cmds.playmusic.*; import fr.Skydust.JdrBot.bases.command.CommandSpec;
import fr.Skydust.JdrBot.cmds.record.CancelRecord; import fr.Skydust.JdrBot.tasks.HeartbeatTask;
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 net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.cache.CacheFlag; import net.dv8tion.jda.api.utils.cache.CacheFlag;
import org.reflections.Reflections;
public class JdrBot { public class JdrBot {
public static String Version = "3.1"; public static String Version = "4.0";
public static JDA jda; public static JDA jda;
public static LocalDateTime basedate; public static LocalDateTime basedate;
@@ -29,7 +28,7 @@ public class JdrBot {
public static boolean debugMode = false; public static boolean debugMode = false;
public static void main(String args[]) { public static void main(String[] args) {
for (int i=0;i<args.length;i++) { for (int i=0;i<args.length;i++) {
if(args[i].equalsIgnoreCase("--heartbeat")) { if(args[i].equalsIgnoreCase("--heartbeat")) {
if(i == args.length-1) { // Check for an argument after heartbeat if(i == args.length-1) { // Check for an argument after heartbeat
@@ -61,32 +60,38 @@ public class JdrBot {
jda = JDABuilder.createDefault(token) jda = JDABuilder.createDefault(token)
.setActivity(Activity.playing("un jeu de rôle")) .setActivity(Activity.playing("un jeu de rôle"))
.enableIntents(GatewayIntent.MESSAGE_CONTENT)
.enableCache(CacheFlag.VOICE_STATE).build(); .enableCache(CacheFlag.VOICE_STATE).build();
jda.awaitReady(); jda.awaitReady();
commandList = new ArrayList<Command>();
registerCommand(new Aide()); registerCommands();
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());
jda.addEventListener(new JdrBotListener()); jda.addEventListener(new JdrBotListener());
} catch (LoginException e) {
System.out.println("The login token is wrong");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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<Command>();
Reflections reflections = new Reflections("fr.Skydust.JdrBot.cmds");
Set<Class<?>> 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);
}
}
} }
} }

View File

@@ -1,19 +1,17 @@
package fr.Skydust.JdrBot; 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.LastTimeOnline;
import fr.Skydust.JdrBot.cmds.playmusic.StopMusic; import fr.Skydust.JdrBot.cmds.playmusic.StopMusic;
import fr.Skydust.JdrBot.menu.MenuSystem; import fr.Skydust.JdrBot.menu.MenuSystem;
import fr.Skydust.JdrBot.stock.Command; import fr.Skydust.JdrBot.tasks.HeartbeatTask;
import fr.Skydust.JdrBot.utils.HeartbeatTask;
import net.dv8tion.jda.api.events.GatewayPingEvent; import net.dv8tion.jda.api.events.GatewayPingEvent;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateOnlineStatusEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateOnlineStatusEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
public class JdrBotListener extends ListenerAdapter { public class JdrBotListener extends ListenerAdapter {
@Override @Override
@@ -38,24 +36,21 @@ public class JdrBotListener extends ListenerAdapter {
/* LastTimeOnline listener */ /* LastTimeOnline listener */
@Override @Override
public void onUserUpdateOnlineStatus(UserUpdateOnlineStatusEvent e) { public void onUserUpdateOnlineStatus(@NotNull UserUpdateOnlineStatusEvent e) {
LastTimeOnline.onUserUpdateOnlineStatus(e); LastTimeOnline.onUserUpdateOnlineStatus(e);
} }
/* Empty voice channel listener */ /* Empty voice channel listener */
@Override @Override
public void onGuildVoiceMove(GuildVoiceMoveEvent e) { public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent e) {
StopMusic.onGuildVoiceMove(e); StopMusic.onGuildVoiceUpdate(e);
}
@Override
public void onGuildVoiceLeave(GuildVoiceLeaveEvent e) {
StopMusic.onGuildVoiceLeave(e);
} }
/* Menu system listener */ /* Menu system listener */
@Override @Override
public void onMessageReactionAdd(MessageReactionAddEvent e) { MenuSystem.onMessageReactionAdd(e); } public void onMessageReactionAdd(@NotNull MessageReactionAddEvent e) { MenuSystem.onMessageReactionAdd(e); }
/* Heartbeat command listener */ /* Heartbeat command listener */
@Override @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) { public boolean isACommand(String message, String cmd) {
return message.matches("^("+ JdrBot.startcmdchar +")("+ cmd +")( .*|)$"); return message.matches("^("+ JdrBot.startcmdchar +")("+ cmd +")( .*|)$");

View File

@@ -1,12 +1,10 @@
package fr.Skydust.JdrBot.audio.handler; 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 fr.Skydust.JdrBot.stock.RecordState;
import net.dv8tion.jda.api.audio.AudioReceiveHandler; import net.dv8tion.jda.api.audio.AudioReceiveHandler;
import net.dv8tion.jda.api.audio.CombinedAudio; import net.dv8tion.jda.api.audio.CombinedAudio;
import net.dv8tion.jda.api.audio.UserAudio; import net.dv8tion.jda.api.audio.UserAudio;
import org.jetbrains.annotations.NotNull;
public class JdrBotARH implements AudioReceiveHandler { public class JdrBotARH implements AudioReceiveHandler {
private final RecordState recordState; private final RecordState recordState;
@@ -20,21 +18,10 @@ public class JdrBotARH implements AudioReceiveHandler {
return true; return true;
} }
@Override @Override
public boolean canReceiveUser() { public void handleCombinedAudio(@NotNull CombinedAudio combinedAudio) {
return false;
}
@Override
public void handleCombinedAudio(CombinedAudio arg0) {
if(recordState.isRecording) { if(recordState.isRecording) {
recordState.addBytes(arg0.getAudioData(1.0)); recordState.addBytes(combinedAudio.getAudioData(1.0));
} }
} }
@Override
public void handleUserAudio(UserAudio arg0) {
}
} }

View File

@@ -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);
}

View File

@@ -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 "";
}

View File

@@ -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 {
}

View File

@@ -0,0 +1,7 @@
package fr.Skydust.JdrBot.bases.command;
public class WrongCommandSpecException extends RuntimeException {
public WrongCommandSpecException(String errorMessage) {
super(errorMessage);
}
}

View File

@@ -1,15 +1,17 @@
package fr.Skydust.JdrBot.cmds; 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; 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 class AddSong extends Command {
public AddSong() {
SetName("addsong");
SetUsage("[Chemin] [URL]");
SetDesc("(Admin) Ajoute une musique au jukebox");
}
@Override @Override
public void call(MessageReceivedEvent e) { public void call(MessageReceivedEvent e) {

View File

@@ -1,21 +1,21 @@
package fr.Skydust.JdrBot.cmds; package fr.Skydust.JdrBot.cmds;
import fr.Skydust.JdrBot.JdrBot; 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.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import java.awt.*; import java.awt.*;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@CommandSpec(
name = "aide",
description = "Pour avoir de l'aide !"
)
public class Aide extends Command { public class Aide extends Command {
public Aide() {
SetName("aide");
SetDesc("Pour avoir de l'aide !");
}
@Override @Override
public void call(MessageReceivedEvent e) { public void call(MessageReceivedEvent e) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@@ -24,11 +24,14 @@ public class Aide extends Command {
{ {
Command cmd = JdrBot.commandList.get(i); Command cmd = JdrBot.commandList.get(i);
if(!cmd.hidden) { 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()) .setDescription(sb.toString())
.setTitle("Aide", null) .setTitle("Aide", null)
.setFooter("Fait le " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy 'a' HH:mm:ss")), e.getJDA().getSelfUser().getAvatarUrl()) .setFooter("Fait le " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy 'a' HH:mm:ss")), e.getJDA().getSelfUser().getAvatarUrl())

View File

@@ -2,15 +2,18 @@ package fr.Skydust.JdrBot.cmds;
import java.util.Arrays; 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; 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 class Emote extends Command {
public Emote() {
SetName("emote");
SetDesc("Donne les informations techniques d'une emote");
}
@Override @Override
public void call(MessageReceivedEvent e) { public void call(MessageReceivedEvent e) {
String[] args = Arrays.copyOfRange(e.getMessage().getContentRaw().split(" "), 1, e.getMessage().getContentRaw().split(" ").length); 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+>")) if(str.matches("<:.*:\\d+>"))
{ {
String id = str.replaceAll("<:.*:(\\d+)>", "$1"); 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) if(emote==null)
{ {
e.getChannel().sendMessage("Unknown emote:\n" e.getChannel().sendMessage("Unknown emote:\n"

View File

@@ -10,23 +10,24 @@ import java.util.Arrays;
import com.sedmelluq.discord.lavaplayer.tools.PlayerLibrary; import com.sedmelluq.discord.lavaplayer.tools.PlayerLibrary;
import fr.Skydust.JdrBot.JdrBot; 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 fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDAInfo; 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.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import oshi.SystemInfo; import oshi.SystemInfo;
import oshi.hardware.HardwareAbstractionLayer; import oshi.hardware.HardwareAbstractionLayer;
@CommandSpec(
name = "status",
description = "Donne le status du bot et du serveur"
)
public class Etat extends Command { public class Etat extends Command {
private static final DecimalFormat df = new DecimalFormat("###.##"); private static final DecimalFormat df = new DecimalFormat("###.##");
public Etat() {
SetName("status");
SetDesc("Donne le status du bot et du serveur");
}
@Override @Override
public void call(MessageReceivedEvent e) { public void call(MessageReceivedEvent e) {
SystemInfo si = new SystemInfo(); SystemInfo si = new SystemInfo();
@@ -37,7 +38,7 @@ public class Etat extends Command {
LocalDateTime currentDate = LocalDateTime.now(); LocalDateTime currentDate = LocalDateTime.now();
Duration difference = Duration.between(JdrBot.basedate, currentDate); 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()) .setAuthor("Etat de "+ e.getGuild().getSelfMember().getEffectiveName())
.addBlankField(false) .addBlankField(false)
.addField("CPU","-----", false) .addField("CPU","-----", false)
@@ -53,7 +54,7 @@ public class Etat extends Command {
.addBlankField(false) .addBlankField(false)
.addField("Servers",e.getJDA().getGuilds().size()+"",true) .addField("Servers",e.getJDA().getGuilds().size()+"",true)
.addField("Versions", "JdrBot: "+ JdrBot.Version +" - JDA: "+ JDAInfo.VERSION +" - Lavaplayer: "+ PlayerLibrary.VERSION, 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()) .setFooter("*Fait le "+ currentDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy à HH:mm:ss")) +"*", e.getJDA().getSelfUser().getAvatarUrl())
.setColor(Color.BLUE) .setColor(Color.BLUE)
.build()).build()).queue(); .build()).build()).queue();

View File

@@ -4,25 +4,25 @@ import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap; import java.util.HashMap;
import fr.Skydust.JdrBot.stock.Command; import fr.Skydust.JdrBot.bases.command.Command;
import fr.Skydust.JdrBot.utils.Utils; import fr.Skydust.JdrBot.bases.command.CommandSpec;
import fr.Skydust.JdrBot.utils.DurationUtils;
import net.dv8tion.jda.api.OnlineStatus; import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateOnlineStatusEvent; 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 { public class LastTimeOnline extends Command {
static HashMap<Long, LocalDateTime> AllUsers = new HashMap<>(); static HashMap<Long, LocalDateTime> AllUsers = new HashMap<>();
public LastTimeOnline() {
SetName("lasttimeonline|lto");
SetDesc("Dit depuis combien de temps un utilisateur est en ligne/hors-ligne");
SetUsage("[Mention]");
}
@Override @Override
public void call(MessageReceivedEvent e) { 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(); e.getChannel().sendMessage("Vous n'avez pas mentionne d'utilisateur !").queue();
return; return;
} }
@@ -41,7 +41,7 @@ public class LastTimeOnline extends Command {
} else { } else {
sb.append(u.getAsMention()+" est en ligne depuis "); 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(); e.getChannel().sendMessage(sb.toString()).queue();
} }

View File

@@ -2,19 +2,19 @@ package fr.Skydust.JdrBot.cmds;
import java.util.*; 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 fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; 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 { public class Roll extends Command {
static Random r = new Random(); 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) { public void call(MessageReceivedEvent e) {
if (e.getMessage().getContentRaw().split(" ").length != 1) if (e.getMessage().getContentRaw().split(" ").length != 1)
{ {

View File

@@ -1,21 +1,23 @@
package fr.Skydust.JdrBot.cmds.playmusic; package fr.Skydust.JdrBot.cmds.playmusic;
import fr.Skydust.JdrBot.stock.Command; import fr.Skydust.JdrBot.bases.command.Command;
import fr.Skydust.JdrBot.utils.MessageType; 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 fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.Arrays; 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 class FLoad extends Command {
public FLoad() {
SetName("fload");
SetDesc("/!\\ Commande test /!\\ Permet de charger une musique de force");
SetUsage("[URL/Recherche]");
Hide();
}
@Override @Override
public void call(MessageReceivedEvent e) { public void call(MessageReceivedEvent e) {
if(e.getMember().getVoiceState().getChannel() != null) { if(e.getMember().getVoiceState().getChannel() != null) {
@@ -24,7 +26,7 @@ public class FLoad extends Command {
e.getGuild().getAudioManager().openAudioConnection(e.getMember().getVoiceState().getChannel()); e.getGuild().getAudioManager().openAudioConnection(e.getMember().getVoiceState().getChannel());
//ytsearch:query //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); Utils.sendMessage(e.getChannel(), MessageType.NORMAL, "Forçage du lancement de "+args);
} else { } else {

View File

@@ -1,21 +1,23 @@
package fr.Skydust.JdrBot.cmds.playmusic; package fr.Skydust.JdrBot.cmds.playmusic;
import fr.Skydust.JdrBot.stock.Command; import fr.Skydust.JdrBot.bases.command.Command;
import fr.Skydust.JdrBot.utils.MessageType; 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 fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.Arrays; 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 class FLoadLoop extends Command {
public FLoadLoop() {
SetName("floadloop");
SetDesc("/!\\ Commande test /!\\ Permet de charger une musique de force");
SetUsage("[URL/Recherche]");
Hide();
}
@Override @Override
public void call(MessageReceivedEvent e) { public void call(MessageReceivedEvent e) {
if(e.getMember().getVoiceState().getChannel() != null) { if(e.getMember().getVoiceState().getChannel() != null) {
@@ -26,7 +28,7 @@ public class FLoadLoop extends Command {
if(!args.matches(".*(https?)://.*")) { if(!args.matches(".*(https?)://.*")) {
args = "ytsearch:"+args; 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 { } else {
Utils.sendMessage(e.getChannel(), MessageType.ERROR, "Vous n'êtes dans un salon vocal"); Utils.sendMessage(e.getChannel(), MessageType.ERROR, "Vous n'êtes dans un salon vocal");
} }

View File

@@ -3,11 +3,12 @@ package fr.Skydust.JdrBot.cmds.playmusic;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; 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.jukebox.JukeboxSystem;
import fr.Skydust.JdrBot.stock.Command;
import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild; 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 net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
@@ -20,6 +21,10 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import fr.Skydust.JdrBot.audio.GuildMusicManager; import fr.Skydust.JdrBot.audio.GuildMusicManager;
@CommandSpec(
name = "playmusic|pm",
description = "(Admin) Demarre le jukebox"
)
public class PlayMusic extends Command { public class PlayMusic extends Command {
private static final AudioPlayerManager playerManager = new DefaultAudioPlayerManager(); private static final AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
static Map<Long, GuildMusicManager> musicManagers; static Map<Long, GuildMusicManager> musicManagers;
@@ -27,12 +32,11 @@ public class PlayMusic extends Command {
public static HashMap<Long, JukeboxSystem> jukeboxSystems = new HashMap<>(); public static HashMap<Long, JukeboxSystem> jukeboxSystems = new HashMap<>();
public PlayMusic() { public PlayMusic() {
super();
musicManagers = new HashMap<>(); musicManagers = new HashMap<>();
AudioSourceManagers.registerRemoteSources(playerManager); AudioSourceManagers.registerRemoteSources(playerManager);
AudioSourceManagers.registerLocalSource(playerManager); AudioSourceManagers.registerLocalSource(playerManager);
SetName("playmusic|pm");
SetDesc("(Admin) Demarre le jukebox");
} }
@Override @Override
@@ -64,7 +68,7 @@ public class PlayMusic extends Command {
return jukeboxSystems.get(guild.getIdLong()); 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); System.out.println(trackUrl);
GuildMusicManager musicManager = getGuildAudioPlayer(guild); GuildMusicManager musicManager = getGuildAudioPlayer(guild);

View File

@@ -1,20 +1,19 @@
package fr.Skydust.JdrBot.cmds.playmusic; 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.cmds.record.Record;
import fr.Skydust.JdrBot.jukebox.JukeboxSystem; import fr.Skydust.JdrBot.jukebox.JukeboxSystem;
import fr.Skydust.JdrBot.stock.Command;
import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; 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 class StopMusic extends Command {
public StopMusic() {
SetName("stopmusic|sm");
SetDesc("(Admin) Arrete le jukebox et supprime son message");
}
@Override @Override
public void call(MessageReceivedEvent e) { public void call(MessageReceivedEvent e) {
if(!e.getGuild().getAudioManager().isConnected() || !e.getMember().hasPermission(Permission.ADMINISTRATOR)) { if(!e.getGuild().getAudioManager().isConnected() || !e.getMember().hasPermission(Permission.ADMINISTRATOR)) {
@@ -24,15 +23,12 @@ public class StopMusic extends Command {
stopMusic(e.getGuild()); 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) { public static void onGuildVoiceUpdate(GuildVoiceUpdateEvent e) {
if(e.getGuild().getAudioManager().isConnected() && e.getChannelLeft().getIdLong() == e.getGuild().getAudioManager().getConnectedChannel().getIdLong() && e.getChannelLeft().getMembers().size() == 1) { if(e.getChannelLeft() != null) {
stopMusic(e.getGuild()); if (e.getGuild().getAudioManager().isConnected() && e.getChannelLeft().getIdLong() == e.getGuild().getAudioManager().getConnectedChannel().getIdLong() && e.getChannelLeft().getMembers().size() == 1) {
stopMusic(e.getGuild());
}
} }
} }

View File

@@ -1,18 +1,18 @@
package fr.Skydust.JdrBot.cmds.record; 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.cmds.playmusic.PlayMusic;
import fr.Skydust.JdrBot.stock.Command;
import fr.Skydust.JdrBot.stock.RecordState; 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 fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@CommandSpec(
name = "crecord|cr",
description = "Annule l'enregistrement"
)
public class CancelRecord extends Command { public class CancelRecord extends Command {
public CancelRecord() {
SetName("crecord|cr");
SetDesc("Annule l'enregistrement");
}
@Override @Override
public void call(MessageReceivedEvent e) { public void call(MessageReceivedEvent e) {
RecordState rs = Record.getGuildRecordState(e.getGuild()); RecordState rs = Record.getGuildRecordState(e.getGuild());

View File

@@ -4,22 +4,22 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import fr.Skydust.JdrBot.audio.handler.JdrBotARH; 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.RecordState;
import fr.Skydust.JdrBot.stock.Command; import fr.Skydust.JdrBot.enums.MessageType;
import fr.Skydust.JdrBot.utils.MessageType;
import fr.Skydust.JdrBot.utils.Utils; import fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@CommandSpec(
name = "record",
description = "(Admin) Enregistre le chat vocal"
)
public class Record extends Command { public class Record extends Command {
public static HashMap<Long, RecordState> recordStates = new HashMap<>(); public static HashMap<Long, RecordState> recordStates = new HashMap<>();
public Record() {
SetName("record");
SetDesc("(Admin) Enregistre le chat vocal");
}
@Override @Override
public void call(MessageReceivedEvent e) public void call(MessageReceivedEvent e)
{ {

View File

@@ -1,18 +1,19 @@
package fr.Skydust.JdrBot.cmds.record; 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.cmds.playmusic.PlayMusic;
import fr.Skydust.JdrBot.stock.Command;
import fr.Skydust.JdrBot.stock.RecordState; 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 fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@CommandSpec(
name = "stoprecord|sr",
description = "Arrete et archive l'enregistrement"
)
public class StopRecord extends Command { public class StopRecord extends Command {
public StopRecord() {
SetName("stoprecord|sr");
SetDesc("Arrete l'enregistrement");
}
@Override @Override
public void call(MessageReceivedEvent e) { public void call(MessageReceivedEvent e) {
RecordState rs = Record.getGuildRecordState(e.getGuild()); RecordState rs = Record.getGuildRecordState(e.getGuild());
@@ -20,7 +21,7 @@ public class StopRecord extends Command {
if(PlayMusic.getGuildsJukebox(e.getGuild()) == null) { if(PlayMusic.getGuildsJukebox(e.getGuild()) == null) {
e.getGuild().getAudioManager().closeAudioConnection(); e.getGuild().getAudioManager().closeAudioConnection();
} }
rs.endRecord(e.getGuild(), e.getChannel()); rs.endRecord(e.getGuild(), (TextChannel) e.getChannel());
} else { } else {
Utils.sendMessage(e.getChannel(), MessageType.ERROR, "Il n'y a aucun enregistrement en cours"); Utils.sendMessage(e.getChannel(), MessageType.ERROR, "Il n'y a aucun enregistrement en cours");
} }

View File

@@ -1,4 +1,4 @@
package fr.Skydust.JdrBot.utils; package fr.Skydust.JdrBot.enums;
public enum MessageType { public enum MessageType {
ERROR, ERROR,

View File

@@ -3,9 +3,10 @@ package fr.Skydust.JdrBot.jukebox;
import fr.Skydust.JdrBot.cmds.playmusic.PlayMusic; import fr.Skydust.JdrBot.cmds.playmusic.PlayMusic;
import fr.Skydust.JdrBot.menu.Menu; import fr.Skydust.JdrBot.menu.Menu;
import fr.Skydust.JdrBot.menu.MenuSystem; 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.Member;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
@@ -42,7 +43,7 @@ public class JukeboxSystem {
// If it isn't the root folder, place the return button // If it isn't the root folder, place the return button
if(isntInRootFolder()) { if(isntInRootFolder()) {
items.add(Utils.ReturnUnicode + " Retour"); items.add(UnicodeEmotes.ReturnUnicode + " Retour");
} }
if(files != null) { if(files != null) {
// Sort files by alphabetical order with directories first // Sort files by alphabetical order with directories first
@@ -59,9 +60,9 @@ public class JukeboxSystem {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (file.isDirectory()) if (file.isDirectory())
sb.append(Utils.FolderUnicode); sb.append(UnicodeEmotes.FolderUnicode);
else else
sb.append(Utils.SongUnicode); sb.append(UnicodeEmotes.SongUnicode);
sb.append(" "); sb.append(" ");
sb.append(file.getName().replaceAll(".mp3", "")); sb.append(file.getName().replaceAll(".mp3", ""));
@@ -80,7 +81,7 @@ public class JukeboxSystem {
String str = items[itemId]; String str = items[itemId];
// Loop back to open a subfolder // Loop back to open a subfolder
if (str.contains(Utils.FolderUnicode)) { if (str.contains(UnicodeEmotes.FolderUnicode)) {
openFolder(currentFolder + "/" + getFileNameFromItem(str)); openFolder(currentFolder + "/" + getFileNameFromItem(str));
return; return;
} }
@@ -95,25 +96,29 @@ public class JukeboxSystem {
} }
// If not already playing // If not already playing
if (str.contains(Utils.SongUnicode)) { if (str.contains(UnicodeEmotes.SongUnicode)) {
if(!songPlayedPath.equals("")) { if(!songPlayedPath.equals("")) {
String folder = songPlayedPath.substring(0, songPlayedPath.lastIndexOf("/")); String folder = songPlayedPath.substring(0, songPlayedPath.lastIndexOf("/"));
int previousSongItemID = Integer.parseInt(songPlayedPath.substring(songPlayedPath.lastIndexOf("/")+1)); int previousSongItemID = Integer.parseInt(songPlayedPath.substring(songPlayedPath.lastIndexOf("/")+1));
Menu previousMenu = linkedPath.get(folder); 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"; 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 // Format: Songs/Folder/SubFolder/2
songPlayedPath = currentFolder + "/" + itemId; songPlayedPath = currentFolder + "/" + itemId;
} else { } else {
//If already playing, stop the song //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(); PlayMusic.getGuildAudioPlayer(member.getGuild()).scheduler.stop();
} }
// Reload the current menu // Reload the current menu
@@ -125,7 +130,7 @@ public class JukeboxSystem {
// Reget the message to update it // Reget the message to update it
Menu finalMenu = menu; Menu finalMenu = menu;
jukeboxMessage.getTextChannel().retrieveMessageById(jukeboxMessage.getIdLong()).queue(msg -> { jukeboxMessage.getChannel().retrieveMessageById(jukeboxMessage.getIdLong()).queue(msg -> {
MenuSystem.changeMenu(msg, finalMenu); MenuSystem.changeMenu(msg, finalMenu);
}); });
} }

View File

@@ -1,10 +1,11 @@
package fr.Skydust.JdrBot.menu; 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.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message; 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.*; import java.awt.*;
@@ -25,17 +26,17 @@ public class Menu {
public void onButtonClicked(Member member, Message msg, int itemId) { } public void onButtonClicked(Member member, Message msg, int itemId) { }
/** Builds the menu message */ /** Builds the menu message */
public Message makeMessage() { public MessageCreateData makeMessage() {
StringBuilder str = new StringBuilder(); StringBuilder str = new StringBuilder();
int i = 0; int i = 0;
for (String s : items) { for (String s : items) {
str.append(Utils.CharsUnicodeArray[i] +" "+ s +"\n"); str.append(UnicodeEmotes.CharsUnicodeArray[i] +" "+ s +"\n");
i++; i++;
} }
return new MessageBuilder() return new MessageCreateBuilder()
.append(name) .addContent(name)
.setEmbeds( .setEmbeds(
new EmbedBuilder() new EmbedBuilder()
.setThumbnail(thumbnail) .setThumbnail(thumbnail)

View File

@@ -1,9 +1,11 @@
package fr.Skydust.JdrBot.menu; 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.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.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.api.utils.messages.MessageEditData;
import java.util.HashMap; import java.util.HashMap;
@@ -13,7 +15,7 @@ public class MenuSystem {
/** Action Listening */ /** Action Listening */
public static void onMessageReactionAdd(MessageReactionAddEvent e) { public static void onMessageReactionAdd(MessageReactionAddEvent e) {
if (e.getChannel() instanceof TextChannel) { if (e.getChannel() instanceof TextChannel) {
if(e.getUser().isBot()) if(e.getUser() != null && e.getUser().isBot())
return; return;
e.getChannel().retrieveMessageById(e.getMessageId()).queue(msg -> { e.getChannel().retrieveMessageById(e.getMessageId()).queue(msg -> {
@@ -26,14 +28,16 @@ public class MenuSystem {
// Check if the emote is valid and get id // Check if the emote is valid and get id
int emoteId = 0; int emoteId = 0;
for(String s : Utils.CharsUnicodeArray){ for(String emote : UnicodeEmotes.CharsUnicodeArray){
if(s.equals(e.getReaction().getReactionEmote().getEmoji().replace("(null)","").replace("RE:",""))) { String cleanedUpEmote = UnicodeEmotes.cleanUpDiscordEmote(
e.getReaction().getEmoji().getAsReactionCode());
if(emote.equals(cleanedUpEmote)) {
break; break;
} }
emoteId++; emoteId++;
} }
// Do not proceed if not valid // Do not proceed if not valid
if(emoteId > Utils.CharsUnicodeArray.length) { if(emoteId > UnicodeEmotes.CharsUnicodeArray.length) {
return; return;
} }
@@ -50,7 +54,7 @@ public class MenuSystem {
System.out.println("Error: No menu on this message"); System.out.println("Error: No menu on this message");
return; return;
} }
currentMessage.editMessage(newMenu.makeMessage()).queue(); currentMessage.editMessage(MessageEditData.fromCreateData(newMenu.makeMessage())).queue();
updateReactions(currentMessage, newMenu); updateReactions(currentMessage, newMenu);
} }
@@ -61,7 +65,7 @@ public class MenuSystem {
} }
// Adds missing reactions // Adds missing reactions
for (int i = msg.getReactions().size(); i < menu.items.length; i++) { 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; return;
} }
currentMessage.editMessage(newMenu.makeMessage()).queue(); currentMessage.editMessage(MessageEditData.fromCreateData(newMenu.makeMessage())).queue();
updateReactions(currentMessage, newMenu); updateReactions(currentMessage, newMenu);
menuHash.put(currentMessage, newMenu); menuHash.put(currentMessage, newMenu);
} }

View File

@@ -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;
}
}

View File

@@ -5,16 +5,15 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import fr.Skydust.JdrBot.utils.MessageType; import fr.Skydust.JdrBot.enums.MessageType;
import fr.Skydust.JdrBot.utils.Utils; import fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.entities.Guild; 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.entities.TextChannel; import net.dv8tion.jda.api.utils.FileUpload;
import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.model.ZipParameters; import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.model.enums.CompressionLevel; import net.lingala.zip4j.model.enums.CompressionLevel;
import net.lingala.zip4j.model.enums.CompressionMethod; import net.lingala.zip4j.model.enums.CompressionMethod;
import org.apache.commons.codec.EncoderException;
import ws.schild.jave.Encoder; import ws.schild.jave.Encoder;
import ws.schild.jave.MultimediaObject; import ws.schild.jave.MultimediaObject;
import ws.schild.jave.encode.AudioAttributes; import ws.schild.jave.encode.AudioAttributes;
@@ -26,7 +25,6 @@ import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem; import javax.sound.sampled.AudioSystem;
public class RecordState { public class RecordState {
private static final int RECORDER_SAMPLERATE = 44100;
public boolean isRecording; public boolean isRecording;
private ByteArrayOutputStream recordData; private ByteArrayOutputStream recordData;
public boolean isProcessing; 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; isRecording = false;
isProcessing = true; isProcessing = true;
@@ -86,7 +84,7 @@ public class RecordState {
}).start(); }).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 //BigEndian, 16 bit signed, 44100hz
String OriginalName = new Date().toString().replaceAll(":", "-"); String OriginalName = new Date().toString().replaceAll(":", "-");
@@ -130,12 +128,14 @@ public class RecordState {
tc.sendMessage("Envoi du fichier audio(Via plusieurs fichiers zip)...").queue(); tc.sendMessage("Envoi du fichier audio(Via plusieurs fichiers zip)...").queue();
for(Object file : zipFile.getSplitZipFiles()) { for(Object file : zipFile.getSplitZipFiles()) {
File currentFile = new File(file+""); 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 { } else {
tc.sendMessage("Envoi du fichier audio(Via un fichier zip)...").queue(); tc.sendMessage("Envoi du fichier audio(Via un fichier zip)...").queue();
File currentFile = new File(zipFile.getSplitZipFiles().get(0)+""); 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());
} }
} }

View File

@@ -1,4 +1,4 @@
package fr.Skydust.JdrBot.utils; package fr.Skydust.JdrBot.tasks;
import fr.Skydust.JdrBot.JdrBot; import fr.Skydust.JdrBot.JdrBot;
import net.dv8tion.jda.api.events.GatewayPingEvent; import net.dv8tion.jda.api.events.GatewayPingEvent;

View File

@@ -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));
}
}

View File

@@ -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:","");
}
}

View File

@@ -1,59 +1,35 @@
package fr.Skydust.JdrBot.utils; package fr.Skydust.JdrBot.utils;
import fr.Skydust.JdrBot.JdrBot; import fr.Skydust.JdrBot.JdrBot;
import fr.Skydust.JdrBot.enums.MessageType;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.entities.TextChannel;
import java.awt.*; import java.awt.*;
import java.time.Duration;
public class Utils { 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", * Simple function to check if a string is parseable as an integer.
/*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"}; * @param str The string to try to parse.
* @return True is the string is parseable, false otherwise.
public static final String PlayUnicode = "\uD83D\uDD09"; */
public static final String SongUnicode = "\uD83C\uDFB5"; public static boolean IsInt(String str) {
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) {
try { try {
Integer.parseInt(info); Integer.parseInt(str);
return true; return true;
} catch(Exception e) { } catch(Exception e) {
return false; 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) { public static void sendMessage(MessageChannel channel, MessageType msgType, String message) {
Color c = Color.GREEN; Color c = Color.GREEN;
String title = "Message"; String title = "Message";
@@ -63,7 +39,7 @@ public class Utils {
title = "Erreur"; title = "Erreur";
} }
channel.sendMessage(new MessageBuilder().setEmbeds(new EmbedBuilder(). channel.sendMessage(new MessageCreateBuilder().setEmbeds(new EmbedBuilder().
setDescription(message) setDescription(message)
.setTitle(title, null) .setTitle(title, null)
.setFooter("", JdrBot.jda.getSelfUser().getAvatarUrl()) .setFooter("", JdrBot.jda.getSelfUser().getAvatarUrl())

2
start.sh Normal file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
java -jar JdrBot.jar