Search in sources :

Example 6 with Emoticon

use of chatty.util.api.Emoticon in project chatty by chatty.

the class WebsocketManager method fetchEmotes.

/**
 * Fetches all emotes of the given emotesets, useable in the given room and
 * sends them to the listener (removing previous EVENT emotes in that room).
 *
 * @param room The room the emotes will be useable in
 * @param emotesets The set of FFZ emotesets
 */
private void fetchEmotes(String room, Set<Integer> emotesets) {
    Set<Emoticon> result = new HashSet<>();
    for (int set : emotesets) {
        Set<Emoticon> fetched = fetchEmoteSet(room, set);
        for (Emoticon emoteToAdd : fetched) {
            // Add info to already existing emotes
            for (Emoticon emote : result) {
                if (emote.equals(emoteToAdd)) {
                    emote.addInfos(emoteToAdd.getInfos());
                    break;
                }
            }
            // Add emote to result if not already added (Set)
            result.add(emoteToAdd);
        }
    }
    EmoticonUpdate update = new EmoticonUpdate(result, Emoticon.Type.FFZ, Emoticon.SubType.EVENT, room);
    listener.channelEmoticonsReceived(update);
}
Also used : Emoticon(chatty.util.api.Emoticon) EmoticonUpdate(chatty.util.api.EmoticonUpdate) HashSet(java.util.HashSet)

Example 7 with Emoticon

use of chatty.util.api.Emoticon in project chatty by chatty.

the class WebsocketManager method fetchEmoteSet.

/**
 * Get the emotes from a specific emoteset, useable in the given room.
 *
 * @param room The channel the emotes should be useable in
 * @param emoteset The FFZ emoteset to fetch
 * @return A set of emotes or an empty set if an error occured
 */
private Set<Emoticon> fetchEmoteSet(String room, int emoteset) {
    UrlRequest r = new UrlRequest("https://api.frankerfacez.com/v1/set/" + emoteset);
    FullResult result = r.sync();
    if (result.getResult() != null) {
        Set<Emoticon> emotes = FrankerFaceZParsing.parseSetEmotes(result.getResult(), Emoticon.SubType.EVENT, room);
        return emotes;
    }
    return new HashSet<>();
}
Also used : Emoticon(chatty.util.api.Emoticon) UrlRequest(chatty.util.UrlRequest) FullResult(chatty.util.UrlRequest.FullResult) HashSet(java.util.HashSet)

Example 8 with Emoticon

use of chatty.util.api.Emoticon in project chatty by chatty.

the class FrankerFaceZTest method testParseEmoteError.

private void testParseEmoteError(String fileName) throws Exception {
    JSONParser parser = new JSONParser();
    JSONObject obj = (JSONObject) parser.parse(loadJSON(fileName));
    Emoticon emote = FrankerFaceZParsing.parseEmote(obj, null, null, null);
    assertNull(emote);
}
Also used : Emoticon(chatty.util.api.Emoticon) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser)

Example 9 with Emoticon

use of chatty.util.api.Emoticon in project chatty by chatty.

the class EmojiUtil method main.

/**
 * For testing.
 *
 * @param args
 */
public static void main(String[] args) {
    Set<Emoticon> emotes = makeEmoticons("e1");
    System.out.println(emotes.size());
    for (Emoticon emote : emotes) {
        System.out.println(emote.getInfos());
    }
}
Also used : Emoticon(chatty.util.api.Emoticon)

Example 10 with Emoticon

use of chatty.util.api.Emoticon in project chatty by chatty.

the class TwitchClient method commandMyEmotes.

/**
 * Outputs the emotesets for the local user. This might not work correctly
 * if the user is changed or the emotesets change during the session.
 */
private void commandMyEmotes() {
    Set<Integer> emotesets = getSpecialUser().getEmoteSet();
    if (emotesets.isEmpty()) {
        g.printLine("No subscriber emotes found. (Only works if you joined" + " any channel before.)");
    } else {
        StringBuilder b = new StringBuilder("Your subemotes: ");
        String sep = "";
        for (Integer emoteset : emotesets) {
            b.append(sep);
            if (Emoticons.isTurboEmoteset(emoteset)) {
                b.append("Turbo/Prime emotes");
            } else {
                String sep2 = "";
                for (Emoticon emote : g.emoticons.getEmoticons(emoteset)) {
                    b.append(sep2);
                    b.append(emote.code);
                    sep2 = ", ";
                }
            }
            sep = " / ";
        }
        g.printLine(b.toString());
    }
}
Also used : CheerEmoticon(chatty.util.api.CheerEmoticon) Emoticon(chatty.util.api.Emoticon)

Aggregations

Emoticon (chatty.util.api.Emoticon)13 JSONObject (org.json.simple.JSONObject)5 CheerEmoticon (chatty.util.api.CheerEmoticon)4 HashSet (java.util.HashSet)3 JSONParser (org.json.simple.parser.JSONParser)3 EmoticonUpdate (chatty.util.api.EmoticonUpdate)2 Emoteset (chatty.util.TwitchEmotes.Emoteset)1 UrlRequest (chatty.util.UrlRequest)1 FullResult (chatty.util.UrlRequest.FullResult)1 Emoticons (chatty.util.api.Emoticons)1 Usericon (chatty.util.api.usericons.Usericon)1 Matcher (java.util.regex.Matcher)1 JSONArray (org.json.simple.JSONArray)1 ParseException (org.json.simple.parser.ParseException)1 Test (org.junit.Test)1