summaryrefslogtreecommitdiff
path: root/scripts/emotes.js
blob: f99bb447658530644a89134fc2eacfb4c80227c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function getBetterTTVChannelEmotes(twitchId, emotes) {
    return fetch(`https://api.betterttv.net/3/cached/users/twitch/${twitchId}`)
        .then((r) => r.json())
        .then((json) => {
            if ("message" in json) {
                addSystemMessage(`${json["message"]} (BetterTTV)`);
                return;
            }
            
            for (const e of [...json["channelEmotes"], ...json["sharedEmotes"]]) {
                emotes[e["code"]] = `https://cdn.betterttv.net/emote/${e["id"]}/1x.webp`;
            }
        });
}

function getBetterTTVGlobalEmotes(emotes) {
    return fetch(`https://api.betterttv.net/3/cached/emotes/global`)
        .then((r) => r.json())
        .then((json) => {
            for (const e of json) {
                emotes[e["code"]] = `https://cdn.betterttv.net/emote/${e["id"]}/1x.webp`;
            }
        });
}

function get7TVChannelEmotes(twitchId, emotes) {
    return fetch(`https://7tv.io/v3/users/twitch/${twitchId}`)
        .then((r) => r.json())
        .then((json) => {
            if ("error" in json) {
                addSystemMessage(`${json["error"]} (7TV)`);
                return;
            }
            
            for (const e of json["emote_set"]["emotes"]) {
                emotes[e["name"]] = `https://cdn.7tv.app/emote/${e["id"]}/1x.webp`;
            }
        });
}

function get7TVGlobalEmotes(emotes) {
    return fetch(`https://7tv.io/v3/emote-sets/global`)
        .then((r) => r.json())
        .then((json) => {
            for (const e of json["emotes"]) {
                emotes[e["name"]] = `https://cdn.7tv.app/emote/${e["id"]}/1x.webp`;
            }
        });
}

function getFFZChannelEmotes(twitchId, emotes) {
    return fetch(`https://api.frankerfacez.com/v1/room/id/${twitchId}`)
        .then((r) => r.json())
        .then((json) => {
            if ("error" in json) {
                addSystemMessage(`${json["error"]} (FFZ)`);
                return;
            }
            
            const room = json["room"];
            
            if ("moderator_badge" in room) {
                badges["moderator/1"] = room["moderator_badge"];
            }
            
            if ("vip_badge" in room) {
                badges["vip/1"] = room["vip_badge"]["1"];
            }
            
            if (room["set"] in json["sets"]) {
                for (const e of json["sets"][room["set"]]["emoticons"]) {
                    emotes[e["name"]] = e["urls"]["1"];
                }
            }
        });
}

function getFFZGlobalEmotes(emotes) {
    return fetch(`https://api.frankerfacez.com/v1/set/global`)
        .then((r) => r.json())
        .then((json) => {
            for (const id of json["default_sets"]) {
                for (const e of json["sets"][id]["emoticons"]) {
                    emotes[e["name"]] = e["urls"]["1"];
                }
            }
        });
}