Search in sources :

Example 1 with Emoteset

use of chatty.util.TwitchEmotes.Emoteset in project chatty by chatty.

the class EmoticonManager2 method checkStreams.

/**
 * Resolve any pending stream names to emotesets and add them to be
 * requested.
 */
private synchronized void checkStreams() {
    // System.out.println("checkStreams:"+pendingStreams+" "+backlogStreams);
    for (String stream : pendingStreams) {
        Set<Emoteset> sets = emotesetInfo.getEmotesetsByStream(stream);
        System.out.println(sets);
        if (sets != null) {
            for (Emoteset set : sets) {
                addEmoteset(set.emoteset_id);
            }
        } else {
            backlogStreams.add(stream);
        }
    }
    pendingStreams.clear();
}
Also used : Emoteset(chatty.util.TwitchEmotes.Emoteset)

Example 2 with Emoteset

use of chatty.util.TwitchEmotes.Emoteset in project chatty by chatty.

the class Emoticons method addInfo.

public static void addInfo(EmotesetInfo data, Emoticon emote) {
    if (!emote.hasGlobalEmoteset() && !emote.hasStreamSet()) {
        Emoteset info = data.getEmotesetInfo(emote.emoteSet);
        if (info != null) {
            emote.setStream(info.stream);
            emote.setEmotesetInfo(info.product);
        }
    }
}
Also used : Emoteset(chatty.util.TwitchEmotes.Emoteset)

Example 3 with Emoteset

use of chatty.util.TwitchEmotes.Emoteset in project chatty by chatty.

the class ChannelTextPane method addTwitchTagsEmoticons.

/**
 * Adds the emoticons from the Twitch IRCv3 tags.
 *
 * @param emoticons Map of emotes associated with Twitch emote id
 * @param text The message text
 * @param ranges The ranges for this message
 * @param rangesStyle The styles for this message
 * @param emotesDef The emotes definition from the IRCv3 tags
 */
private void addTwitchTagsEmoticons(User user, Map<Integer, Emoticon> emoticons, String text, Map<Integer, Integer> ranges, Map<Integer, MutableAttributeSet> rangesStyle, TagEmotes emotesDef) {
    if (emotesDef == null) {
        return;
    }
    Map<Integer, Emoticons.TagEmote> def = emotesDef.emotes;
    /**
     * Iterate over each character of the message and check if an emote starts
     * at the current position.
     *
     * The offset is used to handle supplemantary characters that consist
     * of two UTF-16 characters. Twitch Chat sees these as only one character
     * so that has to be corrected.
     *
     * https://discuss.dev.twitch.tv/t/jtv-2-receiving-messages/1635/10
     *
     * Example message: "Kappa 𠜎 Kappa"
     */
    int offset = 0;
    for (int i = 0; i < text.length(); ) {
        if (def.containsKey(i - offset)) {
            // An emote starts at the current position, so add it.
            Emoticons.TagEmote emoteData = def.get(i - offset);
            int id = emoteData.id;
            int start = i;
            int end = emoteData.end + offset;
            // Get and check emote
            Emoticon emoticon = null;
            Emoticon customEmote = main.emoticons.getCustomEmoteById(id);
            if (customEmote != null && customEmote.allowedForStream(user.getStream())) {
                emoticon = customEmote;
            } else {
                emoticon = emoticons.get(id);
            }
            if (end < text.length()) {
                if (emoticon == null) {
                    /**
                     * Add emote from message alone
                     */
                    String code = text.substring(start, end + 1);
                    String url = Emoticon.getTwitchEmoteUrlById(id, 1);
                    Emoticon.Builder b = new Emoticon.Builder(Emoticon.Type.TWITCH, code, url);
                    b.setNumericId(id);
                    Emoteset emotesetInfo = main.emoticons.getInfoByEmoteId(id);
                    if (emotesetInfo != null) {
                        b.setEmoteset(emotesetInfo.emoteset_id);
                        b.setStream(emotesetInfo.stream);
                        b.setEmotesetInfo(emotesetInfo.product);
                    } else {
                        b.setEmoteset(Emoticon.SET_UNKNOWN);
                    }
                    emoticon = b.build();
                    main.emoticons.addTempEmoticon(emoticon);
                    LOGGER.info("Added emote from message: " + emoticon);
                }
                if (!main.emoticons.isEmoteIgnored(emoticon)) {
                    addEmoticon(emoticon, start, end, ranges, rangesStyle);
                }
            }
        }
        /**
         * If the current position in the String consists of an character
         * thats more than one long (some Unicode characters), then add to
         * the offset and jump ahead accordingly.
         */
        offset += Character.charCount(text.codePointAt(i)) - 1;
        i += Character.charCount(text.codePointAt(i));
    }
}
Also used : CheerEmoticon(chatty.util.api.CheerEmoticon) Emoticon(chatty.util.api.Emoticon) Emoticons(chatty.util.api.Emoticons) Emoteset(chatty.util.TwitchEmotes.Emoteset)

Aggregations

Emoteset (chatty.util.TwitchEmotes.Emoteset)3 CheerEmoticon (chatty.util.api.CheerEmoticon)1 Emoticon (chatty.util.api.Emoticon)1 Emoticons (chatty.util.api.Emoticons)1