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,59 @@
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.
Copy link
Member

Choose a reason for hiding this comment

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

What group? ideally any meta entry should make it immediately clear upon first read (so whose boost count changed or something along those lines)

// <context.new_count> returns the new amount of boosts of the group.
// <context.old_count> returns the old amount of boosts of the group.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe the group's new/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 "new_count" -> new DiscordGroupTag(botID, getEvent().getNewBoostCount());
case "old_count" -> new DiscordUserTag(botID, getEvent().getOldBoostCount());
default -> super.getContext(name);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,44 @@ 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 the group.
Copy link
Member

Choose a reason for hiding this comment

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

that currently boost it.

// -->
tagProcessor.registerTag(ListTag.class, "boosters", (attribute, object) -> {
ListTag list = new ListTag();
for (Member member : object.getGuild().getBoosters()) {
list.addObject(new DiscordUserTag(object.bot, member.getUser()));
}
return list;
Copy link
Member

Choose a reason for hiding this comment

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

Can use the ListTag convertor constructor

});

// <--[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.tier>
Copy link
Member

Choose a reason for hiding this comment

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

Might be better to name it boost_tier, would match with boosts_count as well.

// @returns ElementTag(Number)
// @plugin dDiscordBot
// @description
// Returns the tier of the group currently set by its boosts.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just Returns the group's current boost tier, see <@link> for all possible tiers.?

// 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, "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 @@ -240,6 +240,31 @@ 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
// Returns a boolean indicating whether the user is boosting the specified group or not.
Copy link
Member

Choose a reason for hiding this comment

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

No need to specify a boolean, can just Returns whether X

// -->
tagProcessor.registerTag(ElementTag.class, "is_boosting", (attribute, object) -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

could register with the required discordgrouptag input, see <DiscordUserTag.is_in_group[<group>]> for example

Copy link
Author

Choose a reason for hiding this comment

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

Done 😊 Thank you

if (!attribute.hasParam()) {
return null;
}
DiscordGroupTag group = attribute.paramAsType(DiscordGroupTag.class);
if (group == null) {
return null;
}
if (object.getUserForTag(attribute) == null) {
return null;
}
Member member = group.getGuild().getMember(object.getUser());
if (member == null) {
return null;
}
return new ElementTag(member.isBoosting());
});

// <--[tag]
// @attribute <DiscordUserTag.avatar_url>
// @returns ElementTag
Expand Down Expand Up @@ -457,7 +482,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