Search in sources :

Example 1 with Emoji

use of net.dv8tion.jda.api.entities.Emoji in project dDiscordBot by DenizenScript.

the class DiscordSelectionTag method build.

public SelectMenu.Builder build(TagContext context) {
    ObjectTag id = menuData.getObject("id");
    ObjectTag placeholder = menuData.getObject("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");
    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");
            Emoji emojiData = null;
            if (emoji != null) {
                emojiData = Emoji.fromMarkdown(emoji.toString());
            }
            if (label == null || value == null) {
                return null;
            }
            if (description == null && emoji == null) {
                menu.addOption(label.toString(), value.toString());
            } else if (emoji == null) {
                menu.addOption(label.toString(), value.toString(), description.toString());
            } else if (description == null) {
                menu.addOption(label.toString(), value.toString(), emojiData);
            } else {
                menu.addOption(label.toString(), value.toString(), description.toString(), emojiData);
            }
        }
    }
    return menu;
}
Also used : SelectMenu(net.dv8tion.jda.api.interactions.components.selections.SelectMenu) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) Emoji(net.dv8tion.jda.api.entities.Emoji) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Aggregations

ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 MapTag (com.denizenscript.denizencore.objects.core.MapTag)1 Emoji (net.dv8tion.jda.api.entities.Emoji)1 SelectMenu (net.dv8tion.jda.api.interactions.components.selections.SelectMenu)1