diff --git a/src/main/java/com/denizenscript/ddiscordbot/DiscordConnection.java b/src/main/java/com/denizenscript/ddiscordbot/DiscordConnection.java index 148c2f6..5a06e22 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,13 +168,8 @@ 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'? - autoHandle(event, DiscordThreadArchivedScriptEvent.instance); + public void onChannelUpdateArchived(ChannelUpdateArchivedEvent event) { + autoHandle(event, event.getNewValue() ? DiscordThreadArchivedScriptEvent.instance : DiscordThreadRevealedScriptEvent.instance); } public void autoHandle(Event event, DiscordScriptEvent scriptEvent) { diff --git a/src/main/java/com/denizenscript/ddiscordbot/commands/DiscordConnectCommand.java b/src/main/java/com/denizenscript/ddiscordbot/commands/DiscordConnectCommand.java index 7a79ee3..56506d0 100644 --- a/src/main/java/com/denizenscript/ddiscordbot/commands/DiscordConnectCommand.java +++ b/src/main/java/com/denizenscript/ddiscordbot/commands/DiscordConnectCommand.java @@ -60,7 +60,7 @@ public DiscordConnectCommand() { // Connects to Discord. // // The connection will automatically specify the following gateway intents: - // GUILD_MEMBERS, GUILD_EMOJIS_AND_STICKERS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS, MESSAGE_CONTENT + // GUILD_MEMBERS, GUILD_EXPRESSIONS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS, MESSAGE_CONTENT // Optionally specify additional Gateway Intents to use as a list of any of: // GUILD_BANS, GUILD_WEBHOOKS, GUILD_INVITES, GUILD_VOICE_STATES, GUILD_PRESENCES, GUILD_MESSAGE_TYPING, DIRECT_MESSAGE_TYPING // diff --git a/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadArchivedScriptEvent.java b/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadArchivedScriptEvent.java index 832b753..2eedd15 100644 --- a/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadArchivedScriptEvent.java +++ b/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadArchivedScriptEvent.java @@ -4,7 +4,8 @@ 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 net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; +import net.dv8tion.jda.api.events.channel.update.ChannelUpdateArchivedEvent; public class DiscordThreadArchivedScriptEvent extends DiscordScriptEvent { @@ -18,8 +19,6 @@ public class DiscordThreadArchivedScriptEvent extends DiscordScriptEvent { // // @Triggers when a Discord thread is archived. // - // @Warning Not currently function. Will likely function in the future. - // // @Plugin dDiscordBot // // @Group Discord @@ -38,8 +37,8 @@ public DiscordThreadArchivedScriptEvent() { registerSwitches("group", "parent"); } - public ThreadHiddenEvent getEvent() { - return (ThreadHiddenEvent) event; + public ChannelUpdateArchivedEvent getEvent() { + return (ChannelUpdateArchivedEvent) event; } @Override @@ -47,7 +46,7 @@ public boolean matches(ScriptPath path) { 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 +54,10 @@ 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()); + 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 index 41eaed9..dbea74a 100644 --- a/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadRevealedScriptEvent.java +++ b/src/main/java/com/denizenscript/ddiscordbot/events/DiscordThreadRevealedScriptEvent.java @@ -1,66 +1,63 @@ -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); - } -} +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.entities.channel.concrete.ThreadChannel; +import net.dv8tion.jda.api.events.channel.update.ChannelUpdateArchivedEvent; + +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. + // + // @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 ChannelUpdateArchivedEvent getEvent() { + return (ChannelUpdateArchivedEvent) event; + } + + @Override + public boolean matches(ScriptPath path) { + if (!tryGuild(path, getEvent().getGuild())) { + return false; + } + if (!tryChannel(path, ((ThreadChannel) getEvent().getChannel()).getParentChannel(), "parent")) { + return false; + } + return super.matches(path); + } + + @Override + public ObjectTag getContext(String name) { + return switch (name) { + case "group" -> new DiscordGroupTag(botID, getEvent().getGuild()); + case "thread" -> new DiscordChannelTag(botID, getEvent().getChannel()); + default -> super.getContext(name); + }; + } +}