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
22 changes: 5 additions & 17 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,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand All @@ -38,29 +37,27 @@ public DiscordThreadArchivedScriptEvent() {
registerSwitches("group", "parent");
}

public ThreadHiddenEvent getEvent() {
return (ThreadHiddenEvent) event;
public ChannelUpdateArchivedEvent getEvent() {
return (ChannelUpdateArchivedEvent) event;
}

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

@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);
};
}
}
Original file line number Diff line number Diff line change
@@ -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:<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 pulled out of archive.
//
// @Warning Not currently function. Will likely function in the future.
//
// @Plugin dDiscordBot
//
// @Group Discord
//
// @Context
// <context.bot> returns the relevant DiscordBotTag.
// <context.group> returns the DiscordGroupTag.
// <context.thread> 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:<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 pulled out of archive.
//
// @Plugin dDiscordBot
//
// @Group Discord
//
// @Context
// <context.bot> returns the relevant DiscordBotTag.
// <context.group> returns the DiscordGroupTag.
// <context.thread> 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);
};
}
}