Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/java/com/alttd/AltitudeBot.java
This commit is contained in:
commit
83af33dcc4
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,3 +1,7 @@
|
||||||
.gradle/
|
.gradle/
|
||||||
.idea/
|
.idea/
|
||||||
gradle/
|
gradle/
|
||||||
|
gradlew
|
||||||
|
run
|
||||||
|
build
|
||||||
|
run.sh
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
|
|
@ -39,18 +38,18 @@ tasks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
create<ConfigureShadowRelocation>("relocateJars") {
|
// create<ConfigureShadowRelocation>("relocateJars") {
|
||||||
target = shadowJar.get()
|
// target = shadowJar.get()
|
||||||
prefix = "${project.name}.lib"
|
// prefix = "${project.name}.lib"
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
shadowJar {
|
// shadowJar {
|
||||||
dependsOn(getByName("relocateJars") as ConfigureShadowRelocation)
|
// dependsOn(getByName("relocateJars") as ConfigureShadowRelocation)
|
||||||
archiveFileName.set("${project.name}-${project.version}.jar")
|
// archiveFileName.set("${project.name}-${project.version}.jar")
|
||||||
minimize()
|
// minimize()
|
||||||
configurations = listOf(project.configurations.shadow.get())
|
// configurations = listOf(project.configurations.shadow.get())
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
build {
|
build {
|
||||||
dependsOn(shadowJar)
|
dependsOn(shadowJar)
|
||||||
}
|
}
|
||||||
|
|
@ -59,30 +58,13 @@ tasks {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// JDA
|
// JDA
|
||||||
implementation("net.dv8tion:JDA:5.0.0-alpha.9") {
|
implementation("net.dv8tion:JDA:5.0.0-alpha.10") {
|
||||||
shadow("net.dv8tion:JDA:5.0.0-alpha.9") {
|
exclude("opus-java") // exclude audio
|
||||||
exclude("opus-java") // exclude audio
|
|
||||||
}
|
|
||||||
// MySQL
|
|
||||||
// runtimeOnly("mysql:mysql-connector-java:8.0.23")
|
|
||||||
}
|
}
|
||||||
|
// MySQL
|
||||||
|
implementation("mysql:mysql-connector-java:8.0.28")
|
||||||
|
// implementation("org.mariadb.jdbc:mariadb-java-client:2.1.2")
|
||||||
|
|
||||||
implementation("org.mariadb.jdbc:mariadb-java-client:2.1.2") {
|
|
||||||
shadow("org.mariadb.jdbc:mariadb-java-client:2.1.2")
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks {
|
|
||||||
|
|
||||||
shadowJar {
|
|
||||||
listOf(
|
|
||||||
"net.dv8tion.jda"
|
|
||||||
).forEach { relocate(it, "${rootProject.group}.lib.$it") }
|
|
||||||
}
|
|
||||||
|
|
||||||
build {
|
|
||||||
dependsOn(shadowJar)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Configurate
|
// Configurate
|
||||||
shadow("org.spongepowered:configurate-yaml:4.1.2")
|
implementation("org.spongepowered:configurate-yaml:4.1.2")
|
||||||
}
|
}
|
||||||
185
gradlew
vendored
185
gradlew
vendored
|
|
@ -1,185 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
#
|
|
||||||
# Copyright 2015 the original author or authors.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
#
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
##
|
|
||||||
## 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='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# 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
|
|
||||||
;;
|
|
||||||
MSYS* | 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 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
|
|
||||||
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"
|
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
|
||||||
|
|
@ -1,17 +1,24 @@
|
||||||
package com.alttd;
|
package com.alttd;
|
||||||
|
|
||||||
import com.alttd.commandManager.CommandManager;
|
import com.alttd.commandManager.CommandManager;
|
||||||
|
import com.alttd.commandManager.listeners.JDAListener;
|
||||||
import com.alttd.config.SettingsConfig;
|
import com.alttd.config.SettingsConfig;
|
||||||
import com.alttd.config.MessagesConfig;
|
import com.alttd.config.MessagesConfig;
|
||||||
|
import com.alttd.console.ConsoleCommandManager;
|
||||||
|
import com.alttd.database.Database;
|
||||||
|
import com.alttd.database.DatabaseTables;
|
||||||
import com.alttd.permissions.PermissionManager;
|
import com.alttd.permissions.PermissionManager;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
|
import com.mysql.cj.log.Log;
|
||||||
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.requests.GatewayIntent;
|
import net.dv8tion.jda.api.OnlineStatus;
|
||||||
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
import static java.lang.System.exit;
|
import static java.lang.System.exit;
|
||||||
|
|
||||||
|
|
@ -33,29 +40,27 @@ public class AltitudeBot {
|
||||||
Logger.info("Starting bot...");
|
Logger.info("Starting bot...");
|
||||||
initConfigs();
|
initConfigs();
|
||||||
try {
|
try {
|
||||||
jda = JDABuilder.createDefault(SettingsConfig.TOKEN,
|
jda = JDABuilder.createDefault(SettingsConfig.TOKEN).build();
|
||||||
GatewayIntent.DIRECT_MESSAGE_REACTIONS,
|
|
||||||
GatewayIntent.DIRECT_MESSAGE_TYPING,
|
|
||||||
GatewayIntent.DIRECT_MESSAGES,
|
|
||||||
GatewayIntent.GUILD_BANS,
|
|
||||||
GatewayIntent.GUILD_EMOJIS,
|
|
||||||
GatewayIntent.GUILD_MEMBERS,
|
|
||||||
GatewayIntent.GUILD_MESSAGE_REACTIONS,
|
|
||||||
GatewayIntent.GUILD_MESSAGE_TYPING,
|
|
||||||
GatewayIntent.GUILD_MESSAGES,
|
|
||||||
GatewayIntent.GUILD_PRESENCES,
|
|
||||||
GatewayIntent.GUILD_WEBHOOKS).build();
|
|
||||||
} catch (LoginException e) {
|
} catch (LoginException e) {
|
||||||
Logger.info("Unable to log in, shutting down (check token in settings.yml).");
|
Logger.info("Unable to log in, shutting down (check token in settings.yml).");
|
||||||
exit(1);
|
exit(1);
|
||||||
Logger.exception(e);
|
Logger.exception(e);
|
||||||
}
|
}
|
||||||
|
DatabaseTables.createTables(Database.getDatabase().getConnection());
|
||||||
|
ConsoleCommandManager.startConsoleCommands(jda);
|
||||||
|
try {
|
||||||
|
jda.getPresence().setPresence(
|
||||||
|
OnlineStatus.valueOf(SettingsConfig.STATUS),
|
||||||
|
Activity.listening(SettingsConfig.ACTIVITY));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
Logger.exception(e);
|
||||||
|
}
|
||||||
initListeners();
|
initListeners();
|
||||||
//TODO init permissionManager
|
//TODO init permissionManager
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initListeners() {
|
private void initListeners() {
|
||||||
jda.addEventListener(new CommandManager(jda));
|
jda.addEventListener(new JDAListener(jda));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initConfigs() {
|
private void initConfigs() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.alttd.commandManager;
|
package com.alttd.commandManager;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.commands.AddCommand.CommandManage;
|
||||||
import com.alttd.commandManager.commands.CommandHelp;
|
import com.alttd.commandManager.commands.CommandHelp;
|
||||||
import com.alttd.commandManager.commands.PollCommand.CommandPoll;
|
import com.alttd.commandManager.commands.PollCommand.CommandPoll;
|
||||||
import com.alttd.database.Database;
|
import com.alttd.database.Database;
|
||||||
|
|
@ -28,9 +29,10 @@ public class CommandManager extends ListenerAdapter {
|
||||||
private final HashMap<String, List<ScopeInfo>> commandList = new HashMap<>();
|
private final HashMap<String, List<ScopeInfo>> commandList = new HashMap<>();
|
||||||
|
|
||||||
public CommandManager(JDA jda) {
|
public CommandManager(JDA jda) {
|
||||||
commands = List.of(new CommandHelp(jda, this),
|
|
||||||
new CommandPoll(jda, this));
|
|
||||||
loadCommands();
|
loadCommands();
|
||||||
|
commands = List.of(new CommandHelp(jda, this),
|
||||||
|
new CommandPoll(jda, this),
|
||||||
|
new CommandManage(jda, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -85,9 +87,10 @@ public class CommandManager extends ListenerAdapter {
|
||||||
|
|
||||||
private void loadCommands() {
|
private void loadCommands() {
|
||||||
String sql = "SELECT * FROM commands";
|
String sql = "SELECT * FROM commands";
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
|
|
@ -100,6 +103,13 @@ public class CommandManager extends ListenerAdapter {
|
||||||
}
|
}
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
Logger.sql(exception);
|
Logger.sql(exception);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (statement != null)
|
||||||
|
statement.close();
|
||||||
|
} catch (SQLException exception) {
|
||||||
|
Logger.sql(exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,33 @@
|
||||||
package com.alttd.commandManager;
|
package com.alttd.commandManager;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
|
||||||
public abstract class SubCommand {
|
public abstract class SubCommand extends SubOption{
|
||||||
|
|
||||||
private final DiscordCommand parent;
|
private final SubCommandGroup parentGroup;
|
||||||
|
private final boolean inSubGroup;
|
||||||
|
|
||||||
protected SubCommand(DiscordCommand parent) {
|
protected SubCommand(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
this.parent = parent;
|
super(parent);
|
||||||
|
this.parentGroup = parentGroup;
|
||||||
|
this.inSubGroup = parentGroup != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscordCommand getParent() {
|
public SubCommandGroup getParentGroup() {
|
||||||
return parent;
|
return parentGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getName();
|
public boolean isInSubGroup() {
|
||||||
|
return inSubGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getPermission() {
|
public String getPermission() {
|
||||||
return getParent().getPermission() + "." + getName();
|
if (isInSubGroup())
|
||||||
|
return getParentGroup().getPermission() + "." + getName();
|
||||||
|
else
|
||||||
|
return getParent().getPermission() + "." + getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void execute(SlashCommandInteractionEvent event);
|
public abstract void suggest(CommandAutoCompleteInteractionEvent event);
|
||||||
|
|
||||||
public abstract String getHelpMessage();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.alttd.commandManager;
|
||||||
|
|
||||||
|
public abstract class SubCommandGroup extends SubOption{
|
||||||
|
protected SubCommandGroup(DiscordCommand parent) {
|
||||||
|
super(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/main/java/com/alttd/commandManager/SubOption.java
Normal file
25
src/main/java/com/alttd/commandManager/SubOption.java
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.alttd.commandManager;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public abstract class SubOption {
|
||||||
|
private final DiscordCommand parent;
|
||||||
|
|
||||||
|
protected SubOption(DiscordCommand parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DiscordCommand getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
public String getPermission() {
|
||||||
|
return getParent().getPermission() + "." + getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void execute(SlashCommandInteractionEvent event);
|
||||||
|
|
||||||
|
public abstract String getHelpMessage();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.CommandManager;
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubOption;
|
||||||
|
import com.alttd.permissions.PermissionManager;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
import com.alttd.util.Util;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class CommandManage extends DiscordCommand {
|
||||||
|
private final HashMap<String, SubOption> subOptionsMap = new HashMap<>();
|
||||||
|
|
||||||
|
public CommandManage(JDA jda, CommandManager commandManager) {
|
||||||
|
SlashCommandData slashCommandData = Commands.slash(getName(), "Enable commands and assign permissions")
|
||||||
|
.addSubcommandGroups(
|
||||||
|
new SubcommandGroupData("set", "Set a permission for a user")
|
||||||
|
.addSubcommands(
|
||||||
|
new SubcommandData("user", "Set a permission for a user")
|
||||||
|
.addOption(OptionType.MENTIONABLE, "user", "The user to set the permission for", true)
|
||||||
|
.addOption(OptionType.STRING, "permission", "The permission to set for a user", true, true)
|
||||||
|
.addOption(OptionType.STRING, "state", "To allow or deny the permission (true/false)", true, true),
|
||||||
|
new SubcommandData("group", "Set a permission for a group")
|
||||||
|
.addOption(OptionType.MENTIONABLE, "group", "The group to set the permission for", true)
|
||||||
|
.addOption(OptionType.STRING, "permission", "The permission to set for a group", true, true)
|
||||||
|
.addOption(OptionType.STRING, "state", "To allow or deny the permission (true/false)", true, true)
|
||||||
|
),
|
||||||
|
new SubcommandGroupData("unset", "unset a permission for a user")
|
||||||
|
.addSubcommands(
|
||||||
|
new SubcommandData("user", "Unset a permission for a user")
|
||||||
|
.addOption(OptionType.MENTIONABLE, "user", "The user to unset the permission for", true)
|
||||||
|
.addOption(OptionType.STRING, "permission", "The permission to unset for a user", true, true),
|
||||||
|
new SubcommandData("group", "Unset a permission for a group")
|
||||||
|
.addOption(OptionType.MENTIONABLE, "group", "The group to unset the permission for", true)
|
||||||
|
.addOption(OptionType.STRING, "permission", "The permission to unset for a group", true, true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addSubcommands(
|
||||||
|
new SubcommandData("enable", "Enable a command in a channel")
|
||||||
|
.addOption(OptionType.CHANNEL, "channel", "Channel to enable this command in", true)
|
||||||
|
.addOption(OptionType.STRING, "command", "Name of the command to enable", true, true),
|
||||||
|
new SubcommandData("disable", "Disable a command")
|
||||||
|
.addOption(OptionType.CHANNEL, "channel", "Channel to disable this command in", true)
|
||||||
|
.addOption(OptionType.STRING, "command", "Name of the command to disable", true, true)
|
||||||
|
);
|
||||||
|
slashCommandData.setDefaultEnabled(true);
|
||||||
|
Util.registerSubOptions(subOptionsMap,
|
||||||
|
new SubCommandDisable(commandManager, null, this),
|
||||||
|
new SubCommandEnable(commandManager, null, this));
|
||||||
|
Util.registerCommand(commandManager, jda, slashCommandData, getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "manage";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
if (event.getGuild() == null || event.getMember() == null) {
|
||||||
|
event.replyEmbeds(Util.guildOnlyCommand(getName())).setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (PermissionManager.getInstance().hasPermission(event.getTextChannel(), event.getIdLong(), Util.getGroupIds(event.getMember()), getPermission())) {
|
||||||
|
event.replyEmbeds(Util.noPermission(getName())).setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String subcommandName = event.getInteraction().getSubcommandGroup();
|
||||||
|
subcommandName = subcommandName == null ? event.getInteraction().getSubcommandName() : subcommandName;
|
||||||
|
if (subcommandName == null) {
|
||||||
|
Logger.severe("No subcommand found for %", getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubOption subOption = subOptionsMap.get(subcommandName);
|
||||||
|
if (subOption == null) {
|
||||||
|
event.replyEmbeds(Util.invalidSubcommand(subcommandName))
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
subOption.execute(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.CommandManager;
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public class SubCommandDisable extends SubCommand {
|
||||||
|
|
||||||
|
private final CommandManager commandManager;
|
||||||
|
|
||||||
|
protected SubCommandDisable(CommandManager commandManager, SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
|
super(parentGroup, parent);
|
||||||
|
this.commandManager = commandManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "disable";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.CommandManager;
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public class SubCommandEnable extends SubCommand {
|
||||||
|
|
||||||
|
private final CommandManager commandManager;
|
||||||
|
|
||||||
|
protected SubCommandEnable(CommandManager commandManager, SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
|
super(parentGroup, parent);
|
||||||
|
this.commandManager = commandManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "enable";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import com.alttd.commandManager.SubOption;
|
||||||
|
import com.alttd.permissions.PermissionManager;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
import com.alttd.util.Util;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class SubCommandGroupSet extends SubCommandGroup {
|
||||||
|
|
||||||
|
private final HashMap<String, SubOption> subOptionsMap = new HashMap<>();
|
||||||
|
|
||||||
|
protected SubCommandGroupSet(DiscordCommand parent) {
|
||||||
|
super(parent);
|
||||||
|
Util.registerSubOptions(subOptionsMap,
|
||||||
|
new SubCommandUnsetGroup(this, getParent()),
|
||||||
|
new SubCommandUnsetUser(this, getParent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "set";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
if (PermissionManager.getInstance().hasPermission(event.getTextChannel(), event.getIdLong(), Util.getGroupIds(event.getMember()), getPermission())) {
|
||||||
|
event.replyEmbeds(Util.noPermission(getName())).setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String subcommandName = event.getInteraction().getSubcommandName();
|
||||||
|
if (subcommandName == null) {
|
||||||
|
Logger.severe("No subcommand found for %", getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubOption subOption = subOptionsMap.get(subcommandName);
|
||||||
|
if (subOption == null) {
|
||||||
|
event.replyEmbeds(Util.invalidSubcommand(subcommandName))
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
subOption.execute(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import com.alttd.commandManager.SubOption;
|
||||||
|
import com.alttd.permissions.PermissionManager;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
import com.alttd.util.Util;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class SubCommandGroupUnset extends SubCommandGroup {
|
||||||
|
|
||||||
|
private final HashMap<String, SubOption> subOptionsMap = new HashMap<>();
|
||||||
|
|
||||||
|
protected SubCommandGroupUnset(DiscordCommand parent) {
|
||||||
|
super(parent);
|
||||||
|
Util.registerSubOptions(subOptionsMap,
|
||||||
|
new SubCommandUnsetGroup(this, getParent()),
|
||||||
|
new SubCommandUnsetUser(this, getParent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "unset";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
if (PermissionManager.getInstance().hasPermission(event.getTextChannel(), event.getIdLong(), Util.getGroupIds(event.getMember()), getPermission())) {
|
||||||
|
event.replyEmbeds(Util.noPermission(getName())).setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String subcommandName = event.getInteraction().getSubcommandName();
|
||||||
|
if (subcommandName == null) {
|
||||||
|
Logger.severe("No subcommand found for %", getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubOption subOption = subOptionsMap.get(subcommandName);
|
||||||
|
if (subOption == null) {
|
||||||
|
event.replyEmbeds(Util.invalidSubcommand(subcommandName))
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
subOption.execute(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public class SubCommandSetGroup extends SubCommand {
|
||||||
|
|
||||||
|
protected SubCommandSetGroup(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
|
super(parentGroup, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "group";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public class SubCommandSetUser extends SubCommand {
|
||||||
|
|
||||||
|
protected SubCommandSetUser(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
|
super(parentGroup, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "user";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public class SubCommandUnsetGroup extends SubCommand {
|
||||||
|
|
||||||
|
protected SubCommandUnsetGroup(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
|
super(parentGroup, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "group";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public class SubCommandUnsetUser extends SubCommand {
|
||||||
|
|
||||||
|
protected SubCommandUnsetUser(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
|
super(parentGroup, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "user";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
import com.alttd.commandManager.CommandManager;
|
import com.alttd.commandManager.CommandManager;
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubOption;
|
||||||
import com.alttd.permissions.PermissionManager;
|
import com.alttd.permissions.PermissionManager;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
import com.alttd.util.Util;
|
import com.alttd.util.Util;
|
||||||
|
|
@ -18,7 +19,7 @@ import java.util.HashMap;
|
||||||
|
|
||||||
public class CommandPoll extends DiscordCommand {
|
public class CommandPoll extends DiscordCommand {
|
||||||
|
|
||||||
private final HashMap<String, SubCommand> subCommandMap = new HashMap<>();
|
private final HashMap<String, SubOption> subOptionsMap = new HashMap<>();
|
||||||
|
|
||||||
public CommandPoll(JDA jda, CommandManager commandManager) {
|
public CommandPoll(JDA jda, CommandManager commandManager) {
|
||||||
SlashCommandData slashCommandData = Commands.slash(getName(), "Create, edit, and manage polls")
|
SlashCommandData slashCommandData = Commands.slash(getName(), "Create, edit, and manage polls")
|
||||||
|
|
@ -53,15 +54,15 @@ public class CommandPoll extends DiscordCommand {
|
||||||
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true)
|
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true)
|
||||||
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you want the results for", true));
|
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you want the results for", true));
|
||||||
slashCommandData.setDefaultEnabled(true);
|
slashCommandData.setDefaultEnabled(true);
|
||||||
Util.registerSubcommands(subCommandMap,
|
Util.registerSubOptions(subOptionsMap,
|
||||||
new SubCommandAdd(this),
|
new SubCommandAdd(null,this),
|
||||||
new SubCommandAddButton(this),
|
new SubCommandAddButton(null, this),
|
||||||
new SubCommandClose(this),
|
new SubCommandClose(null,this),
|
||||||
new SubCommandEditDescription(this),
|
new SubCommandEditDescription(null, this),
|
||||||
new SubCommandEditTitle(this),
|
new SubCommandEditTitle(null, this),
|
||||||
new SubCommandOpen(this),
|
new SubCommandOpen(null, this),
|
||||||
new SubCommandRemoveButton(this),
|
new SubCommandRemoveButton(null, this),
|
||||||
new SubCommandResults(this));
|
new SubCommandResults(null,this));
|
||||||
Util.registerCommand(commandManager, jda, slashCommandData, getName());
|
Util.registerCommand(commandManager, jda, slashCommandData, getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,21 +82,22 @@ public class CommandPoll extends DiscordCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String subcommandName = event.getInteraction().getSubcommandName();
|
String subcommandName = event.getInteraction().getSubcommandGroup();
|
||||||
|
subcommandName = subcommandName == null ? event.getInteraction().getSubcommandName() : subcommandName;
|
||||||
if (subcommandName == null) {
|
if (subcommandName == null) {
|
||||||
Logger.severe("No subcommand found for %", getName());
|
Logger.severe("No subcommand found for %", getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SubCommand subCommand = subCommandMap.get(subcommandName);
|
SubOption subOption = subOptionsMap.get(subcommandName);
|
||||||
if (subCommand == null) {
|
if (subOption == null) {
|
||||||
event.replyEmbeds(Util.invalidSubcommand(subcommandName))
|
event.replyEmbeds(Util.invalidSubcommand(subcommandName))
|
||||||
.setEphemeral(true)
|
.setEphemeral(true)
|
||||||
.queue();
|
.queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
subCommand.execute(event);
|
subOption.execute(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.config.MessagesConfig;
|
import com.alttd.config.MessagesConfig;
|
||||||
import com.alttd.templates.Parser;
|
import com.alttd.templates.Parser;
|
||||||
import com.alttd.templates.Template;
|
import com.alttd.templates.Template;
|
||||||
|
|
@ -10,6 +11,7 @@ import com.alttd.util.OptionMappingParsing;
|
||||||
import com.alttd.util.Util;
|
import com.alttd.util.Util;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.*;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
|
|
||||||
|
|
@ -17,8 +19,8 @@ import java.awt.*;
|
||||||
|
|
||||||
public class SubCommandAdd extends SubCommand {
|
public class SubCommandAdd extends SubCommand {
|
||||||
|
|
||||||
protected SubCommandAdd(DiscordCommand parent) {
|
protected SubCommandAdd(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -57,6 +59,11 @@ public class SubCommandAdd extends SubCommand {
|
||||||
.queue(result -> createPoll(channel, title, result));
|
.queue(result -> createPoll(channel, title, result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void createPoll(GuildMessageChannel channel, String title, InteractionHook hook) {
|
private void createPoll(GuildMessageChannel channel, String title, InteractionHook hook) {
|
||||||
channel.sendMessageEmbeds(new EmbedBuilder()
|
channel.sendMessageEmbeds(new EmbedBuilder()
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.templates.Parser;
|
import com.alttd.templates.Parser;
|
||||||
import com.alttd.templates.Template;
|
import com.alttd.templates.Template;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
|
|
@ -12,12 +13,13 @@ import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
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.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
|
|
||||||
public class SubCommandAddButton extends SubCommand {
|
public class SubCommandAddButton extends SubCommand {
|
||||||
protected SubCommandAddButton(DiscordCommand parent) {
|
protected SubCommandAddButton(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -77,6 +79,11 @@ public class SubCommandAddButton extends SubCommand {
|
||||||
throwable -> failedToGetMessage(throwable, hook)));
|
throwable -> failedToGetMessage(throwable, hook)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void failedToGetMessage(Throwable throwable, InteractionHook hook) {
|
private void failedToGetMessage(Throwable throwable, InteractionHook hook) {
|
||||||
Logger.warning(throwable.getMessage());
|
Logger.warning(throwable.getMessage());
|
||||||
hook.editOriginalEmbeds(Util.genericErrorEmbed("Failed to get poll message",
|
hook.editOriginalEmbeds(Util.genericErrorEmbed("Failed to get poll message",
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandClose extends SubCommand {
|
public class SubCommandClose extends SubCommand {
|
||||||
protected SubCommandClose(DiscordCommand parent) {
|
protected SubCommandClose(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -26,6 +28,11 @@ public class SubCommandClose extends SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpMessage() {
|
public String getHelpMessage() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,19 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import com.alttd.util.Util;
|
import com.alttd.util.Util;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
|
|
||||||
public class SubCommandEditDescription extends SubCommand {
|
public class SubCommandEditDescription extends SubCommand {
|
||||||
protected SubCommandEditDescription(DiscordCommand parent) {
|
protected SubCommandEditDescription(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -33,6 +35,11 @@ public class SubCommandEditDescription extends SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//Copied over while working on add button
|
//Copied over while working on add button
|
||||||
private void updatePoll(GuildMessageChannel channel, int rowId, String buttonName, Message message,
|
private void updatePoll(GuildMessageChannel channel, int rowId, String buttonName, Message message,
|
||||||
InteractionHook hook) {
|
InteractionHook hook) {
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandEditTitle extends SubCommand {
|
public class SubCommandEditTitle extends SubCommand {
|
||||||
protected SubCommandEditTitle(DiscordCommand parent) {
|
protected SubCommandEditTitle(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -29,6 +31,11 @@ public class SubCommandEditTitle extends SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpMessage() {
|
public String getHelpMessage() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandOpen extends SubCommand {
|
public class SubCommandOpen extends SubCommand {
|
||||||
protected SubCommandOpen(DiscordCommand parent) {
|
protected SubCommandOpen(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -26,6 +28,11 @@ public class SubCommandOpen extends SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpMessage() {
|
public String getHelpMessage() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandRemoveButton extends SubCommand {
|
public class SubCommandRemoveButton extends SubCommand {
|
||||||
protected SubCommandRemoveButton(DiscordCommand parent) {
|
protected SubCommandRemoveButton(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -29,6 +31,11 @@ public class SubCommandRemoveButton extends SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpMessage() {
|
public String getHelpMessage() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandResults extends SubCommand {
|
public class SubCommandResults extends SubCommand {
|
||||||
protected SubCommandResults(DiscordCommand parent) {
|
protected SubCommandResults(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -26,6 +28,11 @@ public class SubCommandResults extends SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpMessage() {
|
public String getHelpMessage() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.alttd.commandManager.listeners;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.CommandManager;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.events.ReadyEvent;
|
||||||
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class JDAListener extends ListenerAdapter {
|
||||||
|
|
||||||
|
private final JDA jda;
|
||||||
|
|
||||||
|
public JDAListener(JDA jda) {
|
||||||
|
this.jda = jda;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReady(@NotNull ReadyEvent event) {
|
||||||
|
Logger.info("JDA ready registering commands.");
|
||||||
|
jda.addEventListener(new CommandManager(jda));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.alttd.config;
|
package com.alttd.config;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
|
|
||||||
public class SettingsConfig extends AbstractConfig {
|
public class SettingsConfig extends AbstractConfig {
|
||||||
|
|
||||||
static SettingsConfig settingsConfig;
|
static SettingsConfig settingsConfig;
|
||||||
|
|
@ -36,4 +38,22 @@ public class SettingsConfig extends AbstractConfig {
|
||||||
DATABASE_PASSWORD = settingsConfig.getString("settings.database_password", DATABASE_PASSWORD);
|
DATABASE_PASSWORD = settingsConfig.getString("settings.database_password", DATABASE_PASSWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String STATUS = "ONLINE";
|
||||||
|
public static String ACTIVITY = "Testing";
|
||||||
|
private void loadActivity() {
|
||||||
|
STATUS = settingsConfig.getString("settings.status", STATUS);
|
||||||
|
ACTIVITY = settingsConfig.getString("settings.activity", ACTIVITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setActivity(String newActivity) {
|
||||||
|
ACTIVITY = newActivity;
|
||||||
|
settingsConfig.set("settings.activity", ACTIVITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setStatus(String status) {
|
||||||
|
STATUS = status;
|
||||||
|
settingsConfig.set("settings.activity", STATUS);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
43
src/main/java/com/alttd/console/ConsoleActivity.java
Normal file
43
src/main/java/com/alttd/console/ConsoleActivity.java
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.alttd.console;
|
||||||
|
|
||||||
|
import com.alttd.config.SettingsConfig;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ConsoleActivity extends ConsoleCommand {
|
||||||
|
private final JDA jda;
|
||||||
|
|
||||||
|
public ConsoleActivity(JDA jda) {
|
||||||
|
super();
|
||||||
|
this.jda = jda;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "activity";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(String command, String[] args) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
Activity activity = jda.getPresence().getActivity();
|
||||||
|
if (activity == null)
|
||||||
|
Logger.info("No activity found.");
|
||||||
|
else
|
||||||
|
Logger.info("Current activity: Listening to " + activity.getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String newActivity = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
|
||||||
|
SettingsConfig.setActivity(newActivity);
|
||||||
|
jda.getPresence().setActivity(Activity.listening(newActivity));
|
||||||
|
Logger.info("Set activity to: Listening to " + newActivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return "activity [set] [text] Display the current activity or set it.";
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/main/java/com/alttd/console/ConsoleCommand.java
Normal file
11
src/main/java/com/alttd/console/ConsoleCommand.java
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.alttd.console;
|
||||||
|
|
||||||
|
public abstract class ConsoleCommand {
|
||||||
|
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
public abstract void execute(String command, String[] args);
|
||||||
|
|
||||||
|
public abstract String getHelpMessage();
|
||||||
|
|
||||||
|
}
|
||||||
54
src/main/java/com/alttd/console/ConsoleCommandManager.java
Normal file
54
src/main/java/com/alttd/console/ConsoleCommandManager.java
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.alttd.console;
|
||||||
|
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class ConsoleCommandManager {
|
||||||
|
|
||||||
|
private final List<ConsoleCommand> commands = new ArrayList<>();
|
||||||
|
private static ConsoleCommandManager instance = null;
|
||||||
|
|
||||||
|
private ConsoleCommandManager(JDA jda) {
|
||||||
|
commands.addAll(List.of(
|
||||||
|
new ConsoleActivity(jda),
|
||||||
|
new ConsoleHelp(this),
|
||||||
|
new ConsoleReload(),
|
||||||
|
new ConsoleStatus(jda),
|
||||||
|
new ConsoleStop()));
|
||||||
|
new Thread(() -> {
|
||||||
|
while (true)
|
||||||
|
instance.readCommand(new Scanner(System.in));
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readCommand(Scanner scanner) {
|
||||||
|
System.out.print("command: ");
|
||||||
|
String[] args = scanner.nextLine().toLowerCase().split(" +");
|
||||||
|
if (args.length == 0 || args[0].length() == 0)
|
||||||
|
return;
|
||||||
|
String command = args[0];
|
||||||
|
Optional<ConsoleCommand> first = commands.stream()
|
||||||
|
.filter(consoleCommand -> consoleCommand.getName().equalsIgnoreCase(command))
|
||||||
|
.findFirst();
|
||||||
|
if (first.isEmpty()) {
|
||||||
|
Logger.info("Invalid command, see help for more info.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
first.get().execute(command, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<ConsoleCommand> getCommands() {
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void startConsoleCommands(JDA jda) {
|
||||||
|
Logger.info("Starting console commands");
|
||||||
|
if (instance == null)
|
||||||
|
instance = new ConsoleCommandManager(jda);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/main/java/com/alttd/console/ConsoleHelp.java
Normal file
34
src/main/java/com/alttd/console/ConsoleHelp.java
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.alttd.console;
|
||||||
|
|
||||||
|
import com.alttd.templates.Parser;
|
||||||
|
import com.alttd.templates.Template;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ConsoleHelp extends ConsoleCommand {
|
||||||
|
ConsoleCommandManager commandManager;
|
||||||
|
|
||||||
|
public ConsoleHelp(ConsoleCommandManager instance) {
|
||||||
|
super();
|
||||||
|
commandManager = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "help";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(String command, String[] args) {
|
||||||
|
Template template = Template.of("commands", commandManager.getCommands().stream()
|
||||||
|
.map(ConsoleCommand::getHelpMessage)
|
||||||
|
.collect(Collectors.joining("\n")));
|
||||||
|
Logger.info(Parser.parse("Commands:\n<commands>", template));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return "help - Shows this help menu";
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/main/java/com/alttd/console/ConsoleReload.java
Normal file
37
src/main/java/com/alttd/console/ConsoleReload.java
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.alttd.console;
|
||||||
|
|
||||||
|
import com.alttd.config.MessagesConfig;
|
||||||
|
import com.alttd.config.SettingsConfig;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
|
||||||
|
public class ConsoleReload extends ConsoleCommand {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "reload";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(String command, String[] args) {
|
||||||
|
if (args.length != 2) {
|
||||||
|
Logger.info("Invalid argument length: " + getHelpMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (args[1]) {
|
||||||
|
case "config" -> {
|
||||||
|
MessagesConfig.reload();
|
||||||
|
Logger.info("Reloaded Messages config.");
|
||||||
|
SettingsConfig.reload();
|
||||||
|
Logger.info("Reloaded Settings config.");
|
||||||
|
}
|
||||||
|
case "database" -> {
|
||||||
|
Logger.info("NOT IMPLEMENTED YET");
|
||||||
|
}
|
||||||
|
default -> Logger.info("Invalid argument: " + args[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return "reload <config/database> - Reload the configs or databases";
|
||||||
|
}
|
||||||
|
}
|
||||||
53
src/main/java/com/alttd/console/ConsoleStatus.java
Normal file
53
src/main/java/com/alttd/console/ConsoleStatus.java
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.alttd.console;
|
||||||
|
|
||||||
|
import com.alttd.config.SettingsConfig;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.OnlineStatus;
|
||||||
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ConsoleStatus extends ConsoleCommand{
|
||||||
|
|
||||||
|
private final JDA jda;
|
||||||
|
|
||||||
|
public ConsoleStatus(JDA jda) {
|
||||||
|
this.jda = jda;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "status";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(String command, String[] args) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
OnlineStatus status = jda.getPresence().getStatus();
|
||||||
|
Logger.info("Current status: " + status.getKey());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args.length != 2) {
|
||||||
|
Logger.info("Invalid argument length.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
OnlineStatus status = OnlineStatus.fromKey(args[1].toLowerCase());
|
||||||
|
SettingsConfig.setStatus(status.getKey());
|
||||||
|
jda.getPresence().setStatus(status);
|
||||||
|
Logger.info("Set status to: " + SettingsConfig.STATUS);
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
Logger.info("Invalid status please use any of the following "
|
||||||
|
+ Arrays.stream(OnlineStatus.values())
|
||||||
|
.map(OnlineStatus::getKey)
|
||||||
|
.collect(Collectors.joining(", ")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return "status [set] [status] - Display the current status or set it";
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/main/java/com/alttd/console/ConsoleStop.java
Normal file
23
src/main/java/com/alttd/console/ConsoleStop.java
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.alttd.console;
|
||||||
|
|
||||||
|
import com.alttd.AltitudeBot;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
|
||||||
|
public class ConsoleStop extends ConsoleCommand {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "stop";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(String command, String[] args) {
|
||||||
|
Logger.info("Stopping bot...");
|
||||||
|
AltitudeBot.getInstance().getJDA().cancelRequests();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return "stop - Stop the bot";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ import java.sql.SQLException;
|
||||||
|
|
||||||
public class DatabaseTables {
|
public class DatabaseTables {
|
||||||
|
|
||||||
|
private static DatabaseTables instance = null;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
protected DatabaseTables (Connection connection) {
|
protected DatabaseTables (Connection connection) {
|
||||||
|
|
@ -44,7 +45,7 @@ public class DatabaseTables {
|
||||||
"active BIT DEFAULT b'0', " +
|
"active BIT DEFAULT b'0', " +
|
||||||
"poll_title VARCHAR(256) NOT NULL, " +
|
"poll_title VARCHAR(256) NOT NULL, " +
|
||||||
"embed_type VARCHAR(32) DEFAULT 'ABSTRACT_EMBED', " +
|
"embed_type VARCHAR(32) DEFAULT 'ABSTRACT_EMBED', " +
|
||||||
"PRIMARY KEY (UUID, villager_type)" +
|
"PRIMARY KEY (poll_id)" +
|
||||||
")";
|
")";
|
||||||
connection.prepareStatement(sql).executeUpdate();
|
connection.prepareStatement(sql).executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
@ -53,4 +54,24 @@ public class DatabaseTables {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createCommandsTable() {
|
||||||
|
try {
|
||||||
|
String sql = "CREATE TABLE IF NOT EXISTS commands(" +
|
||||||
|
"command_name VARCHAR(64) NOT NULL, " +
|
||||||
|
"scope VARCHAR(16) NOT NULL, " +
|
||||||
|
"location_id BIGINT NOT NULL, " +
|
||||||
|
"PRIMARY KEY (command_name, scope, location_id)" +
|
||||||
|
")";
|
||||||
|
connection.prepareStatement(sql).executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Logger.sql(e);
|
||||||
|
Logger.severe("Unable to create polls table, shutting down...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createTables(Connection connection) {
|
||||||
|
if (instance == null)
|
||||||
|
instance = new DatabaseTables(connection);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,15 @@ public class PermissionManager {
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a user has a certain permission and if that permission is enabled in the specified channel
|
||||||
|
*
|
||||||
|
* @param textChannel Text channel command was executed in
|
||||||
|
* @param member Member to check permission for
|
||||||
|
* @param permission Permission to check for
|
||||||
|
*
|
||||||
|
* @return True if the member has permission or is owner, false if not
|
||||||
|
*/
|
||||||
public boolean hasPermission(TextChannel textChannel, Member member, String permission) {
|
public boolean hasPermission(TextChannel textChannel, Member member, String permission) {
|
||||||
return hasPermission(textChannel,
|
return hasPermission(textChannel,
|
||||||
member.getIdLong(),
|
member.getIdLong(),
|
||||||
|
|
@ -34,12 +43,24 @@ public class PermissionManager {
|
||||||
permission);
|
permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a user has a certain permission and if that permission is enabled in the specified channel
|
||||||
|
*
|
||||||
|
* @param textChannel Text channel command was executed in
|
||||||
|
* @param userId ID of the user to check for
|
||||||
|
* @param groupIds List of group id's a user has (can be null or empty)
|
||||||
|
* @param permission Permission to check for
|
||||||
|
*
|
||||||
|
* @return True if the user has permission or is owner, false if not
|
||||||
|
*/
|
||||||
public boolean hasPermission(TextChannel textChannel, long userId, List<Long> groupIds, String permission) {
|
public boolean hasPermission(TextChannel textChannel, long userId, List<Long> groupIds, String permission) {
|
||||||
permission = permission.toLowerCase();
|
permission = permission.toLowerCase();
|
||||||
if (textChannel instanceof PrivateChannel) {
|
if (textChannel instanceof PrivateChannel) {
|
||||||
if (isDisabled(privateEnabledCommands, permission))
|
if (isDisabled(privateEnabledCommands, permission))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
if (textChannel.getGuild().getOwnerIdLong() == userId)
|
||||||
|
return true;
|
||||||
if (isDisabled(channelEnabledCommands.get(textChannel.getIdLong()), permission.toLowerCase()))
|
if (isDisabled(channelEnabledCommands.get(textChannel.getIdLong()), permission.toLowerCase()))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -70,6 +91,11 @@ public class PermissionManager {
|
||||||
return permissions.contains(permission);
|
return permissions.contains(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the permission manager instance
|
||||||
|
*
|
||||||
|
* @return Permission manager instance
|
||||||
|
*/
|
||||||
public static PermissionManager getInstance() {
|
public static PermissionManager getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ public class Logger { //TODO make this log to a file
|
||||||
if (!logDir.exists())
|
if (!logDir.exists())
|
||||||
{
|
{
|
||||||
if (!logDir.mkdir()) {
|
if (!logDir.mkdir()) {
|
||||||
System.out.println("UNABLE TO CREATE LOGGING DIRECTORY");
|
Logger.info("UNABLE TO CREATE LOGGING DIRECTORY");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.alttd.util;
|
||||||
|
|
||||||
import com.alttd.commandManager.CommandManager;
|
import com.alttd.commandManager.CommandManager;
|
||||||
import com.alttd.commandManager.ScopeInfo;
|
import com.alttd.commandManager.ScopeInfo;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubOption;
|
||||||
import com.alttd.config.MessagesConfig;
|
import com.alttd.config.MessagesConfig;
|
||||||
import com.alttd.templates.Parser;
|
import com.alttd.templates.Parser;
|
||||||
import com.alttd.templates.Template;
|
import com.alttd.templates.Template;
|
||||||
|
|
@ -113,9 +113,9 @@ public class Util {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerSubcommands(HashMap<String, SubCommand> subCommandMap, SubCommand... subCommands) {
|
public static void registerSubOptions(HashMap<String, SubOption> subCommandMap, SubOption... subOptions) {
|
||||||
for (SubCommand subCommand : subCommands)
|
for (SubOption subOption : subOptions)
|
||||||
subCommandMap.put(subCommand.getName(), subCommand);
|
subCommandMap.put(subOption.getName(), subOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean validateGuildMessageChannel(SlashCommandInteraction interaction, GuildMessageChannel channel, ChannelType channelType, @NotNull Member member) {
|
public static boolean validateGuildMessageChannel(SlashCommandInteraction interaction, GuildMessageChannel channel, ChannelType channelType, @NotNull Member member) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user