Added support for role mentions
After a while of trying to test it locally while my PC is already busy, I decided on continuing to test in production. This is alpha stage afterall.
This commit is contained in:
parent
1871dfbb2f
commit
0ff139928b
1 changed files with 14 additions and 14 deletions
|
@ -1,9 +1,5 @@
|
||||||
package buttondevteam.discordplugin;
|
package buttondevteam.discordplugin;
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -41,16 +37,10 @@ public class CommandListener {
|
||||||
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)) // TODO: Resolve mentions: Compound arguments, either a mention or text
|
checkanddeletemention(cmdwithargs, mention, message);
|
||||||
if (cmdwithargs.length() > mention.length() + 1)
|
checkanddeletemention(cmdwithargs, mentionNick, message);
|
||||||
cmdwithargs = cmdwithargs.substring(mention.length() + 1);
|
for (String mentionRole : (Iterable<String>) message.getRoleMentions().stream().map(r -> r.mention())::iterator)
|
||||||
else
|
cmdwithargs = checkanddeletemention(cmdwithargs, mentionRole, message);
|
||||||
cmdwithargs = "help";
|
|
||||||
if (message.getContent().startsWith(mentionNick))
|
|
||||||
if (cmdwithargs.length() > mentionNick.length() + 1)
|
|
||||||
cmdwithargs = cmdwithargs.substring(mentionNick.length() + 1);
|
|
||||||
else
|
|
||||||
cmdwithargs = "help";
|
|
||||||
int index = cmdwithargs.indexOf(' ');
|
int index = cmdwithargs.indexOf(' ');
|
||||||
String cmd;
|
String cmd;
|
||||||
String args;
|
String args;
|
||||||
|
@ -64,4 +54,14 @@ public class CommandListener {
|
||||||
DiscordCommandBase.runCommand(cmd, args, message);
|
DiscordCommandBase.runCommand(cmd, args, message);
|
||||||
message.getChannel().setTypingStatus(false);
|
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";
|
||||||
|
return cmdwithargs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue