Some additions and fixes...
- Made the bot only react when msg starts with the ping unless we're in PM - Now removing color codes from AFK messages - Removed /t as an unconnnected cmd as it doesn't work properly - Added /yeehaw to the unconnected cmds - Allowing bot commands in mc chat
This commit is contained in:
parent
4570b964b3
commit
2bcb47b7b5
4 changed files with 43 additions and 30 deletions
|
@ -98,10 +98,10 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
dc.changeStatus(Status.game("on TBMC"));
|
||||
} else {
|
||||
botchannel = devServer.getChannelByID("239519012529111040"); // bot-room
|
||||
annchannel = devServer.getChannelByID("239519012529111040"); // bot-room
|
||||
genchannel = devServer.getChannelByID("239519012529111040"); // bot-room
|
||||
botroomchannel = devServer.getChannelByID("239519012529111040");// bot-room
|
||||
issuechannel = devServer.getChannelByID("239519012529111040"); // bot-room
|
||||
annchannel = botchannel; // bot-room
|
||||
genchannel = botchannel; // bot-room
|
||||
botroomchannel = botchannel;// bot-room
|
||||
issuechannel = botchannel; // bot-room
|
||||
chatchannel = devServer.getChannelByID("248185455508455424"); // minecraft_chat_test
|
||||
dc.changeStatus(Status.game("testing"));
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class CommandListener {
|
|||
final IChannel channel = event.getMessage().getChannel();
|
||||
if (!channel.getID().equals(DiscordPlugin.botchannel.getID()) && !channel.isPrivate())
|
||||
return;
|
||||
runCommand(event.getMessage());
|
||||
runCommand(event.getMessage(), true);
|
||||
}
|
||||
}, new IListener<MessageReceivedEvent>() {
|
||||
@Override
|
||||
|
@ -28,25 +28,38 @@ public class CommandListener {
|
|||
return;
|
||||
if (event.getMessage().getAuthor().isBot())
|
||||
return;
|
||||
runCommand(event.getMessage());
|
||||
runCommand(event.getMessage(), false);
|
||||
}
|
||||
} };
|
||||
}
|
||||
|
||||
private static void runCommand(IMessage message) {
|
||||
/**
|
||||
* Runs a ChromaBot command.
|
||||
*
|
||||
* @param message
|
||||
* The Discord message
|
||||
* @param mentionedonly
|
||||
* Only run the command if ChromaBot is mentioned at the start of the message
|
||||
* @return Whether it ran the command (always true if mentionedonly is false)
|
||||
*/
|
||||
public static boolean runCommand(IMessage message, boolean mentionedonly) {
|
||||
message.getChannel().setTypingStatus(true);
|
||||
String cmdwithargs = message.getContent();
|
||||
final StringBuilder cmdwithargs = new StringBuilder(message.getContent());
|
||||
final String mention = DiscordPlugin.dc.getOurUser().mention(false);
|
||||
final String mentionNick = DiscordPlugin.dc.getOurUser().mention(true);
|
||||
cmdwithargs = checkanddeletemention(cmdwithargs, mention, message);
|
||||
cmdwithargs = checkanddeletemention(cmdwithargs, mentionNick, message);
|
||||
boolean gotmention = checkanddeletemention(cmdwithargs, mention, message);
|
||||
gotmention = checkanddeletemention(cmdwithargs, mentionNick, message);
|
||||
for (String mentionRole : (Iterable<String>) message.getRoleMentions().stream().map(r -> r.mention())::iterator)
|
||||
cmdwithargs = checkanddeletemention(cmdwithargs, mentionRole, message);
|
||||
int index = cmdwithargs.indexOf(' ');
|
||||
gotmention = checkanddeletemention(cmdwithargs, mentionRole, message);
|
||||
if (mentionedonly && !gotmention) {
|
||||
message.getChannel().setTypingStatus(false);
|
||||
return false;
|
||||
}
|
||||
int index = cmdwithargs.indexOf(" ");
|
||||
String cmd;
|
||||
String args;
|
||||
if (index == -1) {
|
||||
cmd = cmdwithargs;
|
||||
cmd = cmdwithargs.toString();
|
||||
args = "";
|
||||
} else {
|
||||
cmd = cmdwithargs.substring(0, index);
|
||||
|
@ -54,17 +67,20 @@ public class CommandListener {
|
|||
}
|
||||
DiscordCommandBase.runCommand(cmd, args, message);
|
||||
message.getChannel().setTypingStatus(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String checkanddeletemention(String cmdwithargs, String mention, IMessage message) {
|
||||
private static boolean checkanddeletemention(StringBuilder 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 = cmdwithargs.delete(0,
|
||||
cmdwithargs.charAt(mention.length()) == ' ' ? mention.length() + 1 : mention.length());
|
||||
else
|
||||
cmdwithargs = "help";
|
||||
cmdwithargs.replace(0, cmdwithargs.length(), "help");
|
||||
else
|
||||
return false;
|
||||
if (cmdwithargs.length() == 0)
|
||||
cmdwithargs = "help";
|
||||
return cmdwithargs;
|
||||
cmdwithargs.replace(0, cmdwithargs.length(), "help");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,14 +35,13 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
return;
|
||||
if (e.getChannel().equals(Channel.GlobalChat))
|
||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
||||
"<" + (e.getSender() instanceof Player
|
||||
? DiscordPlugin.sanitizeString(((Player) e.getSender()).getDisplayName())
|
||||
: DiscordPlugin.sanitizeString(e.getSender().getName())) + "> "
|
||||
+ DiscordPlugin.sanitizeString(e.getMessage()));
|
||||
DiscordPlugin.sanitizeString("<" + (e.getSender() instanceof Player //
|
||||
? ((Player) e.getSender()).getDisplayName() //
|
||||
: e.getSender().getName()) + "> " + e.getMessage()));
|
||||
}
|
||||
|
||||
private static final String[] UnconnectedCmds = new String[] { "list", "u", "shrug", "tableflip", "unflip", "mwiki",
|
||||
"t" };
|
||||
"yeehaw" };
|
||||
|
||||
public static final HashMap<String, DiscordSender> UnconnectedSenders = new HashMap<>();
|
||||
public static final HashMap<String, DiscordPlayerSender> ConnectedSenders = new HashMap<>();
|
||||
|
@ -55,6 +54,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
if (!event.getMessage().getChannel().getID().equals(DiscordPlugin.chatchannel.getID())
|
||||
/* && !(event.getMessage().getChannel().isPrivate() && privatechat) */)
|
||||
return;
|
||||
if (CommandListener.runCommand(event.getMessage(), true))
|
||||
return;
|
||||
String dmessage = event.getMessage().getContent();
|
||||
try {
|
||||
Optional<? extends Player> player = Bukkit.getOnlinePlayers().stream().filter(p -> { // TODO: Support offline players
|
||||
|
@ -89,7 +90,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
"Sorry, you need to be online on the server and have your accounts connected, you can only access these commands:\n"
|
||||
+ Arrays.stream(UnconnectedCmds).map(uc -> "/" + uc)
|
||||
.collect(Collectors.joining(", "))
|
||||
+ "\nTo connect your accounts, use @ChromaBot connect in "
|
||||
+ "\nTo connect your accounts, use @ChromaBot connect here or in "
|
||||
+ DiscordPlugin.botchannel.mention());
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -56,14 +56,10 @@ public class MCListener implements Listener {
|
|||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel, e.getDeathMessage());
|
||||
}
|
||||
|
||||
/*@EventHandler
|
||||
public void onPlayerYEEHAW(TBMCYEEHAWEvent e) {
|
||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel, e.getSender() + " YEEHAWs");
|
||||
}*/ // It's broadcasted now
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerAFK(AfkStatusChangeEvent e) {
|
||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
||||
e.getAffected().getBase().getDisplayName() + " is " + (e.getValue() ? "now" : "no longer") + " AFK.");
|
||||
DiscordPlugin.sanitizeString(e.getAffected().getBase().getDisplayName()) + " is "
|
||||
+ (e.getValue() ? "now" : "no longer") + " AFK.");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue