streamer-emotes 0.0.2 → 0.0.5

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 (2) hide show
  1. package/dist/index.mjs +26 -15
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -48,14 +48,14 @@ const get7tvEmotes = async (channelLogin, options) => {
48
48
  const channelDataPromise = $fetch(`/users/twitch/${channelId}`, {
49
49
  baseURL: providersURL.sevenTV,
50
50
  method: "GET"
51
- });
51
+ }).catch(() => null);
52
52
  let globalDataPromise;
53
53
  if (globals) globalDataPromise = $fetch("/emote-sets/global", {
54
54
  baseURL: providersURL.sevenTV,
55
55
  method: "GET"
56
56
  });
57
57
  const [channelData, globalData] = await Promise.all([channelDataPromise, globalDataPromise]);
58
- channel.push(...channelData.emote_set.emotes);
58
+ if (channelData) channel.push(...channelData.emote_set.emotes);
59
59
  if (globalData) global.push(...globalData.emotes);
60
60
  const normalizeData = (data) => {
61
61
  if (!data?.length) return [];
@@ -95,14 +95,14 @@ const getBttvEmotes = async (channelLogin, options) => {
95
95
  const channelDataPromise = $fetch(`/cached/users/twitch/${channelId}`, {
96
96
  baseURL: providersURL.bttv,
97
97
  method: "GET"
98
- });
98
+ }).catch(() => null);
99
99
  let globalDataPromise;
100
100
  if (globals) globalDataPromise = $fetch("/cached/emotes/global", {
101
101
  baseURL: providersURL.bttv,
102
102
  method: "GET"
103
103
  });
104
104
  const [channelData, globalData] = await Promise.all([channelDataPromise, globalDataPromise]);
105
- channel.push(...channelData.channelEmotes, ...channelData.sharedEmotes);
105
+ if (channelData) channel.push(...channelData.channelEmotes, ...channelData.sharedEmotes);
106
106
  if (globalData) global.push(...globalData);
107
107
  const normalizeData = (data) => {
108
108
  if (!data?.length) return [];
@@ -149,14 +149,14 @@ const getFfzEmotes = async (channelLogin, options) => {
149
149
  const channelDataPromise = $fetch(`/room/id/${channelId}`, {
150
150
  baseURL: providersURL.ffz,
151
151
  method: "GET"
152
- });
152
+ }).catch(() => null);
153
153
  let globalDataPromise;
154
154
  if (globals) globalDataPromise = $fetch("/set/global", {
155
155
  baseURL: providersURL.ffz,
156
156
  method: "GET"
157
157
  });
158
158
  const [channelData, globalData] = await Promise.all([channelDataPromise, globalDataPromise]);
159
- channel.push(...channelData.sets[channelData.room.set].emoticons);
159
+ if (channelData) channel.push(...channelData.sets[channelData.room.set].emoticons);
160
160
  if (globalData) global.push(...globalData.default_sets.flatMap((setId) => globalData.sets[setId].emoticons));
