Fixes related to mcchat and other fixes
- Fixed crash of PresenceUpdateEvent - Lowered the frequency of full houses - Removed testing-related method - Added support for null exception messages... - Added indicator to show if someone is talking from Discord
This commit is contained in:
parent
e4382bbcd2
commit
9a00c260a4
4 changed files with 21 additions and 16 deletions
|
@ -355,9 +355,4 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
return null;
|
return null;
|
||||||
return RequestBuffer.request(action).get(); // Let the pros handle this
|
return RequestBuffer.request(action).get(); // Let the pros handle this
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkIfSomeoneIsTestingWhileWeArent() {
|
|
||||||
return !TBMCCoreAPI.IsTestServer()
|
|
||||||
&& dc.getOurUser().getPresence().getPlayingText().orElse("").equals("testing");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -89,8 +90,7 @@ public class CommandListener {
|
||||||
}
|
}
|
||||||
if (!event.getMessage().getChannel().isPrivate() //
|
if (!event.getMessage().getChannel().isPrivate() //
|
||||||
|| DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class)
|
|| DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class)
|
||||||
.isMinecraftChatEnabled()
|
.isMinecraftChatEnabled())
|
||||||
|| DiscordPlugin.checkIfSomeoneIsTestingWhileWeArent())
|
|
||||||
return;
|
return;
|
||||||
if (event.getMessage().getAuthor().isBot())
|
if (event.getMessage().getAuthor().isBot())
|
||||||
return;
|
return;
|
||||||
|
@ -99,6 +99,8 @@ public class CommandListener {
|
||||||
}, new IListener<sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent>() {
|
}, new IListener<sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent>() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(PresenceUpdateEvent event) {
|
public void handle(PresenceUpdateEvent event) {
|
||||||
|
if (DiscordPlugin.SafeMode)
|
||||||
|
return;
|
||||||
val devrole = DiscordPlugin.devServer.getRolesByName("Developer").get(0);
|
val devrole = DiscordPlugin.devServer.getRolesByName("Developer").get(0);
|
||||||
if (event.getOldPresence().getStatus().equals(StatusType.OFFLINE)
|
if (event.getOldPresence().getStatus().equals(StatusType.OFFLINE)
|
||||||
&& !event.getNewPresence().getStatus().equals(StatusType.OFFLINE)
|
&& !event.getNewPresence().getStatus().equals(StatusType.OFFLINE)
|
||||||
|
@ -106,7 +108,8 @@ public class CommandListener {
|
||||||
.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) {
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.devofficechannel, "Full house!",
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.devofficechannel, "Full house!",
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.withImage(
|
.withImage(
|
||||||
|
|
|
@ -24,7 +24,8 @@ public class ExceptionListener implements Listener {
|
||||||
return;
|
return;
|
||||||
if (lastthrown.stream()
|
if (lastthrown.stream()
|
||||||
.anyMatch(ex -> Arrays.equals(e.getException().getStackTrace(), ex.getStackTrace())
|
.anyMatch(ex -> Arrays.equals(e.getException().getStackTrace(), ex.getStackTrace())
|
||||||
&& e.getException().getMessage().equals(ex.getMessage()))
|
&& e.getException().getMessage() == null ? ex.getMessage() == null
|
||||||
|
: e.getException().getMessage().equals(ex.getMessage())) // e.Exception.Message==ex.Message
|
||||||
&& lastsourcemsg.contains(e.getSourceMessage()))
|
&& lastsourcemsg.contains(e.getSourceMessage()))
|
||||||
return;
|
return;
|
||||||
SendException(e.getException(), e.getSourceMessage());
|
SendException(e.getException(), e.getSourceMessage());
|
||||||
|
|
|
@ -41,6 +41,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
final EmbedBuilder embed = new EmbedBuilder().withAuthorName(authorPlayer)
|
final EmbedBuilder embed = new EmbedBuilder().withAuthorName(authorPlayer)
|
||||||
.withDescription(e.getMessage()).withColor(new Color(e.getChannel().color.getRed(),
|
.withDescription(e.getMessage()).withColor(new Color(e.getChannel().color.getRed(),
|
||||||
e.getChannel().color.getGreen(), e.getChannel().color.getBlue()));
|
e.getChannel().color.getGreen(), e.getChannel().color.getBlue()));
|
||||||
|
// embed.appendField("Channel", ((e.getSender() instanceof DiscordSenderBase ? "d|" : "")
|
||||||
|
// + DiscordPlugin.sanitizeString(e.getChannel().DisplayName)), false);
|
||||||
if (e.getSender() instanceof Player)
|
if (e.getSender() instanceof Player)
|
||||||
embed.withAuthorIcon("https://minotar.net/avatar/" + ((Player) e.getSender()).getName() + "/32.png")
|
embed.withAuthorIcon("https://minotar.net/avatar/" + ((Player) e.getSender()).getName() + "/32.png")
|
||||||
.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=minecraft&id="
|
.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=minecraft&id="
|
||||||
|
@ -49,16 +51,18 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
embed.withAuthorIcon(((DiscordSenderBase) e.getSender()).getUser().getAvatarURL())
|
embed.withAuthorIcon(((DiscordSenderBase) e.getSender()).getUser().getAvatarURL())
|
||||||
.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=discord&id="
|
.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=discord&id="
|
||||||
+ ((DiscordSenderBase) e.getSender()).getUser().getStringID()); // TODO: Constant/method to get URLs like this
|
+ ((DiscordSenderBase) e.getSender()).getUser().getStringID()); // TODO: Constant/method to get URLs like this
|
||||||
|
if (e.getSender() instanceof DiscordSenderBase)
|
||||||
|
embed.withAuthorName("[D]" + authorPlayer);
|
||||||
final long nanoTime = System.nanoTime();
|
final long nanoTime = System.nanoTime();
|
||||||
Consumer<LastMsgData> doit = lastmsgdata -> {
|
Consumer<LastMsgData> doit = lastmsgdata -> {
|
||||||
final EmbedObject embedObject = embed.build();
|
final EmbedObject embedObject = embed.build();
|
||||||
String msg = lastmsgdata.channel.isPrivate()
|
final String dmsg = lastmsgdata.channel.isPrivate()
|
||||||
? DiscordPlugin.sanitizeString(e.getChannel().DisplayName) : "";
|
? DiscordPlugin.sanitizeString(e.getChannel().DisplayName) : "";
|
||||||
if (lastmsgdata.message == null || lastmsgdata.message.isDeleted()
|
if (lastmsgdata.message == null || lastmsgdata.message.isDeleted()
|
||||||
|| !authorPlayer.equals(lastmsgdata.message.getEmbeds().get(0).getAuthor().getName())
|
|| !authorPlayer.equals(lastmsgdata.message.getEmbeds().get(0).getAuthor().getName())
|
||||||
|| lastmsgdata.time / 1000000000f < nanoTime / 1000000000f - 120
|
|| lastmsgdata.time / 1000000000f < nanoTime / 1000000000f - 120
|
||||||
|| !lastmsgdata.mcchannel.ID.equals(e.getChannel().ID)) {
|
|| !lastmsgdata.mcchannel.ID.equals(e.getChannel().ID)) {
|
||||||
lastmsgdata.message = DiscordPlugin.sendMessageToChannel(lastmsgdata.channel, msg, embedObject);
|
lastmsgdata.message = DiscordPlugin.sendMessageToChannel(lastmsgdata.channel, dmsg, embedObject);
|
||||||
lastmsgdata.time = nanoTime;
|
lastmsgdata.time = nanoTime;
|
||||||
lastmsgdata.mcchannel = e.getChannel();
|
lastmsgdata.mcchannel = e.getChannel();
|
||||||
lastmsgdata.content = embedObject.description;
|
lastmsgdata.content = embedObject.description;
|
||||||
|
@ -67,7 +71,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
lastmsgdata.content = embedObject.description = lastmsgdata.content + "\n"
|
lastmsgdata.content = embedObject.description = lastmsgdata.content + "\n"
|
||||||
+ embedObject.description;// The message object doesn't get updated
|
+ embedObject.description;// The message object doesn't get updated
|
||||||
final LastMsgData _lastmsgdata = lastmsgdata;
|
final LastMsgData _lastmsgdata = lastmsgdata;
|
||||||
DiscordPlugin.perform(() -> _lastmsgdata.message.edit(msg, embedObject));
|
DiscordPlugin.perform(() -> _lastmsgdata.message.edit(dmsg, embedObject));
|
||||||
} catch (MissingPermissionsException | DiscordException e1) {
|
} catch (MissingPermissionsException | DiscordException e1) {
|
||||||
TBMCCoreAPI.SendException("An error occured while editing chat message!", e1);
|
TBMCCoreAPI.SendException("An error occured while editing chat message!", e1);
|
||||||
}
|
}
|
||||||
|
@ -218,8 +222,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
val author = event.getMessage().getAuthor();
|
val author = event.getMessage().getAuthor();
|
||||||
val user = DiscordPlayer.getUser(author.getStringID(), DiscordPlayer.class);
|
val user = DiscordPlayer.getUser(author.getStringID(), DiscordPlayer.class);
|
||||||
if (!event.getMessage().getChannel().getStringID().equals(DiscordPlugin.chatchannel.getStringID())
|
if (!event.getMessage().getChannel().getStringID().equals(DiscordPlugin.chatchannel.getStringID())
|
||||||
&& !(event.getMessage().getChannel().isPrivate() && user.isMinecraftChatEnabled()
|
&& !(event.getMessage().getChannel().isPrivate() && user.isMinecraftChatEnabled()))
|
||||||
&& !DiscordPlugin.checkIfSomeoneIsTestingWhileWeArent()))
|
|
||||||
return;
|
return;
|
||||||
if (!event.getMessage().getChannel().isPrivate())
|
if (!event.getMessage().getChannel().isPrivate())
|
||||||
resetLastMessage();
|
resetLastMessage();
|
||||||
|
@ -281,7 +284,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
Optional<Channel> ch = Channel.getChannels().stream().filter(c -> c.ID.equalsIgnoreCase(topcmd))
|
Optional<Channel> ch = Channel.getChannels().stream().filter(c -> c.ID.equalsIgnoreCase(topcmd))
|
||||||
.findAny();
|
.findAny();
|
||||||
if (!ch.isPresent())
|
if (!ch.isPresent())
|
||||||
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
Bukkit.getScheduler().runTask(DiscordPlugin.plugin,
|
||||||
|
() -> VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd));
|
||||||
else {
|
else {
|
||||||
Channel chc = ch.get();
|
Channel chc = ch.get();
|
||||||
if (!chc.ID.equals(Channel.GlobalChat.ID) && !event.getMessage().getChannel().isPrivate())
|
if (!chc.ID.equals(Channel.GlobalChat.ID) && !event.getMessage().getChannel().isPrivate())
|
||||||
|
@ -312,7 +316,9 @@ 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.SendChatMessage(Channel.GlobalChat, dsender, "pinned a message on Discord."); // TODO: Not chat message
|
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, 0,
|
||||||
|
(dsender instanceof Player ? ((Player) dsender).getDisplayName() : dsender.getName())
|
||||||
|
+ " pinned a message on Discord.");
|
||||||
else {
|
else {
|
||||||
sendChatMessage.accept(dsender.getMcchannel(), dmessage);
|
sendChatMessage.accept(dsender.getMcchannel(), dmessage);
|
||||||
react = true;
|
react = true;
|
||||||
|
|
Loading…
Reference in a new issue