Initial commit
This commit is contained in:
commit
4ee192750e
136
.gitignore
vendored
Normal file
136
.gitignore
vendored
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
|
||||||
|
# Created by https://www.gitignore.io/api/java,gradle,intellij+all
|
||||||
|
# Edit at https://www.gitignore.io/?templates=java,gradle,intellij+all
|
||||||
|
|
||||||
|
### Intellij+all ###
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
# JetBrains templates
|
||||||
|
**___jb_tmp___
|
||||||
|
|
||||||
|
### Intellij+all Patch ###
|
||||||
|
# Ignores the whole .idea folder and all .iml files
|
||||||
|
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
modules.xml
|
||||||
|
.idea/misc.xml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
# Sonarlint plugin
|
||||||
|
.idea/sonarlint
|
||||||
|
|
||||||
|
### Java ###
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
### Gradle ###
|
||||||
|
.gradle
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Ignore Gradle GUI config
|
||||||
|
gradle-app.setting
|
||||||
|
|
||||||
|
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||||
|
!gradle-wrapper.jar
|
||||||
|
|
||||||
|
# Cache of project
|
||||||
|
.gradletasknamecache
|
||||||
|
|
||||||
|
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
|
||||||
|
# gradle/wrapper/gradle-wrapper.properties
|
||||||
|
|
||||||
|
### Gradle Patch ###
|
||||||
|
**/build/
|
||||||
|
|
||||||
|
# End of https://www.gitignore.io/api/java,gradle,intellij+all
|
55
build.gradle
Normal file
55
build.gradle
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'org.jetbrains.kotlin.jvm' version '1.3.31'
|
||||||
|
id 'org.springframework.boot' version '2.1.4.RELEASE'
|
||||||
|
id "io.spring.dependency-management" version "1.0.7.RELEASE"
|
||||||
|
id 'org.jetbrains.kotlin.plugin.spring' version '1.3.31'
|
||||||
|
id 'org.jetbrains.kotlin.plugin.jpa' version '1.3.31'
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'kotlin-jpa'
|
||||||
|
apply plugin: 'io.spring.dependency-management'
|
||||||
|
apply plugin: 'kotlin-kapt'
|
||||||
|
|
||||||
|
|
||||||
|
apply plugin: 'kotlin-allopen'
|
||||||
|
|
||||||
|
allOpen {
|
||||||
|
annotation("javax.persistence.Entity")
|
||||||
|
}
|
||||||
|
|
||||||
|
group 'nl.voidcorp.discord'
|
||||||
|
version '1.0-SNAPSHOT'
|
||||||
|
|
||||||
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||||
|
implementation 'org.jetbrains.kotlin:kotlin-reflect'
|
||||||
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
|
|
||||||
|
implementation 'net.dv8tion:JDA:4.ALPHA.0_88'
|
||||||
|
|
||||||
|
// runtimeOnly "ch.qos.logback:logback-classic:1.2.1"
|
||||||
|
implementation "com.h2database:h2"
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
compileKotlin {
|
||||||
|
kotlinOptions {
|
||||||
|
freeCompilerArgs = ["-Xjsr305=strict"]
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compileTestKotlin {
|
||||||
|
kotlinOptions {
|
||||||
|
freeCompilerArgs = ["-Xjsr305=strict"]
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
}
|
1
gradle.properties
Normal file
1
gradle.properties
Normal file
|
@ -0,0 +1 @@
|
||||||
|
kotlin.code.style=official
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
172
gradlew
vendored
Normal file
172
gradlew
vendored
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
##
|
||||||
|
## Gradle start up script for UN*X
|
||||||
|
##
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# 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
|
||||||
|
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=""
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD="maximum"
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
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"
|
||||||
|
else
|
||||||
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
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, switch paths to Windows format before running java
|
||||||
|
if $cygwin ; 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=$((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
|
||||||
|
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, 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"
|
||||||
|
|
||||||
|
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||||
|
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
84
gradlew.bat
vendored
Normal file
84
gradlew.bat
vendored
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
@if "%DEBUG%" == "" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS=
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if "%ERRORLEVEL%" == "0" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:init
|
||||||
|
@rem Get command-line arguments, handling Windows variants
|
||||||
|
|
||||||
|
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||||
|
|
||||||
|
:win9xME_args
|
||||||
|
@rem Slurp the command line arguments.
|
||||||
|
set CMD_LINE_ARGS=
|
||||||
|
set _SKIP=2
|
||||||
|
|
||||||
|
:win9xME_args_slurp
|
||||||
|
if "x%~1" == "x" goto execute
|
||||||
|
|
||||||
|
set CMD_LINE_ARGS=%*
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if "%ERRORLEVEL%"=="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
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
3
settings.gradle
Normal file
3
settings.gradle
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
rootProject.name = 'OttoBot'
|
||||||
|
rootProject.name = 'OttoBot'
|
||||||
|
|
22
src/main/kotlin/nl/voidcorp/discord/Loader.kt
Normal file
22
src/main/kotlin/nl/voidcorp/discord/Loader.kt
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package nl.voidcorp.discord
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.JDABuilder
|
||||||
|
import nl.voidcorp.discord.command.Command
|
||||||
|
import nl.voidcorp.discord.command.CommandMessage
|
||||||
|
import nl.voidcorp.discord.command.CommandResult
|
||||||
|
import nl.voidcorp.discord.events.CommandListener
|
||||||
|
import nl.voidcorp.discord.events.OttoListener
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class Loader(listener: CommandListener) {
|
||||||
|
init {
|
||||||
|
val token = System.getenv("DISCORD_TOKEN") ?: throw RuntimeException("'DISCORD_TOKEN' not set!")
|
||||||
|
|
||||||
|
val builder = JDABuilder(token)
|
||||||
|
|
||||||
|
builder.addEventListeners(OttoListener, listener)
|
||||||
|
|
||||||
|
jda = builder.build()
|
||||||
|
}
|
||||||
|
}
|
22
src/main/kotlin/nl/voidcorp/discord/Main.kt
Normal file
22
src/main/kotlin/nl/voidcorp/discord/Main.kt
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package nl.voidcorp.discord
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.JDA
|
||||||
|
import net.dv8tion.jda.api.entities.User
|
||||||
|
import org.slf4j.Logger
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
|
import org.springframework.boot.runApplication
|
||||||
|
|
||||||
|
val logger: Logger = LoggerFactory.getLogger("OttoBot")
|
||||||
|
lateinit var jda: JDA
|
||||||
|
|
||||||
|
val creator: User
|
||||||
|
get() = jda.getUserById(168743656738521088)!!
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
class SpringApp
|
||||||
|
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
runApplication<SpringApp>()
|
||||||
|
}
|
125
src/main/kotlin/nl/voidcorp/discord/command/Command.kt
Normal file
125
src/main/kotlin/nl/voidcorp/discord/command/Command.kt
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
package nl.voidcorp.discord.command
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.Permission
|
||||||
|
import net.dv8tion.jda.api.entities.ChannelType
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
|
abstract class Command(
|
||||||
|
val name: String,
|
||||||
|
val helpMesage: String = "",
|
||||||
|
val usage: String = "",
|
||||||
|
val aliases: List<String> = emptyList(),
|
||||||
|
val location: CommandSource = CommandSource.BOTH,
|
||||||
|
val permissions: Set<Permission> = emptySet()
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun onCommand(event: MessageReceivedEvent, prefix: String): CommandResult {
|
||||||
|
val starts =
|
||||||
|
event.message.contentRaw.drop(prefix.length).trim()
|
||||||
|
.startsWith(name) or aliases.any {
|
||||||
|
event.message.contentRaw.drop(prefix.length).trim().startsWith(
|
||||||
|
it
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return if (!starts) CommandResult.NOPE else when (location) {
|
||||||
|
CommandSource.PRIVATE -> if (event.channelType == ChannelType.PRIVATE) guildStuff(
|
||||||
|
event,
|
||||||
|
event.message.contentRaw.drop(prefix.length).trim()
|
||||||
|
) else CommandResult.NOPE
|
||||||
|
CommandSource.GUILD -> if (event.channelType == ChannelType.TEXT) privateStuff(
|
||||||
|
event,
|
||||||
|
event.message.contentRaw.drop(prefix.length).trim()
|
||||||
|
) else CommandResult.NOPE
|
||||||
|
CommandSource.BOTH ->
|
||||||
|
if (event.channelType == ChannelType.PRIVATE) guildStuff(
|
||||||
|
event,
|
||||||
|
event.message.contentRaw.drop(prefix.length).trim()
|
||||||
|
)
|
||||||
|
else privateStuff(event, event.message.contentRaw.drop(prefix.length).trim())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun guildStuff(event: MessageReceivedEvent, str: String): CommandResult {
|
||||||
|
val intersect = permissions.intersect(event.member?.permissions as Iterable<Permission>)
|
||||||
|
return if ((intersect.isNotEmpty() or permissions.isEmpty())) {
|
||||||
|
handle(CommandMessage(event, translateCommandline(str)))
|
||||||
|
} else CommandResult.PERMISSIONS
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun privateStuff(event: MessageReceivedEvent, str: String): CommandResult {
|
||||||
|
return handle(CommandMessage(event, translateCommandline(str)))
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun handle(event: CommandMessage): CommandResult
|
||||||
|
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
var settings = CommandSettings()
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [code borrowed from ant.jar]
|
||||||
|
* Crack a command line.
|
||||||
|
* @param toProcess the command line to process.
|
||||||
|
* @return the command line broken into strings.
|
||||||
|
* An empty or null toProcess parameter results in a zero sized array.
|
||||||
|
*/
|
||||||
|
private fun translateCommandline(toProcess: String): List<String> {
|
||||||
|
if (toProcess.isEmpty()) {
|
||||||
|
//no command? no string
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
// parse with a simple finite state machine
|
||||||
|
|
||||||
|
val normal = 0
|
||||||
|
val inQuote = 1
|
||||||
|
val inDoubleQuote = 2
|
||||||
|
var state = normal
|
||||||
|
val tok = StringTokenizer(toProcess, "\"\' ", true)
|
||||||
|
val result = mutableListOf<String>()
|
||||||
|
val current = StringBuilder()
|
||||||
|
var lastTokenHasBeenQuoted = false
|
||||||
|
|
||||||
|
while (tok.hasMoreTokens()) {
|
||||||
|
val nextTok = tok.nextToken()
|
||||||
|
when (state) {
|
||||||
|
inQuote -> if ("\'" == nextTok) {
|
||||||
|
lastTokenHasBeenQuoted = true
|
||||||
|
state = normal
|
||||||
|
} else {
|
||||||
|
current.append(nextTok)
|
||||||
|
}
|
||||||
|
inDoubleQuote -> if ("\"" == nextTok) {
|
||||||
|
lastTokenHasBeenQuoted = true
|
||||||
|
state = normal
|
||||||
|
} else {
|
||||||
|
current.append(nextTok)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
if ("\'" == nextTok) {
|
||||||
|
state = inQuote
|
||||||
|
} else if ("\"" == nextTok) {
|
||||||
|
state = inDoubleQuote
|
||||||
|
} else if (" " == nextTok) {
|
||||||
|
if (lastTokenHasBeenQuoted || current.isNotEmpty()) {
|
||||||
|
result.add(current.toString())
|
||||||
|
current.setLength(0)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
current.append(nextTok)
|
||||||
|
}
|
||||||
|
lastTokenHasBeenQuoted = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lastTokenHasBeenQuoted || current.isNotEmpty()) {
|
||||||
|
result.add(current.toString())
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package nl.voidcorp.discord.command
|
||||||
|
|
||||||
|
enum class CommandGroup {
|
||||||
|
GENERAL,
|
||||||
|
ADMIN,
|
||||||
|
MEME
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package nl.voidcorp.discord.command
|
||||||
|
|
||||||
|
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.entities.MessageEmbed
|
||||||
|
import net.dv8tion.jda.api.entities.User
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
|
||||||
|
|
||||||
|
data class CommandMessage(
|
||||||
|
private val event: MessageReceivedEvent,
|
||||||
|
val params: List<String>,
|
||||||
|
val message: Message = event.message,
|
||||||
|
val user: User = event.author,
|
||||||
|
val member: Member? = event.member
|
||||||
|
) {
|
||||||
|
fun reply(message: Message) = event.channel.sendMessage(message).queue()
|
||||||
|
|
||||||
|
|
||||||
|
fun reply(message: String) = reply(MessageBuilder(message).build())
|
||||||
|
|
||||||
|
fun reply(messageEmbed: MessageEmbed) = event.channel.sendMessage(messageEmbed).queue()
|
||||||
|
|
||||||
|
}
|
10
src/main/kotlin/nl/voidcorp/discord/command/CommandResult.kt
Normal file
10
src/main/kotlin/nl/voidcorp/discord/command/CommandResult.kt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package nl.voidcorp.discord.command
|
||||||
|
|
||||||
|
enum class CommandResult {
|
||||||
|
SUCCESS,
|
||||||
|
ERROR,
|
||||||
|
PERMISSIONS,
|
||||||
|
NOPE,
|
||||||
|
PARAMETERS,
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package nl.voidcorp.discord.command
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.entities.Guild
|
||||||
|
|
||||||
|
open class CommandSettings(val prefix: String = "?") {
|
||||||
|
open fun getPrefix(guild: Guild) = prefix
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package nl.voidcorp.discord.command
|
||||||
|
|
||||||
|
enum class CommandSource {
|
||||||
|
PRIVATE,
|
||||||
|
GUILD,
|
||||||
|
BOTH
|
||||||
|
}
|
14
src/main/kotlin/nl/voidcorp/discord/commands/Echo.kt
Normal file
14
src/main/kotlin/nl/voidcorp/discord/commands/Echo.kt
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package nl.voidcorp.discord.commands
|
||||||
|
|
||||||
|
import nl.voidcorp.discord.command.Command
|
||||||
|
import nl.voidcorp.discord.command.CommandMessage
|
||||||
|
import nl.voidcorp.discord.command.CommandResult
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class Echo : Command("echo") {
|
||||||
|
override fun handle(event: CommandMessage): CommandResult {
|
||||||
|
event.reply(event.params.drop(1).joinToString(" "))
|
||||||
|
return CommandResult.SUCCESS
|
||||||
|
}
|
||||||
|
}
|
14
src/main/kotlin/nl/voidcorp/discord/commands/Yeet.kt
Normal file
14
src/main/kotlin/nl/voidcorp/discord/commands/Yeet.kt
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package nl.voidcorp.discord.commands
|
||||||
|
|
||||||
|
import nl.voidcorp.discord.command.Command
|
||||||
|
import nl.voidcorp.discord.command.CommandMessage
|
||||||
|
import nl.voidcorp.discord.command.CommandResult
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class Yeet : Command("nice") {
|
||||||
|
override fun handle(event: CommandMessage): CommandResult {
|
||||||
|
event.reply("nice")
|
||||||
|
return CommandResult.SUCCESS
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package nl.voidcorp.discord.events
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder
|
||||||
|
import net.dv8tion.jda.api.entities.ChannelType
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageUpdateEvent
|
||||||
|
import net.dv8tion.jda.api.hooks.ListenerAdapter
|
||||||
|
import nl.voidcorp.discord.command.Command
|
||||||
|
import nl.voidcorp.discord.command.CommandResult
|
||||||
|
import nl.voidcorp.discord.creator
|
||||||
|
import nl.voidcorp.discord.logger
|
||||||
|
import nl.voidcorp.discord.storage.GuildRepo
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class CommandListener(
|
||||||
|
@Autowired val guildRepo: GuildRepo,
|
||||||
|
@Autowired final val commands: Set<Command>
|
||||||
|
) : ListenerAdapter() {
|
||||||
|
|
||||||
|
init {
|
||||||
|
logger.info("Found ${commands.size} commands!")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMessageReceived(event: MessageReceivedEvent) {
|
||||||
|
if (event.author.isBot) return
|
||||||
|
val prefix: String = when {
|
||||||
|
event.channelType == ChannelType.TEXT -> Command.settings.getPrefix(event.guild)
|
||||||
|
event.channelType == ChannelType.PRIVATE -> Command.settings.prefix
|
||||||
|
else -> return
|
||||||
|
}
|
||||||
|
if (!event.message.contentRaw.startsWith(prefix)) return
|
||||||
|
|
||||||
|
val res = commands.map { it to it.onCommand(event, prefix) }.filter { it.second != CommandResult.NOPE }
|
||||||
|
if (res.size > 1) {
|
||||||
|
val mb =
|
||||||
|
MessageBuilder("Well this is awkward... It seems that multiple actions are bound to this command... ")
|
||||||
|
.append("Report this error to the staff of the server or ")
|
||||||
|
val member = event.guild.getMember(creator)
|
||||||
|
if (member != null)
|
||||||
|
mb.append(member)
|
||||||
|
else {
|
||||||
|
mb.append(creator.asTag)
|
||||||
|
}
|
||||||
|
|
||||||
|
event.channel.sendMessage(mb.append(" since this shouldn't happen...").build()).queue()
|
||||||
|
} else if (res.isEmpty()) {
|
||||||
|
event.channel.sendMessage("I don't seem to know this command...").queue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMessageUpdate(event: MessageUpdateEvent) =
|
||||||
|
onMessageReceived(MessageReceivedEvent(event.jda, event.messageIdLong, event.message))
|
||||||
|
|
||||||
|
|
||||||
|
}
|
11
src/main/kotlin/nl/voidcorp/discord/events/OttoListener.kt
Normal file
11
src/main/kotlin/nl/voidcorp/discord/events/OttoListener.kt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package nl.voidcorp.discord.events
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.events.ReadyEvent
|
||||||
|
import net.dv8tion.jda.api.hooks.ListenerAdapter
|
||||||
|
import nl.voidcorp.discord.logger
|
||||||
|
|
||||||
|
object OttoListener : ListenerAdapter() {
|
||||||
|
override fun onReady(event: ReadyEvent) {
|
||||||
|
logger.info("Found ${event.guildTotalCount} different guilds!")
|
||||||
|
}
|
||||||
|
}
|
12
src/main/kotlin/nl/voidcorp/discord/storage/GuildStore.kt
Normal file
12
src/main/kotlin/nl/voidcorp/discord/storage/GuildStore.kt
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package nl.voidcorp.discord.storage
|
||||||
|
|
||||||
|
import javax.annotation.Generated
|
||||||
|
import javax.persistence.Entity
|
||||||
|
import javax.persistence.Id
|
||||||
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
data class GuildStore(
|
||||||
|
@Id
|
||||||
|
@Generated
|
||||||
|
var id: Long? = null)
|
8
src/main/kotlin/nl/voidcorp/discord/storage/Store.kt
Normal file
8
src/main/kotlin/nl/voidcorp/discord/storage/Store.kt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package nl.voidcorp.discord.storage
|
||||||
|
|
||||||
|
import org.springframework.data.repository.Repository
|
||||||
|
|
||||||
|
|
||||||
|
interface GuildRepo : Repository<GuildStore, Long> {
|
||||||
|
fun findById(id: Long): GuildStore
|
||||||
|
}
|
9
src/main/resources/application.properties
Normal file
9
src/main/resources/application.properties
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
spring.jpa.database=H2
|
||||||
|
spring.datasource.platform=h2
|
||||||
|
spring.datasource.url=jdbc:h2:mem:
|
||||||
|
#spring.datasource.username=root
|
||||||
|
#spring.datasource.password=changeme
|
||||||
|
spring.jpa.show-sql=true
|
||||||
|
spring.jpa.generate-ddl=true
|
||||||
|
spring.jpa.hibernate.ddl-auto=create-drop
|
||||||
|
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
|
19
src/main/resources/logback.xml
Normal file
19
src/main/resources/logback.xml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<configuration>
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %logger{0} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT"/>
|
||||||
|
<!--<appender-ref ref="FILE"/>-->
|
||||||
|
</root>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<logger name="org.eclipse.jetty" level="INFO"/>
|
||||||
|
<logger name="io.netty" level="INFO"/>
|
||||||
|
|
||||||
|
</configuration>
|
Loading…
Reference in a new issue