-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
d71759d
d482df3
9644fd9
a724eae
dd0e2b5
f83aa0e
1bfc939
38b308a
cbdbb55
8e2ead3
c32b766
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
// <context.new_count> returns the new amount of boosts of the group. | ||
// <context.old_count> returns the old amount of boosts of the group. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
// --> | ||
|
||
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); | ||
mcmonkey4eva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// --> | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can use the |
||
}); | ||
|
||
// <--[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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be better to name it |
||
// @returns ElementTag(Number) | ||
// @plugin dDiscordBot | ||
// @description | ||
// Returns the tier of the group currently set by its boosts. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just |
||
// 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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,31 @@ public static void register() { | |
return new ElementTag(object.getUser().isBot()); | ||
}); | ||
|
||
// <--[tag] | ||
// @attribute <DiscordUserTag.is_boosting[<group>]> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't discord add an unremovable role for this There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to specify |
||
// --> | ||
tagProcessor.registerTag(ElementTag.class, "is_boosting", (attribute, object) -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could register with the required discordgrouptag input, see There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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()) { | ||
|
There was a problem hiding this comment.
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)