@mkody/twitch-emoticons 2.7.0 → 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.
Files changed (43) hide show
  1. package/.eslintrc.json +143 -143
  2. package/.github/codeql/codeql-config.yml +4 -4
  3. package/.github/workflows/codeql.yml +50 -50
  4. package/.github/workflows/eslint.yml +50 -50
  5. package/.github/workflows/release.yml +22 -0
  6. package/.github/workflows/yarn-test.yml +17 -17
  7. package/.jsdoc.json +39 -39
  8. package/.nvmrc +1 -0
  9. package/LICENSE +22 -22
  10. package/docs/BTTVEmote.html +1319 -1319
  11. package/docs/Channel.html +823 -823
  12. package/docs/Collection.html +797 -797
  13. package/docs/Emote.html +801 -801
  14. package/docs/EmoteFetcher.html +2946 -2946
  15. package/docs/EmoteParser.html +811 -811
  16. package/docs/FFZEmote.html +1473 -1473
  17. package/docs/SevenTV.html +1190 -1190
  18. package/docs/SevenTVEmote.html +1395 -1395
  19. package/docs/TwitchEmote.html +1315 -1315
  20. package/docs/index.html +206 -206
  21. package/docs/struct_BTTVEmote.js.html +132 -132
  22. package/docs/struct_Channel.js.html +127 -127
  23. package/docs/struct_Emote.js.html +138 -138
  24. package/docs/struct_EmoteFetcher.js.html +395 -399
  25. package/docs/struct_EmoteParser.js.html +153 -153
  26. package/docs/struct_FFZEmote.js.html +146 -146
  27. package/docs/struct_SevenTVEmote.js.html +141 -141
  28. package/docs/struct_TwitchEmote.js.html +130 -130
  29. package/docs/util_Collection.js.html +150 -150
  30. package/package.json +57 -57
  31. package/src/index.js +12 -12
  32. package/src/struct/BTTVEmote.js +60 -60
  33. package/src/struct/Channel.js +55 -55
  34. package/src/struct/Emote.js +66 -66
  35. package/src/struct/EmoteFetcher.js +323 -327
  36. package/src/struct/EmoteParser.js +81 -81
  37. package/src/struct/FFZEmote.js +74 -74
  38. package/src/struct/SevenTVEmote.js +69 -69
  39. package/src/struct/TwitchEmote.js +58 -58
  40. package/src/util/Collection.js +78 -78
  41. package/src/util/Constants.js +31 -31
  42. package/test/index.js +174 -174
  43. package/typings/index.d.ts +98 -98
