Added private Minecraft chat, Discord login, show message pinning, Maven project check, some of #12 #39

Merged
NorbiPeti merged 21 commits from dev into master 2017-07-04 16:14:01 +00:00
5 changed files with 24 additions and 22 deletions
Showing only changes of commit 6cd81a6776 - Show all commits

View file

@ -247,7 +247,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
try {
if (channel == chatchannel)
MCChatListener.resetLastMessage(); // If this is a chat message, it'll be set again
final String content = TBMCCoreAPI.IsTestServer() && channel != chatchannel
final String content = TBMCCoreAPI.IsTestServer() && channel != chatchannel || channel == botroomchannel // Both are the same for testing
? "*The following message is from a test server*\n" + message : message;
return perform(
() -> embed == null ? channel.sendMessage(content) : channel.sendMessage(content, embed, false));

View file

@ -27,7 +27,9 @@ public abstract class DiscordCommandBase {
DiscordCommandBase command = commands.get(cmd);
if (command == null) {
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"Unknown command: " + cmd + " with args: " + args + "\nDo @ChromaBot help for help");
"Unknown command: " + cmd + " with args: " + args + "\nDo '"
+ (message.getChannel().isPrivate() ? "" : message.getClient().getOurUser().mention() + " ")
+ "help' for help");
return;
}
try {

View file

@ -21,7 +21,9 @@ public class MCChatCommand extends DiscordCommandBase {
try (final DiscordPlayer user = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)) {
PlayerData<Boolean> mcchat = user.minecraftChat();
mcchat.set(!mcchat.getOrDefault(false));
message.reply("Minecraft chat " + (mcchat.get() ? "enabled." : "disabled."));
message.reply(
"Minecraft chat " + (mcchat.get() ? "enabled. Use '" + message.getClient().getOurUser().mention()
+ " mcchat' (with the mention) to disable." : "disabled."));
} catch (Exception e) {
TBMCCoreAPI.SendException("Error while setting mcchat for user" + message.getAuthor().getName(), e);
}

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.commands.DiscordCommandBase;
import sx.blah.discord.api.events.IListener;
@ -24,20 +25,14 @@ public class CommandListener {
"In 18 commits", // Ali
"After we finish strangling Towny", // Ali
"When we kill every bug in the system", // Ali
"Once the server stops screaming error messages.",// Ali
"After HL3 comes out", //Ali
"It'll be ready next time you ask", //Ali
"Once the server stops screaming error messages.", // Ali
"After HL3 comes out", // Ali
"It'll be ready next time you ask", // Ali
};
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 finished",
"when's the server ready",
"when's the server 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 finished", "when's the server ready", "when's the server open" };
private static final Random serverReadyRandom = new Random();
private static final ArrayList<Short> usableServerReadyStrings = new ArrayList<Short>(serverReadyStrings.length) {
@ -65,6 +60,9 @@ public class CommandListener {
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
if (DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat()
.getOrDefault(false)) // Let the MCChatListener handle it
return;
runCommand(event.getMessage(), true);
}
}, new IListener<MessageReceivedEvent>() {
@ -80,7 +78,9 @@ public class CommandListener {
next = usableServerReadyStrings.remove(serverReadyRandom.nextInt(usableServerReadyStrings.size()));
DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), serverReadyStrings[next]);
}
if (!event.getMessage().getChannel().isPrivate())
if (!event.getMessage().getChannel().isPrivate()
|| DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat()
.getOrDefault(false))
return;
if (event.getMessage().getAuthor().isBot())
return;

View file

@ -15,7 +15,6 @@ import buttondevteam.discordplugin.*;
import buttondevteam.lib.*;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.ChromaGamerBase;
import buttondevteam.lib.player.TBMCPlayer;
import sx.blah.discord.api.events.IListener;
import sx.blah.discord.api.internal.json.objects.EmbedObject;
@ -124,9 +123,9 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
@Override // Discord
public void handle(MessageReceivedEvent event) {
final IUser author = event.getMessage().getAuthor();
final DiscordPlayer user = DiscordPlayer.getUser(author.getStringID(), DiscordPlayer.class);
if (!event.getMessage().getChannel().getStringID().equals(DiscordPlugin.chatchannel.getStringID())
&& !(event.getMessage().getChannel().isPrivate() && DiscordPlayer
.getUser(author.getStringID(), DiscordPlayer.class).minecraftChat().getOrDefault(false)))
&& !(event.getMessage().getChannel().isPrivate() && user.minecraftChat().getOrDefault(false)))
return;
resetLastMessage();
lastlist++;
@ -137,8 +136,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
String dmessage = event.getMessage().getContent();
synchronized (this) {
try {
DiscordPlayer dp = ChromaGamerBase.getUser(author.getStringID(), DiscordPlayer.class);
final DiscordSenderBase dsender = getSender(event.getMessage().getChannel(), author, dp);
final DiscordSenderBase dsender = getSender(event.getMessage().getChannel(), author, user);
for (IUser u : event.getMessage().getMentions()) {
dmessage = dmessage.replace(u.mention(false), "@" + u.getName()); // TODO: IG Formatting
@ -148,7 +146,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
if (dmessage.startsWith("/")) {
DiscordPlugin.perform(() -> {
if (!event.getMessage().isDeleted())
if (!event.getMessage().isDeleted() && !event.getChannel().isPrivate())
event.getMessage().delete();
});
final String cmd = dmessage.substring(1).toLowerCase();