All in a days work mate
This commit is contained in:
parent
7a485e9869
commit
0478c6df63
1
.idea/.name
Normal file
1
.idea/.name
Normal file
@ -0,0 +1 @@
|
||||
ModBot
|
8
.idea/inspectionProfiles/Project_Default.xml
Normal file
8
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,java.net.URLClassLoader,newInstance" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -7,7 +7,7 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import tech.nevets.modbot.api.BotModule;
|
||||
import tech.nevets.modbot.api.IBotModule;
|
||||
import tech.nevets.modbot.api.Config;
|
||||
import tech.nevets.modbot.util.commands.CoreListener;
|
||||
|
||||
@ -19,7 +19,7 @@ public class CoreBot {
|
||||
public static final Config CORE_CONFIG = new Config("core");
|
||||
public static final List<ListenerAdapter> PLUGIN_LISTENERS = new ArrayList<>();
|
||||
private static String botPrefix;
|
||||
private static List<BotModule> modules;
|
||||
private static List<IBotModule> modules;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CoreBot.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -45,7 +45,7 @@ public class CoreBot {
|
||||
}
|
||||
|
||||
coreListener.getCommandRegistry().registerSlashCommands();
|
||||
for (BotModule module : modules) {
|
||||
for (IBotModule module : modules) {
|
||||
if (module.loadCommandRegistry() == null) {
|
||||
LOGGER.warn("Module has no commands to load");
|
||||
} else {
|
||||
|
@ -2,7 +2,7 @@ package tech.nevets.modbot;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import tech.nevets.modbot.api.BotModule;
|
||||
import tech.nevets.modbot.api.IBotModule;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -42,9 +42,12 @@ public class ModuleLoader {
|
||||
return modules;
|
||||
}
|
||||
|
||||
public static List<BotModule> loadModules() {
|
||||
//TODO: make this dynamically wrap all interface modules into abstract modules
|
||||
//TODO: handle both types of modules
|
||||
|
||||
public static List<IBotModule> loadModules() {
|
||||
List<Path> modulePaths = getModules();
|
||||
List<BotModule> modules = new ArrayList<>();
|
||||
List<IBotModule> modules = new ArrayList<>();
|
||||
|
||||
for (Path module : modulePaths) {
|
||||
JarInputStream jarStream;
|
||||
@ -87,9 +90,20 @@ public class ModuleLoader {
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
BotModule newModule;
|
||||
|
||||
String moduleType = attributes.getValue("Module-Type");
|
||||
if (moduleType.equalsIgnoreCase("inherit") || moduleType.equalsIgnoreCase("i")) {
|
||||
|
||||
} else if (moduleType.equalsIgnoreCase("extend") || moduleType.equalsIgnoreCase("e")) {
|
||||
|
||||
} else {
|
||||
LOGGER.error("Error loading module: Module " + module.toString() + " has an invalid Module-Type!");
|
||||
continue;
|
||||
}
|
||||
|
||||
IBotModule newModule;
|
||||
try {
|
||||
newModule = (BotModule) mainClass.getDeclaredConstructor().newInstance();
|
||||
newModule = (IBotModule) mainClass.getDeclaredConstructor().newInstance();
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
LOGGER.error("Error while creating instance of module " + module.toString());
|
||||
e.printStackTrace();
|
||||
@ -109,7 +123,7 @@ public class ModuleLoader {
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.debug("Loaded module: " + modules.toArray().toString());
|
||||
LOGGER.info("Loaded module: " + modules.toArray().toString());
|
||||
return modules;
|
||||
}
|
||||
}
|
||||
|
@ -3,16 +3,22 @@ package tech.nevets.modbot.api;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import tech.nevets.modbot.api.commands.CommandRegistry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
abstract class BotModule {
|
||||
private String moduleName;
|
||||
|
||||
public interface BotModule {
|
||||
public BotModule(String moduleName) {
|
||||
this.moduleName = moduleName;
|
||||
}
|
||||
|
||||
default void onPreEnable() {}
|
||||
public String getModuleName() {
|
||||
return moduleName;
|
||||
}
|
||||
|
||||
CommandRegistry loadCommandRegistry();
|
||||
void onPreEnable() {}
|
||||
|
||||
void onEnable(JDA jda);
|
||||
abstract CommandRegistry loadCommandRegistry();
|
||||
|
||||
void onDisable();
|
||||
abstract void onEnable(JDA jda);
|
||||
|
||||
abstract void onDisable();
|
||||
}
|
||||
|
21
src/main/java/tech/nevets/modbot/api/IBotModule.java
Normal file
21
src/main/java/tech/nevets/modbot/api/IBotModule.java
Normal file
@ -0,0 +1,21 @@
|
||||
package tech.nevets.modbot.api;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import tech.nevets.modbot.api.commands.CommandRegistry;
|
||||
|
||||
public interface IBotModule {
|
||||
|
||||
String moduleName = "";
|
||||
|
||||
default void setModuleName(String moduleName) {
|
||||
this.moduleName = moduleName;
|
||||
}
|
||||
|
||||
default void onPreEnable() {}
|
||||
|
||||
CommandRegistry loadCommandRegistry();
|
||||
|
||||
void onEnable(JDA jda);
|
||||
|
||||
void onDisable();
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package tech.nevets.modbot.api.commands.test;
|
||||
|
||||
public interface Icmd {
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package tech.nevets.modbot.api.commands.test;
|
||||
|
||||
public class cmd {
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package tech.nevets.modbot.api.commands.test;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import tech.nevets.modbot.api.commands.CommandRegistry;
|
||||
|
||||
public interface iicmd {
|
||||
|
||||
default void onPreEnable() {}
|
||||
|
||||
CommandRegistry loadCommandRegistry();
|
||||
|
||||
void onEnable(JDA jda);
|
||||
|
||||
void onDisable();
|
||||
}
|
Loading…
Reference in New Issue
Block a user