Merge pull request #24 from TBMCPlugins/dev
Added removing obfuscated chars from names, delivered reactions are more reliable, added linking to the PR on plugin autoupdate, a fix
This commit is contained in:
commit
85d26d7b9f
4 changed files with 73 additions and 14 deletions
|
@ -64,6 +64,9 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
public static IChannel chatchannel;
|
public static IChannel chatchannel;
|
||||||
public static IChannel issuechannel;
|
public static IChannel issuechannel;
|
||||||
public static IChannel botroomchannel;
|
public static IChannel botroomchannel;
|
||||||
|
/**
|
||||||
|
* Don't send messages, just receive, the same channel is used when testing
|
||||||
|
*/
|
||||||
public static IChannel officechannel;
|
public static IChannel officechannel;
|
||||||
public static IChannel coffeechannel;
|
public static IChannel coffeechannel;
|
||||||
public static IChannel updatechannel;
|
public static IChannel updatechannel;
|
||||||
|
@ -97,7 +100,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
botroomchannel = botchannel;// bot-room
|
botroomchannel = botchannel;// bot-room
|
||||||
issuechannel = botchannel; // bot-room
|
issuechannel = botchannel; // bot-room
|
||||||
chatchannel = devServer.getChannelByID("248185455508455424"); // minecraft_chat_test
|
chatchannel = devServer.getChannelByID("248185455508455424"); // minecraft_chat_test
|
||||||
officechannel = botchannel; // bot-room
|
officechannel = devServer.getChannelByID("219626707458457603"); // developers-office
|
||||||
coffeechannel = botchannel; // bot-room
|
coffeechannel = botchannel; // bot-room
|
||||||
updatechannel = botchannel;
|
updatechannel = botchannel;
|
||||||
dc.changeStatus(Status.game("testing"));
|
dc.changeStatus(Status.game("testing"));
|
||||||
|
@ -228,7 +231,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (channel == chatchannel)
|
if (channel == chatchannel)
|
||||||
MCChatListener.resetLastMessage(); //If this is a chat message, it'll be set again
|
MCChatListener.resetLastMessage(); // If this is a chat message, it'll be set again
|
||||||
final String content = TBMCCoreAPI.IsTestServer() && channel != chatchannel
|
final String content = TBMCCoreAPI.IsTestServer() && channel != chatchannel
|
||||||
? "*The following message is from a test server*\n" + message : message;
|
? "*The following message is from a test server*\n" + message : message;
|
||||||
return embed == null ? channel.sendMessage(content) : channel.sendMessage(content, embed, false);
|
return embed == null ? channel.sendMessage(content) : channel.sendMessage(content, embed, false);
|
||||||
|
@ -269,10 +272,16 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
/** Removes §[char] colour codes from strings */
|
/** Removes §[char] colour codes from strings */
|
||||||
public static String sanitizeString(String string) {
|
public static String sanitizeString(String string) {
|
||||||
String sanitizedString = "";
|
String sanitizedString = "";
|
||||||
|
boolean random = false;
|
||||||
for (int i = 0; i < string.length(); i++) {
|
for (int i = 0; i < string.length(); i++) {
|
||||||
if (string.charAt(i) == '§') {
|
if (string.charAt(i) == '§') {
|
||||||
i++;// Skips the data value, the 4 in "§4Alisolarflare"
|
i++;// Skips the data value, the 4 in "§4Alisolarflare"
|
||||||
|
if (string.charAt(i) == 'k')
|
||||||
|
random = true;
|
||||||
|
else
|
||||||
|
random = false;
|
||||||
} else {
|
} else {
|
||||||
|
if (!random) // Skip random/obfuscated characters
|
||||||
sanitizedString += string.charAt(i);
|
sanitizedString += string.charAt(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
package buttondevteam.discordplugin.listeners;
|
package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import buttondevteam.discordplugin.DiscordPlugin;
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.discordplugin.DiscordSender;
|
import buttondevteam.discordplugin.DiscordSender;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import sx.blah.discord.api.events.IListener;
|
import sx.blah.discord.api.events.IListener;
|
||||||
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
||||||
|
import sx.blah.discord.handle.obj.IEmbed;
|
||||||
|
import sx.blah.discord.util.EmbedBuilder;
|
||||||
import sx.blah.discord.util.RateLimitException;
|
import sx.blah.discord.util.RateLimitException;
|
||||||
|
|
||||||
public class AutoUpdaterListener implements IListener<MessageReceivedEvent> {
|
public class AutoUpdaterListener implements IListener<MessageReceivedEvent> {
|
||||||
|
@ -16,7 +22,8 @@ public class AutoUpdaterListener implements IListener<MessageReceivedEvent> {
|
||||||
return;
|
return;
|
||||||
if (event.getMessage().getEmbedded().size() == 0)
|
if (event.getMessage().getEmbedded().size() == 0)
|
||||||
return;
|
return;
|
||||||
final String title = event.getMessage().getEmbedded().get(0).getTitle();
|
final IEmbed embed = event.getMessage().getEmbedded().get(0);
|
||||||
|
final String title = embed.getTitle();
|
||||||
if (!title.contains("new commit"))
|
if (!title.contains("new commit"))
|
||||||
return;
|
return;
|
||||||
String branch = title.substring(title.indexOf(':') + 1, title.indexOf(']'));
|
String branch = title.substring(title.indexOf(':') + 1, title.indexOf(']'));
|
||||||
|
@ -28,10 +35,37 @@ public class AutoUpdaterListener implements IListener<MessageReceivedEvent> {
|
||||||
? DiscordPlugin.chatchannel //
|
? DiscordPlugin.chatchannel //
|
||||||
: DiscordPlugin.updatechannel),
|
: DiscordPlugin.updatechannel),
|
||||||
branch)
|
branch)
|
||||||
&& (!TBMCCoreAPI.IsTestServer() || !branch.equals("master")))
|
&& ((Supplier<Boolean>) () -> { // Best looking code I've ever written
|
||||||
|
try {
|
||||||
|
int hi, ei, prnum;
|
||||||
|
if ((hi = embed.getDescription().indexOf('#')) > -1
|
||||||
|
&& ((ei = embed.getDescription().indexOf(' ', hi + 1)) > -1
|
||||||
|
|| (ei = embed.getDescription().indexOf(".", hi + 1)) > -1
|
||||||
|
|| (ei = embed.getDescription().length()) > -1)
|
||||||
|
&& (prnum = Integer.parseInt(embed.getDescription().substring(hi + 1, ei))) > -1)
|
||||||
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.updatechannel, "",
|
||||||
|
new EmbedBuilder().withColor(Color.WHITE).withTitle("Update details")
|
||||||
|
.withUrl("https://github.com/TBMCPlugins/" + project + "/pull/" + prnum)
|
||||||
|
.build());
|
||||||
|
else
|
||||||
|
throw new Exception("No PR found");
|
||||||
|
} catch (Exception e) {
|
||||||
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.updatechannel, "",
|
||||||
|
new EmbedBuilder().withColor(Color.WHITE).withTitle("Update details:")
|
||||||
|
.withDescription(embed.getDescription() + " (" + e.getMessage() + ")").build());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}).get() && (!TBMCCoreAPI.IsTestServer() || !branch.equals("master")))
|
||||||
|
while (true)
|
||||||
try {
|
try {
|
||||||
event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION);
|
event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION);
|
||||||
} catch (RateLimitException e) { // TODO: Handle
|
break;
|
||||||
|
} catch (RateLimitException e) {
|
||||||
|
try {
|
||||||
|
if (e.getRetryDelay() > 0)
|
||||||
|
Thread.sleep(e.getRetryDelay());
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("An error occured while reacting to plugin update!", e);
|
TBMCCoreAPI.SendException("An error occured while reacting to plugin update!", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
|
|
||||||
public static final HashMap<String, DiscordSender> UnconnectedSenders = new HashMap<>();
|
public static final HashMap<String, DiscordSender> UnconnectedSenders = new HashMap<>();
|
||||||
public static final HashMap<String, DiscordPlayerSender> ConnectedSenders = new HashMap<>();
|
public static final HashMap<String, DiscordPlayerSender> ConnectedSenders = new HashMap<>();
|
||||||
|
public static short ListC = 0;
|
||||||
|
|
||||||
public static void resetLastMessage() {
|
public static void resetLastMessage() {
|
||||||
lastmessage = null;
|
lastmessage = null;
|
||||||
|
@ -110,17 +111,21 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
"Sorry, you need to be online on the server and have your accounts connected, you can only access these commands:\n"
|
"Sorry, you need to be online on the server and have your accounts connected, you can only access these commands:\n"
|
||||||
+ Arrays.stream(UnconnectedCmds).map(uc -> "/" + uc)
|
+ Arrays.stream(UnconnectedCmds).map(uc -> "/" + uc)
|
||||||
.collect(Collectors.joining(", "))
|
.collect(Collectors.joining(", "))
|
||||||
+ "\nTo connect your accounts, use @ChromaBot connect here or in "
|
+ "\nTo connect your accounts, use @ChromaBot connect in "
|
||||||
+ DiscordPlugin.botchannel.mention());
|
+ DiscordPlugin.botchannel.mention());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (cmd.equals("list") && Bukkit.getOnlinePlayers().size() == 0 && ListC++ > 2) // Lowered already
|
||||||
|
{
|
||||||
|
dsender.sendMessage("Stop it. You know the answer.");
|
||||||
|
ListC = 0;
|
||||||
|
} else
|
||||||
Bukkit.dispatchCommand(dsender, cmd);
|
Bukkit.dispatchCommand(dsender, cmd);
|
||||||
} else
|
} else
|
||||||
TBMCChatAPI.SendChatMessage(Channel.GlobalChat, dsender,
|
TBMCChatAPI.SendChatMessage(Channel.GlobalChat, dsender,
|
||||||
dmessage + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage()
|
dmessage + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage()
|
||||||
.getAttachments().stream().map(a -> a.getUrl()).collect(Collectors.joining("\n"))
|
.getAttachments().stream().map(a -> a.getUrl()).collect(Collectors.joining("\n"))
|
||||||
: ""));
|
: ""));
|
||||||
event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION);
|
|
||||||
event.getMessage().getChannel().getMessages().stream().forEach(m -> {
|
event.getMessage().getChannel().getMessages().stream().forEach(m -> {
|
||||||
try {
|
try {
|
||||||
final IReaction reaction = m.getReactionByName(DiscordPlugin.DELIVERED_REACTION);
|
final IReaction reaction = m.getReactionByName(DiscordPlugin.DELIVERED_REACTION);
|
||||||
|
@ -139,6 +144,16 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
TBMCCoreAPI.SendException("An error occured while removing reactions from chat!", e);
|
TBMCCoreAPI.SendException("An error occured while removing reactions from chat!", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
while (true)
|
||||||
|
try {
|
||||||
|
event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION);
|
||||||
|
break;
|
||||||
|
} catch (RateLimitException e) {
|
||||||
|
if (e.getRetryDelay() > 0)
|
||||||
|
Thread.sleep(e.getRetryDelay());
|
||||||
|
else
|
||||||
|
Thread.sleep(100);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("An error occured while handling message \"" + dmessage + "\"!", e);
|
TBMCCoreAPI.SendException("An error occured while handling message \"" + dmessage + "\"!", e);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class MCListener implements Listener {
|
||||||
}
|
}
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
||||||
e.GetPlayer().getPlayerName() + " joined the game");
|
e.GetPlayer().getPlayerName() + " joined the game");
|
||||||
|
MCChatListener.ListC = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
Loading…
Reference in a new issue