11package 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 ;
73import com .javadiscord .javabot .events .*;
84import com .javadiscord .javabot .properties .MultiProperties ;
95import net .dv8tion .jda .api .JDA ;
106import net .dv8tion .jda .api .JDABuilder ;
117import net .dv8tion .jda .api .OnlineStatus ;
12- import net .dv8tion .jda .api .entities .Activity ;
138import net .dv8tion .jda .api .requests .GatewayIntent ;
149import net .dv8tion .jda .api .utils .MemberCachePolicy ;
1510import net .dv8tion .jda .api .utils .cache .CacheFlag ;
16- import org .reflections .Reflections ;
1711
18- import java .lang .reflect .Modifier ;
1912import java .nio .file .Path ;
20- import java .util .List ;
21- import java .util .Objects ;
2213import java .util .Properties ;
23- import java .util .concurrent .TimeUnit ;
24-
2514
2615public 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