@mkody/twitch-emoticons 2.6.2 → 2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +143 -143
- package/.github/codeql/codeql-config.yml +4 -4
- package/.github/workflows/codeql.yml +50 -50
- package/.github/workflows/eslint.yml +50 -50
- package/.github/workflows/release.yml +22 -0
- package/.github/workflows/yarn-test.yml +17 -17
- package/.jsdoc.json +39 -39
- package/.nvmrc +1 -0
- package/LICENSE +22 -22
- package/README.md +13 -8
- package/docs/BTTVEmote.html +83 -5
- package/docs/Channel.html +1 -1
- package/docs/Collection.html +1 -1
- package/docs/Emote.html +3 -3
- package/docs/EmoteFetcher.html +271 -19
- package/docs/EmoteParser.html +1 -1
- package/docs/FFZEmote.html +162 -6
- package/docs/SevenTV.html +1190 -1190
- package/docs/SevenTVEmote.html +84 -6
- package/docs/TwitchEmote.html +83 -5
- package/docs/index.html +15 -10
- package/docs/struct_BTTVEmote.js.html +61 -55
- package/docs/struct_Channel.js.html +56 -56
- package/docs/struct_Emote.js.html +67 -66
- package/docs/struct_EmoteFetcher.js.html +324 -284
- package/docs/struct_EmoteParser.js.html +82 -81
- package/docs/struct_FFZEmote.js.html +75 -62
- package/docs/struct_SevenTVEmote.js.html +70 -64
- package/docs/struct_TwitchEmote.js.html +59 -53
- package/docs/util_Collection.js.html +79 -79
- package/package.json +57 -57
- package/src/index.js +12 -12
- package/src/struct/BTTVEmote.js +60 -54
- package/src/struct/Channel.js +55 -55
- package/src/struct/Emote.js +66 -65
- package/src/struct/EmoteFetcher.js +323 -283
- package/src/struct/EmoteParser.js +81 -80
- package/src/struct/FFZEmote.js +74 -61
- package/src/struct/SevenTVEmote.js +69 -63
- package/src/struct/TwitchEmote.js +58 -52
- package/src/util/Collection.js +78 -78
- package/src/util/Constants.js +31 -25
- package/test/index.js +174 -166
- package/typings/index.d.ts +98 -93
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<nav >
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BTTVEmote.html">BTTVEmote</a><ul class='methods'><li data-type='method'><a href="BTTVEmote.html#toLink">toLink</a></li><li data-type='method'><a href="BTTVEmote.html#toString">toString</a></li></ul></li><li><a href="Channel.html">Channel</a><ul class='methods'><li data-type='method'><a href="Channel.html#fetchBTTVEmotes">fetchBTTVEmotes</a></li><li data-type='method'><a href="Channel.html#fetchFFZEmotes">fetchFFZEmotes</a></li><li data-type='method'><a href="Channel.html#fetchSevenTVEmotes">fetchSevenTVEmotes</a></li></ul></li><li><a href="Collection.html">Collection</a><ul class='methods'><li data-type='method'><a href="Collection.html#filter">filter</a></li><li data-type='method'><a href="Collection.html#find">find</a></li><li data-type='method'><a href="Collection.html#map">map</a></li></ul></li><li><a href="Emote.html">Emote</a><ul class='methods'><li data-type='method'><a href="Emote.html#toString">toString</a></li></ul></li><li><a href="EmoteFetcher.html">EmoteFetcher</a><ul class='methods'><li data-type='method'><a href="EmoteFetcher.html#_cacheBTTVEmote">_cacheBTTVEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheFFZEmote">_cacheFFZEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheSevenTVEmote">_cacheSevenTVEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheTwitchEmote">_cacheTwitchEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawBTTVEmotes">_getRawBTTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawFFZEmotes">_getRawFFZEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawSevenTVEmotes">_getRawSevenTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawTwitchEmotes">_getRawTwitchEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchBTTVEmotes">fetchBTTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchFFZEmotes">fetchFFZEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchSevenTVEmotes">fetchSevenTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchTwitchEmotes">fetchTwitchEmotes</a></li></ul></li><li><a href="EmoteParser.html">EmoteParser</a><ul class='methods'><li data-type='method'><a href="EmoteParser.html#parse">parse</a></li></ul></li><li><a href="FFZEmote.html">FFZEmote</a><ul class='methods'><li data-type='method'><a href="FFZEmote.html#toLink">toLink</a></li><li data-type='method'><a href="FFZEmote.html#toString">toString</a></li></ul></li><li><a href="SevenTVEmote.html">SevenTVEmote</a><ul class='methods'><li data-type='method'><a href="SevenTVEmote.html#toLink">toLink</a></li><li data-type='method'><a href="SevenTVEmote.html#toString">toString</a></li></ul></li><li><a href="TwitchEmote.html">TwitchEmote</a><ul class='methods'><li data-type='method'><a href="TwitchEmote.html#toLink">toLink</a></li><li data-type='method'><a href="TwitchEmote.html#toString">toString</a></li></ul></li></ul>
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BTTVEmote.html">BTTVEmote</a><ul class='methods'><li data-type='method'><a href="BTTVEmote.html#toLink">toLink</a></li><li data-type='method'><a href="BTTVEmote.html#toString">toString</a></li></ul></li><li><a href="Channel.html">Channel</a><ul class='methods'><li data-type='method'><a href="Channel.html#fetchBTTVEmotes">fetchBTTVEmotes</a></li><li data-type='method'><a href="Channel.html#fetchFFZEmotes">fetchFFZEmotes</a></li><li data-type='method'><a href="Channel.html#fetchSevenTVEmotes">fetchSevenTVEmotes</a></li></ul></li><li><a href="Collection.html">Collection</a><ul class='methods'><li data-type='method'><a href="Collection.html#filter">filter</a></li><li data-type='method'><a href="Collection.html#find">find</a></li><li data-type='method'><a href="Collection.html#map">map</a></li></ul></li><li><a href="Emote.html">Emote</a><ul class='methods'><li data-type='method'><a href="Emote.html#toString">toString</a></li></ul></li><li><a href="EmoteFetcher.html">EmoteFetcher</a><ul class='methods'><li data-type='method'><a href="EmoteFetcher.html#_cacheBTTVEmote">_cacheBTTVEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheFFZEmote">_cacheFFZEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheSevenTVEmote">_cacheSevenTVEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheTwitchEmote">_cacheTwitchEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawBTTVEmotes">_getRawBTTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawFFZEmoteSet">_getRawFFZEmoteSet</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawFFZEmotes">_getRawFFZEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawSevenTVEmotes">_getRawSevenTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawTwitchEmotes">_getRawTwitchEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchBTTVEmotes">fetchBTTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchFFZEmotes">fetchFFZEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchSevenTVEmotes">fetchSevenTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchTwitchEmotes">fetchTwitchEmotes</a></li></ul></li><li><a href="EmoteParser.html">EmoteParser</a><ul class='methods'><li data-type='method'><a href="EmoteParser.html#parse">parse</a></li></ul></li><li><a href="FFZEmote.html">FFZEmote</a><ul class='methods'><li data-type='method'><a href="FFZEmote.html#toLink">toLink</a></li><li data-type='method'><a href="FFZEmote.html#toString">toString</a></li></ul></li><li><a href="SevenTVEmote.html">SevenTVEmote</a><ul class='methods'><li data-type='method'><a href="SevenTVEmote.html#toLink">toLink</a></li><li data-type='method'><a href="SevenTVEmote.html#toString">toString</a></li></ul></li><li><a href="TwitchEmote.html">TwitchEmote</a><ul class='methods'><li data-type='method'><a href="TwitchEmote.html#toLink">toLink</a></li><li data-type='method'><a href="TwitchEmote.html#toString">toString</a></li></ul></li></ul>
|
|
33
33
|
|
|
34
34
|
</nav>
|
|
35
35
|
|
|
@@ -45,289 +45,329 @@
|
|
|
45
45
|
|
|
46
46
|
<section>
|
|
47
47
|
<article>
|
|
48
|
-
<pre class="prettyprint source linenums"><code>const BTTVEmote = require('./BTTVEmote');
|
|
49
|
-
const Channel = require('./Channel');
|
|
50
|
-
const Collection = require('../util/Collection');
|
|
51
|
-
const Constants = require('../util/Constants');
|
|
52
|
-
const FFZEmote = require('./FFZEmote');
|
|
53
|
-
const SevenTVEmote = require('./SevenTVEmote');
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
const { ApiClient } = require('@twurple/api');
|
|
58
|
-
const { AppTokenAuthProvider } = require('@twurple/auth');
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
*
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
*
|
|
108
|
-
* @
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return this.apiClient.chat.
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
*
|
|
126
|
-
* @
|
|
127
|
-
* @
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
channel.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* @
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
*
|
|
166
|
-
* @
|
|
167
|
-
* @
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
channel.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
*
|
|
186
|
-
* @
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
*
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
*
|
|
240
|
-
* @
|
|
241
|
-
* @param {
|
|
242
|
-
* @returns {
|
|
243
|
-
*/
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Fetches the
|
|
276
|
-
* Use `null` for the global emotes channel.
|
|
277
|
-
* @param {int} [channel=null] - ID of the channel.
|
|
278
|
-
* @returns {Promise<Collection<string,
|
|
279
|
-
*/
|
|
280
|
-
|
|
281
|
-
return this.
|
|
282
|
-
for (const
|
|
283
|
-
this.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
*
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
*
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
48
|
+
<pre class="prettyprint source linenums"><code>const BTTVEmote = require('./BTTVEmote');
|
|
49
|
+
const Channel = require('./Channel');
|
|
50
|
+
const Collection = require('../util/Collection');
|
|
51
|
+
const Constants = require('../util/Constants');
|
|
52
|
+
const FFZEmote = require('./FFZEmote');
|
|
53
|
+
const SevenTVEmote = require('./SevenTVEmote');
|
|
54
|
+
const TwitchEmote = require('./TwitchEmote');
|
|
55
|
+
|
|
56
|
+
const axios = require('axios');
|
|
57
|
+
const { ApiClient } = require('@twurple/api');
|
|
58
|
+
const { AppTokenAuthProvider } = require('@twurple/auth');
|
|
59
|
+
|
|
60
|
+
class EmoteFetcher {
|
|
61
|
+
/**
|
|
62
|
+
* Fetches and caches emotes.
|
|
63
|
+
* @param {string} clientId The client id for the twitch api.
|
|
64
|
+
* @param {string} clientSecret The client secret for the twitch api.
|
|
65
|
+
*/
|
|
66
|
+
constructor(clientId, clientSecret) {
|
|
67
|
+
if (clientId !== undefined && clientSecret !== undefined) {
|
|
68
|
+
const authProvider = new AppTokenAuthProvider(clientId, clientSecret);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Twitch api client.
|
|
72
|
+
*/
|
|
73
|
+
this.apiClient = new ApiClient({ authProvider });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Cached emotes.
|
|
78
|
+
* Collectionped by emote code to Emote instance.
|
|
79
|
+
* @type {Collection<string, Emote>}
|
|
80
|
+
*/
|
|
81
|
+
this.emotes = new Collection();
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Cached channels.
|
|
85
|
+
* Collectionped by name to Channel instance.
|
|
86
|
+
* @type {Collection<string, Channel>}
|
|
87
|
+
*/
|
|
88
|
+
this.channels = new Collection();
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Save if we fetched FFZ's modifier emotes once.
|
|
92
|
+
* @type {boolean}
|
|
93
|
+
*/
|
|
94
|
+
this.ffzModifiersFetched = false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The global channel for Twitch, BTTV and 7TV.
|
|
99
|
+
* @readonly
|
|
100
|
+
* @type {?Channel}
|
|
101
|
+
*/
|
|
102
|
+
get globalChannel() {
|
|
103
|
+
return this.channels.get(null);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Gets the raw Twitch emotes data for a channel.
|
|
108
|
+
* @private
|
|
109
|
+
* @param {int} id - ID of the channel.
|
|
110
|
+
* @returns {Promise<Object[]>}
|
|
111
|
+
*/
|
|
112
|
+
_getRawTwitchEmotes(id) {
|
|
113
|
+
if (!this.apiClient) {
|
|
114
|
+
throw new Error('Client id or client secret not provided.');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (id) {
|
|
118
|
+
return this.apiClient.chat.getChannelEmotes(id);
|
|
119
|
+
} else {
|
|
120
|
+
return this.apiClient.chat.getGlobalEmotes();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Converts and caches a raw twitch emote.
|
|
126
|
+
* @private
|
|
127
|
+
* @param {int} channel_id - ID of the channel.
|
|
128
|
+
* @param {Object} data - Raw data.
|
|
129
|
+
* @returns {TwitchEmote}
|
|
130
|
+
*/
|
|
131
|
+
_cacheTwitchEmote(channel_id, data) {
|
|
132
|
+
let channel = this.channels.get(channel_id);
|
|
133
|
+
if (!channel) {
|
|
134
|
+
channel = new Channel(this, channel_id);
|
|
135
|
+
this.channels.set(channel_id, channel);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const emote = new TwitchEmote(channel, data.id, data);
|
|
139
|
+
this.emotes.set(emote.code, emote);
|
|
140
|
+
channel.emotes.set(emote.code, emote);
|
|
141
|
+
return emote;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Gets the raw BTTV emotes data for a channel.
|
|
146
|
+
* Use `null` for the global emotes channel.
|
|
147
|
+
* @private
|
|
148
|
+
* @param {int} [id=null] - ID of the channel.
|
|
149
|
+
* @returns {Promise<Object[]>}
|
|
150
|
+
*/
|
|
151
|
+
_getRawBTTVEmotes(id) {
|
|
152
|
+
const endpoint = !id
|
|
153
|
+
? Constants.BTTV.Global
|
|
154
|
+
: Constants.BTTV.Channel(id); // eslint-disable-line new-cap
|
|
155
|
+
|
|
156
|
+
return axios.get(endpoint).then(req => {
|
|
157
|
+
// Global emotes
|
|
158
|
+
if (req.data instanceof Array) return req.data;
|
|
159
|
+
// Channel emotes
|
|
160
|
+
return [...req.data.channelEmotes, ...req.data.sharedEmotes];
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Converts and caches a raw BTTV emote.
|
|
166
|
+
* @private
|
|
167
|
+
* @param {int} channel_id - ID of the channel.
|
|
168
|
+
* @param {Object} data - Raw data.
|
|
169
|
+
* @returns {BTTVEmote}
|
|
170
|
+
*/
|
|
171
|
+
_cacheBTTVEmote(channel_id, data) {
|
|
172
|
+
let channel = this.channels.get(channel_id);
|
|
173
|
+
if (!channel) {
|
|
174
|
+
channel = new Channel(this, channel_id);
|
|
175
|
+
this.channels.set(channel_id, channel);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const emote = new BTTVEmote(channel, data.id, data);
|
|
179
|
+
this.emotes.set(emote.code, emote);
|
|
180
|
+
channel.emotes.set(emote.code, emote);
|
|
181
|
+
return emote;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Gets the raw FFZ emote data from a set.
|
|
186
|
+
* @private
|
|
187
|
+
* @param {int} id - ID of the set.
|
|
188
|
+
* @returns {Promise<Object[]>}
|
|
189
|
+
*/
|
|
190
|
+
_getRawFFZEmoteSet(id) {
|
|
191
|
+
const endpoint = Constants.FFZ.Set(id); // eslint-disable-line new-cap
|
|
192
|
+
|
|
193
|
+
return axios.get(endpoint).then(req => {
|
|
194
|
+
return req.data.set.emoticons;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Gets the raw FFZ emotes data for a channel.
|
|
200
|
+
* @private
|
|
201
|
+
* @param {int} id - ID of the channel.
|
|
202
|
+
* @returns {Promise<Object[]>}
|
|
203
|
+
*/
|
|
204
|
+
_getRawFFZEmotes(id) {
|
|
205
|
+
const endpoint = Constants.FFZ.Channel(id); // eslint-disable-line new-cap
|
|
206
|
+
|
|
207
|
+
return axios.get(endpoint).then(req => {
|
|
208
|
+
const emotes = [];
|
|
209
|
+
for (const key of Object.keys(req.data.sets)) {
|
|
210
|
+
const set = req.data.sets[key];
|
|
211
|
+
emotes.push(...set.emoticons);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return emotes;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Converts and caches a raw FFZ emote.
|
|
220
|
+
* @private
|
|
221
|
+
* @param {int} channel_id - ID of the channel.
|
|
222
|
+
* @param {Object} data - Raw data.
|
|
223
|
+
* @returns {FFZEmote}
|
|
224
|
+
*/
|
|
225
|
+
_cacheFFZEmote(channel_id, data) {
|
|
226
|
+
let channel = this.channels.get(channel_id);
|
|
227
|
+
if (!channel) {
|
|
228
|
+
channel = new Channel(this, channel_id);
|
|
229
|
+
this.channels.set(channel_id, channel);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const emote = new FFZEmote(channel, data.id, data);
|
|
233
|
+
this.emotes.set(emote.code, emote);
|
|
234
|
+
channel.emotes.set(emote.code, emote);
|
|
235
|
+
return emote;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Gets the raw 7TV emotes data for a channel.
|
|
240
|
+
* @private
|
|
241
|
+
* @param {int} [id=null] - ID of the channel.
|
|
242
|
+
* @returns {Promise<Object[]>}
|
|
243
|
+
*/
|
|
244
|
+
_getRawSevenTVEmotes(id) {
|
|
245
|
+
const endpoint = !id
|
|
246
|
+
? Constants.SevenTV.Global
|
|
247
|
+
: Constants.SevenTV.Channel(id); // eslint-disable-line new-cap
|
|
248
|
+
|
|
249
|
+
return axios.get(endpoint).then(req => req.data);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Converts and caches a raw 7TV emote.
|
|
254
|
+
* @private
|
|
255
|
+
* @param {int} channel_id - ID of the channel.
|
|
256
|
+
* @param {Object} data - Raw data.
|
|
257
|
+
* @param {string} format - The type file format to use (webp/avif).
|
|
258
|
+
* @returns {SevenTVEmote}
|
|
259
|
+
*/
|
|
260
|
+
_cacheSevenTVEmote(channel_id, data, format) {
|
|
261
|
+
let channel = this.channels.get(channel_id);
|
|
262
|
+
if (!channel) {
|
|
263
|
+
channel = new Channel(this, channel_id);
|
|
264
|
+
this.channels.set(channel_id, channel);
|
|
265
|
+
}
|
|
266
|
+
channel.format = format;
|
|
267
|
+
|
|
268
|
+
const emote = new SevenTVEmote(channel, data.id, data);
|
|
269
|
+
this.emotes.set(emote.code, emote);
|
|
270
|
+
channel.emotes.set(emote.code, emote);
|
|
271
|
+
return emote;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Fetches the Twitch emotes for a channel.
|
|
276
|
+
* Use `null` for the global emotes channel.
|
|
277
|
+
* @param {int} [channel=null] - ID of the channel.
|
|
278
|
+
* @returns {Promise<Collection<string, TwitchEmote>>}
|
|
279
|
+
*/
|
|
280
|
+
fetchTwitchEmotes(channel = null) {
|
|
281
|
+
return this._getRawTwitchEmotes(channel).then(rawEmotes => {
|
|
282
|
+
for (const emote of rawEmotes) {
|
|
283
|
+
this._cacheTwitchEmote(channel, {
|
|
284
|
+
code: emote.name, id: emote.id, formats: emote.formats
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return this.channels.get(channel).emotes.filter(e => e.type === 'twitch');
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Fetches the BTTV emotes for a channel.
|
|
294
|
+
* Use `null` for the global emotes channel.
|
|
295
|
+
* @param {int} [channel=null] - ID of the channel.
|
|
296
|
+
* @returns {Promise<Collection<string, BTTVEmote>>}
|
|
297
|
+
*/
|
|
298
|
+
fetchBTTVEmotes(channel = null) {
|
|
299
|
+
return this._getRawBTTVEmotes(channel).then(rawEmotes => {
|
|
300
|
+
for (const data of rawEmotes) {
|
|
301
|
+
this._cacheBTTVEmote(channel, data);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return this.channels.get(channel).emotes.filter(e => e.type === 'bttv');
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Fetches the FFZ emotes for a channel.
|
|
310
|
+
* @param {int} [channel=null] - ID of the channel.
|
|
311
|
+
* @returns {Promise<Collection<string, FFZEmote>>}
|
|
312
|
+
*/
|
|
313
|
+
async fetchFFZEmotes(channel) {
|
|
314
|
+
// Fetch modifier emotes at least once
|
|
315
|
+
if (!this.ffzModifiersFetched) {
|
|
316
|
+
this.ffzModifiersFetched = true;
|
|
317
|
+
|
|
318
|
+
await this._getRawFFZEmoteSet(Constants.FFZ.sets.Modifiers).then(rawEmotes => {
|
|
319
|
+
for (const data of rawEmotes) {
|
|
320
|
+
this._cacheFFZEmote(null, data);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// If no channel specified, fetch the Global set
|
|
326
|
+
if (!channel) {
|
|
327
|
+
return this._getRawFFZEmoteSet(Constants.FFZ.sets.Global).then(rawEmotes => {
|
|
328
|
+
for (const data of rawEmotes) {
|
|
329
|
+
this._cacheFFZEmote(channel, data);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return this.channels.get(channel).emotes.filter(e => e.type === 'ffz');
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return this._getRawFFZEmotes(channel).then(rawEmotes => {
|
|
337
|
+
for (const data of rawEmotes) {
|
|
338
|
+
this._cacheFFZEmote(channel, data);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return this.channels.get(channel).emotes.filter(e => e.type === 'ffz');
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Fetches the 7TV emotes for a channel.
|
|
347
|
+
* @param {int} [channel=null] - ID of the channel.
|
|
348
|
+
* @param {('webp'|'avif')} [format='webp'] - The type file format to use (webp/avif).
|
|
349
|
+
* @returns {Promise<Collection<string, SevenTVEmote>>}
|
|
350
|
+
*/
|
|
351
|
+
fetchSevenTVEmotes(channel = null, format = 'webp') {
|
|
352
|
+
return this._getRawSevenTVEmotes(channel).then(rawEmotes => {
|
|
353
|
+
if ('emotes' in rawEmotes) {
|
|
354
|
+
// From an emote set (like "global")
|
|
355
|
+
for (const data of rawEmotes.emotes) {
|
|
356
|
+
this._cacheSevenTVEmote(channel, data.data, format);
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
// From users
|
|
360
|
+
for (const data of rawEmotes.emote_set.emotes) {
|
|
361
|
+
this._cacheSevenTVEmote(channel, data.data, format);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return this.channels.get(channel).emotes.filter(e => e.type === '7tv');
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
module.exports = EmoteFetcher;
|
|
331
371
|
</code></pre>
|
|
332
372
|
</article>
|
|
333
373
|
</section>
|