Did some old open issues
#5 - Post if the server crashes #7 - When announcing a Reddit post, use Discord names, if known #9 - Print "full house" when full house
This commit is contained in:
parent
11ecabe325
commit
b0c791e622
3 changed files with 58 additions and 12 deletions
|
@ -20,6 +20,8 @@ import buttondevteam.discordplugin.listeners.*;
|
||||||
import buttondevteam.discordplugin.mccommands.DiscordMCCommandBase;
|
import buttondevteam.discordplugin.mccommands.DiscordMCCommandBase;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
|
import lombok.val;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import sx.blah.discord.api.*;
|
import sx.blah.discord.api.*;
|
||||||
import sx.blah.discord.api.events.IListener;
|
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 officechannel;
|
||||||
public static IChannel updatechannel;
|
public static IChannel updatechannel;
|
||||||
|
public static IChannel devofficechannel;
|
||||||
public static IGuild mainServer;
|
public static IGuild mainServer;
|
||||||
public static IGuild devServer;
|
public static IGuild devServer;
|
||||||
|
|
||||||
|
@ -91,6 +94,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
botroomchannel = devServer.getChannelByID(239519012529111040L); // bot-room
|
botroomchannel = devServer.getChannelByID(239519012529111040L); // bot-room
|
||||||
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
||||||
updatechannel = devServer.getChannelByID(233724163519414272L); // server-updates
|
updatechannel = devServer.getChannelByID(233724163519414272L); // server-updates
|
||||||
|
devofficechannel = officechannel; // developers-office
|
||||||
dc.online("on TBMC");
|
dc.online("on TBMC");
|
||||||
} else {
|
} else {
|
||||||
botchannel = devServer.getChannelByID(239519012529111040L); // bot-room
|
botchannel = devServer.getChannelByID(239519012529111040L); // bot-room
|
||||||
|
@ -100,6 +104,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
chatchannel = botchannel;// bot-room
|
chatchannel = botchannel;// bot-room
|
||||||
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
||||||
updatechannel = botchannel;
|
updatechannel = botchannel;
|
||||||
|
devofficechannel = botchannel;// bot-room
|
||||||
dc.online("testing");
|
dc.online("testing");
|
||||||
}
|
}
|
||||||
if (botchannel == null || annchannel == null || genchannel == null || botroomchannel == null
|
if (botchannel == null || annchannel == null || genchannel == null || botroomchannel == null
|
||||||
|
@ -109,17 +114,26 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
if (task != null)
|
if (task != null)
|
||||||
task.cancel();
|
task.cancel();
|
||||||
if (!sent) {
|
if (!sent) {
|
||||||
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Color.GREEN)
|
if (getConfig().getBoolean("serverup", false)) {
|
||||||
.withTitle("Server started - chat connected.").build());
|
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Color.YELLOW)
|
||||||
try {
|
.withTitle("Server recovered from a crash - chat connected.").build());
|
||||||
List<IMessage> msgs = genchannel.getPinnedMessages();
|
TBMCCoreAPI.SendException("The server crashed!", new Throwable(
|
||||||
for (int i = msgs.size() - 1; i >= 10; i--) { // Unpin all pinned messages except the newest 10
|
"The server shut down unexpectedly. See the log of the previous run for more details."));
|
||||||
genchannel.unpin(msgs.get(i));
|
} else
|
||||||
Thread.sleep(10);
|
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;
|
sent = true;
|
||||||
}
|
}
|
||||||
}, 0, 10);
|
}, 0, 10);
|
||||||
|
@ -172,6 +186,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
getConfig().set("lastannouncementtime", lastannouncementtime);
|
getConfig().set("lastannouncementtime", lastannouncementtime);
|
||||||
getConfig().set("lastseentime", lastseentime);
|
getConfig().set("lastseentime", lastseentime);
|
||||||
getConfig().set("gameroles", GameRoles);
|
getConfig().set("gameroles", GameRoles);
|
||||||
|
getConfig().set("serverup", false);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Restart ? Color.ORANGE : Color.RED)
|
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Restart ? Color.ORANGE : Color.RED)
|
||||||
.withTitle(Restart ? "Server restarting" : "Server stopping").build());
|
.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--) {
|
for (int i = json.size() - 1; i >= 0; i--) {
|
||||||
JsonObject item = json.get(i).getAsJsonObject();
|
JsonObject item = json.get(i).getAsJsonObject();
|
||||||
final JsonObject data = item.get("data").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");
|
JsonElement distinguishedjson = data.get("distinguished");
|
||||||
String distinguished;
|
String distinguished;
|
||||||
if (distinguishedjson.isJsonNull())
|
if (distinguishedjson.isJsonNull())
|
||||||
|
@ -215,6 +230,15 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
if (date > lastseentime)
|
if (date > lastseentime)
|
||||||
lastseentime = date;
|
lastseentime = date;
|
||||||
else if (date > lastannouncementtime) {
|
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)
|
(distinguished != null && distinguished.equals("moderator") ? modmsgsb : msgsb)
|
||||||
.append("A new post was submitted to the subreddit by ").append(author).append("\n")
|
.append("A new post was submitted to the subreddit by ").append(author).append("\n")
|
||||||
.append(permalink).append("\n");
|
.append(permalink).append("\n");
|
||||||
|
|
|
@ -8,11 +8,15 @@ import buttondevteam.discordplugin.DiscordPlayer;
|
||||||
import buttondevteam.discordplugin.DiscordPlugin;
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.discordplugin.commands.DiscordCommandBase;
|
import buttondevteam.discordplugin.commands.DiscordCommandBase;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
import lombok.val;
|
||||||
import sx.blah.discord.api.events.IListener;
|
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.MentionEvent;
|
||||||
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
|
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.IChannel;
|
||||||
import sx.blah.discord.handle.obj.IMessage;
|
import sx.blah.discord.handle.obj.IMessage;
|
||||||
|
import sx.blah.discord.handle.obj.StatusType;
|
||||||
|
import sx.blah.discord.util.EmbedBuilder;
|
||||||
|
|
||||||
public class CommandListener {
|
public class CommandListener {
|
||||||
|
|
||||||
|
@ -89,6 +93,22 @@ public class CommandListener {
|
||||||
return;
|
return;
|
||||||
runCommand(event.getMessage(), false);
|
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.");
|
dsender.sendMessage("Stop it. You know the answer.");
|
||||||
lastlist = 0;
|
lastlist = 0;
|
||||||
} else
|
} else {
|
||||||
|
String topcmd = null; // TODO: Channels
|
||||||
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
||||||
|
}
|
||||||
lastlistp = (short) Bukkit.getOnlinePlayers().size();
|
lastlistp = (short) Bukkit.getOnlinePlayers().size();
|
||||||
} else {
|
} else {
|
||||||
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0)
|
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0)
|
||||||
|
|
Loading…
Reference in a new issue