Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
20 changes: 4 additions & 16 deletions src/main/java/com/denizenscript/ddiscordbot/DiscordConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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:<bot> to only process the event for a specified Discord bot.
// @Switch group:<group_id> to only process the event for a specified Discord group.
// @Switch parent:<channel_id> 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
//
Expand All @@ -28,39 +29,52 @@ public class DiscordThreadArchivedScriptEvent extends DiscordScriptEvent {
// <context.bot> returns the relevant DiscordBotTag.
// <context.group> returns the DiscordGroupTag.
// <context.thread> returns the thread DiscordChannelTag.
// <context.old_state> returns whether the thread was previously archived.
// <context.new_state> 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);
}

@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);
};
}
}

This file was deleted.