Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boosts Events and Tags #60

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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 +131,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
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