Merge remote-tracking branch 'refs/remotes/origin/master' into Ali
# Conflicts: # src/main/java/buttondevteam/discordplugin/DiscordPlugin.java
This commit is contained in:
commit
f7c6614c2a
10 changed files with 113 additions and 18 deletions
|
@ -14,6 +14,10 @@ import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
|
import buttondevteam.discordplugin.listeners.ChatListener;
|
||||||
|
import buttondevteam.discordplugin.listeners.CommandListener;
|
||||||
|
import buttondevteam.discordplugin.listeners.ExceptionListener;
|
||||||
|
import buttondevteam.discordplugin.listeners.MCListener;
|
||||||
import buttondevteam.discordplugin.mccommands.DiscordMCCommandBase;
|
import buttondevteam.discordplugin.mccommands.DiscordMCCommandBase;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
|
@ -57,6 +61,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
dc.getDispatcher().registerListener(this);
|
dc.getDispatcher().registerListener(this);
|
||||||
for (IListener<?> listener : CommandListener.getListeners())
|
for (IListener<?> listener : CommandListener.getListeners())
|
||||||
dc.getDispatcher().registerListener(listener);
|
dc.getDispatcher().registerListener(listener);
|
||||||
|
dc.getDispatcher().registerListener(new ChatListener());
|
||||||
Bukkit.getPluginManager().registerEvents(new ExceptionListener(), this);
|
Bukkit.getPluginManager().registerEvents(new ExceptionListener(), this);
|
||||||
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this);
|
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this);
|
||||||
TBMCChatAPI.AddCommands(this, DiscordMCCommandBase.class);
|
TBMCChatAPI.AddCommands(this, DiscordMCCommandBase.class);
|
||||||
|
@ -71,6 +76,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
public static IChannel genchannel;
|
public static IChannel genchannel;
|
||||||
public static IChannel issuechannel;
|
public static IChannel issuechannel;
|
||||||
public static IChannel debugchannel;
|
public static IChannel debugchannel;
|
||||||
|
public static IChannel chatchannel;
|
||||||
|
|
||||||
public static boolean Test = true;
|
public static boolean Test = true;
|
||||||
|
|
||||||
|
@ -90,6 +96,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
genchannel = mainServer.getChannelByID("125813020357165056"); // general
|
genchannel = mainServer.getChannelByID("125813020357165056"); // general
|
||||||
issuechannel = devServer.getChannelByID("219643416496046081"); // server-issues
|
issuechannel = devServer.getChannelByID("219643416496046081"); // server-issues
|
||||||
debugchannel = devServer.getChannelByID("250332016199860224"); // debug-channel
|
debugchannel = devServer.getChannelByID("250332016199860224"); // debug-channel
|
||||||
|
chatchannel = mainServer.getChannelByID("249663564057411596"); // minecraft_chat
|
||||||
dc.changeStatus(Status.game("on TBMC"));
|
dc.changeStatus(Status.game("on TBMC"));
|
||||||
} else {
|
} else {
|
||||||
botchannel = devServer.getChannelByID("239519012529111040"); // bottest
|
botchannel = devServer.getChannelByID("239519012529111040"); // bottest
|
||||||
|
@ -97,6 +104,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
genchannel = devServer.getChannelByID("239519012529111040"); // bottest
|
genchannel = devServer.getChannelByID("239519012529111040"); // bottest
|
||||||
issuechannel = devServer.getChannelByID("239519012529111040"); // bottest
|
issuechannel = devServer.getChannelByID("239519012529111040"); // bottest
|
||||||
debugchannel = devServer.getChannelByID("239519012529111040"); //bottest
|
debugchannel = devServer.getChannelByID("239519012529111040"); //bottest
|
||||||
|
chatchannel = devServer.getChannelByID("248185455508455424"); // minecraft_chat_test
|
||||||
dc.changeStatus(Status.game("testing"));
|
dc.changeStatus(Status.game("testing"));
|
||||||
}
|
}
|
||||||
// sendMessageToChannel(botchannel, "Minecraft server started up");
|
// sendMessageToChannel(botchannel, "Minecraft server started up");
|
||||||
|
|
|
@ -65,4 +65,13 @@ public class ConnectCommand extends DiscordCommandBase {
|
||||||
+ message.getAuthor().getDiscriminator() + " do /discord accept");
|
+ message.getAuthor().getDiscriminator() + " do /discord accept");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getHelpText() {
|
||||||
|
return new String[] { //
|
||||||
|
"---- Connect command ----", //
|
||||||
|
"This commands let's you connect your acoount with a Minecraft account. This'd allow using the Minecraft chat and other things.", //
|
||||||
|
"Usage: connect <Minecraftname>" //
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,18 +11,21 @@ public abstract class DiscordCommandBase {
|
||||||
|
|
||||||
public abstract void run(IMessage message, String args);
|
public abstract void run(IMessage message, String args);
|
||||||
|
|
||||||
|
public abstract String[] getHelpText();
|
||||||
|
|
||||||
static final HashMap<String, DiscordCommandBase> commands = new HashMap<String, DiscordCommandBase>();
|
static final HashMap<String, DiscordCommandBase> commands = new HashMap<String, DiscordCommandBase>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
commands.put("connect", new ConnectCommand()); // TODO: API for adding commands?
|
commands.put("connect", new ConnectCommand()); // TODO: API for adding commands?
|
||||||
commands.put("userinfo", new UserinfoCommand());
|
commands.put("userinfo", new UserinfoCommand());
|
||||||
|
commands.put("help", new HelpCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runCommand(String cmd, String args, IMessage message) {
|
public static void runCommand(String cmd, String args, IMessage message) {
|
||||||
DiscordCommandBase command = commands.get(cmd);
|
DiscordCommandBase command = commands.get(cmd);
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
// TODO: Help command
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "Unknown command: " + cmd + " with args: " + args);
|
"Unknown command: " + cmd + " with args: " + args + "\nDo @ChromaBot help for help");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package buttondevteam.discordplugin.commands;
|
package buttondevteam.discordplugin.commands;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import buttondevteam.discordplugin.DiscordPlugin;
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
|
@ -14,8 +15,24 @@ public class HelpCommand extends DiscordCommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(IMessage message, String args) {
|
public void run(IMessage message, String args) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "Available commands:\n" + DiscordCommandBase.commands
|
DiscordCommandBase argdc;
|
||||||
.values().stream().map(dc -> dc.getCommandName()).collect(Collectors.joining("\n")));
|
if (args.length() == 0)
|
||||||
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
|
"Available commands:\n" + DiscordCommandBase.commands.values().stream()
|
||||||
|
.map(dc -> dc.getCommandName()).collect(Collectors.joining("\n")));
|
||||||
|
else
|
||||||
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
|
(argdc = DiscordCommandBase.commands.get(args)) == null ? "Command not found: " + args
|
||||||
|
: Arrays.stream(argdc.getHelpText()).collect(Collectors.joining("\n")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getHelpText() {
|
||||||
|
return new String[] { //
|
||||||
|
"---- Help command ----", //
|
||||||
|
"Shows some info about a command or lists the available commands.", //
|
||||||
|
"Usage: help [command]"//
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class UserinfoCommand extends DiscordCommandBase {
|
||||||
target = message.getMentions().get(0);
|
target = message.getMentions().get(0);
|
||||||
else if (args.contains("#")) {
|
else if (args.contains("#")) {
|
||||||
String[] targettag = args.split("#");
|
String[] targettag = args.split("#");
|
||||||
final List<IUser> targets = message.getGuild().getUsersByName(targettag[0], true);
|
final List<IUser> targets = getUsers(message, targettag[0]);
|
||||||
if (targets.size() == 0) {
|
if (targets.size() == 0) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "The user cannot be found (by name): " + args);
|
DiscordPlugin.sendMessageToChannel(message.getChannel(), "The user cannot be found (by name): " + args);
|
||||||
return;
|
return;
|
||||||
|
@ -48,12 +48,7 @@ public class UserinfoCommand extends DiscordCommandBase {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final List<IUser> targets;
|
final List<IUser> targets = getUsers(message, args);
|
||||||
if (message.getChannel().isPrivate())
|
|
||||||
targets = DiscordPlugin.dc.getUsers().stream().filter(u -> u.getName().equalsIgnoreCase(args))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
else
|
|
||||||
targets = message.getGuild().getUsersByName(args, true);
|
|
||||||
if (targets.size() == 0) {
|
if (targets.size() == 0) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
"The user cannot be found on Discord: " + args);
|
"The user cannot be found on Discord: " + args);
|
||||||
|
@ -82,4 +77,23 @@ public class UserinfoCommand extends DiscordCommandBase {
|
||||||
"The user is not found in our system (player has to be on the MC server for now)!");
|
"The user is not found in our system (player has to be on the MC server for now)!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<IUser> getUsers(IMessage message, String args) {
|
||||||
|
final List<IUser> targets;
|
||||||
|
if (message.getChannel().isPrivate())
|
||||||
|
targets = DiscordPlugin.dc.getUsers().stream().filter(u -> u.getName().equalsIgnoreCase(args))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
else
|
||||||
|
targets = message.getGuild().getUsersByName(args, true);
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getHelpText() {
|
||||||
|
return new String[] { //
|
||||||
|
"---- User information ----", //
|
||||||
|
"Shows some information about users, from Discord, from Minecraft or from Reddit if they have these accounts connected.", //
|
||||||
|
"Usage: userinfo <Discordname>" //
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
|
import sx.blah.discord.api.events.IListener;
|
||||||
|
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
||||||
|
|
||||||
|
public class ChatListener implements IListener<MessageReceivedEvent> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(MessageReceivedEvent event) {
|
||||||
|
if (!event.getMessage().getChannel().getID().equals(DiscordPlugin.chatchannel.getID()))
|
||||||
|
return;
|
||||||
|
if (event.getMessage().getContent().startsWith("/"))
|
||||||
|
; // Call API method
|
||||||
|
else
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package buttondevteam.discordplugin;
|
package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.discordplugin.commands.DiscordCommandBase;
|
import buttondevteam.discordplugin.commands.DiscordCommandBase;
|
||||||
import sx.blah.discord.api.events.IListener;
|
import sx.blah.discord.api.events.IListener;
|
||||||
import sx.blah.discord.handle.impl.events.MentionEvent;
|
import sx.blah.discord.handle.impl.events.MentionEvent;
|
||||||
|
@ -33,13 +34,14 @@ public class CommandListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void runCommand(IMessage message) {
|
private static void runCommand(IMessage message) {
|
||||||
|
message.getChannel().setTypingStatus(true);
|
||||||
String cmdwithargs = message.getContent();
|
String cmdwithargs = message.getContent();
|
||||||
final String mention = DiscordPlugin.dc.getOurUser().mention(false);
|
final String mention = DiscordPlugin.dc.getOurUser().mention(false);
|
||||||
final String mentionNick = DiscordPlugin.dc.getOurUser().mention(true);
|
final String mentionNick = DiscordPlugin.dc.getOurUser().mention(true);
|
||||||
if (message.getContent().startsWith(mention) && cmdwithargs.length() > mention.length() + 1) // TODO: Resolve mentions: Compound arguments, either a mention or text
|
cmdwithargs = checkanddeletemention(cmdwithargs, mention, message);
|
||||||
cmdwithargs = cmdwithargs.substring(mention.length() + 1);
|
cmdwithargs = checkanddeletemention(cmdwithargs, mentionNick, message);
|
||||||
if (message.getContent().startsWith(mentionNick) && cmdwithargs.length() > mentionNick.length() + 1)
|
for (String mentionRole : (Iterable<String>) message.getRoleMentions().stream().map(r -> r.mention())::iterator)
|
||||||
cmdwithargs = cmdwithargs.substring(mentionNick.length() + 1);
|
cmdwithargs = checkanddeletemention(cmdwithargs, mentionRole, message);
|
||||||
int index = cmdwithargs.indexOf(' ');
|
int index = cmdwithargs.indexOf(' ');
|
||||||
String cmd;
|
String cmd;
|
||||||
String args;
|
String args;
|
||||||
|
@ -51,5 +53,18 @@ public class CommandListener {
|
||||||
args = cmdwithargs.substring(index + 1);
|
args = cmdwithargs.substring(index + 1);
|
||||||
}
|
}
|
||||||
DiscordCommandBase.runCommand(cmd, args, message);
|
DiscordCommandBase.runCommand(cmd, args, message);
|
||||||
|
message.getChannel().setTypingStatus(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String checkanddeletemention(String cmdwithargs, String mention, IMessage message) {
|
||||||
|
if (message.getContent().startsWith(mention)) // TODO: Resolve mentions: Compound arguments, either a mention or text
|
||||||
|
if (cmdwithargs.length() > mention.length() + 1)
|
||||||
|
cmdwithargs = cmdwithargs.substring(
|
||||||
|
cmdwithargs.charAt(mention.length() + 1) == ' ' ? mention.length() + 1 : mention.length());
|
||||||
|
else
|
||||||
|
cmdwithargs = "help";
|
||||||
|
if (cmdwithargs.length() == 0)
|
||||||
|
cmdwithargs = "help";
|
||||||
|
return cmdwithargs;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,10 @@
|
||||||
package buttondevteam.discordplugin;
|
package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.lib.TBMCExceptionEvent;
|
import buttondevteam.lib.TBMCExceptionEvent;
|
||||||
|
|
||||||
public class ExceptionListener implements Listener {
|
public class ExceptionListener implements Listener {
|
|
@ -0,0 +1,7 @@
|
||||||
|
package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class MCChatListener implements Listener {
|
||||||
|
// Custom event
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package buttondevteam.discordplugin;
|
package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -6,6 +6,8 @@ import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.server.ServerCommandEvent;
|
import org.bukkit.event.server.ServerCommandEvent;
|
||||||
|
|
||||||
|
import buttondevteam.discordplugin.DiscordPlayer;
|
||||||
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.discordplugin.commands.ConnectCommand;
|
import buttondevteam.discordplugin.commands.ConnectCommand;
|
||||||
import buttondevteam.lib.TBMCPlayerGetInfoEvent;
|
import buttondevteam.lib.TBMCPlayerGetInfoEvent;
|
||||||
import buttondevteam.lib.TBMCPlayerJoinEvent;
|
import buttondevteam.lib.TBMCPlayerJoinEvent;
|
Loading…
Reference in a new issue