Added mute support, fixed chat msg removal, added a bit more support for mentions, fixes etc. #28
9 changed files with 62 additions and 64 deletions
|
@ -76,29 +76,29 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
try {
|
||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
|
||||
if (mainServer == null || devServer == null) {
|
||||
mainServer = event.getClient().getGuildByID("125813020357165056");
|
||||
devServer = event.getClient().getGuildByID("219529124321034241");
|
||||
mainServer = event.getClient().getGuildByID(125813020357165056L);
|
||||
devServer = event.getClient().getGuildByID(219529124321034241L);
|
||||
}
|
||||
if (mainServer == null || devServer == null)
|
||||
return; // Retry
|
||||
if (!TBMCCoreAPI.IsTestServer()) {
|
||||
botchannel = mainServer.getChannelByID("209720707188260864"); // bot
|
||||
annchannel = mainServer.getChannelByID("126795071927353344"); // announcements
|
||||
genchannel = mainServer.getChannelByID("125813020357165056"); // general
|
||||
chatchannel = mainServer.getChannelByID("249663564057411596"); // minecraft_chat
|
||||
botroomchannel = devServer.getChannelByID("239519012529111040"); // bot-room
|
||||
officechannel = devServer.getChannelByID("219626707458457603"); // developers-office
|
||||
updatechannel = devServer.getChannelByID("233724163519414272"); // server-updates
|
||||
dc.changeStatus(Status.game("on TBMC"));
|
||||
botchannel = mainServer.getChannelByID(209720707188260864L); // bot
|
||||
annchannel = mainServer.getChannelByID(126795071927353344L); // announcements
|
||||
genchannel = mainServer.getChannelByID(125813020357165056L); // general
|
||||
chatchannel = mainServer.getChannelByID(249663564057411596L); // minecraft_chat
|
||||
botroomchannel = devServer.getChannelByID(239519012529111040L); // bot-room
|
||||
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
||||
updatechannel = devServer.getChannelByID(233724163519414272L); // server-updates
|
||||
dc.online("on TBMC");
|
||||
} else {
|
||||
botchannel = devServer.getChannelByID("239519012529111040"); // bot-room
|
||||
botchannel = devServer.getChannelByID(239519012529111040L); // bot-room
|
||||
annchannel = botchannel; // bot-room
|
||||
genchannel = botchannel; // bot-room
|
||||
botroomchannel = botchannel;// bot-room
|
||||
chatchannel = botchannel;// bot-room
|
||||
officechannel = devServer.getChannelByID("219626707458457603"); // developers-office
|
||||
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
||||
updatechannel = botchannel;
|
||||
dc.changeStatus(Status.game("testing"));
|
||||
dc.online("testing");
|
||||
}
|
||||
if (botchannel == null || annchannel == null || genchannel == null || botroomchannel == null
|
||||
|| chatchannel == null || officechannel == null || updatechannel == null)
|
||||
|
@ -155,7 +155,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Restart ? Color.ORANGE : Color.RED)
|
||||
.withTitle(Restart ? "Server restarting" : "Server stopping").build());
|
||||
try {
|
||||
dc.changeStatus(Status.game("on TBMC"));
|
||||
dc.online("on TBMC");
|
||||
dc.logout();
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while disabling DiscordPlugin!", e);
|
||||
|
|
|
@ -37,10 +37,10 @@ public class ConnectCommand extends DiscordCommandBase {
|
|||
"Too many arguments.\nUsage: connect <Minecraftname>");
|
||||
return;
|
||||
}
|
||||
if (WaitingToConnect.inverse().containsKey(message.getAuthor().getID())) {
|
||||
if (WaitingToConnect.inverse().containsKey(message.getAuthor().getStringID())) {
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||
"Replacing " + WaitingToConnect.inverse().get(message.getAuthor().getID()) + " with " + args);
|
||||
WaitingToConnect.inverse().remove(message.getAuthor().getID());
|
||||
"Replacing " + WaitingToConnect.inverse().get(message.getAuthor().getStringID()) + " with " + args);
|
||||
WaitingToConnect.inverse().remove(message.getAuthor().getStringID());
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(args);
|
||||
|
@ -50,7 +50,7 @@ public class ConnectCommand extends DiscordCommandBase {
|
|||
}
|
||||
try (TBMCPlayer pl = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class)) {
|
||||
DiscordPlayer dp = pl.getAs(DiscordPlayer.class);
|
||||
if (dp != null && message.getAuthor().getID().equals(dp.getDiscordID())) {
|
||||
if (dp != null && message.getAuthor().getStringID().equals(dp.getDiscordID())) {
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "You already have this account connected.");
|
||||
return;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class ConnectCommand extends DiscordCommandBase {
|
|||
TBMCCoreAPI.SendException("An error occured while connecting a Discord account!", e);
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "An internal error occured!\n" + e);
|
||||
}
|
||||
WaitingToConnect.put(p.getName(), message.getAuthor().getID());
|
||||
WaitingToConnect.put(p.getName(), message.getAuthor().getStringID());
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||
"Pending connection - accept connection in Minecraft from the account " + args
|
||||
+ " before the server gets restarted. You can also adjust the Minecraft name you want to connect to with the same command.");
|
||||
|
|
|
@ -50,7 +50,7 @@ public class RoleCommand extends DiscordCommandBase {
|
|||
"List of game roles:\n" + DiscordPlugin.GameRoles.stream().collect(Collectors.joining("\n")));
|
||||
} else if (argsa[0].equalsIgnoreCase("addrole")) {
|
||||
if (!message.getAuthor().getRolesForGuild(DiscordPlugin.mainServer).stream()
|
||||
.anyMatch(r -> r.getID().equals("126030201472811008"))) {
|
||||
.anyMatch(r -> r.getLongID() == 126030201472811008L)) {
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||
"You need to be a moderator to use this command.");
|
||||
return;
|
||||
|
|
|
@ -30,7 +30,7 @@ public class UserinfoCommand extends DiscordCommandBase {
|
|||
target = message.getAuthor();
|
||||
else {
|
||||
final Optional<IUser> firstmention = message.getMentions().stream()
|
||||
.filter(m -> !m.getID().equals(DiscordPlugin.dc.getOurUser().getID())).findFirst();
|
||||
.filter(m -> !m.getStringID().equals(DiscordPlugin.dc.getOurUser().getStringID())).findFirst();
|
||||
if (firstmention.isPresent())
|
||||
target = firstmention.get();
|
||||
else if (args.contains("#")) {
|
||||
|
@ -68,7 +68,7 @@ public class UserinfoCommand extends DiscordCommandBase {
|
|||
target = targets.get(0);
|
||||
}
|
||||
}
|
||||
try (DiscordPlayer dp = ChromaGamerBase.getUser(target.getID(), DiscordPlayer.class)) {
|
||||
try (DiscordPlayer dp = ChromaGamerBase.getUser(target.getStringID(), DiscordPlayer.class)) {
|
||||
StringBuilder uinfo = new StringBuilder("User info for ").append(target.getName()).append(":\n");
|
||||
uinfo.append(dp.getInfo(InfoTarget.Discord));
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), uinfo.toString());
|
||||
|
|
|
@ -7,7 +7,7 @@ import buttondevteam.discordplugin.DiscordPlugin;
|
|||
import buttondevteam.discordplugin.DiscordSender;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import sx.blah.discord.api.events.IListener;
|
||||
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
||||
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
|
||||
import sx.blah.discord.handle.obj.IEmbed;
|
||||
import sx.blah.discord.util.EmbedBuilder;
|
||||
|
||||
|
@ -16,13 +16,13 @@ public class AutoUpdaterListener implements IListener<MessageReceivedEvent> {
|
|||
public void handle(MessageReceivedEvent event) {
|
||||
if (DiscordPlugin.SafeMode)
|
||||
return;
|
||||
if (!event.getMessage().getChannel().getID().equals(DiscordPlugin.officechannel.getID()))
|
||||
if (!event.getMessage().getChannel().getStringID().equals(DiscordPlugin.officechannel.getStringID()))
|
||||
return;
|
||||
if (!"239123781401051138".equals(event.getMessage().getWebhookID()))
|
||||
if (239123781401051138L != event.getMessage().getWebhookLongID())
|
||||
return;
|
||||
if (event.getMessage().getEmbedded().size() == 0)
|
||||
if (event.getMessage().getEmbeds().size() == 0)
|
||||
return;
|
||||
final IEmbed embed = event.getMessage().getEmbedded().get(0);
|
||||
final IEmbed embed = event.getMessage().getEmbeds().get(0);
|
||||
final String title = embed.getTitle();
|
||||
if (!title.contains("new commit"))
|
||||
return;
|
||||
|
|
|
@ -3,8 +3,8 @@ package buttondevteam.discordplugin.listeners;
|
|||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.commands.DiscordCommandBase;
|
||||
import sx.blah.discord.api.events.IListener;
|
||||
import sx.blah.discord.handle.impl.events.MentionEvent;
|
||||
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
||||
import sx.blah.discord.handle.impl.events.guild.channel.message.MentionEvent;
|
||||
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
|
||||
import sx.blah.discord.handle.obj.IChannel;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
|
||||
|
@ -19,9 +19,9 @@ public class CommandListener {
|
|||
if (event.getMessage().getAuthor().isBot())
|
||||
return;
|
||||
final IChannel channel = event.getMessage().getChannel();
|
||||
if (!channel.getID().equals(DiscordPlugin.botchannel.getID()) && !channel.isPrivate())
|
||||
if (!channel.getStringID().equals(DiscordPlugin.botchannel.getStringID()) && !channel.isPrivate())
|
||||
return;
|
||||
if (channel.getID().equals(DiscordPlugin.chatchannel.getID()))
|
||||
if (channel.getStringID().equals(DiscordPlugin.chatchannel.getStringID()))
|
||||
return; // The chat code already handles this - Right now while testing botchannel is the same as chatchannel
|
||||
runCommand(event.getMessage(), true);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package buttondevteam.discordplugin.listeners;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -17,7 +16,7 @@ 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;
|
||||
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
||||
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
|
||||
import sx.blah.discord.handle.obj.*;
|
||||
import sx.blah.discord.util.*;
|
||||
|
||||
|
@ -41,13 +40,13 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
: embed.build();
|
||||
final long nanoTime = System.nanoTime();
|
||||
if (lastmessage == null || lastmessage.isDeleted()
|
||||
|| !authorPlayer.equals(lastmessage.getEmbedded().get(0).getAuthor().getName())
|
||||
|| !authorPlayer.equals(lastmessage.getEmbeds().get(0).getAuthor().getName())
|
||||
|| lastmsgtime / 1000000000f < nanoTime / 1000000000f - 120) {
|
||||
lastmessage = DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel, "", embedObject);
|
||||
lastmsgtime = nanoTime;
|
||||
} else
|
||||
try {
|
||||
embedObject.description = lastmessage.getEmbedded().get(0).getDescription() + "\n"
|
||||
embedObject.description = lastmessage.getEmbeds().get(0).getDescription() + "\n"
|
||||
+ embedObject.description;
|
||||
DiscordPlugin.perform(() -> lastmessage.edit("", embedObject));
|
||||
} catch (MissingPermissionsException | DiscordException e1) {
|
||||
|
@ -73,9 +72,9 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
}
|
||||
|
||||
@Override // Discord
|
||||
public void handle(MessageReceivedEvent event) {
|
||||
public void handle(sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent event) {
|
||||
final IUser author = event.getMessage().getAuthor();
|
||||
if (!event.getMessage().getChannel().getID().equals(DiscordPlugin.chatchannel.getID())
|
||||
if (!event.getMessage().getChannel().getStringID().equals(DiscordPlugin.chatchannel.getStringID())
|
||||
/* && !(event.getMessage().getChannel().isPrivate() && privatechat) */)
|
||||
return;
|
||||
lastmessage = null;
|
||||
|
@ -87,28 +86,28 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
String dmessage = event.getMessage().getContent();
|
||||
synchronized (this) {
|
||||
try {
|
||||
DiscordPlayer dp = ChromaGamerBase.getUser(author.getID(), DiscordPlayer.class);
|
||||
DiscordPlayer dp = ChromaGamerBase.getUser(author.getStringID(), DiscordPlayer.class);
|
||||
final DiscordSenderBase dsender;
|
||||
Player mcp = null; // Offline players can't really run commands
|
||||
final String cid;
|
||||
if ((cid = dp.getConnectedID(TBMCPlayer.class)) != null // Connected?
|
||||
&& (mcp = Bukkit.getPlayer(cid)) != null) { // Execute as ingame player, if online
|
||||
if (!ConnectedSenders.containsKey(author.getID()))
|
||||
ConnectedSenders.put(author.getID(),
|
||||
if (!ConnectedSenders.containsKey(author.getStringID()))
|
||||
ConnectedSenders.put(author.getStringID(),
|
||||
new DiscordPlayerSender(author, event.getMessage().getChannel(), mcp));
|
||||
dsender = ConnectedSenders.get(author.getID());
|
||||
dsender = ConnectedSenders.get(author.getStringID());
|
||||
} else {
|
||||
TBMCPlayer p = dp.getAs(TBMCPlayer.class);
|
||||
if (!UnconnectedSenders.containsKey(author.getID()))
|
||||
UnconnectedSenders.put(author.getID(), new DiscordSender(author,
|
||||
if (!UnconnectedSenders.containsKey(author.getStringID()))
|
||||
UnconnectedSenders.put(author.getStringID(), new DiscordSender(author,
|
||||
event.getMessage().getChannel(), p == null ? null : p.PlayerName().get())); // Display the playername, if found
|
||||
dsender = UnconnectedSenders.get(author.getID());
|
||||
dsender = UnconnectedSenders.get(author.getStringID());
|
||||
}
|
||||
|
||||
for (IUser u : event.getMessage().getMentions()) {
|
||||
dmessage = dmessage.replace(u.mention(false), "@" + u.getName()); // TODO: IG Formatting
|
||||
final Optional<String> nick = u.getNicknameForGuild(DiscordPlugin.mainServer);
|
||||
dmessage = dmessage.replace(u.mention(true), "@" + (nick.isPresent() ? nick.get() : u.getName()));
|
||||
final String nick = u.getNicknameForGuild(DiscordPlugin.mainServer);
|
||||
dmessage = dmessage.replace(u.mention(true), "@" + (nick != null ? nick : u.getName()));
|
||||
}
|
||||
|
||||
if (dmessage.startsWith("/")) {
|
||||
|
@ -142,9 +141,9 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
dmessage + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage()
|
||||
.getAttachments().stream().map(a -> a.getUrl()).collect(Collectors.joining("\n"))
|
||||
: ""));
|
||||
event.getMessage().getChannel().getMessages().stream().forEach(m -> {
|
||||
event.getMessage().getChannel().getMessageHistory().stream().forEach(m -> {
|
||||
try {
|
||||
final IReaction reaction = m.getReactionByName(DiscordPlugin.DELIVERED_REACTION);
|
||||
final IReaction reaction = m.getReactionByUnicode(DiscordPlugin.DELIVERED_REACTION);
|
||||
if (reaction != null)
|
||||
DiscordPlugin.perform(() -> m.removeReaction(reaction));
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -18,7 +18,6 @@ import buttondevteam.lib.player.*;
|
|||
import net.ess3.api.events.*;
|
||||
import sx.blah.discord.handle.obj.IRole;
|
||||
import sx.blah.discord.handle.obj.IUser;
|
||||
import sx.blah.discord.handle.obj.Status.StatusType;
|
||||
import sx.blah.discord.util.DiscordException;
|
||||
import sx.blah.discord.util.MissingPermissionsException;
|
||||
|
||||
|
@ -28,7 +27,7 @@ public class MCListener implements Listener {
|
|||
final Player p = Bukkit.getPlayer(e.GetPlayer().getUUID());
|
||||
if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().get())) {
|
||||
IUser user = DiscordPlugin.dc
|
||||
.getUserByID(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().get()));
|
||||
.getUserByID(Long.parseLong(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().get())));
|
||||
p.sendMessage("§bTo connect with the Discord account @" + user.getName() + "#" + user.getDiscriminator()
|
||||
+ " do /discord accept");
|
||||
p.sendMessage("§bIf it wasn't you, do /discord decline");
|
||||
|
@ -51,15 +50,13 @@ public class MCListener implements Listener {
|
|||
DiscordPlayer dp = e.getPlayer().getAs(DiscordPlayer.class);
|
||||
if (dp == null || dp.getDiscordID() == null || dp.getDiscordID() == "")
|
||||
return;
|
||||
IUser user = DiscordPlugin.dc.getUserByID(dp.getDiscordID());
|
||||
IUser user = DiscordPlugin.dc.getUserByID(Long.parseLong(dp.getDiscordID()));
|
||||
e.addInfo("Discord tag: " + user.getName() + "#" + user.getDiscriminator());
|
||||
if (!user.getStatus().getType().equals(StatusType.NONE)) {
|
||||
if (user.getStatus().getType().equals(StatusType.GAME))
|
||||
e.addInfo("Discord status: Playing " + user.getStatus().getStatusMessage());
|
||||
else if (user.getStatus().getType().equals(StatusType.STREAM))
|
||||
e.addInfo("Discord status: Streaming " + user.getStatus().getStatusMessage() + " - "
|
||||
+ user.getStatus().getUrl());
|
||||
}
|
||||
e.addInfo(user.getPresence().getStatus().toString());
|
||||
if (user.getPresence().getPlayingText().isPresent())
|
||||
e.addInfo("Playing " + user.getPresence().getPlayingText().get());
|
||||
else if (user.getPresence().getStreamingUrl().isPresent())
|
||||
e.addInfo("Streaming " + user.getPresence().getStreamingUrl().get());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
|
@ -85,13 +82,13 @@ public class MCListener implements Listener {
|
|||
public void onPlayerMute(MuteStatusChangeEvent e) {
|
||||
try {
|
||||
DiscordPlugin.perform(() -> {
|
||||
final IRole role = DiscordPlugin.dc.getRoleByID("164090010461667328");
|
||||
final IRole role = DiscordPlugin.dc.getRoleByID(164090010461667328L);
|
||||
final CommandSource source = e.getAffected().getSource();
|
||||
if (!source.isPlayer())
|
||||
return;
|
||||
final IUser user = DiscordPlugin.dc
|
||||
.getUserByID(TBMCPlayerBase.getPlayer(source.getPlayer().getUniqueId(), TBMCPlayer.class)
|
||||
.getAs(DiscordPlayer.class).getDiscordID());
|
||||
final IUser user = DiscordPlugin.dc.getUserByID(
|
||||
Long.parseLong(TBMCPlayerBase.getPlayer(source.getPlayer().getUniqueId(), TBMCPlayer.class)
|
||||
.getAs(DiscordPlayer.class).getDiscordID())); // TODO: Use long
|
||||
if (e.getValue())
|
||||
user.addRole(role);
|
||||
else
|
||||
|
|
|
@ -37,7 +37,8 @@ public class AppTest extends TestCase {
|
|||
public void testApp() {
|
||||
/*String sourcemessage = "Test message";
|
||||
Exception e = new Exception("Test exception");
|
||||
StringBuilder sb = TBMCCoreAPI.IsTestServer() ? new StringBuilder() : new StringBuilder("").append("\n");
|
||||
StringBuilder sb = TBMCCoreAPI.IsTestServer() ? new StringBuilder()
|
||||
: new StringBuilder("Coder role").append("\n");
|
||||
sb.append(sourcemessage).append("\n");
|
||||
sb.append("```").append("\n");
|
||||
String stackTrace = Arrays.stream(ExceptionUtils.getStackTrace(e).split("\\n"))
|
||||
|
@ -52,7 +53,8 @@ public class AppTest extends TestCase {
|
|||
stackTrace = stackTrace.substring(0, 1800);
|
||||
sb.append(stackTrace).append("\n");
|
||||
sb.append("```");
|
||||
System.out.println(sb.toString()); */
|
||||
System.out.println(sb.toString());
|
||||
assertTrue(sb.toString().contains("Coder role"));*/
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue