Moved project into bot package, added fx package, isolated Main class, added CommandHandler

This commit is contained in:
Savvy
2017-11-10 17:38:03 -05:00
parent 4e48aa3d6c
commit 835db67880
21 changed files with 113 additions and 46 deletions

View File

@@ -0,0 +1,35 @@
package io.rixa.bot.commands;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import java.util.Collections;
import java.util.List;
public abstract class Command {
@Getter @Setter private String command, description;
@Getter @Setter private RixaPermission permission;
@Getter @Setter private List<String> aliases;
public Command(String command) {
this(command, RixaPermission.NONE, "Undefined", Collections.emptyList());
}
public Command(String command, RixaPermission rixaPermission) {
this(command, rixaPermission, "Undefined", Collections.emptyList());
}
public Command(String command, RixaPermission rixaPermission, String description) {
this(command, rixaPermission, description, Collections.emptyList());
}
public Command(String command, RixaPermission rixaPermission, String description, List<String> aliases) {
setCommand(command);
setPermission(rixaPermission);
setDescription(description);
setAliases(aliases);
}
public abstract boolean execute(GuildMessageReceivedEvent event);
}

View File

@@ -0,0 +1,25 @@
package io.rixa.bot.commands;
import io.rixa.bot.commands.exceptions.CommandNotFoundException;
import java.util.HashMap;
import java.util.Map;
public class CommandHandler {
private Map<String, Command> commandMap = new HashMap<>();
public void registerCommand(Command command) {
if (commandMap.containsKey(command.getCommand())) return;
commandMap.put(command.getCommand(), command);
}
public Command getCommand(String commandName) throws CommandNotFoundException {
for(Command command: commandMap.values()) {
if (command.getAliases().contains(commandName)) {
return command;
}
}
throw new CommandNotFoundException("Could not find command");
}
}

View File

@@ -0,0 +1,14 @@
package io.rixa.bot.commands;
public enum RixaPermission {
NONE;
public static RixaPermission fromString(String string) {
for (RixaPermission value : values()) {
if (value.toString().equalsIgnoreCase(string)) {
return value;
}
}
return null;
}
}

View File

@@ -0,0 +1,17 @@
package io.rixa.bot.commands.cmds;
import io.rixa.bot.commands.Command;
import io.rixa.bot.commands.RixaPermission;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
public class HelpCommand extends Command {
public HelpCommand(String command, RixaPermission rixaPermission, String description) {
super(command, rixaPermission, description);
}
@Override
public boolean execute(GuildMessageReceivedEvent event) {
return false;
}
}

View File

@@ -0,0 +1,8 @@
package io.rixa.bot.commands.exceptions;
public class CommandNotFoundException extends Exception {
public CommandNotFoundException(String message) {
super(message);
}
}