From 4a05cefbdd3fde3f586a22f70d55f379e0de3360 Mon Sep 17 00:00:00 2001 From: Reason <28310208+Reasonlesss@users.noreply.github.com> Date: Sat, 20 Apr 2024 13:42:49 +0100 Subject: [PATCH] Fix bugs + make messages work in threads --- .../impl/codeblock/AbstractSingleQueryCommand.java | 13 +++++++------ .../bot/command/impl/codeblock/CodeCommand.java | 5 +++-- .../bot/command/impl/codeblock/RawCommand.java | 5 +++-- .../bot/command/impl/codeblock/TagsCommand.java | 5 +++-- .../command/impl/other/dev/FetchDataCommand.java | 9 +++++---- .../bot/command/impl/other/fun/NbsCommand.java | 3 ++- .../bot/command/impl/other/mod/PurgeCommand.java | 3 ++- .../helpbot/bot/command/reply/ReplyHandler.java | 7 ++++--- .../helpbot/bot/events/CommandEvent.java | 2 +- .../java/com/diamondfire/helpbot/df/ranks/Rank.java | 2 +- .../helpbot/sys/message/acceptors/TagAcceptor.java | 2 +- .../java/com/diamondfire/helpbot/sys/tag/Tag.java | 3 ++- .../helpbot/sys/tasks/impl/VIPStarTask.java | 2 +- 13 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/AbstractSingleQueryCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/AbstractSingleQueryCommand.java index f512dee2..f2dccdf8 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/AbstractSingleQueryCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/AbstractSingleQueryCommand.java @@ -14,6 +14,7 @@ import com.diamondfire.helpbot.util.*; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.interactions.components.buttons.Button; @@ -24,7 +25,7 @@ public abstract class AbstractSingleQueryCommand extends Command { - public static void sendMultipleMessage(List actions, TextChannel channel, long userToWait, BiConsumer onChosen) { + public static void sendMultipleMessage(List actions, GuildMessageChannel channel, long userToWait, BiConsumer onChosen) { // This here is to determine if all the duplicate types are the same. If not, we need to make sure that we filter those out first.. CodeObject referenceData = actions.get(0); Class classReference = referenceData.getClass(); @@ -67,7 +68,7 @@ public static void sendMultipleMessage(List actions, TextChannel cha // when msg is deleted causes nullpointer when tries to remove reactions! FIX CodeObject object = buttonMap.get(event.getComponentId()); - onChosen.accept(object, message.getChannel().asTextChannel()); + onChosen.accept(object, message.getChannel().asGuildMessageChannel()); }); }); @@ -85,9 +86,9 @@ public void run(CommandEvent event) { getData(event, onDataReceived()); } - public abstract BiConsumer onDataReceived(); + public abstract BiConsumer onDataReceived(); - protected void getData(CommandEvent event, BiConsumer onChosen) { + protected void getData(CommandEvent event, BiConsumer onChosen) { String name = event.getArgument("name"); PresetBuilder preset = new PresetBuilder(); @@ -120,9 +121,9 @@ protected void getData(CommandEvent event, BiConsumer o // If none, proceed. Else we need to special case that. if (sameActions.size() == 1) { - onChosen.accept(sameActions.get(0), event.getChannel().asTextChannel()); + onChosen.accept(sameActions.get(0), event.getChannel().asGuildMessageChannel()); } else if (sameActions.size() > 1) { - sendMultipleMessage(sameActions, event.getChannel().asTextChannel(), event.getMember().getIdLong(), onChosen); + sendMultipleMessage(sameActions, event.getChannel().asGuildMessageChannel(), event.getMember().getIdLong(), onChosen); } return; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/CodeCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/CodeCommand.java index 759baba5..cde99c68 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/CodeCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/CodeCommand.java @@ -7,6 +7,7 @@ import com.diamondfire.helpbot.util.Util; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.utils.FileUpload; import java.io.File; @@ -15,7 +16,7 @@ public class CodeCommand extends AbstractSingleQueryCommand { - public static void sendHelpMessage(T data, TextChannel channel) { + public static void sendHelpMessage(T data, GuildMessageChannel channel) { EmbedBuilder builder = data.getEnum().getEmbedBuilder().generateEmbed(data); String customHead = data.getItem().getHead(); @@ -57,7 +58,7 @@ public void run(CommandEvent event) { } @Override - public BiConsumer onDataReceived() { + public BiConsumer onDataReceived() { return CodeCommand::sendHelpMessage; } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java index 75d5c4be..2be76c85 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java @@ -7,13 +7,14 @@ import com.diamondfire.helpbot.util.StringUtil; import com.google.gson.*; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import java.util.function.BiConsumer; public class RawCommand extends AbstractSingleQueryCommand { - private static void sendRawMessage(CodeObject data, TextChannel channel) { + private static void sendRawMessage(CodeObject data, GuildMessageChannel channel) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); String json = gson.toJson(data.getJson()); @@ -55,7 +56,7 @@ public void run(CommandEvent event) { } @Override - public BiConsumer onDataReceived() { + public BiConsumer onDataReceived() { return RawCommand::sendRawMessage; } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/TagsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/TagsCommand.java index 92f84dee..d7a84a72 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/TagsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/TagsCommand.java @@ -7,6 +7,7 @@ import com.diamondfire.helpbot.util.Util; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.utils.FileUpload; import java.io.File; @@ -15,7 +16,7 @@ public class TagsCommand extends AbstractSingleQueryCommand { - private static void sendTagMessage(CodeObject data, TextChannel channel) { + private static void sendTagMessage(CodeObject data, GuildMessageChannel channel) { EmbedBuilder builder = new EmbedBuilder(); ActionData actionData; @@ -92,7 +93,7 @@ public void run(CommandEvent event) { } @Override - public BiConsumer onDataReceived() { + public BiConsumer onDataReceived() { return TagsCommand::sendTagMessage; } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java index d868e11e..779c3bb6 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java @@ -16,6 +16,7 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.utils.FileUpload; import java.io.*; @@ -61,7 +62,7 @@ public Permission getPermission() { public void run(CommandEvent event) { List flags = event.getArgument("flag"); if (flags == null) { - setup(event.getChannel().asTextChannel()); + setup(event.getChannel().asGuildMessageChannel()); } else { boolean includeColors = false; boolean updateDb = true; @@ -72,15 +73,15 @@ public void run(CommandEvent event) { updateDb = false; } } - setup(event.getChannel().asTextChannel(), includeColors, updateDb); + setup(event.getChannel().asGuildMessageChannel(), includeColors, updateDb); } } - public void setup(TextChannel channel) { + public void setup(GuildMessageChannel channel) { setup(channel, false, true); } - public void setup(TextChannel channel, boolean includeColors, boolean updateDb) { + public void setup(GuildMessageChannel channel, boolean includeColors, boolean updateDb) { EmbedBuilder builder = new EmbedBuilder(); builder.setTitle("Fetching Code Database..."); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java index 9688bc54..9ba93905 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java @@ -11,6 +11,7 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.utils.FileUpload; import java.awt.*; @@ -44,7 +45,7 @@ public Permission getPermission() { @Override public void run(CommandEvent event) { - TextChannel channel = event.getChannel().asTextChannel(); + GuildMessageChannel channel = event.getChannel().asGuildMessageChannel(); PresetBuilder attachNbsMsg = new PresetBuilder().withPreset(new InformativeReply(InformativeReplyType.ERROR,"You need to attach an nbs file!")); PresetBuilder errorMsg = new PresetBuilder().withPreset(new InformativeReply(InformativeReplyType.ERROR,"Something went wrong while generating!")); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java index f439efd8..cbdc99db 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java @@ -12,6 +12,7 @@ import com.diamondfire.helpbot.sys.externalfile.ExternalFileUtil; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.utils.FileUpload; import java.io.File; @@ -57,7 +58,7 @@ public void run(CommandEvent event) { ); event.reply(builder); } else { - TextChannel channel = event.getChannel().asTextChannel(); + GuildMessageChannel channel = event.getChannel().asGuildMessageChannel(); channel.getHistory().retrievePast(messagesToRemove).queue((messages) -> { // Adds the messages to the messageBuilder object StringBuilder stringBuilder = new StringBuilder(); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/reply/ReplyHandler.java b/src/main/java/com/diamondfire/helpbot/bot/command/reply/ReplyHandler.java index 5f7e2184..426fc6d1 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/reply/ReplyHandler.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/reply/ReplyHandler.java @@ -3,6 +3,7 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.requests.RestAction; import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; @@ -10,13 +11,13 @@ public class ReplyHandler { - private final TextChannel channel; + private final GuildMessageChannel channel; - public ReplyHandler(TextChannel channel) { + public ReplyHandler(GuildMessageChannel channel) { this.channel = channel; } - public TextChannel getChannel() { + public GuildMessageChannel getChannel() { return channel; } diff --git a/src/main/java/com/diamondfire/helpbot/bot/events/CommandEvent.java b/src/main/java/com/diamondfire/helpbot/bot/events/CommandEvent.java index 6a980cef..c5220bd9 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/events/CommandEvent.java +++ b/src/main/java/com/diamondfire/helpbot/bot/events/CommandEvent.java @@ -15,7 +15,7 @@ public class CommandEvent extends MessageReceivedEvent { private Command command; - private final ReplyHandler replyHandler = new ReplyHandler(getChannel().asTextChannel()); + private final ReplyHandler replyHandler = new ReplyHandler(getChannel().asGuildMessageChannel()); //TODO Cleanup and refactor this. // I'd like to see stuff like replying be put into it's whole own section and refactored as well. private ParsedArgumentSet parsedArgumentSet = null; diff --git a/src/main/java/com/diamondfire/helpbot/df/ranks/Rank.java b/src/main/java/com/diamondfire/helpbot/df/ranks/Rank.java index fa6b48a3..771f5121 100644 --- a/src/main/java/com/diamondfire/helpbot/df/ranks/Rank.java +++ b/src/main/java/com/diamondfire/helpbot/df/ranks/Rank.java @@ -37,7 +37,7 @@ public enum Rank { this.rankName = rankName; this.number = number; this.category = category; - this.emote = HelpBotInstance.getJda().getGuildById(615846886414483465L).getEmojiById(emote); + this.emote = HelpBotInstance.getJda().getGuildById(615846886414483465L).getEmojisByName(emote, false).get(0); } public String getRankName() { diff --git a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java index 05cdc074..0f8a4700 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java +++ b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java @@ -21,7 +21,7 @@ public boolean accept(Message message) { try { // Get Tag and send response TagHandler.getTag(parsedText) - .sendResponse(message.getChannel().asTextChannel(), message.getAuthor()); + .sendResponse(message.getChannel().asGuildMessageChannel(), message.getAuthor()); } catch (TagDoesNotExistException | IOException ignored) { return false; diff --git a/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java b/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java index 4f47f71d..b8c89ed1 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java @@ -5,6 +5,7 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import org.jetbrains.annotations.NotNull; import java.io.Serializable; @@ -66,7 +67,7 @@ public void setImage(String image) { this.image = image; } - public void sendResponse(TextChannel channel, @NotNull User requester) { + public void sendResponse(GuildMessageChannel channel, @NotNull User requester) { EmbedBuilder embed = new EmbedBuilder() .setTitle(getTitle()) diff --git a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/VIPStarTask.java b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/VIPStarTask.java index 4151b192..93207b64 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/VIPStarTask.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/VIPStarTask.java @@ -39,7 +39,7 @@ public void run() { .queue(); return; } - if (member.getRoles().contains(role)) { + if (!vipIds.contains(member.getIdLong()) && member.getRoles().contains(role)) { guild.removeRoleFromMember(member, role) .reason("User's VIP Pass has expired") .queue();