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 issuechannel;
|
||||
public static IChannel botroomchannel;
|
||||
/**
|
||||
* Don't send messages, just receive, the same channel is used when testing
|
||||
*/
|
||||
public static IChannel officechannel;
|
||||
public static IChannel coffeechannel;
|
||||
public static IChannel updatechannel;
|
||||
|
@ -97,7 +100,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
botroomchannel = botchannel;// bot-room
|
||||
issuechannel = botchannel; // bot-room
|
||||
chatchannel = devServer.getChannelByID("248185455508455424"); // minecraft_chat_test
|
||||
officechannel = botchannel; // bot-room
|
||||
officechannel = devServer.getChannelByID("219626707458457603"); // developers-office
|
||||
coffeechannel = botchannel; // bot-room
|
||||
updatechannel = botchannel;
|
||||
dc.changeStatus(Status.game("testing"));
|
||||
|
@ -228,7 +231,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
}
|
||||
try {
|
||||
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
|
||||
? "*The following message is from a test server*\n" + message : message;
|
||||
return embed == null ? channel.sendMessage(content) : channel.sendMessage(content, embed, false);
|
||||
|
@ -269,11 +272,17 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
/** Removes §[char] colour codes from strings */
|
||||
public static String sanitizeString(String string) {
|
||||
String sanitizedString = "";
|
||||
boolean random = false;
|
||||
for (int i = 0; i < string.length(); i++) {
|
||||
if (string.charAt(i) == '§') {
|
||||
i++;// Skips the data value, the 4 in "§4Alisolarflare"
|
||||
if (string.charAt(i) == 'k')
|
||||
random = true;
|
||||
else
|
||||
random = false;
|
||||
} else {
|
||||
sanitizedString += string.charAt(i);
|
||||
if (!random) // Skip random/obfuscated characters
|
||||
sanitizedString += string.charAt(i);
|
||||
}
|
||||
}
|
||||
return sanitizedString;
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
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.DiscordSender;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import sx.blah.discord.api.events.IListener;
|
||||
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;
|
||||
|
||||
public class AutoUpdaterListener implements IListener<MessageReceivedEvent> {
|
||||
|
@ -16,7 +22,8 @@ public class AutoUpdaterListener implements IListener<MessageReceivedEvent> {
|
|||
return;
|
||||
if (event.getMessage().getEmbedded().size() == 0)
|
||||
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"))
|
||||
return;
|
||||
String branch = title.substring(title.indexOf(':') + 1, title.indexOf(']'));
|
||||
|
@ -28,12 +35,39 @@ public class AutoUpdaterListener implements IListener<MessageReceivedEvent> {
|
|||
? DiscordPlugin.chatchannel //
|
||||
: DiscordPlugin.updatechannel),
|
||||
branch)
|
||||
&& (!TBMCCoreAPI.IsTestServer() || !branch.equals("master")))
|
||||
try {
|
||||
event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION);
|
||||
} catch (RateLimitException e) { // TODO: Handle
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while reacting to plugin update!", e);
|
||||
}
|
||||
&& ((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 {
|
||||
event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION);
|
||||
break;
|
||||
} catch (RateLimitException e) {
|
||||
try {
|
||||
if (e.getRetryDelay() > 0)
|
||||
Thread.sleep(e.getRetryDelay());
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
} catch (Exception 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, DiscordPlayerSender> ConnectedSenders = new HashMap<>();
|
||||
public static short ListC = 0;
|
||||
|
||||
public static void resetLastMessage() {
|
||||
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"
|
||||
+ Arrays.stream(UnconnectedCmds).map(uc -> "/" + uc)
|
||||
.collect(Collectors.joining(", "))
|
||||
+ "\nTo connect your accounts, use @ChromaBot connect here or in "
|
||||
+ "\nTo connect your accounts, use @ChromaBot connect in "
|
||||
+ DiscordPlugin.botchannel.mention());
|
||||
return;
|
||||
}
|
||||
Bukkit.dispatchCommand(dsender, cmd);
|
||||
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);
|
||||
} else
|
||||
TBMCChatAPI.SendChatMessage(Channel.GlobalChat, dsender,
|
||||
dmessage + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage()
|
||||
.getAttachments().stream().map(a -> a.getUrl()).collect(Collectors.joining("\n"))
|
||||
: ""));
|
||||
event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION);
|
||||
event.getMessage().getChannel().getMessages().stream().forEach(m -> {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
});
|
||||
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) {
|
||||
TBMCCoreAPI.SendException("An error occured while handling message \"" + dmessage + "\"!", e);
|
||||
return;
|
||||
|
|
|
@ -29,6 +29,7 @@ public class MCListener implements Listener {
|
|||
}
|
||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
||||
e.GetPlayer().getPlayerName() + " joined the game");
|
||||
MCChatListener.ListC = 0;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
Loading…
Reference in a new issue