diff --git a/src/main/java/com/denizenscript/ddiscordbot/DenizenDiscordBot.java b/src/main/java/com/denizenscript/ddiscordbot/DenizenDiscordBot.java index 54f8cd3..e4b4423 100644 --- a/src/main/java/com/denizenscript/ddiscordbot/DenizenDiscordBot.java +++ b/src/main/java/com/denizenscript/ddiscordbot/DenizenDiscordBot.java @@ -30,6 +30,7 @@ public class DenizenDiscordBot extends JavaPlugin { public static Warning oldEditMessage = new Warning("oldEditMessage", "dDiscordBot's 'discord edit_message' sub-command has been moved to the 'discordmessage' command."); public static Warning oldTokenFile = new Warning("oldTokenFile", "dDiscordBot used to recommend 'tokenfile' for 'discordconnect', however it is now recommended that you use a SecretTag and the 'secrets.secret' file for the token."); public static Warning discordMessageAttachFile = new SlowWarning("discordMessageAttachFile", "'discordmessage' previously used 'attach_file_name' and 'attach_file_text': it is now 'attach_files' as a MapTag"); + public static Warning threadArchiveEvent = new SlowWarning("discordThreadArchiveEvent", "The 'discord thread archived' and 'discord thread revealed' events have been merged together into the 'discord thread archive status changes' event."); public static DenizenDiscordBot instance; @@ -76,7 +77,6 @@ public void onEnable() { ScriptEvent.registerScriptEvent(DiscordModalSubmittedScriptEvent.class); ScriptEvent.registerScriptEvent(DiscordSelectionUsedScriptEvent.class); ScriptEvent.registerScriptEvent(DiscordThreadArchivedScriptEvent.class); - ScriptEvent.registerScriptEvent(DiscordThreadRevealedScriptEvent.class); ScriptEvent.registerScriptEvent(DiscordUserJoinsScriptEvent.class); ScriptEvent.registerScriptEvent(DiscordUserLeavesScriptEvent.class); ScriptEvent.registerScriptEvent(DiscordUserNicknameChangeScriptEvent.class); diff --git a/src/main/java/com/denizenscript/ddiscordbot/DiscordConnection.java b/src/main/java/com/denizenscript/ddiscordbot/DiscordConnection.java index 148c2f6..b50d16a 100644 --- a/src/main/java/com/denizenscript/ddiscordbot/DiscordConnection.java +++ b/src/main/java/com/denizenscript/ddiscordbot/DiscordConnection.java @@ -9,25 +9,18 @@ import net.dv8tion.jda.api.events.Event; import net.dv8tion.jda.api.events.channel.ChannelCreateEvent; import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent; -import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; -import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent; -import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent; -import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent; +import net.dv8tion.jda.api.events.channel.update.ChannelUpdateArchivedEvent; +import net.dv8tion.jda.api.events.guild.member.*; import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateNicknameEvent; import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; -import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; -import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent; -import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent; +import net.dv8tion.jda.api.events.interaction.command.*; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.GenericSelectMenuInteractionEvent; import net.dv8tion.jda.api.events.message.MessageDeleteEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageUpdateEvent; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent; -import net.dv8tion.jda.api.events.thread.ThreadHiddenEvent; -import net.dv8tion.jda.api.events.thread.ThreadRevealedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.bukkit.Bukkit; @@ -175,12 +168,7 @@ public void onChannelDelete(ChannelDeleteEvent event) { } @Override - public void onThreadRevealed(ThreadRevealedEvent event) { - autoHandle(event, DiscordThreadRevealedScriptEvent.instance); - } - - @Override - public void onThreadHidden(ThreadHiddenEvent event) { // TODO: Is 'hidden' the same as 'archived'? + public void onChannelUpdateArchived(ChannelUpdateArchivedEvent event) { autoHandle(event, DiscordThreadArchivedScriptEvent.instance); } diff --git a/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadArchivedScriptEvent.java b/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadArchivedScriptEvent.java index 832b753..febe5a0 100644 --- a/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadArchivedScriptEvent.java +++ b/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadArchivedScriptEvent.java @@ -1,24 +1,25 @@ package com.denizenscript.ddiscordbot.events; +import com.denizenscript.ddiscordbot.DenizenDiscordBot; import com.denizenscript.ddiscordbot.DiscordScriptEvent; import com.denizenscript.ddiscordbot.objects.DiscordChannelTag; import com.denizenscript.ddiscordbot.objects.DiscordGroupTag; import com.denizenscript.denizencore.objects.ObjectTag; -import net.dv8tion.jda.api.events.thread.ThreadHiddenEvent; +import com.denizenscript.denizencore.objects.core.ElementTag; +import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; +import net.dv8tion.jda.api.events.channel.update.ChannelUpdateArchivedEvent; public class DiscordThreadArchivedScriptEvent extends DiscordScriptEvent { // <--[event] // @Events - // discord thread archived + // discord thread archive status changes // // @Switch for: to only process the event for a specified Discord bot. // @Switch group: to only process the event for a specified Discord group. // @Switch parent: to only process the event for a specific parent channel ID. // - // @Triggers when a Discord thread is archived. - // - // @Warning Not currently function. Will likely function in the future. + // @Triggers when a Discord thread's archive status changes. // // @Plugin dDiscordBot // @@ -28,26 +29,39 @@ public class DiscordThreadArchivedScriptEvent extends DiscordScriptEvent { // returns the relevant DiscordBotTag. // returns the DiscordGroupTag. // returns the thread DiscordChannelTag. + // returns whether the thread was previously archived. + // returns whether the thread is now archived. // --> public static DiscordThreadArchivedScriptEvent instance; public DiscordThreadArchivedScriptEvent() { instance = this; - registerCouldMatcher("discord thread archived"); + registerCouldMatcher("discord thread archive status changes"); + registerCouldMatcher("discord thread archived|revealed"); // Backwards compat registerSwitches("group", "parent"); } - public ThreadHiddenEvent getEvent() { - return (ThreadHiddenEvent) event; + public ChannelUpdateArchivedEvent getEvent() { + return (ChannelUpdateArchivedEvent) event; } @Override public boolean matches(ScriptPath path) { + String type = path.eventArgLowerAt(2); + if (type.equals("archived") || type.equals("revealed")) { + DenizenDiscordBot.threadArchiveEvent.warn(); + if (type.equals("archived") && !getEvent().getNewValue()) { + return false; + } + else if (type.equals("revealed") && getEvent().getNewValue()) { + return false; + } + } if (!tryGuild(path, getEvent().getGuild())) { return false; } - if (!tryChannel(path, getEvent().getThread().getParentChannel(), "parent")) { + if (!tryChannel(path, ((ThreadChannel) getEvent().getChannel()).getParentChannel(), "parent")) { return false; } return super.matches(path); @@ -55,12 +69,12 @@ public boolean matches(ScriptPath path) { @Override public ObjectTag getContext(String name) { - switch (name) { - case "group": - return new DiscordGroupTag(botID, getEvent().getGuild()); - case "thread": - return new DiscordChannelTag(botID, getEvent().getThread()); - } - return super.getContext(name); + return switch (name) { + case "group" -> new DiscordGroupTag(botID, getEvent().getGuild()); + case "thread" -> new DiscordChannelTag(botID, getEvent().getChannel()); + case "old_state" -> getEvent().getOldValue() != null ? new ElementTag(getEvent().getOldValue()) : null; + case "new_state" -> getEvent().getNewValue() != null ? new ElementTag(getEvent().getNewValue()) : null; + default -> super.getContext(name); + }; } } diff --git a/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadRevealedScriptEvent.java b/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadRevealedScriptEvent.java deleted file mode 100644 index 41eaed9..0000000 --- a/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadRevealedScriptEvent.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.denizenscript.ddiscordbot.events; - -import com.denizenscript.ddiscordbot.DiscordScriptEvent; -import com.denizenscript.ddiscordbot.objects.DiscordChannelTag; -import com.denizenscript.ddiscordbot.objects.DiscordGroupTag; -import com.denizenscript.denizencore.objects.ObjectTag; -import net.dv8tion.jda.api.events.thread.ThreadRevealedEvent; - -public class DiscordThreadRevealedScriptEvent extends DiscordScriptEvent { - - // <--[event] - // @Events - // discord thread revealed - // - // @Switch for: to only process the event for a specified Discord bot. - // @Switch group: to only process the event for a specified Discord group. - // @Switch parent: to only process the event for a specific parent channel ID. - // - // @Triggers when a Discord thread is pulled out of archive. - // - // @Warning Not currently function. Will likely function in the future. - // - // @Plugin dDiscordBot - // - // @Group Discord - // - // @Context - // returns the relevant DiscordBotTag. - // returns the DiscordGroupTag. - // returns the thread DiscordChannelTag. - // --> - - public static DiscordThreadRevealedScriptEvent instance; - - public DiscordThreadRevealedScriptEvent() { - instance = this; - registerCouldMatcher("discord thread revealed"); - registerSwitches("group", "parent"); - } - - public ThreadRevealedEvent getEvent() { - return (ThreadRevealedEvent) event; - } - - @Override - public boolean matches(ScriptPath path) { - if (!tryGuild(path, getEvent().getGuild())) { - return false; - } - if (!tryChannel(path, getEvent().getThread().getParentChannel(), "parent")) { - return false; - } - return super.matches(path); - } - - @Override - public ObjectTag getContext(String name) { - switch (name) { - case "group": - return new DiscordGroupTag(botID, getEvent().getGuild()); - case "thread": - return new DiscordChannelTag(botID, getEvent().getThread()); - } - return super.getContext(name); - } -}