Skip to content

Commit

Permalink
update for core tag return type registration
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 20, 2021
1 parent 1eeed01 commit 47a53ed
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 147 deletions.
24 changes: 12 additions & 12 deletions src/main/java/com/denizenscript/ddiscordbot/DenizenDiscordBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void onEnable() {
// @description
// Returns the Discord bot for the given bot ID.
// -->
TagManager.registerTagHandler("discord", (attribute) -> {
TagManager.registerTagHandler(DiscordBotTag.class, "discord", (attribute) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("Discord tag base must have input.");
return null;
Expand All @@ -94,7 +94,7 @@ public void onEnable() {
// Or, if given an input, returns a Discord Button object constructed from the input value.
// Refer to <@link objecttype DiscordButtonTag>.
// -->
TagManager.registerTagHandler("discord_button", (attribute) -> {
TagManager.registerTagHandler(DiscordButtonTag.class, "discord_button", (attribute) -> {
if (!attribute.hasContext(1)) {
return new DiscordButtonTag();
}
Expand All @@ -108,7 +108,7 @@ public void onEnable() {
// Returns a Discord Channel object constructed from the input value.
// Refer to <@link objecttype DiscordChannelTag>.
// -->
TagManager.registerTagHandler("discord_channel", (attribute) -> {
TagManager.registerTagHandler(DiscordChannelTag.class, "discord_channel", (attribute) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("Discord channel tag base must have input.");
return null;
Expand All @@ -123,7 +123,7 @@ public void onEnable() {
// Returns a Discord Command object constructed from the input value.
// Refer to <@link objecttype DiscordCommandTag>.
// -->
TagManager.registerTagHandler("discord_command", (attribute) -> {
TagManager.registerTagHandler(DiscordCommandTag.class, "discord_command", (attribute) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("Discord command tag base must have input.");
return null;
Expand All @@ -139,7 +139,7 @@ public void onEnable() {
// Or, if given an input, returns a Discord Embed object constructed from the input value.
// Refer to <@link objecttype DiscordEmbedTag>.
// -->
TagManager.registerTagHandler("discord_embed", (attribute) -> {
TagManager.registerTagHandler(DiscordEmbedTag.class, "discord_embed", (attribute) -> {
if (!attribute.hasContext(1)) {
return new DiscordEmbedTag();
}
Expand All @@ -153,7 +153,7 @@ public void onEnable() {
// Returns a Discord Group object constructed from the input value.
// Refer to <@link objecttype DiscordGroupTag>.
// -->
TagManager.registerTagHandler("discord_group", (attribute) -> {
TagManager.registerTagHandler(DiscordGroupTag.class, "discord_group", (attribute) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("Discord group tag base must have input.");
return null;
Expand All @@ -168,7 +168,7 @@ public void onEnable() {
// Returns a Discord Interaction object constructed from the input value.
// Refer to <@link objecttype DiscordInteractionTag>.
// -->
TagManager.registerTagHandler("discord_interaction", (attribute) -> {
TagManager.registerTagHandler(DiscordInteractionTag.class, "discord_interaction", (attribute) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("Discord interaction tag base must have input.");
return null;
Expand All @@ -183,7 +183,7 @@ public void onEnable() {
// Returns a Discord Message object constructed from the input value.
// Refer to <@link objecttype DiscordMessageTag>.
// -->
TagManager.registerTagHandler("discord_message", (attribute) -> {
TagManager.registerTagHandler(DiscordMessageTag.class, "discord_message", (attribute) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("Discord message tag base must have input.");
return null;
Expand All @@ -198,7 +198,7 @@ public void onEnable() {
// Returns a Discord Reaction object constructed from the input value.
// Refer to <@link objecttype DiscordReactionTag>.
// -->
TagManager.registerTagHandler("discord_reaction", (attribute) -> {
TagManager.registerTagHandler(DiscordReactionTag.class, "discord_reaction", (attribute) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("Discord reaction tag base must have input.");
return null;
Expand All @@ -213,7 +213,7 @@ public void onEnable() {
// Returns a Discord Role object constructed from the input value.
// Refer to <@link objecttype DiscordRoleTag>.
// -->
TagManager.registerTagHandler("discord_role", (attribute) -> {
TagManager.registerTagHandler(DiscordRoleTag.class, "discord_role", (attribute) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("Discord role tag base must have input.");
return null;
Expand All @@ -229,7 +229,7 @@ public void onEnable() {
// Or, if given an input, returns a Discord Selection object constructed from the input value.
// Refer to <@link objecttype DiscordSelectionTag>.
// -->
TagManager.registerTagHandler("discord_selection", (attribute) -> {
TagManager.registerTagHandler(DiscordSelectionTag.class, "discord_selection", (attribute) -> {
if (!attribute.hasContext(1)) {
return new DiscordSelectionTag();
}
Expand All @@ -243,7 +243,7 @@ public void onEnable() {
// Returns a Discord User object constructed from the input value.
// Refer to <@link objecttype DiscordUserTag>.
// -->
TagManager.registerTagHandler("discord_user", (attribute) -> {
TagManager.registerTagHandler(DiscordUserTag.class, "discord_user", (attribute) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("Discord user tag base must have input.");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void onButtonClick(ButtonClickEvent event) {
@Override
public void onSelectionMenu(SelectionMenuEvent event) {
autoHandle(event, DiscordSelectionUsedScriptEvent.instance);
};
}

public void autoHandle(Event event, DiscordScriptEvent scriptEvent) {
Bukkit.getScheduler().runTask(DenizenDiscordBot.instance, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static void registerTags() {
// @description
// Returns the name of the bot.
// -->
registerTag("name", (attribute, object) -> {
tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
return new ElementTag(object.bot);

});
Expand All @@ -106,7 +106,7 @@ public static void registerTags() {
// @description
// Returns the bot's own Discord user object.
// -->
registerTag("self_user", (attribute, object) -> {
tagProcessor.registerTag(DiscordUserTag.class, "self_user", (attribute, object) -> {
DiscordConnection connection = DenizenDiscordBot.instance.connections.get(object.bot);
if (connection == null) {
return null;
Expand All @@ -122,7 +122,7 @@ public static void registerTags() {
// @description
// Returns a list of all groups (aka 'guilds' or 'servers') that this Discord bot has access to.
// -->
registerTag("groups", (attribute, object) -> {
tagProcessor.registerTag(ListTag.class, "groups", (attribute, object) -> {
DiscordConnection connection = DenizenDiscordBot.instance.connections.get(object.bot);
if (connection == null) {
return null;
Expand All @@ -141,7 +141,7 @@ public static void registerTags() {
// @description
// Returns a list of all application commands.
// -->
registerTag("commands", (attribute, object) -> {
tagProcessor.registerTag(ListTag.class, "commands", (attribute, object) -> {
DiscordConnection connection = DenizenDiscordBot.instance.connections.get(object.bot);
if (connection == null) {
return null;
Expand All @@ -160,7 +160,7 @@ public static void registerTags() {
// @description
// Returns the Discord group (aka 'guild' or 'server') that best matches the input name, or null if there's no match.
// -->
registerTag("group", (attribute, object) -> {
tagProcessor.registerTag(DiscordGroupTag.class, "group", (attribute, object) -> {
if (!attribute.hasContext(1)) {
return null;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ public static void registerTags() {
// @description
// Returns the application command that best matches the input name, or null if there's no match.
// -->
registerTag("command", (attribute, object) -> {
tagProcessor.registerTag(DiscordCommandTag.class, "command", (attribute, object) -> {
if (!attribute.hasContext(1)) {
return null;
}
Expand Down Expand Up @@ -223,10 +223,6 @@ public static void registerTags() {

public static ObjectTagProcessor<DiscordBotTag> tagProcessor = new ObjectTagProcessor<>();

public static void registerTag(String name, TagRunnable.ObjectInterface<DiscordBotTag> runnable, String... variants) {
tagProcessor.registerTag(name, runnable, variants);
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
return tagProcessor.getObjectAttribute(this, attribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static void registerTags() {
// Returns a copy of this Button tag, with the map of keys to values applied.
// Refer to <@link tag DiscordButtonTag.with.as>.
// -->
registerTag("with_map", (attribute, object) -> {
tagProcessor.registerTag(DiscordButtonTag.class, "with_map", (attribute, object) -> {
DiscordButtonTag button = object.duplicate();
if (!attribute.hasContext(1)) {
attribute.echoError("Invalid button.with_map[...] tag: must have an input value.");
Expand Down Expand Up @@ -166,7 +166,7 @@ public static void registerTags() {
// label: ElementTag
// emoji: ElementTag
// -->
registerTag("with", (attribute, object) -> {
tagProcessor.registerTag(DiscordButtonTag.class, "with", (attribute, object) -> {
DiscordButtonTag button = object.duplicate();
if (!attribute.hasContext(1)) {
attribute.echoError("Invalid button.with[...] tag: must have an input value.");
Expand Down Expand Up @@ -197,17 +197,13 @@ public static void registerTags() {
// @description
// Returns the MapTag internally backing this button tag.
// -->
registerTag("map", (attribute, object) -> {
tagProcessor.registerTag(MapTag.class, "map", (attribute, object) -> {
return object.buttonData.duplicate();
});
}

public static ObjectTagProcessor<DiscordButtonTag> tagProcessor = new ObjectTagProcessor<>();

public static void registerTag(String name, TagRunnable.ObjectInterface<DiscordButtonTag> runnable, String... variants) {
tagProcessor.registerTag(name, runnable, variants);
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
return tagProcessor.getObjectAttribute(this, attribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static void registerTags() {
// @description
// Returns the name of the channel.
// -->
registerTag("name", (attribute, object) -> {
tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
MessageChannel chan = object.getChannel();
String name;
if (chan instanceof GuildChannel) {
Expand All @@ -158,7 +158,7 @@ else if (chan instanceof PrivateChannel) {
// Returns the type of the channel.
// Will be any of: TEXT, PRIVATE, VOICE, GROUP, CATEGORY, STORE, UNKNOWN.
// -->
registerTag("channel_type", (attribute, object) -> {
tagProcessor.registerTag(ElementTag.class, "channel_type", (attribute, object) -> {
return new ElementTag(object.getChannel().getType().name());
}, "type");

Expand All @@ -169,7 +169,7 @@ else if (chan instanceof PrivateChannel) {
// @description
// Returns the ID number of the channel.
// -->
registerTag("id", (attribute, object) -> {
tagProcessor.registerTag(ElementTag.class, "id", (attribute, object) -> {
return new ElementTag(object.channel_id);
});

Expand All @@ -180,7 +180,7 @@ else if (chan instanceof PrivateChannel) {
// @description
// Returns the raw mention string for the channel.
// -->
registerTag("mention", (attribute, object) -> {
tagProcessor.registerTag(ElementTag.class, "mention", (attribute, object) -> {
return new ElementTag("<#" + object.channel_id + ">");
});

Expand All @@ -191,7 +191,7 @@ else if (chan instanceof PrivateChannel) {
// @description
// Returns the group that owns this channel.
// -->
registerTag("group", (attribute, object) -> {
tagProcessor.registerTag(DiscordGroupTag.class, "group", (attribute, object) -> {
MessageChannel chan = object.getChannel();
Guild guild;
if (chan instanceof GuildChannel) {
Expand All @@ -210,7 +210,7 @@ else if (chan instanceof PrivateChannel) {
// @description
// Returns a list of the messages that are pinned in the channel.
// -->
registerTag("pinned_messages", (attribute, object) -> {
tagProcessor.registerTag(ListTag.class, "pinned_messages", (attribute, object) -> {
ListTag list = new ListTag();
for (Message message : object.getChannel().retrievePinnedMessages().complete()) {
list.addObject(new DiscordMessageTag(object.bot, message));
Expand All @@ -225,7 +225,7 @@ else if (chan instanceof PrivateChannel) {
// @description
// Returns the first message sent in the channel.
// -->
registerTag("first_message", (attribute, object) -> {
tagProcessor.registerTag(DiscordMessageTag.class, "first_message", (attribute, object) -> {
Message first = object.getChannel().getHistoryFromBeginning(1).complete().getRetrievedHistory().get(0);
return new DiscordMessageTag(object.bot, first);
});
Expand All @@ -237,7 +237,7 @@ else if (chan instanceof PrivateChannel) {
// @description
// Returns the last message sent in the channel.
// -->
registerTag("last_message", (attribute, object) -> {
tagProcessor.registerTag(DiscordMessageTag.class, "last_message", (attribute, object) -> {
if (object.getChannel().hasLatestMessage()) {
return new DiscordMessageTag(object.bot, object.channel_id, object.getChannel().getLatestMessageIdLong());
}
Expand All @@ -249,10 +249,6 @@ else if (chan instanceof PrivateChannel) {

public static ObjectTagProcessor<DiscordChannelTag> tagProcessor = new ObjectTagProcessor<>();

public static void registerTag(String name, TagRunnable.ObjectInterface<DiscordChannelTag> runnable, String... variants) {
tagProcessor.registerTag(name, runnable, variants);
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
return tagProcessor.getObjectAttribute(this, attribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static void registerTags() {
// @description
// Returns the ID of the command.
// -->
registerTag("id", (attribute, object) -> {
tagProcessor.registerTag(ElementTag.class, "id", (attribute, object) -> {
return new ElementTag(object.command_id);
});

Expand All @@ -195,7 +195,7 @@ public static void registerTags() {
// @description
// Returns the name of the command.
// -->
registerTag("name", (attribute, object) -> {
tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
return new ElementTag(object.getCommand().getName());
});

Expand All @@ -206,7 +206,7 @@ public static void registerTags() {
// @description
// Returns the description of the command.
// -->
registerTag("description", (attribute, object) -> {
tagProcessor.registerTag(ElementTag.class, "description", (attribute, object) -> {
return new ElementTag(object.getCommand().getDescription());
});

Expand All @@ -217,7 +217,7 @@ public static void registerTags() {
// @description
// Returns the option MapTags of the command. This is the same value as the one provided when creating a command, as documented in <@link command DiscordCommand>.
// -->
registerTag("options", (attribute, object) -> {
tagProcessor.registerTag(ListTag.class, "options", (attribute, object) -> {
ListTag options = new ListTag();
for (Command.Option option : object.getCommand().getOptions()) {
MapTag map = new MapTag();
Expand Down Expand Up @@ -248,10 +248,6 @@ public static void registerTags() {

public static ObjectTagProcessor<DiscordCommandTag> tagProcessor = new ObjectTagProcessor<>();

public static void registerTag(String name, TagRunnable.ObjectInterface<DiscordCommandTag> runnable, String... variants) {
tagProcessor.registerTag(name, runnable, variants);
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
return tagProcessor.getObjectAttribute(this, attribute);
Expand Down
Loading

0 comments on commit 47a53ed

Please sign in to comment.