Converted all commands

Well, haven't finished the role command
This commit is contained in:
Norbi Peti 2019-02-22 00:44:13 +01:00
parent 0c9da49add
commit 325b094bf7
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
15 changed files with 130 additions and 267 deletions

View file

@ -16,7 +16,7 @@ import sx.blah.discord.handle.obj.IMessage;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
public class AnnouncerModule extends Component { public class AnnouncerModule extends Component<DiscordPlugin> {
public ConfigData<IChannel> channel() { public ConfigData<IChannel> channel() {
return DPUtils.channelData(getConfig(), "channel", 239519012529111040L); return DPUtils.channelData(getConfig(), "channel", 239519012529111040L);
} }

View file

@ -1,15 +1,11 @@
package buttondevteam.discordplugin; package buttondevteam.discordplugin;
import buttondevteam.discordplugin.broadcaster.GeneralEventBroadcasterModule; import buttondevteam.discordplugin.broadcaster.GeneralEventBroadcasterModule;
import buttondevteam.discordplugin.commands.Command2DC; import buttondevteam.discordplugin.commands.*;
import buttondevteam.discordplugin.commands.DiscordCommandBase;
import buttondevteam.discordplugin.commands.UserinfoCommand;
import buttondevteam.discordplugin.commands.VersionCommand;
import buttondevteam.discordplugin.exceptions.ExceptionListenerModule; import buttondevteam.discordplugin.exceptions.ExceptionListenerModule;
import buttondevteam.discordplugin.fun.FunModule; import buttondevteam.discordplugin.fun.FunModule;
import buttondevteam.discordplugin.listeners.CommonListeners; import buttondevteam.discordplugin.listeners.CommonListeners;
import buttondevteam.discordplugin.listeners.MCListener; import buttondevteam.discordplugin.listeners.MCListener;
import buttondevteam.discordplugin.mcchat.ChannelconCommand;
import buttondevteam.discordplugin.mcchat.MCChatPrivate; import buttondevteam.discordplugin.mcchat.MCChatPrivate;
import buttondevteam.discordplugin.mcchat.MCChatUtils; import buttondevteam.discordplugin.mcchat.MCChatUtils;
import buttondevteam.discordplugin.mcchat.MinecraftChatModule; import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
@ -126,10 +122,11 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
Component.registerComponent(this, new FunModule()); Component.registerComponent(this, new FunModule());
new ChromaBot(this).updatePlayerList(); //Initialize ChromaBot - The MCCHatModule is tested to be enabled new ChromaBot(this).updatePlayerList(); //Initialize ChromaBot - The MCCHatModule is tested to be enabled
DiscordCommandBase.registerCommands();
getManager().registerCommand(new VersionCommand()); getManager().registerCommand(new VersionCommand());
getManager().registerCommand(new UserinfoCommand()); getManager().registerCommand(new UserinfoCommand());
getManager().registerCommand(new ChannelconCommand()); getManager().registerCommand(new HelpCommand());
getManager().registerCommand(new DebugCommand());
getManager().registerCommand(new ConnectCommand());
if (ResetMCCommand.resetting) //These will only execute if the chat is enabled if (ResetMCCommand.resetting) //These will only execute if the chat is enabled
ChromaBot.getInstance().sendMessageCustomAsWell("", new EmbedBuilder().withColor(Color.CYAN) ChromaBot.getInstance().sendMessageCustomAsWell("", new EmbedBuilder().withColor(Color.CYAN)
.withTitle("Discord plugin restarted - chat connected.").build(), ChannelconBroadcast.RESTART); //Really important to note the chat, hmm .withTitle("Discord plugin restarted - chat connected.").build(), ChannelconBroadcast.RESTART); //Really important to note the chat, hmm

View file

@ -1,11 +1,12 @@
package buttondevteam.discordplugin.broadcaster; package buttondevteam.discordplugin.broadcaster;
import buttondevteam.discordplugin.DPUtils; import buttondevteam.discordplugin.DPUtils;
import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.Component;
import lombok.Getter; import lombok.Getter;
public class GeneralEventBroadcasterModule extends Component { public class GeneralEventBroadcasterModule extends Component<DiscordPlugin> {
private static @Getter boolean hooked = false; private static @Getter boolean hooked = false;
@Override @Override

View file

@ -3,26 +3,10 @@ package buttondevteam.discordplugin.commands;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.Command2;
import java.util.HashMap;
import java.util.function.Function;
public class Command2DC extends Command2<ICommand2DC, Command2DCSender> { public class Command2DC extends Command2<ICommand2DC, Command2DCSender> {
private HashMap<String, SubcommandData<ICommand2DC>> subcommands = new HashMap<>();
private HashMap<Class<?>, ParamConverter<?>> paramConverters = new HashMap<>();
@Override
public <T> void addParamConverter(Class<T> cl, Function<String, T> converter, String errormsg) {
addParamConverter(cl, converter, errormsg, paramConverters);
}
@Override
public boolean handleCommand(Command2DCSender sender, String commandLine) throws Exception {
return handleCommand(sender, commandLine, subcommands, paramConverters);
}
@Override @Override
public void registerCommand(ICommand2DC command) { public void registerCommand(ICommand2DC command) {
registerCommand(command, subcommands, DiscordPlugin.getPrefix()); //Needs to be configurable for the helps super.registerCommand(command, DiscordPlugin.getPrefix()); //Needs to be configurable for the helps
} }
@Override @Override

View file

@ -1,76 +1,61 @@
package buttondevteam.discordplugin.commands; package buttondevteam.discordplugin.commands;
import buttondevteam.discordplugin.DiscordPlayer; import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.player.TBMCPlayerBase; import buttondevteam.lib.chat.CommandClass;
import com.google.common.collect.HashBiMap; import buttondevteam.lib.player.TBMCPlayer;
import org.bukkit.Bukkit; import buttondevteam.lib.player.TBMCPlayerBase;
import org.bukkit.OfflinePlayer; import com.google.common.collect.HashBiMap;
import org.bukkit.entity.Player; import org.bukkit.Bukkit;
import sx.blah.discord.handle.obj.IMessage; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public class ConnectCommand extends DiscordCommandBase { import sx.blah.discord.handle.obj.IMessage;
@Override @CommandClass(helpText = {
public String getCommandName() { "Connect command", //
return "connect"; "This command lets you connect your account with a Minecraft account. This allows using the Minecraft chat and other things.", //
} })
public class ConnectCommand extends ICommand2DC {
/**
* Key: Minecraft name<br> /**
* Value: Discord ID * Key: Minecraft name<br>
*/ * Value: Discord ID
public static HashBiMap<String, String> WaitingToConnect = HashBiMap.create(); */
public static HashBiMap<String, String> WaitingToConnect = HashBiMap.create();
@Override
public boolean run(IMessage message, String args) { @Command2.Subcommand
if (args.length() == 0) public boolean def(IMessage message, String Minecraftname) {
return false; if (WaitingToConnect.inverse().containsKey(message.getAuthor().getStringID())) {
if (args.contains(" ")) { DiscordPlugin.sendMessageToChannel(message.getChannel(),
DiscordPlugin.sendMessageToChannel(message.getChannel(), "Replacing " + WaitingToConnect.inverse().get(message.getAuthor().getStringID()) + " with " + Minecraftname);
"Too many arguments.\nUsage: " + DiscordPlugin.getPrefix() + "connect <Minecraftname>"); WaitingToConnect.inverse().remove(message.getAuthor().getStringID());
return true; }
} @SuppressWarnings("deprecation")
if (WaitingToConnect.inverse().containsKey(message.getAuthor().getStringID())) { OfflinePlayer p = Bukkit.getOfflinePlayer(Minecraftname);
DiscordPlugin.sendMessageToChannel(message.getChannel(), if (p == null) {
"Replacing " + WaitingToConnect.inverse().get(message.getAuthor().getStringID()) + " with " + args); DiscordPlugin.sendMessageToChannel(message.getChannel(), "The specified Minecraft player cannot be found");
WaitingToConnect.inverse().remove(message.getAuthor().getStringID()); return true;
} }
@SuppressWarnings("deprecation") try (TBMCPlayer pl = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class)) {
OfflinePlayer p = Bukkit.getOfflinePlayer(args); DiscordPlayer dp = pl.getAs(DiscordPlayer.class);
if (p == null) { if (dp != null && message.getAuthor().getStringID().equals(dp.getDiscordID())) {
DiscordPlugin.sendMessageToChannel(message.getChannel(), "The specified Minecraft player cannot be found"); DiscordPlugin.sendMessageToChannel(message.getChannel(), "You already have this account connected.");
return true; return true;
} }
try (TBMCPlayer pl = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class)) { } catch (Exception e) {
DiscordPlayer dp = pl.getAs(DiscordPlayer.class); TBMCCoreAPI.SendException("An error occured while connecting a Discord account!", e);
if (dp != null && message.getAuthor().getStringID().equals(dp.getDiscordID())) { DiscordPlugin.sendMessageToChannel(message.getChannel(), "An internal error occured!\n" + e);
DiscordPlugin.sendMessageToChannel(message.getChannel(), "You already have this account connected."); }
return true; WaitingToConnect.put(p.getName(), message.getAuthor().getStringID());
} DiscordPlugin.sendMessageToChannel(message.getChannel(),
} catch (Exception e) { "Alright! Now accept the connection in Minecraft from the account " + Minecraftname
TBMCCoreAPI.SendException("An error occured while connecting a Discord account!", e); + " before the next server restart. You can also adjust the Minecraft name you want to connect to with the same command.");
DiscordPlugin.sendMessageToChannel(message.getChannel(), "An internal error occured!\n" + e); if (p.isOnline())
} ((Player) p).sendMessage("§bTo connect with the Discord account " + message.getAuthor().getName() + "#"
WaitingToConnect.put(p.getName(), message.getAuthor().getStringID()); + message.getAuthor().getDiscriminator() + " do /discord accept");
DiscordPlugin.sendMessageToChannel(message.getChannel(), return true;
"Alright! Now accept the connection in Minecraft from the account " + args }
+ " before the next server restart. You can also adjust the Minecraft name you want to connect to with the same command.");
if (p.isOnline()) }
((Player) p).sendMessage("§bTo connect with the Discord account " + message.getAuthor().getName() + "#"
+ message.getAuthor().getDiscriminator() + " do /discord accept");
return true;
}
@Override
public String[] getHelpText() {
return new String[] { //
"---- Connect command ----", //
"This command lets you connect your account with a Minecraft account. This allows using the Minecraft chat and other things.", //
"Usage: /connect <Minecraftname>" //
};
}
}

View file

@ -2,25 +2,20 @@ package buttondevteam.discordplugin.commands;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.listeners.CommonListeners; import buttondevteam.discordplugin.listeners.CommonListeners;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
import sx.blah.discord.handle.obj.IMessage; import sx.blah.discord.handle.obj.IMessage;
public class DebugCommand extends DiscordCommandBase { @CommandClass(helpText = {
@Override "Switches debug mode."
public String getCommandName() { })
return "debug"; public class DebugCommand extends ICommand2DC {
} @Command2.Subcommand
public boolean def(IMessage message, String args) {
@Override if (message.getAuthor().hasRole(DiscordPlugin.mainServer.getRoleByID(126030201472811008L))) //TODO: Make configurable
public boolean run(IMessage message, String args) {
if (message.getAuthor().hasRole(DiscordPlugin.mainServer.getRoleByID(126030201472811008L)))
message.reply("Debug " + (CommonListeners.debug() ? "enabled" : "disabled")); message.reply("Debug " + (CommonListeners.debug() ? "enabled" : "disabled"));
else else
message.reply("You need to be a moderator to use this command."); message.reply("You need to be a moderator to use this command.");
return true; return true;
} }
@Override
public String[] getHelpText() {
return new String[]{"Switches debug mode."};
}
} }

View file

@ -1,61 +0,0 @@
package buttondevteam.discordplugin.commands;
import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.mcchat.MCChatCommand;
import buttondevteam.lib.TBMCCoreAPI;
import sx.blah.discord.handle.obj.IMessage;
import java.util.Arrays;
import java.util.HashMap;
import java.util.stream.Collectors;
import static buttondevteam.discordplugin.listeners.CommonListeners.debug;
public abstract class DiscordCommandBase {
public abstract String getCommandName();
public abstract boolean run(IMessage message, String args);
public abstract String[] getHelpText();
static final HashMap<String, DiscordCommandBase> commands = new HashMap<String, DiscordCommandBase>();
public static void registerCommands() {
commands.put("connect", new ConnectCommand()); // TODO: API for adding commands?
commands.put("help", new HelpCommand());
commands.put("mcchat", new MCChatCommand());
commands.put("debug", new DebugCommand());
}
public static void runCommand(String cmd, String args, IMessage message) {
debug("F"); //Not sure if needed
DiscordCommandBase command = commands.get(cmd);
//if(command==null)
// DiscordPlugin.plugin.getManager().handleCommand(new Command2DCSender(message), cmd+" "+args); //TODO!
if (command == null) {
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"Unknown command: " + cmd + " with args: " + args + "\nDo '"
+ (message.getChannel().isPrivate() ? "" : message.getClient().getOurUser().mention() + " ")
+ "help' for help");
return;
}
debug("G");
try {
if (!command.run(message, args))
DiscordPlugin.sendMessageToChannel(message.getChannel(), Arrays.stream(command.getHelpText()).collect(Collectors.joining("\n")));
} catch (Exception e) {
TBMCCoreAPI.SendException("An error occured while executing command " + cmd + "!", e);
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"An internal error occured while executing this command. For more technical details see the server-issues channel on the dev Discord.");
}
debug("H");
}
protected String[] splitargs(String args) {
return args.split("\\s+");
}
public static void registerCommand(String name, DiscordCommandBase dcb) {
commands.put(name, dcb);
}
}

View file

@ -1,38 +1,18 @@
package buttondevteam.discordplugin.commands; package buttondevteam.discordplugin.commands;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.lib.chat.CommandClass;
import sx.blah.discord.handle.obj.IMessage;
@CommandClass(helpText = {
import java.util.stream.Collectors; "Help command", //
"Shows some info about a command or lists the available commands.", //
public class HelpCommand extends DiscordCommandBase { })
public class HelpCommand extends ICommand2DC {
@Override @Override
public String getCommandName() { public boolean def(Command2DCSender sender, String args) {
return "help"; if (args.length() == 0)
} sender.sendMessage(getManager().getCommandsText());
else
@Override sender.sendMessage("Soon:tm:"); //TODO
public boolean run(IMessage message, String args) { return true;
DiscordCommandBase argdc; }
if (args.length() == 0) }
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"Available commands:\n" + DiscordCommandBase.commands.values().stream()
.map(dc -> DiscordPlugin.getPrefix() + dc.getCommandName()).collect(Collectors.joining("\n")));
else
DiscordPlugin.sendMessageToChannel(message.getChannel(),
(argdc = DiscordCommandBase.commands.get(args)) == null ? "Command not found: " + args
: String.join("\n", argdc.getHelpText()));
return true;
}
@Override
public String[] getHelpText() {
return new String[] { //
"---- Help command ----", //
"Shows some info about a command or lists the available commands.", //
"Usage: " + DiscordPlugin.getPrefix() + "help [command]"//
};
}
}

View file

@ -19,7 +19,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ExceptionListenerModule extends Component implements Listener { public class ExceptionListenerModule extends Component<DiscordPlugin> implements Listener {
private List<Throwable> lastthrown = new ArrayList<>(); private List<Throwable> lastthrown = new ArrayList<>();
private List<String> lastsourcemsg = new ArrayList<>(); private List<String> lastsourcemsg = new ArrayList<>();

View file

@ -26,7 +26,7 @@ import java.util.Random;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream; import java.util.stream.IntStream;
public class FunModule extends Component implements Listener { public class FunModule extends Component<DiscordPlugin> implements Listener {
private static FunModule mod; private static FunModule mod;
private static final String[] serverReadyStrings = new String[]{"In one week from now", // Ali private static final String[] serverReadyStrings = new String[]{"In one week from now", // Ali

View file

@ -45,17 +45,6 @@ public class CommandListener {
} catch (Exception e) { } catch (Exception e) {
TBMCCoreAPI.SendException("Failed to process Discord command: " + cmdwithargsString, e); TBMCCoreAPI.SendException("Failed to process Discord command: " + cmdwithargsString, e);
} }
/*int index = cmdwithargsString.indexOf(" ");
String cmd;
String args;
if (index == -1) {
cmd = cmdwithargsString;
args = "";
} else {
cmd = cmdwithargsString.substring(0, index);
args = cmdwithargsString.substring(index + 1).trim(); //In case there are multiple spaces
}
DiscordCommandBase.runCommand(cmd.toLowerCase(), args, message);*/
message.getChannel().setTypingStatus(false); message.getChannel().setTypingStatus(false);
return true; return true;
} }

View file

@ -2,44 +2,38 @@ package buttondevteam.discordplugin.mcchat;
import buttondevteam.discordplugin.DiscordPlayer; import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.commands.DiscordCommandBase; import buttondevteam.discordplugin.commands.Command2DCSender;
import buttondevteam.discordplugin.commands.ICommand2DC;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import sx.blah.discord.handle.obj.IMessage; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
import lombok.val;
public class MCChatCommand extends DiscordCommandBase { @CommandClass(helpText = {
"MC Chat",
"This command enables or disables the Minecraft chat in private messages.", //
"It can be useful if you don't want your messages to be visible, for example when talking in a private channel.", //
"You can also run all of the ingame commands you have access to using this command, if you have your accounts connected." //
})
public class MCChatCommand extends ICommand2DC {
@Override @Command2.Subcommand
public String getCommandName() { public boolean def(Command2DCSender sender, String args) {
return "mcchat"; val message = sender.getMessage();
}
@Override //TODO: Only register if module is enabled
public boolean run(IMessage message, String args) {
if (!message.getChannel().isPrivate()) { if (!message.getChannel().isPrivate()) {
DiscordPlugin.sendMessageToChannel(message.getChannel(), message.reply("this command can only be issued in a direct message with the bot.");
"This command can only be issued in a direct message with the bot.");
return true; return true;
} }
try (final DiscordPlayer user = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)) { try (final DiscordPlayer user = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)) {
boolean mcchat = !user.isMinecraftChatEnabled(); boolean mcchat = !user.isMinecraftChatEnabled();
MCChatPrivate.privateMCChat(message.getChannel(), mcchat, message.getAuthor(), user); MCChatPrivate.privateMCChat(message.getChannel(), mcchat, message.getAuthor(), user);
DiscordPlugin.sendMessageToChannel(message.getChannel(), message.reply("Minecraft chat " + (mcchat //
"Minecraft chat " + (mcchat // ? "enabled. Use '" + DiscordPlugin.getPrefix() + "mcchat' again to turn it off." //
? "enabled. Use '" + DiscordPlugin.getPrefix() + "mcchat' again to turn it off." // : "disabled."));
: "disabled."));
} catch (Exception e) { } catch (Exception e) {
TBMCCoreAPI.SendException("Error while setting mcchat for user" + message.getAuthor().getName(), e); TBMCCoreAPI.SendException("Error while setting mcchat for user" + message.getAuthor().getName(), e);
} }
return true; return true;
} } // TODO: Pin channel switching to indicate the current channel
@Override
public String[] getHelpText() {
return new String[] { //
DiscordPlugin.getPrefix() + "mcchat enables or disables the Minecraft chat in private messages.", //
"It can be useful if you don't want your messages to be visible, for example when talking in a private channel.", //
"You can also run all of the ingame commands you have access to using this command, if you have your accounts connected." //
}; // TODO: Pin channel switching to indicate the current channel
}
} }

View file

@ -19,7 +19,7 @@ import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class MinecraftChatModule extends Component { public class MinecraftChatModule extends Component<DiscordPlugin> {
private @Getter MCChatListener listener; private @Getter MCChatListener listener;
public MCChatListener getListener() { //It doesn't want to generate public MCChatListener getListener() { //It doesn't want to generate
@ -45,6 +45,8 @@ public class MinecraftChatModule extends Component {
DiscordPlugin.dc.getDispatcher().registerListener(listener); DiscordPlugin.dc.getDispatcher().registerListener(listener);
TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin()); TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin());
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(this), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(this), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled
getPlugin().getManager().registerCommand(new MCChatCommand());
getPlugin().getManager().registerCommand(new ChannelconCommand());
val chcons = getConfig().getConfig().getConfigurationSection("chcons"); val chcons = getConfig().getConfig().getConfigurationSection("chcons");
if (chcons == null) //Fallback to old place if (chcons == null) //Fallback to old place

View file

@ -3,7 +3,6 @@ package buttondevteam.discordplugin.role;
import buttondevteam.core.ComponentManager; import buttondevteam.core.ComponentManager;
import buttondevteam.discordplugin.DPUtils; import buttondevteam.discordplugin.DPUtils;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.commands.DiscordCommandBase;
import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ConfigData; import buttondevteam.lib.architecture.ConfigData;
import lombok.val; import lombok.val;
@ -19,12 +18,12 @@ import java.awt.*;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class GameRoleModule extends Component { public class GameRoleModule extends Component<DiscordPlugin> {
public List<String> GameRoles; public List<String> GameRoles;
@Override @Override
protected void enable() { protected void enable() {
DiscordCommandBase.registerCommand("role", new RoleCommand(this)); getPlugin().getManager().registerCommand(new RoleCommand(this));
GameRoles = DiscordPlugin.mainServer.getRoles().stream().filter(this::isGameRole).map(IRole::getName).collect(Collectors.toList()); GameRoles = DiscordPlugin.mainServer.getRoles().stream().filter(this::isGameRole).map(IRole::getName).collect(Collectors.toList());
} }

View file

@ -2,15 +2,18 @@ package buttondevteam.discordplugin.role;
import buttondevteam.discordplugin.DPUtils; import buttondevteam.discordplugin.DPUtils;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.commands.DiscordCommandBase; import buttondevteam.discordplugin.commands.ICommand2DC;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
import sx.blah.discord.handle.obj.IMessage; import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IRole; import sx.blah.discord.handle.obj.IRole;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class RoleCommand extends DiscordCommandBase { //TODO: Use Command2's parser @CommandClass
public class RoleCommand extends ICommand2DC { //TODO
private GameRoleModule grm; private GameRoleModule grm;
@ -18,13 +21,8 @@ public class RoleCommand extends DiscordCommandBase { //TODO: Use Command2's par
this.grm = grm; this.grm = grm;
} }
@Override @Command2.Subcommand
public String getCommandName() { public boolean def(IMessage message, String args) {
return "role";
}
@Override
public boolean run(IMessage message, String args) {
if (args.length() == 0) if (args.length() == 0)
return false; return false;
String[] argsa = splitargs(args); String[] argsa = splitargs(args);