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:
Norbi Peti 2018-06-08 23:45:10 +02:00
parent b8814030e2
commit 1b85eb027a
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
5 changed files with 179 additions and 167 deletions

View file

@ -6,5 +6,5 @@ if [ $1 = 'production' ]; then
echo Production mode
echo $UPLOAD_KEY > 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

View file

@ -3,7 +3,7 @@ package buttondevteam.discordplugin.commands;
import buttondevteam.discordplugin.DiscordConnectedPlayer;
import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.discordplugin.listeners.MCChatListener;
import buttondevteam.lib.TBMCChannelConnectEvent;
import buttondevteam.lib.TBMCChannelConnectFakeEvent;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.player.TBMCPlayer;
import lombok.val;
@ -17,7 +17,7 @@ import java.util.Arrays;
public class ChannelconCommand extends DiscordCommandBase {
@Override
public String getCommandName() {
return "here";
return "channelcon";
}
@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
if (MCChatListener.hasCustomChat(message.getChannel())) {
if (args.equalsIgnoreCase("remove")) {
MCChatListener.removeCustomChat(message.getChannel());
if (MCChatListener.removeCustomChat(message.getChannel()))
message.reply("channel connection removed.");
else
message.reply("wait what, couldn't remove channel connection.");
return true;
}
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>");
return true;
}
val ev = new TBMCChannelConnectEvent(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
if (ev.isCancelled() || ev.getGroupid() == null) {
val ev = new TBMCChannelConnectFakeEvent(new DiscordConnectedPlayer(message.getAuthor(), message.getChannel(), chp.getUUID(), Bukkit.getOfflinePlayer(chp.getUUID()).getName()), chan.get());
//Using a fake player with no login/logout, should be fine for this event
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.");
return true;
}
MCChatListener.addCustomChat(message.getChannel(), args, ev.getChannel());
message.reply("alright, connection made!");
message.reply("alright, connection made to group `" + groupid + "`!");
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).", //
"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>.", //
"Call this command from the channel you want to use. Usage: /channelcon <mcchannel>", //
"To remove a connection use /channelcon remove in the channel.", //
"Invite link: https://discordapp.com/oauth2/authorize?client_id=226443037893591041&scope=bot" //
"Call this command from the channel you want to use. Usage: @ChromaBot channelcon <mcchannel>", //
"To remove a connection use @ChromaBot channelcon remove in the channel.", //
"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>" //
};
}
}

View file

@ -25,7 +25,7 @@ public class MCChatCommand extends DiscordCommandBase {
MCChatListener.privateMCChat(message.getChannel(), mcchat, message.getAuthor(), user);
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"Minecraft chat " + (mcchat //
? "enabled. Use '/mcchat' to disable." //
? "enabled. Use '/mcchat' again to turn it off." //
: "disabled."));
} catch (Exception e) {
TBMCCoreAPI.SendException("Error while setting mcchat for user" + message.getAuthor().getName(), e);

View file

@ -50,6 +50,7 @@ public class CommandListener {
private static final Random serverReadyRandom = new Random();
private static final ArrayList<Short> usableServerReadyStrings = new ArrayList<Short>(serverReadyStrings.length) {
private static final long serialVersionUID = 2213771460909848770L;
{
createUsableServerReadyStrings(this);
}
@ -71,7 +72,8 @@ public class CommandListener {
if (event.getMessage().getAuthor().isBot())
return;
final IChannel channel = event.getMessage().getChannel();
if (!channel.getStringID().equals(DiscordPlugin.botchannel.getStringID()))
if (!channel.getStringID().equals(DiscordPlugin.botchannel.getStringID())
&& !event.getMessage().getContent().contains("channelcon"))
return;
if (channel.getStringID().equals(DiscordPlugin.chatchannel.getStringID()))
return; // The chat code already handles this - Right now while testing botchannel is the same as chatchannel
@ -93,7 +95,9 @@ public class CommandListener {
DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), serverReadyStrings[next]);
return;
}
if (!event.getMessage().getChannel().isPrivate()) //
if (!event.getMessage().getChannel().isPrivate()
&& !(event.getMessage().getContent().startsWith("/")
&& event.getChannel().getStringID().equals(DiscordPlugin.botchannel.getStringID()))) //
return;
if (DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class)
.isMinecraftChatEnabled())
@ -153,10 +157,8 @@ public class CommandListener {
/**
* 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
* @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) {
@ -213,8 +215,11 @@ public class CommandListener {
cmdwithargs.charAt(mention.length()) == ' ' ? mention.length() + 1 : mention.length());
else
cmdwithargs.replace(0, cmdwithargs.length(), "help");
else
else {
if (cmdwithargs.charAt(0) == '/')
cmdwithargs.deleteCharAt(0); //Don't treat / as mention, mentions can be used in public mcchat
return false;
}
if (cmdwithargs.length() == 0)
cmdwithargs.replace(0, cmdwithargs.length(), "help");
return true;

View file

@ -373,9 +373,9 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
event.getMessage().delete();
});
preprocessChat(dsender, dmessage);
final String cmd = dmessage.substring(1).toLowerCase();
final String cmdlowercased = dmessage.substring(1).toLowerCase();
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
dsender.sendMessage("Sorry, you can only access these commands:\n"
+ Arrays.stream(UnconnectedCmds).map(uc -> "/" + uc)
@ -392,20 +392,23 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
ListC = 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.");
lastlist = 0;
} else {
int spi = cmd.indexOf(' ');
final String topcmd = spi == -1 ? cmd : cmd.substring(0, spi);
int spi = cmdlowercased.indexOf(' ');
final String topcmd = spi == -1 ? cmdlowercased : cmdlowercased.substring(0, spi);
Optional<Channel> ch = Channel.getChannels().stream()
.filter(c -> c.ID.equalsIgnoreCase(topcmd)
|| (c.IDs != null && c.IDs.length > 0
&& Arrays.stream(c.IDs).anyMatch(id -> id.equalsIgnoreCase(topcmd)))).findAny();
if (!ch.isPresent())
Bukkit.getScheduler().runTask(DiscordPlugin.plugin,
() -> VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd));
() -> {
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmdlowercased);
Bukkit.getLogger().info(dsender.getName() + " issued command from Discord: /" + cmdlowercased);
});
else {
Channel chc = ch.get();
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: "
+ DPUtils.sanitizeString(dsender.getMcchannel().DisplayName));
} else { // Send single message
sendChatMessage.accept(chc, cmd.substring(spi + 1));
sendChatMessage.accept(chc, event.getMessage().getContent().substring(spi + 2));
react = true;
}
}
@ -436,7 +439,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
} else {// Not a command
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
&& !event.getChannel().isPrivate())
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, 0,
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, 0, "everyone",
(dsender instanceof Player ? ((Player) dsender).getDisplayName()
: dsender.getName()) + " pinned a message on Discord.");
else {