Crash detect, chat channels, fixed mcchat, improvements #43
3 changed files with 58 additions and 12 deletions
|
@ -20,6 +20,8 @@ import buttondevteam.discordplugin.listeners.*;
|
|||
import buttondevteam.discordplugin.mccommands.DiscordMCCommandBase;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import lombok.val;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import sx.blah.discord.api.*;
|
||||
import sx.blah.discord.api.events.IListener;
|
||||
|
@ -67,6 +69,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
*/
|
||||
public static IChannel officechannel;
|
||||
public static IChannel updatechannel;
|
||||
public static IChannel devofficechannel;
|
||||
public static IGuild mainServer;
|
||||
public static IGuild devServer;
|
||||
|
||||
|
@ -91,6 +94,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
botroomchannel = devServer.getChannelByID(239519012529111040L); // bot-room
|
||||
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
||||
updatechannel = devServer.getChannelByID(233724163519414272L); // server-updates
|
||||
devofficechannel = officechannel; // developers-office
|
||||
dc.online("on TBMC");
|
||||
} else {
|
||||
botchannel = devServer.getChannelByID(239519012529111040L); // bot-room
|
||||
|
@ -100,6 +104,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
chatchannel = botchannel;// bot-room
|
||||
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
||||
updatechannel = botchannel;
|
||||
devofficechannel = botchannel;// bot-room
|
||||
dc.online("testing");
|
||||
}
|
||||
if (botchannel == null || annchannel == null || genchannel == null || botroomchannel == null
|
||||
|
@ -109,17 +114,26 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
if (task != null)
|
||||
task.cancel();
|
||||
if (!sent) {
|
||||
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Color.GREEN)
|
||||
.withTitle("Server started - chat connected.").build());
|
||||
try {
|
||||
List<IMessage> msgs = genchannel.getPinnedMessages();
|
||||
for (int i = msgs.size() - 1; i >= 10; i--) { // Unpin all pinned messages except the newest 10
|
||||
genchannel.unpin(msgs.get(i));
|
||||
Thread.sleep(10);
|
||||
if (getConfig().getBoolean("serverup", false)) {
|
||||
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Color.YELLOW)
|
||||
.withTitle("Server recovered from a crash - chat connected.").build());
|
||||
TBMCCoreAPI.SendException("The server crashed!", new Throwable(
|
||||
"The server shut down unexpectedly. See the log of the previous run for more details."));
|
||||
} else
|
||||
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Color.GREEN)
|
||||
.withTitle("Server started - chat connected.").build());
|
||||
getConfig().set("serverup", true);
|
||||
saveConfig();
|
||||
perform(() -> {
|
||||
try {
|
||||
List<IMessage> msgs = genchannel.getPinnedMessages();
|
||||
for (int i = msgs.size() - 1; i >= 10; i--) { // Unpin all pinned messages except the newest 10
|
||||
genchannel.unpin(msgs.get(i));
|
||||
Thread.sleep(10);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error occured while unpinning messages!", e);
|
||||
}
|
||||
});
|
||||
sent = true;
|
||||
}
|
||||
}, 0, 10);
|
||||
|
@ -172,6 +186,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
getConfig().set("lastannouncementtime", lastannouncementtime);
|
||||
getConfig().set("lastseentime", lastseentime);
|
||||
getConfig().set("gameroles", GameRoles);
|
||||
getConfig().set("serverup", false);
|
||||
saveConfig();
|
||||
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Restart ? Color.ORANGE : Color.RED)
|
||||
.withTitle(Restart ? "Server restarting" : "Server stopping").build());
|
||||
|
@ -203,7 +218,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
for (int i = json.size() - 1; i >= 0; i--) {
|
||||
JsonObject item = json.get(i).getAsJsonObject();
|
||||
final JsonObject data = item.get("data").getAsJsonObject();
|
||||
String author = data.get("author").getAsString();
|
||||
String author = "/u/" + data.get("author").getAsString();
|
||||
JsonElement distinguishedjson = data.get("distinguished");
|
||||
String distinguished;
|
||||
if (distinguishedjson.isJsonNull())
|
||||
|
@ -215,6 +230,15 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
if (date > lastseentime)
|
||||
lastseentime = date;
|
||||
else if (date > lastannouncementtime) {
|
||||
do {
|
||||
val reddituserclass = ChromaGamerBase.getTypeForFolder("reddit");
|
||||
if (reddituserclass == null)
|
||||
break;
|
||||
val user = ChromaGamerBase.getUser(author, reddituserclass);
|
||||
String id = user.getConnectedID(DiscordPlayer.class);
|
||||
if (id != null)
|
||||
author = "<@" + id + ">";
|
||||
} while (false);
|
||||
(distinguished != null && distinguished.equals("moderator") ? modmsgsb : msgsb)
|
||||
.append("A new post was submitted to the subreddit by ").append(author).append("\n")
|
||||
.append(permalink).append("\n");
|
||||
|
|
|
@ -8,11 +8,15 @@ import buttondevteam.discordplugin.DiscordPlayer;
|
|||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.commands.DiscordCommandBase;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import lombok.val;
|
||||
import sx.blah.discord.api.events.IListener;
|
||||
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.impl.events.user.PresenceUpdateEvent;
|
||||
import sx.blah.discord.handle.obj.IChannel;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
import sx.blah.discord.handle.obj.StatusType;
|
||||
import sx.blah.discord.util.EmbedBuilder;
|
||||
|
||||
public class CommandListener {
|
||||
|
||||
|
@ -89,6 +93,22 @@ public class CommandListener {
|
|||
return;
|
||||
runCommand(event.getMessage(), false);
|
||||
}
|
||||
}, new IListener<sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent>() {
|
||||
@Override
|
||||
public void handle(PresenceUpdateEvent event) {
|
||||
val devrole = DiscordPlugin.devServer.getRolesByName("Developer").get(0);
|
||||
if (event.getOldPresence().getStatus().equals(StatusType.OFFLINE)
|
||||
&& !event.getNewPresence().getStatus().equals(StatusType.OFFLINE)
|
||||
&& event.getUser().getRolesForGuild(DiscordPlugin.devServer).stream()
|
||||
.anyMatch(r -> r.getLongID() == devrole.getLongID())
|
||||
&& DiscordPlugin.devServer.getUsersByRole(devrole).stream()
|
||||
.noneMatch(u -> u.getPresence().getStatus().equals(StatusType.OFFLINE)))
|
||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.devofficechannel, "Full house!",
|
||||
new EmbedBuilder()
|
||||
.withImage(
|
||||
"https://cdn.discordapp.com/attachments/249295547263877121/249687682618359808/poker-hand-full-house-aces-kings-playing-cards-15553791.png")
|
||||
.build());
|
||||
}
|
||||
} };
|
||||
}
|
||||
|
||||
|
|
|
@ -238,8 +238,10 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
{
|
||||
dsender.sendMessage("Stop it. You know the answer.");
|
||||
lastlist = 0;
|
||||
} else
|
||||
} else {
|
||||
String topcmd = null; // TODO: Channels
|
||||
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
||||
}
|
||||
lastlistp = (short) Bukkit.getOnlinePlayers().size();
|
||||
} else {
|
||||
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0)
|
||||
|
|
Loading…
Reference in a new issue