161
161
  const normalizeData = (data) => {
162
162
  if (!data?.length) return [];
@@ -190,6 +190,7 @@ const getFfzEmotes = async (channelLogin, options) => {
190
190
  const getTwitchEmotes = async (channelLogin, options) => {
191
191
  channelLogin = channelLogin.toLowerCase();
192
192
  const { globals = true } = options ?? {};
193
+ const channelId = await getTwitchIdByLogin(channelLogin);
193
194
  const emotesFields = [
194
195
  "id",
195
196
  "token",
@@ -211,9 +212,19 @@ const getTwitchEmotes = async (channelLogin, options) => {
211
212
  } },
212
213
  fields: [{ emotes: emotesFields }]
213
214
  };
215
+ const localEmotesQuery = {
216
+ operation: "channel",
217
+ variables: { channelId: {
218
+ name: "id",
219
+ value: channelId,
220
+ type: "ID!"
221
+ } },
222
+ fields: [{ localEmoteSets: [{ emotes: emotesFields }] }]
223
+ };
214
224
  const toQuery = [];
215
225
  if (globals) toQuery.push(globalQuery);
216
226
  toQuery.push(channelQuery);
227
+ toQuery.push(localEmotesQuery);
217
228
  const { data } = await $fetch(providersURL.twitch, {
218
229
  method: "POST",
219
230
  headers: {
@@ -229,15 +240,15 @@ const getTwitchEmotes = async (channelLogin, options) => {
229
240
  id: emote.id,
230
241
  images: [
231
242
  {
232
- url: `https://static-cdn.jtvnw.net/emoticons/v1/${emote.id}/1.0`,
243
+ url: `https://static-cdn.jtvnw.net/emoticons/v2/${emote.id}/default/dark/1.0`,
233
244
  version: "1.0"
234
245
  },
235
246
  {
236
- url: `https://static-cdn.jtvnw.net/emoticons/v1/${emote.id}/2.0`,
247
+ url: `https://static-cdn.jtvnw.net/emoticons/v2/${emote.id}/default/dark/2.0`,
237
248
  version: "2.0"
238
249
  },
239
250
  {
240
- url: `https://static-cdn.jtvnw.net/emoticons/v1/${emote.id}/3.0`,
251
+ url: `https://static-cdn.jtvnw.net/emoticons/v2/${emote.id}/default/dark/3.0`,
241
252
  version: "3.0"
242
253
  }
243
254
  ],
@@ -246,7 +257,7 @@ const getTwitchEmotes = async (channelLogin, options) => {
246
257
  }));
247
258
  };
248
259
  return {
249
- channel: normalizeData(data?.subscriptionProduct?.emotes),
260
+ channel: [...normalizeData(data?.channel.localEmoteSets?.[0]?.emotes), ...normalizeData(data?.subscriptionProduct?.emotes)],
250
261
  ...globals && { global: normalizeData(data?.emoteSet?.emotes) }
251
262
  };
252
263
  };
@@ -267,11 +278,11 @@ const getStreamerEmotes = async (channelLogin, options) => {
267
278
  const { bttv, ffz, sevenTV, twitch } = options;
268
279
  const data = {};
269
280
  let bttvPromise, ffzPromise, sevenTvPromise, twitchPromise;
270
- if (bttv || ffz || sevenTV) await getTwitchIdByLogin(channelLogin);
271
- if (bttv) bttvPromise = getBttvEmotes(channelLogin, { globals: typeof bttv === "boolean" ? true : bttv?.globals }).catch(() => null);
272
- if (ffz) ffzPromise = getFfzEmotes(channelLogin, { globals: typeof ffz === "boolean" ? true : ffz?.globals }).catch(() => null);
273
- if (sevenTV) sevenTvPromise = get7tvEmotes(channelLogin, { globals: typeof sevenTV === "boolean" ? true : sevenTV?.globals }).catch(() => null);
274
- if (twitch) twitchPromise = getTwitchEmotes(channelLogin, { globals: typeof twitch === "boolean" ? true : twitch?.globals }).catch(() => null);
281
+ if (bttv || ffz || sevenTV || twitch) await getTwitchIdByLogin(channelLogin);
282
+ if (bttv) bttvPromise = getBttvEmotes(channelLogin, { globals: typeof bttv === "boolean" ? true : bttv?.globals ?? true }).catch(() => null);
283
+ if (ffz) ffzPromise = getFfzEmotes(channelLogin, { globals: typeof ffz === "boolean" ? true : ffz?.globals ?? true }).catch(() => null);
284
+ if (sevenTV) sevenTvPromise = get7tvEmotes(channelLogin, { globals: typeof sevenTV === "boolean" ? true : sevenTV?.globals ?? true }).catch(() => null);
285
+ if (twitch) twitchPromise = getTwitchEmotes(channelLogin, { globals: typeof twitch === "boolean" ? true : twitch?.globals ?? true }).catch(() => null);
275
286
  const [bttvEmotes, ffzEmotes, sevenTvEmotes, twitchEmotes] = await Promise.all([
276
287
  bttvPromise,
277
288
  ffzPromise,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "streamer-emotes",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.5",
5
5
  "description": "A library to get Twitch, BTTV, FFZ and 7TV emotes for a given Twitch channel.",
6
6
  "keywords": [
7
7
  "streamer",