@@ -1,327 +1,323 @@
1
- const BTTVEmote = require('./BTTVEmote');
2
- const Channel = require('./Channel');
3
- const Collection = require('../util/Collection');
4
- const Constants = require('../util/Constants');
5
- const FFZEmote = require('./FFZEmote');
6
- const SevenTVEmote = require('./SevenTVEmote');
7
-
8
- const got = require('got');
9
- const TwitchEmote = require('./TwitchEmote');
10
- const { ApiClient } = require('@twurple/api');
11
- const { AppTokenAuthProvider } = require('@twurple/auth');
12
-
13
- const options = {
14
- responseType: 'json'
15
- };
16
-
17
- class EmoteFetcher {
18
- /**
19
- * Fetches and caches emotes.
20
- * @param {string} clientId The client id for the twitch api.
21
- * @param {string} clientSecret The client secret for the twitch api.
22
- */
23
- constructor(clientId, clientSecret) {
24
- if (clientId !== undefined && clientSecret !== undefined) {
25
- const authProvider = new AppTokenAuthProvider(clientId, clientSecret);
26
-
27
- /**
28
- * Twitch api client.
29
- */
30
- this.apiClient = new ApiClient({ authProvider });
31
- }
32
-
33
- /**
34
- * Cached emotes.
35
- * Collectionped by emote code to Emote instance.
36
- * @type {Collection<string, Emote>}
37
- */
38
- this.emotes = new Collection();
39
-
40
- /**
41
- * Cached channels.
42
- * Collectionped by name to Channel instance.
43
- * @type {Collection<string, Channel>}
44
- */
45
- this.channels = new Collection();
46
-
47
- /**
48
- * Save if we fetched FFZ's modifier emotes once.
49
- * @type {boolean}
50
- */
51
- this.ffzModifiersFetched = false;
52
- }
53
-
54
- /**
55
- * The global channel for Twitch, BTTV and 7TV.
56
- * @readonly
57
- * @type {?Channel}
58
- */
59
- get globalChannel() {
60
- return this.channels.get(null);
61
- }
62
-
63
- /**
64
- * Gets the raw Twitch emotes data for a channel.
65
- * @private
66
- * @param {int} id - ID of the channel.
67
- * @returns {Promise<Object[]>}
68
- */
69
- _getRawTwitchEmotes(id) {
70
- if (!this.apiClient) {
71
- throw new Error('Client id or client secret not provided.');
72
- }
73
-
74
- if (id) {
75
- return this.apiClient.chat.getChannelEmotes(id);
76
- } else {
77
- return this.apiClient.chat.getGlobalEmotes();
78
- }
79
- }
80
-
81
- /**
82
- * Converts and caches a raw twitch emote.
83
- * @private
84
- * @param {int} channel_id - ID of the channel.
85
- * @param {Object} data - Raw data.
86
- * @returns {TwitchEmote}
87
- */
88
- _cacheTwitchEmote(channel_id, data) {
89
- let channel = this.channels.get(channel_id);
90
- if (!channel) {
91
- channel = new Channel(this, channel_id);
92
- this.channels.set(channel_id, channel);
93
- }
94
-
95
- const emote = new TwitchEmote(channel, data.id, data);
96
- this.emotes.set(emote.code, emote);
97
- channel.emotes.set(emote.code, emote);
98
- return emote;
99
- }
100
-
101
- /**
102
- * Gets the raw BTTV emotes data for a channel.
103
- * Use `null` for the global emotes channel.
104
- * @private
105
- * @param {int} [id=null] - ID of the channel.
106
- * @returns {Promise<Object[]>}
107
- */
108
- _getRawBTTVEmotes(id) {
109
- const endpoint = !id
110
- ? Constants.BTTV.Global
111
- : Constants.BTTV.Channel(id); // eslint-disable-line new-cap
112
-
113
- return got(endpoint, options).then(req => {
114
- // Global emotes
115
- if (req.body instanceof Array) return req.body;
116
- // Channel emotes
117
- return [...req.body.channelEmotes, ...req.body.sharedEmotes];
118
- });
119
- }
120
-
121
- /**
122
- * Converts and caches a raw BTTV emote.
123
- * @private
124
- * @param {int} channel_id - ID of the channel.
125
- * @param {Object} data - Raw data.
126
- * @returns {BTTVEmote}
127
- */
128
- _cacheBTTVEmote(channel_id, data) {
129
- let channel = this.channels.get(channel_id);
130
- if (!channel) {
131
- channel = new Channel(this, channel_id);
132
- this.channels.set(channel_id, channel);
133
- }
134
-
135
- const emote = new BTTVEmote(channel, data.id, data);
136
- this.emotes.set(emote.code, emote);
137
- channel.emotes.set(emote.code, emote);
138
- return emote;
139
- }
140
-
141
- /**
142
- * Gets the raw FFZ emote data from a set.
143
- * @private
144
- * @param {int} id - ID of the set.
145
- * @returns {Promise<Object[]>}
146
- */
147
- _getRawFFZEmoteSet(id) {
148
- const endpoint = Constants.FFZ.Set(id); // eslint-disable-line new-cap
149
-
150
- return got(endpoint, options).then(req => {
151
- return req.body.set.emoticons;
152
- });
153
- }
154
-
155
- /**
156
- * Gets the raw FFZ emotes data for a channel.
157
- * @private
158
- * @param {int} id - ID of the channel.
159
- * @returns {Promise<Object[]>}
160
- */
161
- _getRawFFZEmotes(id) {
162
- const endpoint = Constants.FFZ.Channel(id); // eslint-disable-line new-cap
163
-
164
- return got(endpoint, options).then(req => {
165
- const emotes = [];
166
- for (const key of Object.keys(req.body.sets)) {
167
- const set = req.body.sets[key];
168
- emotes.push(...set.emoticons);
169
- }
170
-
171
- return emotes;
172
- });
173
- }
174
-
175
- /**
176
- * Converts and caches a raw FFZ emote.
177
- * @private
178
- * @param {int} channel_id - ID of the channel.
179
- * @param {Object} data - Raw data.
180
- * @returns {FFZEmote}
181
- */
182
- _cacheFFZEmote(channel_id, data) {
183
- let channel = this.channels.get(channel_id);
184
- if (!channel) {
185
- channel = new Channel(this, channel_id);
186
- this.channels.set(channel_id, channel);
187
- }
188
-
189
- const emote = new FFZEmote(channel, data.id, data);
190
- this.emotes.set(emote.code, emote);
191
- channel.emotes.set(emote.code, emote);
192
- return emote;
193
- }
194
-
195
- /**
196
- * Gets the raw 7TV emotes data for a channel.
197
- * @private
198
- * @param {int} [id=null] - ID of the channel.
199
- * @returns {Promise<Object[]>}
200
- */
201
- _getRawSevenTVEmotes(id) {
202
- const endpoint = !id
203
- ? Constants.SevenTV.Global
204
- : Constants.SevenTV.Channel(id); // eslint-disable-line new-cap
205
-
206
- return got(endpoint, options).then(req => req.body);
207
- }
208
-
209
- /**
210
- * Converts and caches a raw 7TV emote.
211
- * @private
212
- * @param {int} channel_id - ID of the channel.
213
- * @param {Object} data - Raw data.
214
- * @param {string} format - The type file format to use (webp/avif).
215
- * @returns {SevenTVEmote}
216
- */
217
- _cacheSevenTVEmote(channel_id, data, format) {
218
- let channel = this.channels.get(channel_id);
219
- if (!channel) {
220
- channel = new Channel(this, channel_id);
221
- this.channels.set(channel_id, channel);
222
- }
223
- channel.format = format;
224
-
225
- const emote = new SevenTVEmote(channel, data.id, data);
226
- this.emotes.set(emote.code, emote);
227
- channel.emotes.set(emote.code, emote);
228
- return emote;
229
- }
230
-
231
- /**
232
- * Fetches the Twitch emotes for a channel.
233
- * Use `null` for the global emotes channel.
234
- * @param {int} [channel=null] - ID of the channel.
235
- * @returns {Promise<Collection<string, TwitchEmote>>}
236
- */
237
- fetchTwitchEmotes(channel = null) {
238
- return this._getRawTwitchEmotes(channel).then(rawEmotes => {
239
- for (const emote of rawEmotes) {
240
- this._cacheTwitchEmote(channel, {
241
- code: emote.name, id: emote.id, formats: emote.formats
242
- });
243
- }
244
-
245
- return this.channels.get(channel).emotes.filter(e => e.type === 'twitch');
246
- });
247
- }
248
-
249
- /**
250
- * Fetches the BTTV emotes for a channel.
251
- * Use `null` for the global emotes channel.
252
- * @param {int} [channel=null] - ID of the channel.
253
- * @returns {Promise<Collection<string, BTTVEmote>>}
254
- */
255
- fetchBTTVEmotes(channel = null) {
256
- return this._getRawBTTVEmotes(channel).then(rawEmotes => {
257
- for (const data of rawEmotes) {
258
- this._cacheBTTVEmote(channel, data);
259
- }
260
-
261
- return this.channels.get(channel).emotes.filter(e => e.type === 'bttv');
262
- });
263
- }
264
-
265
- /**
266
- * Fetches the FFZ emotes for a channel.
267
- * @param {int} [channel=null] - ID of the channel.
268
- * @returns {Promise<Collection<string, FFZEmote>>}
269
- */
270
- async fetchFFZEmotes(channel) {
271
- // Fetch modifier emotes at least once
272
- if (!this.ffzModifiersFetched) {
273
- this.ffzModifiersFetched = true;
274
-
275
- await this._getRawFFZEmoteSet(Constants.FFZ.sets.Modifiers).then(rawEmotes => {
276
- for (const data of rawEmotes) {
277
- this._cacheFFZEmote(null, data);
278
- }
279
- });
280
- }
281
-
282
- // If no channel specified, fetch the Global set
283
- if (!channel) {
284
- return this._getRawFFZEmoteSet(Constants.FFZ.sets.Global).then(rawEmotes => {
285
- for (const data of rawEmotes) {
286
- this._cacheFFZEmote(channel, data);
287
- }
288
-
289
- return this.channels.get(channel).emotes.filter(e => e.type === 'ffz');
290
- });
291
- }
292
-
293
- return this._getRawFFZEmotes(channel).then(rawEmotes => {
294
- for (const data of rawEmotes) {
295
- this._cacheFFZEmote(channel, data);
296
- }
297
-
298
- return this.channels.get(channel).emotes.filter(e => e.type === 'ffz');
299
- });
300
- }
301
-
302
- /**
303
- * Fetches the 7TV emotes for a channel.
304
- * @param {int} [channel=null] - ID of the channel.
305
- * @param {('webp'|'avif')} [format='webp'] - The type file format to use (webp/avif).
306
- * @returns {Promise<Collection<string, SevenTVEmote>>}
307
- */
308
- fetchSevenTVEmotes(channel = null, format = 'webp') {
309
- return this._getRawSevenTVEmotes(channel).then(rawEmotes => {
310
- if ('emotes' in rawEmotes) {
311
- // From an emote set (like "global")
312
- for (const data of rawEmotes.emotes) {
313
- this._cacheSevenTVEmote(channel, data.data, format);
314
- }
315
- } else {
316
- // From users
317
- for (const data of rawEmotes.emote_set.emotes) {
318
- this._cacheSevenTVEmote(channel, data.data, format);
319
- }
320
- }
321
-
322
- return this.channels.get(channel).emotes.filter(e => e.type === '7tv');
323
- });
324
- }
325
- }
326
-
327
- module.exports = EmoteFetcher;
1
+ const BTTVEmote = require('./BTTVEmote');
2
+ const Channel = require('./Channel');
3
+ const Collection = require('../util/Collection');
4
+ const Constants = require('../util/Constants');
5
+ const FFZEmote = require('./FFZEmote');
6
+ const SevenTVEmote = require('./SevenTVEmote');
7
+ const TwitchEmote = require('./TwitchEmote');
8
+
9
+ const axios = require('axios');
10
+ const { ApiClient } = require('@twurple/api');
11
+ const { AppTokenAuthProvider } = require('@twurple/auth');
12
+
13
+ class EmoteFetcher {
14
+ /**
15
+ * Fetches and caches emotes.
16
+ * @param {string} clientId The client id for the twitch api.
17
+ * @param {string} clientSecret The client secret for the twitch api.
18
+ */
19
+ constructor(clientId, clientSecret) {
20
+ if (clientId !== undefined && clientSecret !== undefined) {
21
+ const authProvider = new AppTokenAuthProvider(clientId, clientSecret);
22
+
23
+ /**
24
+ * Twitch api client.
25
+ */
26
+ this.apiClient = new ApiClient({ authProvider });
27
+ }
28
+
29
+ /**
30
+ * Cached emotes.
31
+ * Collectionped by emote code to Emote instance.
32
+ * @type {Collection<string, Emote>}
33
+ */
34
+ this.emotes = new Collection();
35
+
36
+ /**
37
+ * Cached channels.
38
+ * Collectionped by name to Channel instance.
39
+ * @type {Collection<string, Channel>}
40
+ */
41
+ this.channels = new Collection();
42
+
43
+ /**
44
+ * Save if we fetched FFZ's modifier emotes once.
45
+ * @type {boolean}
46
+ */
47
+ this.ffzModifiersFetched = false;
48
+ }
49
+
50
+ /**
51
+ * The global channel for Twitch, BTTV and 7TV.
52
+ * @readonly
53
+ * @type {?Channel}
54
+ */
55
+ get globalChannel() {
56
+ return this.channels.get(null);
57
+ }
58
+
59
+ /**
60
+ * Gets the raw Twitch emotes data for a channel.
61
+ * @private
62
+ * @param {int} id - ID of the channel.
63
+ * @returns {Promise<Object[]>}
64
+ */
65
+ _getRawTwitchEmotes(id) {
66
+ if (!this.apiClient) {
67
+ throw new Error('Client id or client secret not provided.');
68
+ }
69
+
70
+ if (id) {
71
+ return this.apiClient.chat.getChannelEmotes(id);
72
+ } else {
73
+ return this.apiClient.chat.getGlobalEmotes();
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Converts and caches a raw twitch emote.
79
+ * @private
80
+ * @param {int} channel_id - ID of the channel.
81
+ * @param {Object} data - Raw data.
82
+ * @returns {TwitchEmote}
83
+ */
84
+ _cacheTwitchEmote(channel_id, data) {
85
+ let channel = this.channels.get(channel_id);
86
+ if (!channel) {
87
+ channel = new Channel(this, channel_id);
88
+ this.channels.set(channel_id, channel);
89
+ }
90
+
91
+ const emote = new TwitchEmote(channel, data.id, data);
92
+ this.emotes.set(emote.code, emote);
93
+ channel.emotes.set(emote.code, emote);
94
+ return emote;
95
+ }
96
+
97
+ /**
98
+ * Gets the raw BTTV emotes data for a channel.
99
+ * Use `null` for the global emotes channel.
100
+ * @private
101
+ * @param {int} [id=null] - ID of the channel.
102
+ * @returns {Promise<Object[]>}
103
+ */
104
+ _getRawBTTVEmotes(id) {
105
+ const endpoint = !id
106
+ ? Constants.BTTV.Global
107
+ : Constants.BTTV.Channel(id); // eslint-disable-line new-cap
108
+
109
+ return axios.get(endpoint).then(req => {
110
+ // Global emotes
111
+ if (req.data instanceof Array) return req.data;
112
+ // Channel emotes
113
+ return [...req.data.channelEmotes, ...req.data.sharedEmotes];
114
+ });
115
+ }
116
+
117
+ /**
118
+ * Converts and caches a raw BTTV emote.
119
+ * @private
120
+ * @param {int} channel_id - ID of the channel.
121
+ * @param {Object} data - Raw data.
122
+ * @returns {BTTVEmote}
123
+ */
124
+ _cacheBTTVEmote(channel_id, data) {
125
+ let channel = this.channels.get(channel_id);
126
+ if (!channel) {
127
+ channel = new Channel(this, channel_id);
128
+ this.channels.set(channel_id, channel);
129
+ }
130
+
131
+ const emote = new BTTVEmote(channel, data.id, data);
132
+ this.emotes.set(emote.code, emote);
133
+ channel.emotes.set(emote.code, emote);
134
+ return emote;
135
+ }
136
+
137
+ /**
138
+ * Gets the raw FFZ emote data from a set.
139
+ * @private
140
+ * @param {int} id - ID of the set.
141
+ * @returns {Promise<Object[]>}
142
+ */
143
+ _getRawFFZEmoteSet(id) {
144
+ const endpoint = Constants.FFZ.Set(id); // eslint-disable-line new-cap
145
+
146
+ return axios.get(endpoint).then(req => {
147
+ return req.data.set.emoticons;
148
+ });
149
+ }
150
+
151
+ /**
152
+ * Gets the raw FFZ emotes data for a channel.
153
+ * @private
154
+ * @param {int} id - ID of the channel.
155
+ * @returns {Promise<Object[]>}
156
+ */
157
+ _getRawFFZEmotes(id) {
158
+ const endpoint = Constants.FFZ.Channel(id); // eslint-disable-line new-cap
159
+
160
+ return axios.get(endpoint).then(req => {
161
+ const emotes = [];
162
+ for (const key of Object.keys(req.data.sets)) {
163
+ const set = req.data.sets[key];
164
+ emotes.push(...set.emoticons);
165
+ }
166
+
167
+ return emotes;
168
+ });
169
+ }
170
+
171
+ /**
172
+ * Converts and caches a raw FFZ emote.
173
+ * @private
174
+ * @param {int} channel_id - ID of the channel.
175
+ * @param {Object} data - Raw data.
176
+ * @returns {FFZEmote}
177
+ */
178
+ _cacheFFZEmote(channel_id, data) {
179
+ let channel = this.channels.get(channel_id);
180
+ if (!channel) {
181
+ channel = new Channel(this, channel_id);
182
+ this.channels.set(channel_id, channel);
183
+ }
184
+
185
+ const emote = new FFZEmote(channel, data.id, data);
186
+ this.emotes.set(emote.code, emote);
187
+ channel.emotes.set(emote.code, emote);
188
+ return emote;
189
+ }
190
+
191
+ /**
192
+ * Gets the raw 7TV emotes data for a channel.
193
+ * @private
194
+ * @param {int} [id=null] - ID of the channel.
195
+ * @returns {Promise<Object[]>}
196
+ */
197
+ _getRawSevenTVEmotes(id) {
198
+ const endpoint = !id
199
+ ? Constants.SevenTV.Global
200
+ : Constants.SevenTV.Channel(id); // eslint-disable-line new-cap
201
+
202
+ return axios.get(endpoint).then(req => req.data);
203
+ }
204
+
205
+ /**
206
+ * Converts and caches a raw 7TV emote.
207
+ * @private
208
+ * @param {int} channel_id - ID of the channel.
209
+ * @param {Object} data - Raw data.
210
+ * @param {string} format - The type file format to use (webp/avif).
211
+ * @returns {SevenTVEmote}
212
+ */
213
+ _cacheSevenTVEmote(channel_id, data, format) {
214
+ let channel = this.channels.get(channel_id);
215
+ if (!channel) {
216
+ channel = new Channel(this, channel_id);
217
+ this.channels.set(channel_id, channel);
218
+ }
219
+ channel.format = format;
220
+
221
+ const emote = new SevenTVEmote(channel, data.id, data);
222
+ this.emotes.set(emote.code, emote);
223
+ channel.emotes.set(emote.code, emote);
224
+ return emote;
225
+ }
226
+
227
+ /**
228
+ * Fetches the Twitch emotes for a channel.
229
+ * Use `null` for the global emotes channel.
230
+ * @param {int} [channel=null] - ID of the channel.
231
+ * @returns {Promise<Collection<string, TwitchEmote>>}
232
+ */
233
+ fetchTwitchEmotes(channel = null) {
234
+ return this._getRawTwitchEmotes(channel).then(rawEmotes => {
235
+ for (const emote of rawEmotes) {
236
+ this._cacheTwitchEmote(channel, {
237
+ code: emote.name, id: emote.id, formats: emote.formats
238
+ });
239
+ }
240
+
241
+ return this.channels.get(channel).emotes.filter(e => e.type === 'twitch');
242
+ });
243
+ }
244
+
245
+ /**
246
+ * Fetches the BTTV emotes for a channel.
247
+ * Use `null` for the global emotes channel.
248
+ * @param {int} [channel=null] - ID of the channel.
249
+ * @returns {Promise<Collection<string, BTTVEmote>>}
250
+ */
251
+ fetchBTTVEmotes(channel = null) {
252
+ return this._getRawBTTVEmotes(channel).then(rawEmotes => {
253
+ for (const data of rawEmotes) {
254
+ this._cacheBTTVEmote(channel, data);
255
+ }
256
+
257
+ return this.channels.get(channel).emotes.filter(e => e.type === 'bttv');
258
+ });
259
+ }
260
+
261
+ /**
262
+ * Fetches the FFZ emotes for a channel.
263
+ * @param {int} [channel=null] - ID of the channel.
264
+ * @returns {Promise<Collection<string, FFZEmote>>}
265
+ */
266
+ async fetchFFZEmotes(channel) {
267
+ // Fetch modifier emotes at least once
268
+ if (!this.ffzModifiersFetched) {
269
+ this.ffzModifiersFetched = true;
270
+
271
+ await this._getRawFFZEmoteSet(Constants.FFZ.sets.Modifiers).then(rawEmotes => {
272
+ for (const data of rawEmotes) {
273
+ this._cacheFFZEmote(null, data);
274
+ }
275
+ });
276
+ }
277
+
278
+ // If no channel specified, fetch the Global set
279
+ if (!channel) {
280
+ return this._getRawFFZEmoteSet(Constants.FFZ.sets.Global).then(rawEmotes => {
281
+ for (const data of rawEmotes) {
282
+ this._cacheFFZEmote(channel, data);
283
+ }
284
+
285
+ return this.channels.get(channel).emotes.filter(e => e.type === 'ffz');
286
+ });
287
+ }
288
+
289
+ return this._getRawFFZEmotes(channel).then(rawEmotes => {
290
+ for (const data of rawEmotes) {
291
+ this._cacheFFZEmote(channel, data);
292
+ }
293
+
294
+ return this.channels.get(channel).emotes.filter(e => e.type === 'ffz');
295
+ });
296
+ }
297
+
298
+ /**
299
+ * Fetches the 7TV emotes for a channel.
300
+ * @param {int} [channel=null] - ID of the channel.
301
+ * @param {('webp'|'avif')} [format='webp'] - The type file format to use (webp/avif).
302
+ * @returns {Promise<Collection<string, SevenTVEmote>>}
303
+ */
304
+ fetchSevenTVEmotes(channel = null, format = 'webp') {
305
+ return this._getRawSevenTVEmotes(channel).then(rawEmotes => {
306
+ if ('emotes' in rawEmotes) {
307
+ // From an emote set (like "global")
308
+ for (const data of rawEmotes.emotes) {
309
+ this._cacheSevenTVEmote(channel, data.data, format);
310
+ }
311
+ } else {
312
+ // From users
313
+ for (const data of rawEmotes.emote_set.emotes) {
314
+ this._cacheSevenTVEmote(channel, data.data, format);
315
+ }
316
+ }
317
+
318
+ return this.channels.get(channel).emotes.filter(e => e.type === '7tv');
319
+ });
320
+ }
321
+ }
322
+
323
+ module.exports = EmoteFetcher;