Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ dependencies {
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

compile 'net.dv8tion:JDA:4.3.0_277'
compile 'com.jagrosh:jda-utilities:3.0.5'
compile 'org.mongodb:mongodb-driver:3.6.0'
compile 'com.google.code.gson:gson:2.8.6'
compile 'org.yaml:snakeyaml:1.29'

compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.14.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.14.0'
Expand All @@ -37,9 +37,6 @@ dependencies {
//compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.4'
//compile group: 'com.jcabi', name: 'jcabi-aspects', version: '0.22.6'
//compile 'com.jagrosh:jda-utilities-doc:3.0.5'

// Reflections API
compile group: 'org.reflections', name: 'reflections', version: '0.9.12'
}

jar {
Expand Down
49 changes: 4 additions & 45 deletions src/main/java/com/javadiscord/javabot/Bot.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
package com.javadiscord.javabot;

import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandClient;
import com.jagrosh.jdautilities.command.CommandClientBuilder;
import com.javadiscord.javabot.commands.other.Version;
import com.javadiscord.javabot.events.*;
import com.javadiscord.javabot.properties.MultiProperties;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.MemberCachePolicy;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import org.reflections.Reflections;

import java.lang.reflect.Modifier;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.TimeUnit;


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

);

public static SlashCommands slashCommands;

public static void main(String[] args) throws Exception {
CommandClient client = new CommandClientBuilder()
.setOwnerId(getProperty("ownerId"))
.setCoOwnerIds(getProperty("coOwnerIds").split("\\s*,\\s*"))
.setPrefix(getProperty("prefix"))
.setEmojis(getProperty("emojis.success"), getProperty("emojis.warning"), getProperty("emojis.error"))
.useHelpBuilder(false)
.addCommands(discoverCommands())
.build();
slashCommands = new SlashCommands();

JDA jda = JDABuilder.createDefault(properties.getProperty("token", "null"))
.setStatus(OnlineStatus.DO_NOT_DISTURB)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.enableCache(CacheFlag.ACTIVITY)
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES)
.addEventListeners(client, new SlashCommands(client))
.addEventListeners(slashCommands)
.build();

//EVENTS
Expand Down Expand Up @@ -81,30 +65,5 @@ public static String getProperty(String key) {
public static String getProperty(String key, String defaultValue) {
return properties.getProperty(key, defaultValue);
}

/**
* Discovers and instantiates all commands found in the bot's "commands"
* package. This uses the reflections API to find all classes in that
* package which extend from the base {@link Command} class.
* <p>
* <strong>All command classes MUST have a no-args constructor.</strong>
* </p>
* @return The array of commands.
*/
private static Command[] discoverCommands() {
Reflections reflections = new Reflections(getProperty("commandsPackage"));
return reflections.getSubTypesOf(Command.class).stream()
.map(type -> {
try {
if (Modifier.isAbstract(type.getModifiers())) return null;
return (Command) type.getDeclaredConstructor().newInstance();
} catch (Exception e) {
e.printStackTrace();
return null;
}
})
.filter(Objects::nonNull)
.toArray(Command[]::new);
}
}

Loading