Skip to content

Commit

Permalink
use new MapTag input methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 13, 2022
1 parent 4f16c64 commit 2f0c978
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 70 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<BUILD_NUMBER>Unknown</BUILD_NUMBER>
<bukkit.version>1.18.2-R0.1-SNAPSHOT</bukkit.version>
<denizen.version>1.2.4-SNAPSHOT</denizen.version>
<bukkit.version>1.19-R0.1-SNAPSHOT</bukkit.version>
<denizen.version>1.2.5-SNAPSHOT</denizen.version>
</properties>

<!-- Repositories -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,17 @@ else if (name == null) {
}
for (ObjectTag optionObj : options.map.values()) {
MapTag option = optionObj.asType(MapTag.class, scriptEntry.getContext());
ElementTag typeStr = (ElementTag) option.getObject("type");
ElementTag typeStr = option.getElement("type");
if (typeStr == null) {
Debug.echoError(scriptEntry, "Command options must specify a type!");
scriptEntry.setFinished(true);
return;
}
OptionType optionType = OptionType.valueOf(typeStr.toString().toUpperCase());
ElementTag optionName = (ElementTag) option.getObject("name");
ElementTag optionDescription = (ElementTag) option.getObject("description");
ElementTag optionIsRequired = (ElementTag) option.getObject("required");
MapTag optionChoices = (MapTag) option.getObject("choices");
OptionType optionType = typeStr.asEnum(OptionType.class);
ElementTag optionName = option.getElement("name");
ElementTag optionDescription = option.getElement("description");
ElementTag optionIsRequired = option.getElement("required");
MapTag optionChoices = option.getObjectAs("choices", MapTag.class, scriptEntry.context);
if (optionName == null) {
Debug.echoError(scriptEntry, "Command options must specify a name!");
scriptEntry.setFinished(true);
Expand Down Expand Up @@ -306,8 +306,8 @@ else if (optionType == OptionType.SUB_COMMAND_GROUP) {
}
for (Map.Entry<StringHolder, ObjectTag> subChoiceValue : optionChoices.map.entrySet()) {
MapTag choice = subChoiceValue.getValue().asType(MapTag.class, scriptEntry.getContext());
ElementTag choiceName = (ElementTag) choice.getObject("name");
ElementTag choiceValue = (ElementTag) choice.getObject("value");
ElementTag choiceName = choice.getElement("name");
ElementTag choiceValue = choice.getElement("value");
if (choiceName == null) {
Debug.echoError(scriptEntry, "Command option choices must specify a name!");
scriptEntry.setFinished(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,14 @@ public DiscordButtonTag(Button button) {
}

public Button build() {
ObjectTag id = buttonData.getObject("id");
ElementTag id = buttonData.getElement("id");
if (id == null) {
return null;
}
ObjectTag label = buttonData.getObject("label");
ObjectTag emoji = buttonData.getObject("emoji");
ObjectTag style = buttonData.getObject("style");
ButtonStyle styleData = ButtonStyle.PRIMARY;
if (style != null) {
styleData = ButtonStyle.valueOf(style.toString().toUpperCase());
}
ElementTag label = buttonData.getElement("label");
ElementTag emoji = buttonData.getElement("emoji");
ElementTag style = buttonData.getElement("style", "PRIMARY");
ButtonStyle styleData = style.asEnum(ButtonStyle.class);
return Button.of(styleData, id.toString(), label == null ? null : label.toString(), emoji == null ? null : Emoji.fromMarkdown(emoji.toString()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ public DiscordEmbedTag(MessageEmbed embed) {

public EmbedBuilder build(TagContext context) {
EmbedBuilder builder = new EmbedBuilder();
ObjectTag author_name = embedData.getObject("author_name");
ObjectTag author_url = embedData.getObject("author_url");
ObjectTag author_icon_url = embedData.getObject("author_icon_url");
ObjectTag color = embedData.getObject("color");
ObjectTag description = embedData.getObject("description");
ObjectTag footer = embedData.getObject("footer");
ObjectTag footer_icon = embedData.getObject("footer_icon");
ObjectTag image = embedData.getObject("image");
ObjectTag thumbnail = embedData.getObject("thumbnail");
ObjectTag timestamp = embedData.getObject("timestamp");
ObjectTag title = embedData.getObject("title");
ObjectTag title_url = embedData.getObject("title_url");
ElementTag author_name = embedData.getElement("author_name");
ElementTag author_url = embedData.getElement("author_url");
ElementTag author_icon_url = embedData.getElement("author_icon_url");
ColorTag color = embedData.getObjectAs("color", ColorTag.class, context);
ElementTag description = embedData.getElement("description");
ElementTag footer = embedData.getElement("footer");
ElementTag footer_icon = embedData.getElement("footer_icon");
ElementTag image = embedData.getElement("image");
ElementTag thumbnail = embedData.getElement("thumbnail");
TimeTag timestamp = embedData.getObjectAs("timestamp", TimeTag.class, context);
ElementTag title = embedData.getElement("title");
ElementTag title_url = embedData.getElement("title_url");
ObjectTag fields = embedData.getObject("fields");
if (author_name != null) {
if (author_url != null) {
Expand All @@ -158,7 +158,7 @@ public EmbedBuilder build(TagContext context) {
}
}
if (color != null) {
builder.setColor(ColorTag.valueOf(color.toString(), context).getColor().asRGB());
builder.setColor(color.getColor().asRGB());
}
if (description != null) {
builder.setDescription(description.toString());
Expand All @@ -178,7 +178,7 @@ public EmbedBuilder build(TagContext context) {
builder.setThumbnail(thumbnail.toString());
}
if (timestamp != null) {
builder.setTimestamp(TimeTag.valueOf(timestamp.toString(), context).instant);
builder.setTimestamp(timestamp.instant);
}
if (title != null) {
if (title_url != null) {
Expand All @@ -193,10 +193,10 @@ public EmbedBuilder build(TagContext context) {
for (ObjectTag field : fieldList) {
MapTag fieldMap = MapTag.getMapFor(field, context);
if (fieldMap != null) {
ObjectTag fieldTitle = fieldMap.getObject("title");
ObjectTag fieldValue = fieldMap.getObject("value");
ObjectTag fieldInline = fieldMap.getObject("inline");
builder.addField(fieldTitle.toString(), fieldValue.toString(), fieldInline != null && fieldInline.toString().equals("true"));
ElementTag fieldTitle = fieldMap.getElement("title");
ElementTag fieldValue = fieldMap.getElement("value");
ElementTag fieldInline = fieldMap.getElement("inline");
builder.addField(fieldTitle.toString(), fieldValue.toString(), fieldInline != null && fieldInline.asBoolean());
}
}
}
Expand Down Expand Up @@ -334,15 +334,11 @@ else if (key.equals("color")) {
MapTag fieldMap = new MapTag();
fieldMap.putObject("title", new ElementTag(title));
fieldMap.putObject("value", new ElementTag(value));
ObjectTag fieldsData = embed.embedData.getObject("fields");
ListTag fieldList;
if (fieldsData == null) {
ListTag fieldList = embed.embedData.getObjectAs("fields", ListTag.class, attribute.context);
if (fieldList == null) {
fieldList = new ListTag();
embed.embedData.putObject("fields", fieldList);
}
else {
fieldList = ListTag.getListFor(fieldsData, attribute.context);
}
fieldList.addObject(fieldMap);
return embed;
});
Expand Down Expand Up @@ -370,15 +366,11 @@ else if (key.equals("color")) {
fieldMap.putObject("title", new ElementTag(title));
fieldMap.putObject("value", new ElementTag(value));
fieldMap.putObject("inline", new ElementTag("true"));
ObjectTag fieldsData = embed.embedData.getObject("fields");
ListTag fieldList;
if (fieldsData == null) {
ListTag fieldList = embed.embedData.getObjectAs("fields", ListTag.class, attribute.context);
if (fieldList == null) {
fieldList = new ListTag();
embed.embedData.putObject("fields", fieldList);
}
else {
fieldList = ListTag.getListFor(fieldsData, attribute.context);
}
fieldList.addObject(fieldMap);
return embed;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ public static void registerTags() {
// @plugin dDiscordBot
// @description
// Returns the full jump URL to this message.
// This returns link text that looks something like "https://discord.com/channels/315163488085475337/315163488085475337/980909305589026906"
// Where the URL is Discord's webserver, followed by Group ID, Channel ID, then Message ID.
// DM messages follow a slightly different but very similar format.
// -->
tagProcessor.registerTag(ElementTag.class, "url", (attribute, object) -> {
return new ElementTag(object.getMessage().getJumpUrl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,23 @@ public DiscordSelectionTag(SelectMenu menu) {
}

public SelectMenu.Builder build(TagContext context) {
ObjectTag id = menuData.getObject("id");
ObjectTag placeholder = menuData.getObject("placeholder");
ElementTag id = menuData.getElement("id");
ElementTag placeholder = menuData.getElement("placeholder");
if (id == null) {
return null;
}
SelectMenu.Builder menu = SelectMenu.create(id.toString());
if (placeholder != null) {
menu.setPlaceholder(placeholder.toString());
}
MapTag options = (MapTag) menuData.getObject("options");
MapTag options = menuData.getObjectAs("options", MapTag.class, context);
if (options != null) {
for (ObjectTag optionObj : options.map.values()) {
MapTag option = optionObj.asType(MapTag.class, context);
ElementTag label = (ElementTag) option.getObject("label");
ElementTag value = (ElementTag) option.getObject("value");
ElementTag description = (ElementTag) option.getObject("description");
ElementTag emoji = (ElementTag) option.getObject("emoji");
ElementTag label = option.getElement("label");
ElementTag value = option.getElement("value");
ElementTag description = option.getElement("description");
ElementTag emoji = option.getElement("emoji");
Emoji emojiData = null;
if (emoji != null) {
emojiData = Emoji.fromMarkdown(emoji.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,29 @@ public DiscordTextInputTag(TextInput textInput) {
}

public TextInput build() {
ObjectTag id = textInputData.getObject("id");
ElementTag id = textInputData.getElement("id");
if (id == null) {
return null;
}
ObjectTag label = textInputData.getObject("label");
ObjectTag style = textInputData.getObject("style");
TextInputStyle textInputStyle = TextInputStyle.SHORT;
if (style != null) {
textInputStyle = style.asElement().asEnum(TextInputStyle.class);
}
ElementTag label = textInputData.getElement("label");
ElementTag style = textInputData.getElement("style", "SHORT");
TextInputStyle textInputStyle = style.asEnum(TextInputStyle.class);
TextInput.Builder textInput = TextInput.create(id.toString(), label.toString(), textInputStyle);
ObjectTag minLength = textInputData.getObject("min_length");
ElementTag minLength = textInputData.getElement("min_length");
if (minLength != null) {
textInput.setMinLength(Integer.parseInt(minLength.toString()));
textInput.setMinLength(minLength.asInt());
}
ObjectTag maxLength = textInputData.getObject("max_length");
ElementTag maxLength = textInputData.getElement("max_length");
if (maxLength != null) {
textInput.setMaxLength(Integer.parseInt(maxLength.toString()));
textInput.setMaxLength(maxLength.asInt());
}
ObjectTag isRequired = textInputData.getObject("is_required");
ElementTag isRequired = textInputData.getElement("is_required");
if (isRequired != null) {
textInput.setRequired(Boolean.parseBoolean(isRequired.toString()));
textInput.setRequired(isRequired.asBoolean());
}
ObjectTag value = textInputData.getObject("value");
ElementTag value = textInputData.getElement("value");
textInput.setValue(value == null ? null : value.toString());
ObjectTag placeholder = textInputData.getObject("placeholder");
ElementTag placeholder = textInputData.getElement("placeholder");
textInput.setPlaceholder(placeholder == null ? null : placeholder.toString());
return textInput.build();
}
Expand Down

0 comments on commit 2f0c978

Please sign in to comment.