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 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.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -89,8 +90,7 @@ public class CommandListener {
|
|||
}
|
||||
if (!event.getMessage().getChannel().isPrivate() //
|
||||
|| DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class)
|
||||
.isMinecraftChatEnabled()
|
||||
|| DiscordPlugin.checkIfSomeoneIsTestingWhileWeArent())
|
||||
.isMinecraftChatEnabled())
|
||||
return;
|
||||
if (event.getMessage().getAuthor().isBot())
|
||||
return;
|
||||
|
@ -99,6 +99,8 @@ public class CommandListener {
|
|||
}, new IListener<sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent>() {
|
||||
@Override
|
||||
public void handle(PresenceUpdateEvent event) {
|
||||
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)
|
||||
|
@ -106,7 +108,8 @@ public class CommandListener {
|
|||
.anyMatch(r -> r.getLongID() == devrole.getLongID())
|
||||
&& DiscordPlugin.devServer.getUsersByRole(devrole).stream()
|
||||
.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!",
|
||||
new EmbedBuilder()
|
||||
.withImage(
|
||||
|
|
|
@ -24,7 +24,8 @@ public class ExceptionListener implements Listener {
|
|||
return;
|
||||
if (lastthrown.stream()
|
||||
.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()))
|
||||
return;
|
||||
SendException(e.getException(), e.getSourceMessage());
|
||||
|
|
|
@ -41,6 +41,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
final EmbedBuilder embed = new EmbedBuilder().withAuthorName(authorPlayer)
|
||||
.withDescription(e.getMessage()).withColor(new Color(e.getChannel().color.getRed(),
|
||||
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)
|
||||
embed.withAuthorIcon("https://minotar.net/avatar/" + ((Player) e.getSender()).getName() + "/32.png")
|
||||
.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())
|
||||
.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=discord&id="
|
||||
+ ((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();
|
||||
Consumer<LastMsgData> doit = lastmsgdata -> {
|
||||
final EmbedObject embedObject = embed.build();
|
||||
String msg = lastmsgdata.channel.isPrivate()
|
||||
final String dmsg = lastmsgdata.channel.isPrivate()
|
||||
? DiscordPlugin.sanitizeString(e.getChannel().DisplayName) : "";
|
||||
if (lastmsgdata.message == null || lastmsgdata.message.isDeleted()
|
||||
|| !authorPlayer.equals(lastmsgdata.message.getEmbeds().get(0).getAuthor().getName())
|
||||
|| lastmsgdata.time / 1000000000f < nanoTime / 1000000000f - 120
|
||||
|| !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.mcchannel = e.getChannel();
|
||||
lastmsgdata.content = embedObject.description;
|
||||
|
@ -67,7 +71,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
lastmsgdata.content = embedObject.description = lastmsgdata.content + "\n"
|
||||
+ embedObject.description;// The message object doesn't get updated
|
||||
final LastMsgData _lastmsgdata = lastmsgdata;
|
||||
DiscordPlugin.perform(() -> _lastmsgdata.message.edit(msg, embedObject));
|
||||
DiscordPlugin.perform(() -> _lastmsgdata.message.edit(dmsg, embedObject));
|
||||
} catch (MissingPermissionsException | DiscordException 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 user = DiscordPlayer.getUser(author.getStringID(), DiscordPlayer.class);
|
||||
if (!event.getMessage().getChannel().getStringID().equals(DiscordPlugin.chatchannel.getStringID())
|
||||
&& !(event.getMessage().getChannel().isPrivate() && user.isMinecraftChatEnabled()
|
||||
&& !DiscordPlugin.checkIfSomeoneIsTestingWhileWeArent()))
|
||||
&& !(event.getMessage().getChannel().isPrivate() && user.isMinecraftChatEnabled()))
|
||||
return;
|
||||
if (!event.getMessage().getChannel().isPrivate())
|
||||
resetLastMessage();
|
||||
|
@ -281,7 +284,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
Optional<Channel> ch = Channel.getChannels().stream().filter(c -> c.ID.equalsIgnoreCase(topcmd))
|
||||
.findAny();
|
||||
if (!ch.isPresent())
|
||||
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin,
|
||||
() -> VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd));
|
||||
else {
|
||||
Channel chc = ch.get();
|
||||
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
|
||||
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
|
||||
&& !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 {
|
||||
sendChatMessage.accept(dsender.getMcchannel(), dmessage);
|
||||
react = true;
|
||||
|
|
Loading…
Reference in a new issue