Channelcon works, chat not yet
Sending/receiving or saving connections doesn't work yet Command logging for Discord / prefix works from #bot Plugin update update (#37) #52
This commit is contained in:
parent
b8814030e2
commit
1b85eb027a
5 changed files with 179 additions and 167 deletions
|
@ -6,5 +6,5 @@ if [ $1 = 'production' ]; then
|
||||||
echo Production mode
|
echo Production mode
|
||||||
echo $UPLOAD_KEY > upload_key
|
echo $UPLOAD_KEY > upload_key
|
||||||
chmod 400 upload_key
|
chmod 400 upload_key
|
||||||
yes | scp -B -i upload_key -o StrictHostKeyChecking=no $FILENAME travis@server.figytuna.com:/minecraft/main/plugins
|
yes | scp -B -i upload_key -o StrictHostKeyChecking=no $FILENAME travis@server.figytuna.com:/minecraft/main/pluginupdates
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -3,7 +3,7 @@ package buttondevteam.discordplugin.commands;
|
||||||
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
||||||
import buttondevteam.discordplugin.DiscordPlayer;
|
import buttondevteam.discordplugin.DiscordPlayer;
|
||||||
import buttondevteam.discordplugin.listeners.MCChatListener;
|
import buttondevteam.discordplugin.listeners.MCChatListener;
|
||||||
import buttondevteam.lib.TBMCChannelConnectEvent;
|
import buttondevteam.lib.TBMCChannelConnectFakeEvent;
|
||||||
import buttondevteam.lib.chat.Channel;
|
import buttondevteam.lib.chat.Channel;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
@ -17,7 +17,7 @@ import java.util.Arrays;
|
||||||
public class ChannelconCommand extends DiscordCommandBase {
|
public class ChannelconCommand extends DiscordCommandBase {
|
||||||
@Override
|
@Override
|
||||||
public String getCommandName() {
|
public String getCommandName() {
|
||||||
return "here";
|
return "channelcon";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -31,8 +31,10 @@ public class ChannelconCommand extends DiscordCommandBase {
|
||||||
//TODO: What if they no longer have permission to view the channel - check on some message events and startup - if somebody who can view the channel (on both platforms) has their accounts connected, keep it
|
//TODO: What if they no longer have permission to view the channel - check on some message events and startup - if somebody who can view the channel (on both platforms) has their accounts connected, keep it
|
||||||
if (MCChatListener.hasCustomChat(message.getChannel())) {
|
if (MCChatListener.hasCustomChat(message.getChannel())) {
|
||||||
if (args.equalsIgnoreCase("remove")) {
|
if (args.equalsIgnoreCase("remove")) {
|
||||||
MCChatListener.removeCustomChat(message.getChannel());
|
if (MCChatListener.removeCustomChat(message.getChannel()))
|
||||||
message.reply("channel connection removed.");
|
message.reply("channel connection removed.");
|
||||||
|
else
|
||||||
|
message.reply("wait what, couldn't remove channel connection.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
message.reply("this channel is already connected to a Minecraft channel. Use `/channelcon remove` to remove it.");
|
message.reply("this channel is already connected to a Minecraft channel. Use `/channelcon remove` to remove it.");
|
||||||
|
@ -48,14 +50,15 @@ public class ChannelconCommand extends DiscordCommandBase {
|
||||||
message.reply("you need to connect your Minecraft account. In this channel or on our server in #bot do /connect <MCname>");
|
message.reply("you need to connect your Minecraft account. In this channel or on our server in #bot do /connect <MCname>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
val ev = new TBMCChannelConnectEvent(new DiscordConnectedPlayer(message.getAuthor(), message.getChannel(), chp.getUUID(), Bukkit.getOfflinePlayer(chp.getUUID()).getName()), chan.get());
|
val ev = new TBMCChannelConnectFakeEvent(new DiscordConnectedPlayer(message.getAuthor(), message.getChannel(), chp.getUUID(), Bukkit.getOfflinePlayer(chp.getUUID()).getName()), chan.get());
|
||||||
Bukkit.getPluginManager().callEvent(ev); //Using a fake player with no login/logout, should be fine for this event
|
//Using a fake player with no login/logout, should be fine for this event
|
||||||
if (ev.isCancelled() || ev.getGroupid() == null) {
|
String groupid = ev.getGroupID(ev.getSender()); //We're not trying to send in a specific group, we want to know which group the user belongs to (so not getGroupID())
|
||||||
|
if (groupid == null) {
|
||||||
message.reply("sorry, that didn't work. You cannot use that Minecraft channel.");
|
message.reply("sorry, that didn't work. You cannot use that Minecraft channel.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
MCChatListener.addCustomChat(message.getChannel(), args, ev.getChannel());
|
MCChatListener.addCustomChat(message.getChannel(), args, ev.getChannel());
|
||||||
message.reply("alright, connection made!");
|
message.reply("alright, connection made to group `" + groupid + "`!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,9 +69,10 @@ public class ChannelconCommand extends DiscordCommandBase {
|
||||||
"This command allows you to connect a Minecraft channel to a Discord channel (just like how the global chat is connected to #minecraft-chat).", //
|
"This command allows you to connect a Minecraft channel to a Discord channel (just like how the global chat is connected to #minecraft-chat).", //
|
||||||
"You need to have access to the MC channel and have manage permissions on the Discord channel.", //
|
"You need to have access to the MC channel and have manage permissions on the Discord channel.", //
|
||||||
"You also need to have your Minecraft account connected. In #bot use /connect <mcname>.", //
|
"You also need to have your Minecraft account connected. In #bot use /connect <mcname>.", //
|
||||||
"Call this command from the channel you want to use. Usage: /channelcon <mcchannel>", //
|
"Call this command from the channel you want to use. Usage: @ChromaBot channelcon <mcchannel>", //
|
||||||
"To remove a connection use /channelcon remove in the channel.", //
|
"To remove a connection use @ChromaBot channelcon remove in the channel.", //
|
||||||
"Invite link: https://discordapp.com/oauth2/authorize?client_id=226443037893591041&scope=bot" //
|
"Mentioning the bot is needed in this case because the / prefix only works in #bot.", //
|
||||||
|
"Invite link: <https://discordapp.com/oauth2/authorize?client_id=226443037893591041&scope=bot>" //
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class MCChatCommand extends DiscordCommandBase {
|
||||||
MCChatListener.privateMCChat(message.getChannel(), mcchat, message.getAuthor(), user);
|
MCChatListener.privateMCChat(message.getChannel(), mcchat, message.getAuthor(), user);
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
"Minecraft chat " + (mcchat //
|
"Minecraft chat " + (mcchat //
|
||||||
? "enabled. Use '/mcchat' to disable." //
|
? "enabled. Use '/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);
|
||||||
|
|
|
@ -26,105 +26,109 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class CommandListener {
|
public class CommandListener {
|
||||||
|
|
||||||
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
|
||||||
"Between now and the heat-death of the universe.", // Ghostise
|
"Between now and the heat-death of the universe.", // Ghostise
|
||||||
"Soon™", "Ask again this time next month", // Ghostise
|
"Soon™", "Ask again this time next month", // Ghostise
|
||||||
"In about 3 seconds", // Nicolai
|
"In about 3 seconds", // Nicolai
|
||||||
"After we finish 8 plugins", // Ali
|
"After we finish 8 plugins", // Ali
|
||||||
"Tomorrow.", // Ali
|
"Tomorrow.", // Ali
|
||||||
"After one tiiiny feature", // Ali
|
"After one tiiiny feature", // Ali
|
||||||
"Next commit", // Ali
|
"Next commit", // Ali
|
||||||
"After we finish strangling Towny", // Ali
|
"After we finish strangling Towny", // Ali
|
||||||
"When we kill every *fucking* bug", // Ali
|
"When we kill every *fucking* bug", // Ali
|
||||||
"Once the server stops screaming.", // Ali
|
"Once the server stops screaming.", // Ali
|
||||||
"After HL3 comes out", // Ali
|
"After HL3 comes out", // Ali
|
||||||
"Next time you ask", // Ali
|
"Next time you ask", // Ali
|
||||||
"When will *you* be open?" // Ali
|
"When will *you* be open?" // Ali
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String[] serverReadyQuestions = new String[] { "when will the server be open",
|
private static final String[] serverReadyQuestions = new String[]{"when will the server be open",
|
||||||
"when will the server be ready", "when will the server be done", "when will the server be complete",
|
"when will the server be ready", "when will the server be done", "when will the server be complete",
|
||||||
"when will the server be finished", "when's the server ready", "when's the server open",
|
"when will the server be finished", "when's the server ready", "when's the server open",
|
||||||
"Vhen vill ze server be open?" };
|
"Vhen vill ze server be open?"};
|
||||||
|
|
||||||
private static final Random serverReadyRandom = new Random();
|
private static final Random serverReadyRandom = new Random();
|
||||||
private static final ArrayList<Short> usableServerReadyStrings = new ArrayList<Short>(serverReadyStrings.length) {
|
private static final ArrayList<Short> usableServerReadyStrings = new ArrayList<Short>(serverReadyStrings.length) {
|
||||||
private static final long serialVersionUID = 2213771460909848770L;
|
private static final long serialVersionUID = 2213771460909848770L;
|
||||||
{
|
|
||||||
createUsableServerReadyStrings(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static void createUsableServerReadyStrings(ArrayList<Short> list) {
|
{
|
||||||
for (short i = 0; i < serverReadyStrings.length; i++)
|
createUsableServerReadyStrings(this);
|
||||||
list.add(i);
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
private static long lasttime = 0;
|
private static void createUsableServerReadyStrings(ArrayList<Short> list) {
|
||||||
|
for (short i = 0; i < serverReadyStrings.length; i++)
|
||||||
|
list.add(i);
|
||||||
|
}
|
||||||
|
|
||||||
public static IListener<?>[] getListeners() {
|
private static long lasttime = 0;
|
||||||
return new IListener[] { new IListener<MentionEvent>() {
|
|
||||||
@Override
|
public static IListener<?>[] getListeners() {
|
||||||
public void handle(MentionEvent event) {
|
return new IListener[]{new IListener<MentionEvent>() {
|
||||||
if (DiscordPlugin.SafeMode)
|
@Override
|
||||||
return;
|
public void handle(MentionEvent event) {
|
||||||
if (event.getMessage().getAuthor().isBot())
|
if (DiscordPlugin.SafeMode)
|
||||||
return;
|
return;
|
||||||
final IChannel channel = event.getMessage().getChannel();
|
if (event.getMessage().getAuthor().isBot())
|
||||||
if (!channel.getStringID().equals(DiscordPlugin.botchannel.getStringID()))
|
return;
|
||||||
return;
|
final IChannel channel = event.getMessage().getChannel();
|
||||||
if (channel.getStringID().equals(DiscordPlugin.chatchannel.getStringID()))
|
if (!channel.getStringID().equals(DiscordPlugin.botchannel.getStringID())
|
||||||
return; // The chat code already handles this - Right now while testing botchannel is the same as chatchannel
|
&& !event.getMessage().getContent().contains("channelcon"))
|
||||||
event.getMessage().getChannel().setTypingStatus(true); // Fun
|
return;
|
||||||
runCommand(event.getMessage(), true);
|
if (channel.getStringID().equals(DiscordPlugin.chatchannel.getStringID()))
|
||||||
}
|
return; // The chat code already handles this - Right now while testing botchannel is the same as chatchannel
|
||||||
}, new IListener<MessageReceivedEvent>() {
|
event.getMessage().getChannel().setTypingStatus(true); // Fun
|
||||||
@Override
|
runCommand(event.getMessage(), true);
|
||||||
public void handle(MessageReceivedEvent event) {
|
}
|
||||||
if (DiscordPlugin.SafeMode)
|
}, new IListener<MessageReceivedEvent>() {
|
||||||
return;
|
@Override
|
||||||
final String msglowercase = event.getMessage().getContent().toLowerCase();
|
public void handle(MessageReceivedEvent event) {
|
||||||
if (!TBMCCoreAPI.IsTestServer()
|
if (DiscordPlugin.SafeMode)
|
||||||
&& Arrays.stream(serverReadyQuestions).anyMatch(s -> msglowercase.contains(s))) {
|
return;
|
||||||
int next;
|
final String msglowercase = event.getMessage().getContent().toLowerCase();
|
||||||
if (usableServerReadyStrings.size() == 0)
|
if (!TBMCCoreAPI.IsTestServer()
|
||||||
createUsableServerReadyStrings(usableServerReadyStrings);
|
&& Arrays.stream(serverReadyQuestions).anyMatch(s -> msglowercase.contains(s))) {
|
||||||
next = usableServerReadyStrings.remove(serverReadyRandom.nextInt(usableServerReadyStrings.size()));
|
int next;
|
||||||
DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), serverReadyStrings[next]);
|
if (usableServerReadyStrings.size() == 0)
|
||||||
return;
|
createUsableServerReadyStrings(usableServerReadyStrings);
|
||||||
}
|
next = usableServerReadyStrings.remove(serverReadyRandom.nextInt(usableServerReadyStrings.size()));
|
||||||
if (!event.getMessage().getChannel().isPrivate()) //
|
DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), serverReadyStrings[next]);
|
||||||
return;
|
return;
|
||||||
if (DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class)
|
}
|
||||||
.isMinecraftChatEnabled())
|
if (!event.getMessage().getChannel().isPrivate()
|
||||||
if (!event.getMessage().getContent().equalsIgnoreCase("mcchat"))
|
&& !(event.getMessage().getContent().startsWith("/")
|
||||||
return;
|
&& event.getChannel().getStringID().equals(DiscordPlugin.botchannel.getStringID()))) //
|
||||||
if (event.getMessage().getAuthor().isBot())
|
return;
|
||||||
return;
|
if (DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class)
|
||||||
runCommand(event.getMessage(), false);
|
.isMinecraftChatEnabled())
|
||||||
}
|
if (!event.getMessage().getContent().equalsIgnoreCase("mcchat"))
|
||||||
}, new IListener<sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent>() {
|
return;
|
||||||
@Override
|
if (event.getMessage().getAuthor().isBot())
|
||||||
public void handle(PresenceUpdateEvent event) {
|
return;
|
||||||
if (DiscordPlugin.SafeMode)
|
runCommand(event.getMessage(), false);
|
||||||
return;
|
}
|
||||||
val devrole = DiscordPlugin.devServer.getRolesByName("Developer").get(0);
|
}, new IListener<sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent>() {
|
||||||
if (event.getOldPresence().getStatus().equals(StatusType.OFFLINE)
|
@Override
|
||||||
&& !event.getNewPresence().getStatus().equals(StatusType.OFFLINE)
|
public void handle(PresenceUpdateEvent event) {
|
||||||
&& event.getUser().getRolesForGuild(DiscordPlugin.devServer).stream()
|
if (DiscordPlugin.SafeMode)
|
||||||
|
return;
|
||||||
|
val devrole = DiscordPlugin.devServer.getRolesByName("Developer").get(0);
|
||||||
|
if (event.getOldPresence().getStatus().equals(StatusType.OFFLINE)
|
||||||
|
&& !event.getNewPresence().getStatus().equals(StatusType.OFFLINE)
|
||||||
|
&& event.getUser().getRolesForGuild(DiscordPlugin.devServer).stream()
|
||||||
.anyMatch(r -> r.getLongID() == devrole.getLongID())
|
.anyMatch(r -> r.getLongID() == devrole.getLongID())
|
||||||
&& DiscordPlugin.devServer.getUsersByRole(devrole).stream()
|
&& DiscordPlugin.devServer.getUsersByRole(devrole).stream()
|
||||||
.noneMatch(u -> u.getPresence().getStatus().equals(StatusType.OFFLINE))
|
.noneMatch(u -> u.getPresence().getStatus().equals(StatusType.OFFLINE))
|
||||||
&& lasttime + 10 < TimeUnit.NANOSECONDS.toHours(System.nanoTime())
|
&& lasttime + 10 < TimeUnit.NANOSECONDS.toHours(System.nanoTime())
|
||||||
&& Calendar.getInstance().get(Calendar.DAY_OF_MONTH) % 5 == 0) {
|
&& Calendar.getInstance().get(Calendar.DAY_OF_MONTH) % 5 == 0) {
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.devofficechannel, "Full house!",
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.devofficechannel, "Full house!",
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.withImage(
|
.withImage(
|
||||||
"https://cdn.discordapp.com/attachments/249295547263877121/249687682618359808/poker-hand-full-house-aces-kings-playing-cards-15553791.png")
|
"https://cdn.discordapp.com/attachments/249295547263877121/249687682618359808/poker-hand-full-house-aces-kings-playing-cards-15553791.png")
|
||||||
.build());
|
.build());
|
||||||
lasttime = TimeUnit.NANOSECONDS.toHours(System.nanoTime());
|
lasttime = TimeUnit.NANOSECONDS.toHours(System.nanoTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, (IListener<RoleCreateEvent>) event -> {
|
}, (IListener<RoleCreateEvent>) event -> {
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
|
Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
|
||||||
if (event.getRole().isDeleted() || DiscordPlugin.plugin.isGameRole(event.getRole()))
|
if (event.getRole().isDeleted() || DiscordPlugin.plugin.isGameRole(event.getRole()))
|
||||||
|
@ -135,65 +139,63 @@ public class CommandListener {
|
||||||
}, (IListener<RoleDeleteEvent>) event -> {
|
}, (IListener<RoleDeleteEvent>) event -> {
|
||||||
if (DiscordPlugin.GameRoles.remove(event.getRole().getName()))
|
if (DiscordPlugin.GameRoles.remove(event.getRole().getName()))
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Removed " + event.getRole().getName() + " as a game role.");
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Removed " + event.getRole().getName() + " as a game role.");
|
||||||
}, (IListener<RoleUpdateEvent>) event -> { //Role update event
|
}, (IListener<RoleUpdateEvent>) event -> { //Role update event
|
||||||
if (!DiscordPlugin.plugin.isGameRole(event.getNewRole())) {
|
if (!DiscordPlugin.plugin.isGameRole(event.getNewRole())) {
|
||||||
if (DiscordPlugin.GameRoles.remove(event.getOldRole().getName()))
|
if (DiscordPlugin.GameRoles.remove(event.getOldRole().getName()))
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Removed " + event.getOldRole().getName() + " as a game role because it's color changed.");
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Removed " + event.getOldRole().getName() + " as a game role because it's color changed.");
|
||||||
} else {
|
} else {
|
||||||
boolean removed = DiscordPlugin.GameRoles.remove(event.getOldRole().getName()); //Regardless of whether it was a game role
|
boolean removed = DiscordPlugin.GameRoles.remove(event.getOldRole().getName()); //Regardless of whether it was a game role
|
||||||
DiscordPlugin.GameRoles.add(event.getNewRole().getName()); //Add it because it has no color
|
DiscordPlugin.GameRoles.add(event.getNewRole().getName()); //Add it because it has no color
|
||||||
if (removed)
|
if (removed)
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Changed game role from " + event.getOldRole().getName() + " to " + event.getNewRole().getName() + ".");
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Changed game role from " + event.getOldRole().getName() + " to " + event.getNewRole().getName() + ".");
|
||||||
else
|
else
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Added " + event.getNewRole().getName() + " as game role because it has the default color.");
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Added " + event.getNewRole().getName() + " as game role because it has the default color.");
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a ChromaBot command.
|
* Runs a ChromaBot command.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message The Discord message
|
||||||
* The Discord message
|
* @param mentionedonly Only run the command if ChromaBot is mentioned at the start of the message
|
||||||
* @param mentionedonly
|
* @return Whether it ran the command (always true if mentionedonly is false)
|
||||||
* 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) {
|
||||||
*/
|
|
||||||
public static boolean runCommand(IMessage message, boolean mentionedonly) {
|
|
||||||
debug("A");
|
debug("A");
|
||||||
if (DiscordPlugin.SafeMode)
|
if (DiscordPlugin.SafeMode)
|
||||||
return true;
|
return true;
|
||||||
debug("B");
|
debug("B");
|
||||||
final StringBuilder cmdwithargs = new StringBuilder(message.getContent());
|
final StringBuilder cmdwithargs = new StringBuilder(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);
|
||||||
boolean gotmention = checkanddeletemention(cmdwithargs, mention, message);
|
boolean gotmention = checkanddeletemention(cmdwithargs, mention, message);
|
||||||
gotmention = checkanddeletemention(cmdwithargs, mentionNick, message) || gotmention;
|
gotmention = checkanddeletemention(cmdwithargs, mentionNick, message) || gotmention;
|
||||||
for (String mentionRole : (Iterable<String>) message.getRoleMentions().stream().filter(r -> DiscordPlugin.dc.getOurUser().hasRole(r)).map(r -> r.mention())::iterator)
|
for (String mentionRole : (Iterable<String>) message.getRoleMentions().stream().filter(r -> DiscordPlugin.dc.getOurUser().hasRole(r)).map(r -> r.mention())::iterator)
|
||||||
gotmention = checkanddeletemention(cmdwithargs, mentionRole, message) || gotmention; // Delete all mentions
|
gotmention = checkanddeletemention(cmdwithargs, mentionRole, message) || gotmention; // Delete all mentions
|
||||||
debug("C");
|
debug("C");
|
||||||
if (mentionedonly && !gotmention) {
|
if (mentionedonly && !gotmention) {
|
||||||
message.getChannel().setTypingStatus(false);
|
message.getChannel().setTypingStatus(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
debug("D");
|
debug("D");
|
||||||
message.getChannel().setTypingStatus(true);
|
message.getChannel().setTypingStatus(true);
|
||||||
String cmdwithargsString = cmdwithargs.toString().trim(); //Remove spaces between mention and command
|
String cmdwithargsString = cmdwithargs.toString().trim(); //Remove spaces between mention and command
|
||||||
int index = cmdwithargsString.indexOf(" ");
|
int index = cmdwithargsString.indexOf(" ");
|
||||||
String cmd;
|
String cmd;
|
||||||
String args;
|
String args;
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
cmd = cmdwithargsString;
|
cmd = cmdwithargsString;
|
||||||
args = "";
|
args = "";
|
||||||
} else {
|
} else {
|
||||||
cmd = cmdwithargsString.substring(0, index);
|
cmd = cmdwithargsString.substring(0, index);
|
||||||
args = cmdwithargsString.substring(index + 1).trim(); //In case there are multiple spaces
|
args = cmdwithargsString.substring(index + 1).trim(); //In case there are multiple spaces
|
||||||
}
|
}
|
||||||
debug("E");
|
debug("E");
|
||||||
DiscordCommandBase.runCommand(cmd.toLowerCase(), args, message);
|
DiscordCommandBase.runCommand(cmd.toLowerCase(), args, message);
|
||||||
message.getChannel().setTypingStatus(false);
|
message.getChannel().setTypingStatus(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean debug = false;
|
private static boolean debug = false;
|
||||||
|
|
||||||
|
@ -206,17 +208,20 @@ public class CommandListener {
|
||||||
return debug = !debug;
|
return debug = !debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean checkanddeletemention(StringBuilder 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 (message.getContent().startsWith(mention)) // TODO: Resolve mentions: Compound arguments, either a mention or text
|
||||||
if (cmdwithargs.length() > mention.length() + 1)
|
if (cmdwithargs.length() > mention.length() + 1)
|
||||||
cmdwithargs = cmdwithargs.delete(0,
|
cmdwithargs = cmdwithargs.delete(0,
|
||||||
cmdwithargs.charAt(mention.length()) == ' ' ? mention.length() + 1 : mention.length());
|
cmdwithargs.charAt(mention.length()) == ' ' ? mention.length() + 1 : mention.length());
|
||||||
else
|
else
|
||||||
cmdwithargs.replace(0, cmdwithargs.length(), "help");
|
cmdwithargs.replace(0, cmdwithargs.length(), "help");
|
||||||
else
|
else {
|
||||||
return false;
|
if (cmdwithargs.charAt(0) == '/')
|
||||||
if (cmdwithargs.length() == 0)
|
cmdwithargs.deleteCharAt(0); //Don't treat / as mention, mentions can be used in public mcchat
|
||||||
cmdwithargs.replace(0, cmdwithargs.length(), "help");
|
return false;
|
||||||
return true;
|
}
|
||||||
}
|
if (cmdwithargs.length() == 0)
|
||||||
|
cmdwithargs.replace(0, cmdwithargs.length(), "help");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -373,9 +373,9 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
event.getMessage().delete();
|
event.getMessage().delete();
|
||||||
});
|
});
|
||||||
preprocessChat(dsender, dmessage);
|
preprocessChat(dsender, dmessage);
|
||||||
final String cmd = dmessage.substring(1).toLowerCase();
|
final String cmdlowercased = dmessage.substring(1).toLowerCase();
|
||||||
if (dsender instanceof DiscordSender && Arrays.stream(UnconnectedCmds)
|
if (dsender instanceof DiscordSender && Arrays.stream(UnconnectedCmds)
|
||||||
.noneMatch(s -> cmd.equals(s) || cmd.startsWith(s + " "))) {
|
.noneMatch(s -> cmdlowercased.equals(s) || cmdlowercased.startsWith(s + " "))) {
|
||||||
// Command not whitelisted
|
// Command not whitelisted
|
||||||
dsender.sendMessage("Sorry, you can only access these commands:\n"
|
dsender.sendMessage("Sorry, you can only access these commands:\n"
|
||||||
+ Arrays.stream(UnconnectedCmds).map(uc -> "/" + uc)
|
+ Arrays.stream(UnconnectedCmds).map(uc -> "/" + uc)
|
||||||
|
@ -392,20 +392,23 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
ListC = 0;
|
ListC = 0;
|
||||||
lastlist = 0;
|
lastlist = 0;
|
||||||
}
|
}
|
||||||
if (cmd.equals("list") && Bukkit.getOnlinePlayers().size() == lastlistp && ListC++ > 2) // Lowered already
|
if (cmdlowercased.equals("list") && Bukkit.getOnlinePlayers().size() == lastlistp && ListC++ > 2) // Lowered already
|
||||||
{
|
{
|
||||||
dsender.sendMessage("Stop it. You know the answer.");
|
dsender.sendMessage("Stop it. You know the answer.");
|
||||||
lastlist = 0;
|
lastlist = 0;
|
||||||
} else {
|
} else {
|
||||||
int spi = cmd.indexOf(' ');
|
int spi = cmdlowercased.indexOf(' ');
|
||||||
final String topcmd = spi == -1 ? cmd : cmd.substring(0, spi);
|
final String topcmd = spi == -1 ? cmdlowercased : cmdlowercased.substring(0, spi);
|
||||||
Optional<Channel> ch = Channel.getChannels().stream()
|
Optional<Channel> ch = Channel.getChannels().stream()
|
||||||
.filter(c -> c.ID.equalsIgnoreCase(topcmd)
|
.filter(c -> c.ID.equalsIgnoreCase(topcmd)
|
||||||
|| (c.IDs != null && c.IDs.length > 0
|
|| (c.IDs != null && c.IDs.length > 0
|
||||||
&& Arrays.stream(c.IDs).anyMatch(id -> id.equalsIgnoreCase(topcmd)))).findAny();
|
&& Arrays.stream(c.IDs).anyMatch(id -> id.equalsIgnoreCase(topcmd)))).findAny();
|
||||||
if (!ch.isPresent())
|
if (!ch.isPresent())
|
||||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin,
|
Bukkit.getScheduler().runTask(DiscordPlugin.plugin,
|
||||||
() -> VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd));
|
() -> {
|
||||||
|
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmdlowercased);
|
||||||
|
Bukkit.getLogger().info(dsender.getName() + " issued command from Discord: /" + cmdlowercased);
|
||||||
|
});
|
||||||
else {
|
else {
|
||||||
Channel chc = ch.get();
|
Channel chc = ch.get();
|
||||||
if (!chc.ID.equals(Channel.GlobalChat.ID) && !chc.ID.equals("rp") && !event.getMessage().getChannel().isPrivate())
|
if (!chc.ID.equals(Channel.GlobalChat.ID) && !chc.ID.equals("rp") && !event.getMessage().getChannel().isPrivate())
|
||||||
|
@ -426,7 +429,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
dsender.sendMessage("You're now talking in: "
|
dsender.sendMessage("You're now talking in: "
|
||||||
+ DPUtils.sanitizeString(dsender.getMcchannel().DisplayName));
|
+ DPUtils.sanitizeString(dsender.getMcchannel().DisplayName));
|
||||||
} else { // Send single message
|
} else { // Send single message
|
||||||
sendChatMessage.accept(chc, cmd.substring(spi + 1));
|
sendChatMessage.accept(chc, event.getMessage().getContent().substring(spi + 2));
|
||||||
react = true;
|
react = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -436,7 +439,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
} else {// Not a command
|
} else {// Not a command
|
||||||
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
|
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
|
||||||
&& !event.getChannel().isPrivate())
|
&& !event.getChannel().isPrivate())
|
||||||
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, 0,
|
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, 0, "everyone",
|
||||||
(dsender instanceof Player ? ((Player) dsender).getDisplayName()
|
(dsender instanceof Player ? ((Player) dsender).getDisplayName()
|
||||||
: dsender.getName()) + " pinned a message on Discord.");
|
: dsender.getName()) + " pinned a message on Discord.");
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in a new issue