Skip to content

Commit 576867d

Browse files
author
Dynxsty
authored
Merge pull request #12 from Java-Discord/andrew/external_command_data
Clean Up Slash Command Design
2 parents 34f786e + 8b5ce94 commit 576867d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1691
-2181
lines changed

build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ dependencies {
1818
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
1919

2020
compile 'net.dv8tion:JDA:4.3.0_277'
21-
compile 'com.jagrosh:jda-utilities:3.0.5'
2221
compile 'org.mongodb:mongodb-driver:3.6.0'
2322
compile 'com.google.code.gson:gson:2.8.6'
23+
compile 'org.yaml:snakeyaml:1.29'
2424

2525
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.14.0'
2626
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.14.0'
@@ -37,9 +37,6 @@ dependencies {
3737
//compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.4'
3838
//compile group: 'com.jcabi', name: 'jcabi-aspects', version: '0.22.6'
3939
//compile 'com.jagrosh:jda-utilities-doc:3.0.5'
40-
41-
// Reflections API
42-
compile group: 'org.reflections', name: 'reflections', version: '0.9.12'
4340
}
4441

4542
jar {
Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
package com.javadiscord.javabot;
22

3-
import com.jagrosh.jdautilities.command.Command;
4-
import com.jagrosh.jdautilities.command.CommandClient;
5-
import com.jagrosh.jdautilities.command.CommandClientBuilder;
6-
import com.javadiscord.javabot.commands.other.Version;
73
import com.javadiscord.javabot.events.*;
84
import com.javadiscord.javabot.properties.MultiProperties;
95
import net.dv8tion.jda.api.JDA;
106
import net.dv8tion.jda.api.JDABuilder;
117
import net.dv8tion.jda.api.OnlineStatus;
12-
import net.dv8tion.jda.api.entities.Activity;
138
import net.dv8tion.jda.api.requests.GatewayIntent;
149
import net.dv8tion.jda.api.utils.MemberCachePolicy;
1510
import net.dv8tion.jda.api.utils.cache.CacheFlag;
16-
import org.reflections.Reflections;
1711

18-
import java.lang.reflect.Modifier;
1912
import java.nio.file.Path;
20-
import java.util.List;
21-
import java.util.Objects;
2213
import java.util.Properties;
23-
import java.util.concurrent.TimeUnit;
24-
2514

2615
public class Bot {
2716
private static final Properties properties = new MultiProperties(
@@ -30,22 +19,17 @@ public class Bot {
3019

3120
);
3221

22+
public static SlashCommands slashCommands;
23+
3324
public static void main(String[] args) throws Exception {
34-
CommandClient client = new CommandClientBuilder()
35-
.setOwnerId(getProperty("ownerId"))
36-
.setCoOwnerIds(getProperty("coOwnerIds").split("\\s*,\\s*"))
37-
.setPrefix(getProperty("prefix"))
38-
.setEmojis(getProperty("emojis.success"), getProperty("emojis.warning"), getProperty("emojis.error"))
39-
.useHelpBuilder(false)
40-
.addCommands(discoverCommands())
41-
.build();
25+
slashCommands = new SlashCommands();
4226

4327
JDA jda = JDABuilder.createDefault(properties.getProperty("token", "null"))
4428
.setStatus(OnlineStatus.DO_NOT_DISTURB)
4529
.setMemberCachePolicy(MemberCachePolicy.ALL)
4630
.enableCache(CacheFlag.ACTIVITY)
4731
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES)
48-
.addEventListeners(client, new SlashCommands(client))
32+
.addEventListeners(slashCommands)
4933
.build();
5034

5135
//EVENTS
@@ -81,30 +65,5 @@ public static String getProperty(String key) {
8165
public static String getProperty(String key, String defaultValue) {
8266
return properties.getProperty(key, defaultValue);
8367
}
84-
85-
/**
86-
* Discovers and instantiates all commands found in the bot's "commands"
87-
* package. This uses the reflections API to find all classes in that
88-
* package which extend from the base {@link Command} class.
89-
* <p>
90-
* <strong>All command classes MUST have a no-args constructor.</strong>
91-
* </p>
92-
* @return The array of commands.
93-
*/
94-
private static Command[] discoverCommands() {
95-
Reflections reflections = new Reflections(getProperty("commandsPackage"));
96-
return reflections.getSubTypesOf(Command.class).stream()
97-
.map(type -> {
98-
try {
99-
if (Modifier.isAbstract(type.getModifiers())) return null;
100-
return (Command) type.getDeclaredConstructor().newInstance();
101-
} catch (Exception e) {
102-
e.printStackTrace();
103-
return null;
104-
}
105-
})
106-
.filter(Objects::nonNull)
107-
.toArray(Command[]::new);
108-
}
10968
}
11069

0 commit comments

Comments
 (0)