Listeners progress
This commit is contained in:
parent
30bb267366
commit
373a889f95
2
.gitignore
vendored
2
.gitignore
vendored
@ -147,4 +147,4 @@ bin/
|
||||
build
|
||||
|
||||
*-config.yml
|
||||
modules/
|
||||
modulesre/
|
||||
|
@ -8,7 +8,7 @@ plugins {
|
||||
mainClassName = 'tech.nevets.modbot.CoreBot'
|
||||
|
||||
group 'tech.nevets'
|
||||
version '1.1.0'
|
||||
version '1.2.0'
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
@ -25,7 +25,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'net.dv8tion:JDA:4.4.0_350'
|
||||
implementation 'ch.qos.logback:logback-classic:1.2.11'
|
||||
implementation 'ch.qos.logback:logback-classic:1.4.0'
|
||||
implementation 'com.google.code.gson:gson:2.9.0'
|
||||
implementation 'me.carleslc.Simple-YAML:Simple-Yaml:1.7.2'
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package tech.nevets.modbot.util.commands;
|
||||
package tech.nevets.modbot;
|
||||
|
||||
import tech.nevets.modbot.api.commands.CommandRegistry;
|
||||
import tech.nevets.modbot.api.commands.ICommand;
|
||||
import tech.nevets.modbot.api.commands.IPrefixCommand;
|
||||
import tech.nevets.modbot.api.commands.ISlashCommand;
|
||||
import tech.nevets.modbot.api.commands.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
@ -14,6 +11,20 @@ public class CommandManager {
|
||||
public static final List<IPrefixCommand> ALL_PREFIX_COMMANDS = new ArrayList<>();
|
||||
public static final List<ISlashCommand> ALL_SLASH_COMMANDS = new ArrayList<>();
|
||||
|
||||
public static void addFromRegistry(List<? extends ICommand> cmds) {
|
||||
for (ICommand cmd : cmds) {
|
||||
ALL_COMMANDS.add(cmd);
|
||||
if (cmd instanceof IPrefixCommand) {
|
||||
ALL_PREFIX_COMMANDS.add((IPrefixCommand) cmd);
|
||||
}
|
||||
if (cmd instanceof ISlashCommand) {
|
||||
ALL_SLASH_COMMANDS.add((ISlashCommand) cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void addFromRegistry(CommandRegistry registry) {
|
||||
ALL_COMMANDS.addAll(registry.getCommands());
|
||||
ALL_PREFIX_COMMANDS.addAll(registry.getPrefixCommands());
|
@ -9,7 +9,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import tech.nevets.modbot.api.BotModule;
|
||||
import tech.nevets.modbot.api.Config;
|
||||
import tech.nevets.modbot.util.commands.CoreListener;
|
||||
import tech.nevets.modbot.internal.InternalListener;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.util.*;
|
||||
@ -28,7 +28,7 @@ public class CoreBot {
|
||||
CORE_CONFIG.loadConfig();
|
||||
botPrefix = CORE_CONFIG.getConfig().getString("bot.prefix");
|
||||
modules = ModuleLoader.loadModules();
|
||||
CoreListener coreListener = new CoreListener();
|
||||
InternalListener coreListener = new InternalListener();
|
||||
|
||||
JDABuilder builder = JDABuilder.createDefault(CORE_CONFIG.getConfig().getString("bot.token"))
|
||||
.enableCache(CacheFlag.VOICE_STATE)
|
||||
|
1019
src/main/java/tech/nevets/modbot/EventExecutor.java
Normal file
1019
src/main/java/tech/nevets/modbot/EventExecutor.java
Normal file
File diff suppressed because it is too large
Load Diff
15
src/main/java/tech/nevets/modbot/Listener.java
Normal file
15
src/main/java/tech/nevets/modbot/Listener.java
Normal file
@ -0,0 +1,15 @@
|
||||
package tech.nevets.modbot;
|
||||
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import tech.nevets.modbot.api.commands.ICommand;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Listener extends ListenerAdapter {
|
||||
public final List<ICommand> commands = new ArrayList<>();
|
||||
|
||||
void addCommand(ICommand cmd) {
|
||||
commands.add(cmd);
|
||||
}
|
||||
}
|
@ -44,9 +44,6 @@ public class ModuleLoader {
|
||||
return modules;
|
||||
}
|
||||
|
||||
//TODO: make this dynamically wrap all interface modules into abstract modules
|
||||
//TODO: handle both types of modules
|
||||
|
||||
public static List<BotModule> loadModules() {
|
||||
List<Path> modulePaths = getModules();
|
||||
List<BotModule> modules = new ArrayList<>();
|
||||
@ -103,6 +100,7 @@ public class ModuleLoader {
|
||||
iNewModule = (IBotModule) mainClass.getDeclaredConstructor().newInstance();
|
||||
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
|
||||
LOGGER.error("Error while creating instance of module " + moduleName);
|
||||
//TODO: Check if setting Module-Type to inherit wile using extend breaks here
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
@ -112,6 +110,7 @@ public class ModuleLoader {
|
||||
newModule = (BotModule) mainClass.getDeclaredConstructor(String.class).newInstance(moduleName);
|
||||
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
|
||||
LOGGER.error("Error while creating instance of module " + moduleName);
|
||||
LOGGER.error("HINT: Check the Module-Type of module " + moduleName);
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
@ -137,7 +136,7 @@ public class ModuleLoader {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < modules.size(); i++) {
|
||||
sb.append(modules.get(i).getModuleName());
|
||||
if (i < modules.size()) {
|
||||
if ((i + 1) < modules.size()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
|
20
src/main/java/tech/nevets/modbot/Registry.java
Normal file
20
src/main/java/tech/nevets/modbot/Registry.java
Normal file
@ -0,0 +1,20 @@
|
||||
package tech.nevets.modbot;
|
||||
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import tech.nevets.modbot.api.commands.IPrefixCommand;
|
||||
import tech.nevets.modbot.api.commands.ISlashCommand;
|
||||
|
||||
public class Registry {
|
||||
|
||||
public static void register(IPrefixCommand cmd) {
|
||||
|
||||
}
|
||||
|
||||
public static void register(ISlashCommand cmd) {
|
||||
|
||||
}
|
||||
|
||||
public static void register(ListenerAdapter listener) {
|
||||
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ public interface IBotModule {
|
||||
|
||||
default void onPreEnable() {}
|
||||
|
||||
CommandRegistry loadCommandRegistry();
|
||||
void registry();
|
||||
|
||||
void onEnable(JDA jda);
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
package tech.nevets.modbot.util.commands;
|
||||
package tech.nevets.modbot.api.commands;
|
||||
|
||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import tech.nevets.modbot.api.commands.ICommandContext;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -8,7 +8,6 @@ import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import tech.nevets.modbot.CoreBot;
|
||||
import tech.nevets.modbot.util.commands.CommandContext;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package tech.nevets.modbot.util.commands;
|
||||
package tech.nevets.modbot.api.commands;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.*;
|
@ -1,7 +1,5 @@
|
||||
package tech.nevets.modbot.api.commands;
|
||||
|
||||
import tech.nevets.modbot.util.commands.CommandContext;
|
||||
|
||||
public interface IPrefixCommand extends ICommand {
|
||||
|
||||
void handle(CommandContext ctx);
|
||||
|
@ -1,7 +1,6 @@
|
||||
package tech.nevets.modbot.api.commands;
|
||||
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
import tech.nevets.modbot.util.commands.CommandContext;
|
||||
|
||||
public interface ISlashCommand extends ICommand {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package tech.nevets.modbot.util.commands;
|
||||
package tech.nevets.modbot.internal;
|
||||
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.ReadyEvent;
|
||||
@ -9,11 +9,14 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import tech.nevets.modbot.CoreBot;
|
||||
import tech.nevets.modbot.api.commands.CommandRegistry;
|
||||
import tech.nevets.modbot.CommandManager;
|
||||
import tech.nevets.modbot.internal.commands.HelpCmd;
|
||||
import tech.nevets.modbot.internal.commands.TestCmd;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class CoreListener extends ListenerAdapter {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CoreListener.class);
|
||||
public class InternalListener extends ListenerAdapter {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(InternalListener.class);
|
||||
private final CommandRegistry registry = new CommandRegistry();
|
||||
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
package tech.nevets.modbot.util.commands;
|
||||
package tech.nevets.modbot.internal.commands;
|
||||
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.interactions.commands.Command;
|
||||
@ -7,7 +7,9 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import tech.nevets.modbot.CommandManager;
|
||||
import tech.nevets.modbot.CoreBot;
|
||||
import tech.nevets.modbot.api.commands.CommandContext;
|
||||
import tech.nevets.modbot.api.commands.ICommand;
|
||||
import tech.nevets.modbot.api.commands.IPrefixCommand;
|
||||
import tech.nevets.modbot.api.commands.ISlashCommand;
|
@ -1,8 +1,9 @@
|
||||
package tech.nevets.modbot.util.commands;
|
||||
package tech.nevets.modbot.internal.commands;
|
||||
|
||||
import net.dv8tion.jda.api.entities.IMentionable;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
import tech.nevets.modbot.api.commands.CommandContext;
|
||||
import tech.nevets.modbot.api.commands.ISlashCommand;
|
||||
|
||||
public class TestCmd implements ISlashCommand {
|
@ -29,6 +29,6 @@ public class Pair<L,R> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Pair{" + left + ", right=" + right + "}";
|
||||
return "Pair{left=" + left + ", right=" + right + "}";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user