From f9ecebd5c98a6928baf5305470965365e7bf39ce Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Thu, 9 Mar 2023 09:36:59 -0600 Subject: [PATCH] Fix Minor Discrepancy --- .../main/java/me/totalfreedom/discord/Bot.java | 10 ---------- .../discord/listener/ReactionListener.java | 14 +++++++------- .../totalfreedom/discord/util/Utilities.java | 18 ++++++++---------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/discord/src/main/java/me/totalfreedom/discord/Bot.java b/discord/src/main/java/me/totalfreedom/discord/Bot.java index 078e4d7f..d56a92ac 100644 --- a/discord/src/main/java/me/totalfreedom/discord/Bot.java +++ b/discord/src/main/java/me/totalfreedom/discord/Bot.java @@ -241,16 +241,6 @@ public class Bot return false; } - TextChannel channel = server.getChannelById(SnowflakeEntry.reportChannelID) - .ofType(TextChannel.class) - .block(); - - if (channel == null) - { - FLog.severe("The report channel ID specified in the config is invalid."); - return false; - } - return true; } } diff --git a/discord/src/main/java/me/totalfreedom/discord/listener/ReactionListener.java b/discord/src/main/java/me/totalfreedom/discord/listener/ReactionListener.java index f91b7cac..a6d6bedb 100644 --- a/discord/src/main/java/me/totalfreedom/discord/listener/ReactionListener.java +++ b/discord/src/main/java/me/totalfreedom/discord/listener/ReactionListener.java @@ -5,6 +5,7 @@ import discord4j.core.object.Embed; import discord4j.core.object.entity.Member; import discord4j.core.object.entity.Message; import discord4j.core.object.entity.channel.Channel; +import discord4j.core.object.entity.channel.TextChannel; import discord4j.discordjson.json.MessageCreateRequest; import me.totalfreedom.discord.TFD4J; import me.totalfreedom.discord.util.SnowflakeEntry; @@ -44,13 +45,12 @@ public class ReactionListener public void reactionWork(ReactionAddEvent event) { - final Channel archiveChannel = tfd4j.getBot().getClient().getChannelById(SnowflakeEntry.archiveChannelID).block(); - - if (archiveChannel == null) - { - FLog.warning("Report archive channel is defined in the config, yet doesn't actually exist!"); - return; - } + final TextChannel archiveChannel = tfd4j.getBot() + .getClient() + .getChannelById(SnowflakeEntry.archiveChannelID) + .ofType(TextChannel.class) + .blockOptional() + .orElseThrow(); final Message message = event.getMessage().blockOptional().orElseThrow(); final Member completer = event.getMember().orElseThrow(); diff --git a/discord/src/main/java/me/totalfreedom/discord/util/Utilities.java b/discord/src/main/java/me/totalfreedom/discord/util/Utilities.java index f918cb31..79c0e62e 100644 --- a/discord/src/main/java/me/totalfreedom/discord/util/Utilities.java +++ b/discord/src/main/java/me/totalfreedom/discord/util/Utilities.java @@ -14,6 +14,7 @@ import me.totalfreedom.discord.TFD4J; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FLog; import org.apache.commons.lang.WordUtils; +import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import reactor.core.publisher.Flux; @@ -136,9 +137,10 @@ public class Utilities if (server == null) return false; - final Channel channel = server.getChannelById(SnowflakeEntry.reportChannelID).block(); - - if (!(channel instanceof TextChannel tch)) return false; + final TextChannel channel = server.getChannelById(SnowflakeEntry.reportChannelID) + .ofType(TextChannel.class) + .blockOptional() + .orElseThrow(); final EmbedCreateSpec.Builder builder = EmbedCreateSpec.builder() .title("Report for " + reported.getName() + " (offline)") @@ -157,7 +159,7 @@ public class Utilities } } EmbedCreateSpec embed = builder.build(); - Message message = tch.createMessage(embed).block(); + Message message = channel.createMessage(embed).block(); if (message != null && !ConfigEntry.DISCORD_REPORT_ARCHIVE_CHANNEL_ID.getString().isEmpty()) { @@ -187,13 +189,9 @@ public class Utilities final TextChannel channel = server.getChannelById(SnowflakeEntry.reportChannelID) .ofType(TextChannel.class) - .block(); + .blockOptional() + .orElseThrow(); - if (channel == null) - { - FLog.severe("The report channel ID specified in the config is invalid."); - return false; - } String location = "World: " + Objects.requireNonNull(reported.getLocation().getWorld()).getName() + ", X: " + reported.getLocation().getBlockX() + ", Y: " + reported.getLocation().getBlockY() + ", Z: " + reported.getLocation().getBlockZ(); final EmbedCreateSpec spec = EmbedCreateSpec.builder()