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 @@ -68,6 +68,7 @@ public void onEnable() {
ScriptEvent.registerScriptEvent(DiscordChannelCreateScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordChannelDeleteScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordCommandAutocompleteScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordInviteCreateScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordMessageDeletedScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordMessageModifiedScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordMessageReactionAddScriptEvent.class);
Expand All @@ -77,6 +78,7 @@ public void onEnable() {
ScriptEvent.registerScriptEvent(DiscordSelectionUsedScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordThreadArchivedScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordThreadRevealedScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordUpdateBoostCountEvent.class);
ScriptEvent.registerScriptEvent(DiscordUserJoinsScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordUserLeavesScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordUserNicknameChangeScriptEvent.class);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/denizenscript/ddiscordbot/DiscordConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
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.invite.GuildInviteCreateEvent;
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.guild.member.update.GuildMemberUpdateNicknameEvent;
import net.dv8tion.jda.api.events.guild.update.GuildUpdateBoostCountEvent;
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;
Expand Down Expand Up @@ -130,6 +132,11 @@ public void onGuildMemberUpdateNickname(GuildMemberUpdateNicknameEvent event) {
autoHandle(event, DiscordUserNicknameChangeScriptEvent.instance);
}

@Override
public void onGuildUpdateBoostCount(GuildUpdateBoostCountEvent event) {
autoHandle(event, DiscordUpdateBoostCountEvent.instance);
}

@Override
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
autoHandle(event, DiscordApplicationCommandScriptEvent.instance);
Expand Down Expand Up @@ -165,6 +172,11 @@ public void onGenericSelectMenuInteraction(GenericSelectMenuInteractionEvent eve
autoHandle(event, DiscordSelectionUsedScriptEvent.instance);
}

@Override
public void onGuildInviteCreate(GuildInviteCreateEvent event) {
autoHandle(event, DiscordInviteCreateScriptEvent.instance);
}

@Override
public void onChannelCreate(@Nonnull ChannelCreateEvent event) {
autoHandle(event, DiscordChannelCreateScriptEvent.instance);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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.ddiscordbot.objects.DiscordUserTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import net.dv8tion.jda.api.events.guild.invite.GuildInviteCreateEvent;

public class DiscordInviteCreateScriptEvent extends DiscordScriptEvent {

// <--[event]
// @Events
// discord invitation created
//
// @Switch for:<bot> to only process the event for a specified Discord bot.
// @Switch channel:<channel_id> to only process the event for a specified Discord channel.
// @Switch group:<group_id> to only process the event for a specified Discord group.
//
// @Triggers when a Discord user creates an invitation.
//
// @Plugin dDiscordBot
//
// @Group Discord
//
// @Context
// <context.bot> returns the relevant DiscordBotTag.
// <context.group> returns the DiscordGroupTag of the created invitation.
// <context.channel> returns the DiscordChannelTag of the created invitation.
// <context.user> returns the DiscordUserTag of the invitation creator.
// <context.code> returns the invitation code (after the last "/" in the URL).
// <context.url> returns the invitation URL.
// -->

public static DiscordInviteCreateScriptEvent instance;

public DiscordInviteCreateScriptEvent() {
instance = this;
registerCouldMatcher("discord invitation created");
registerSwitches("channel", "group");
}

public GuildInviteCreateEvent getEvent() {
return (GuildInviteCreateEvent) event;
}

@Override
public boolean matches(ScriptPath path) {
if (!tryChannel(path, getEvent().getChannel())) {
return false;
}
if (!tryGuild(path, getEvent().getGuild())) {
return false;
}
return super.matches(path);
}

@Override
public ObjectTag getContext(String name) {
return switch (name) {
case "channel" -> new DiscordChannelTag(botID, getEvent().getChannel());
case "group" -> new DiscordGroupTag(botID, getEvent().getGuild());
case "user" -> new DiscordUserTag(botID, getEvent().getInvite().getInviter());
case "code" -> new ElementTag(getEvent().getInvite().getCode(), true);
case "url" -> new ElementTag(getEvent().getInvite().getUrl(), true);
default -> super.getContext(name);
};
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.denizenscript.ddiscordbot.events;

import com.denizenscript.ddiscordbot.DiscordScriptEvent;
import com.denizenscript.ddiscordbot.objects.DiscordGroupTag;
import com.denizenscript.ddiscordbot.objects.DiscordUserTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import net.dv8tion.jda.api.events.guild.update.GuildUpdateBoostCountEvent;

public class DiscordUpdateBoostCountEvent extends DiscordScriptEvent {

// <--[event]
// @Events
// discord boosts count 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.
//
// @Triggers when the boosts count of the server changes
//
// @Plugin dDiscordBot
//
// @Group Discord
//
// @Context
// <context.bot> returns the relevant DiscordBotTag.
// <context.group> returns the DiscordGroupTag whose boost count changed.
// <context.new_count> returns the group's new new amount of boosts.
// <context.old_count> returns the group's old amount of boosts.
// -->

public static DiscordUpdateBoostCountEvent instance;

public DiscordUpdateBoostCountEvent() {
instance = this;
registerCouldMatcher("discord boosts count changes");
registerSwitches("group");
}

public GuildUpdateBoostCountEvent getEvent() {
return (GuildUpdateBoostCountEvent) event;
}

@Override
public boolean matches(ScriptPath path) {
if (!tryGuild(path, getEvent().getGuild())) {
return false;
}
return super.matches(path);
}

@Override
public ObjectTag getContext(String name) {
return switch (name) {
case "group" -> new DiscordGroupTag(botID, getEvent().getGuild());
case "new_count" -> new DiscordGroupTag(botID, getEvent().getNewBoostCount());
case "old_count" -> new DiscordGroupTag(botID, getEvent().getOldBoostCount());
default -> super.getContext(name);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,41 @@ public static void register() {
return list;
});

// <--[tag]
// @attribute <DiscordGroupTag.boosters>
// @returns ListTag(DiscordUserTag)
// @plugin dDiscordBot
// @description
// Returns a list of all users in the group that currently boosts it.
// -->
tagProcessor.registerTag(ListTag.class, "boosters", (attribute, object) -> {
List<Member> boosters = object.getGuild().getBoosters();
return new ListTag(boosters, member -> new DiscordUserTag(object.bot, member.getUser()));
});

// <--[tag]
// @attribute <DiscordGroupTag.boosts_count>
// @returns ElementTag(Number)
// @plugin dDiscordBot
// @description
// Returns the amount of boosts the group currently has.
// -->
tagProcessor.registerTag(ElementTag.class, "boosts_count", (attribute, object) -> {
return new ElementTag(object.getGuild().getBoostCount());
});

// <--[tag]
// @attribute <DiscordGroupTag.boost_tier>
// @returns ElementTag
// @plugin dDiscordBot
// @description
// Returns the current tier of the group set by its boosts.
// You can get a list of possible outputs here: <@link url https://docs.jda.wiki/net/dv8tion/jda/api/entities/Guild.BoostTier.html>
// -->
tagProcessor.registerTag(ElementTag.class, "boost_tier", (attribute, object) -> {
return new ElementTag(object.getGuild().getBoostTier());
});

// <--[tag]
// @attribute <DiscordGroupTag.banned_members>
// @returns ListTag(DiscordUserTag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public static void register() {
// @returns ListTag
// @plugin dDiscordBot
// @description
// Returns a list of permissions that the role provides for users. You can get a list of possible outputs here: <@link url https://ci.dv8tion.net/job/JDA5/javadoc/net/dv8tion/jda/api/Permission.html>
// Returns a list of permissions that the role provides for users. You can get a list of possible outputs here: <@link url https://docs.jda.wiki/net/dv8tion/jda/api/Permission.html>
// -->
tagProcessor.registerTag(ListTag.class, "permissions", (attribute, object) -> {
ListTag list = new ListTag();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public static void register() {
// @returns ElementTag(Boolean)
// @plugin dDiscordBot
// @description
// Returns a boolean indicating whether the user is a bot.
// Returns whether the user is a bot or not.
// -->
tagProcessor.registerTag(ElementTag.class, "is_bot", (attribute, object) -> {
if (object.getUserForTag(attribute) == null) {
Expand All @@ -240,6 +240,21 @@ public static void register() {
return new ElementTag(object.getUser().isBot());
});

// <--[tag]
// @attribute <DiscordUserTag.is_boosting[<group>]>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't discord add an unremovable role for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ie most of these tags and the event can be replaced by just scripts checking the role

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The role can be renamed, this tag comes as an reliable alternative mean without using a RoleTag based input.

// @returns ElementTag(Boolean)
// @plugin dDiscordBot
// @description
// Return whether the user is boosting the specified group or not.
// -->
tagProcessor.registerTag(ElementTag.class, DiscordGroupTag.class, "is_boosting", (attribute, object, group) -> {
if (object.getUserForTag(attribute) == null) {
return new ElementTag(false);
}
Member member = group.getGuild().getMember(object.getUser());
return new ElementTag(member.isBoosting());
});

// <--[tag]
// @attribute <DiscordUserTag.avatar_url>
// @returns ElementTag
Expand Down Expand Up @@ -457,7 +472,7 @@ public static void register() {
// @returns ListTag
// @plugin dDiscordBot
// @description
// Returns a list of permissions that the user has in a certain group. You can get a list of possible outputs here: <@link url https://ci.dv8tion.net/job/JDA5/javadoc/net/dv8tion/jda/api/Permission.html>
// Returns a list of permissions that the user has in a certain group. You can get a list of possible outputs here: <@link url https://docs.jda.wiki/net/dv8tion/jda/api/Permission.html>
// -->
tagProcessor.registerTag(ListTag.class, "permissions", (attribute, object) -> {
if (!attribute.hasParam()) {
Expand Down