Search in sources :

Example 1 with CustomEmojiImpl

use of org.javacord.core.entity.emoji.CustomEmojiImpl in project Javacord by BtoBastian.

the class DiscordApiImpl method getKnownCustomEmojiOrCreateCustomEmoji.

/**
 * Gets a known custom emoji or creates a new (unknown) custom emoji object.
 *
 * @param data The data of the emoji.
 * @return The emoji for the given json object.
 */
public CustomEmoji getKnownCustomEmojiOrCreateCustomEmoji(JsonNode data) {
    long id = Long.parseLong(data.get("id").asText());
    CustomEmoji emoji = customEmojis.get(id);
    return emoji == null ? new CustomEmojiImpl(this, data) : emoji;
}
Also used : CustomEmoji(org.javacord.api.entity.emoji.CustomEmoji) KnownCustomEmoji(org.javacord.api.entity.emoji.KnownCustomEmoji) KnownCustomEmojiImpl(org.javacord.core.entity.emoji.KnownCustomEmojiImpl) CustomEmojiImpl(org.javacord.core.entity.emoji.CustomEmojiImpl)

Example 2 with CustomEmojiImpl

use of org.javacord.core.entity.emoji.CustomEmojiImpl in project Javacord by BtoBastian.

the class SelectMenuOptionImpl method toJson.

/**
 * Gets the select menu option as a {@link ObjectNode}. This is what is sent to Discord.
 *
 * @return The select menu option as a ObjectNode.
 */
public ObjectNode toJson() {
    ObjectNode object = JsonNodeFactory.instance.objectNode();
    if (emoji != null) {
        ObjectNode emojiObj = JsonNodeFactory.instance.objectNode();
        if (emoji instanceof CustomEmojiImpl) {
            emojiObj.put("id", ((CustomEmojiImpl) emoji).getId());
            emojiObj.put("name", ((CustomEmojiImpl) emoji).getName());
        } else {
            emojiObj.put("name", emoji.asUnicodeEmoji().get());
        }
        object.set("emoji", emojiObj);
    }
    object.put("label", label);
    object.put("value", value);
    object.put("default", isDefault);
    if (description != null) {
        object.put("description", description);
    }
    return object;
}
Also used : CustomEmojiImpl(org.javacord.core.entity.emoji.CustomEmojiImpl) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Aggregations

CustomEmojiImpl (org.javacord.core.entity.emoji.CustomEmojiImpl)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 CustomEmoji (org.javacord.api.entity.emoji.CustomEmoji)1 KnownCustomEmoji (org.javacord.api.entity.emoji.KnownCustomEmoji)1 KnownCustomEmojiImpl (org.javacord.core.entity.emoji.KnownCustomEmojiImpl)1