Added PR linking - in the condition
This commit is contained in:
parent
6cdac8696d
commit
7aeff53967
1 changed files with 43 additions and 8 deletions
|
@ -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,38 @@ 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 detauls: " + 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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue