From b084316b9928a12a57378f99ff3f0175c24979c4 Mon Sep 17 00:00:00 2001 From: "Weston Rye (Demod)" Date: Wed, 28 Jun 2017 16:24:47 -0400 Subject: [PATCH] Added error reporting channel. --- .../fbsr/app/BlueprintBotDiscordService.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/app/BlueprintBotDiscordService.java b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/app/BlueprintBotDiscordService.java index b52ea49..12db0b0 100644 --- a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/app/BlueprintBotDiscordService.java +++ b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/app/BlueprintBotDiscordService.java @@ -53,7 +53,9 @@ import javafx.util.Pair; import net.dv8tion.jda.core.EmbedBuilder; import net.dv8tion.jda.core.Permission; import net.dv8tion.jda.core.entities.Message; +import net.dv8tion.jda.core.entities.MessageEmbed; import net.dv8tion.jda.core.entities.PrivateChannel; +import net.dv8tion.jda.core.entities.TextChannel; import net.dv8tion.jda.core.events.message.MessageReceivedEvent; public class BlueprintBotDiscordService extends AbstractIdleService { @@ -68,6 +70,8 @@ public class BlueprintBotDiscordService extends AbstractIdleService { private JSONObject configJson; + private String reportingChannelID; + private CommandHandler createDataRawCommandHandler(Function> query) { return event -> { String content = event.getMessage().getStrippedContent(); @@ -189,6 +193,8 @@ public class BlueprintBotDiscordService extends AbstractIdleService { processBlueprints(BlueprintFinder.search(content, reporting), event, reporting); } + reporting.addException(new Exception("I can't believe its not butter!")); + if (reporting.getImages().isEmpty() && reporting.getDownloads().isEmpty() && reporting.getWarnings().isEmpty() && reporting.getExceptions().isEmpty() && reporting.getInfo().isEmpty()) { if (content.split("\\s").length == 1) { @@ -436,8 +442,15 @@ public class BlueprintBotDiscordService extends AbstractIdleService { false); } + MessageEmbed embed = builder.build(); PrivateChannel privateChannel = bot.getJDA().getUserById(reportingUserID).openPrivateChannel().complete(); - privateChannel.sendMessage(builder.build()).complete(); + privateChannel.sendMessage(embed).complete(); + if (!exceptions.isEmpty()) { + TextChannel textChannel = bot.getJDA().getTextChannelById(reportingChannelID); + if (textChannel != null) { + textChannel.sendMessage(embed).complete(); + } + } } catch (Exception e) { PrivateChannel privateChannel = bot.getJDA().getUserById(reportingUserID).openPrivateChannel().complete(); @@ -516,6 +529,7 @@ public class BlueprintBotDiscordService extends AbstractIdleService { bot.startAsync().awaitRunning(); reportingUserID = configJson.getString("reporting_user_id"); + reportingChannelID = configJson.getString("reporting_channel_id"); ServiceFinder.addService(this); ServiceFinder.addService(WatchdogReporter.class, new WatchdogReporter() {