streamer-emotes 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ahmed Rangel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # streamer-emotes
2
+ A library to get Twitch, BTTV, FFZ and 7TV emotes for a given Twitch channel.
3
+
4
+ ## Usage
5
+
6
+ ```js
7
+ import { getStreamerEmotes } from "streamer-emotes";
8
+
9
+ const rubiusEmotes = await getStreamerEmotes("rubius", {
10
+ sevenTV: true, // Get 7TV emotes
11
+ twitch: { globals: false } // Get Twitch emotes but exclude global ones
12
+ });
13
+
14
+ console.log(rubiusEmotes);
15
+
16
+ ```
@@ -0,0 +1,43 @@
1
+ //#region src/types/index.d.ts
2
+ interface StreamerEmotesProps {
3
+ animated: boolean;
4
+ id: string;
5
+ images: {
6
+ url: string;
7
+ version: string;
8
+ }[];
9
+ name: string;
10
+ provider: "7tv" | "bttv" | "ffz" | "twitch";
11
+ }
12
+ interface StreamerEmotesProviderResponse {
13
+ channel: StreamerEmotesProps[];
14
+ global?: StreamerEmotesProps[];
15
+ }
16
+ //#endregion
17
+ //#region src/index.d.ts
18
+ /**
19
+ *
20
+ * @param channelLogin
21
+ * @param options.bttv Get emotes from BetterTTV if `true`. Defaults to `false`.
22
+ * @param options.ffz Get emotes from FrankerFaceZ if `true`. Defaults to `false`.
23
+ * @param options.sevenTV Get emotes from 7TV if `true`. Defaults to `false`.
24
+ * @param options.twitch Get emotes from Twitch if `true`. Defaults to `false`.
25
+ * @param options.globals Include global emotes in the response. Defaults to `true`.
26
+ * @returns
27
+ */
28
+ declare const getStreamerEmotes: (channelLogin: string, options: {
29
+ bttv?: boolean | StreamerEmotesProviderOptions;
30
+ ffz?: boolean | StreamerEmotesProviderOptions;
31
+ sevenTV?: boolean | StreamerEmotesProviderOptions;
32
+ twitch?: boolean | StreamerEmotesProviderOptions;
33
+ }) => Promise<{
34
+ bttv?: StreamerEmotesProviderResponse;
35
+ ffz?: StreamerEmotesProviderResponse;
36
+ sevenTV?: StreamerEmotesProviderResponse;
37
+ twitch?: StreamerEmotesProviderResponse;
38
+ }>;
39
+ interface StreamerEmotesProviderOptions {
40
+ globals: boolean;
41
+ }
42
+ //#endregion
43
+ export { getStreamerEmotes };
package/dist/index.mjs ADDED
@@ -0,0 +1,288 @@
1
+ import { $fetch } from "ofetch";
2
+ import { gqlQuery } from "gql-payload";
3
+ //#region src/utils/helpers.ts
4
+ const providersURL = {
5
+ sevenTV: "https://7tv.io/v3",
6
+ bttv: "https://api.betterttv.net/3",
7
+ ffz: "https://api.frankerfacez.com/v1",
8
+ twitch: "https://gql.twitch.tv/gql"
9
+ };
10
+ let twitchIdMemory = {};
11
+ const getTwitchIdByLogin = async (login) => {
12
+ login = login.toLowerCase();
13
+ if (twitchIdMemory[login]) return twitchIdMemory[login];
14
+ const { data } = await $fetch(providersURL.twitch, {
15
+ method: "POST",
16
+ headers: {
17
+ "Client-ID": "kimne78kx3ncx6brgo4mv6wki5h1ko",
18
+ "Content-Type": "application/json"
19
+ },
20
+ body: gqlQuery({
21
+ operation: "user",
22
+ variables: { login: {
23
+ value: login,
24
+ type: "String!"
25
+ } },
26
+ fields: ["id"]
27
+ })
28
+ });
29
+ const channelId = data?.user?.id;
30
+ if (!channelId) throw new Error(`Twitch channel with login '${login}' not found.`);
31
+ twitchIdMemory[login] = channelId;
32
+ return channelId;
33
+ };
34
+ //#endregion
35
+ //#region src/providers/7tv.ts
36
+ /**
37
+ *
38
+ * @param twitchLogin Twitch channel login.
39
+ * @param {boolean} options.globals Include global Twitch emotes in the response. Defaults to `true`.
40
+ * @returns
41
+ */
42
+ const get7tvEmotes = async (channelLogin, options) => {
43
+ channelLogin = channelLogin.toLowerCase();
44
+ const { globals = true } = options ?? {};
45
+ const channelId = await getTwitchIdByLogin(channelLogin);
46
+ const channel = [];
47
+ const global = [];
48
+ const channelDataPromise = $fetch(`/users/twitch/${channelId}`, {
49
+ baseURL: providersURL.sevenTV,
50
+ method: "GET"
51
+ });
52
+ let globalDataPromise;
53
+ if (globals) globalDataPromise = $fetch("/emote-sets/global", {
54
+ baseURL: providersURL.sevenTV,
55
+ method: "GET"
56
+ });
57
+ const [channelData, globalData] = await Promise.all([channelDataPromise, globalDataPromise]);
58
+ channel.push(...channelData.emote_set.emotes);
59
+ if (globalData) global.push(...globalData.emotes);
60
+ const normalizeData = (data) => {
61
+ if (!data?.length) return [];
62
+ return data.map((emote) => {
63
+ const images = emote.data.host.files.map((file) => ({
64
+ url: `https:${emote.data.host.url}/${file.name}`,
65
+ version: file.name
66
+ }));
67
+ return {
68
+ animated: emote.data?.animated || false,
69
+ id: emote.id,
70
+ images,
71
+ name: emote.name,
72
+ provider: "7tv"
73
+ };
74
+ });
75
+ };
76
+ return {
77
+ channel: normalizeData(channel),
78
+ ...globals && { global: normalizeData(global) }
79
+ };
80
+ };
81
+ //#endregion
82
+ //#region src/providers/bttv.ts
83
+ /**
84
+ *
85
+ * @param twitchLogin Twitch channel login.
86
+ * @param {boolean} options.globals Include global Twitch emotes in the response. Defaults to `true`.
87
+ * @returns
88
+ */
89
+ const getBttvEmotes = async (channelLogin, options) => {
90
+ channelLogin = channelLogin.toLowerCase();
91
+ const { globals = true } = options ?? {};
92
+ const channelId = await getTwitchIdByLogin(channelLogin);
93
+ const channel = [];
94
+ const global = [];
95
+ const channelDataPromise = $fetch(`/cached/users/twitch/${channelId}`, {
96
+ baseURL: providersURL.bttv,
97
+ method: "GET"
98
+ });
99
+ let globalDataPromise;
100
+ if (globals) globalDataPromise = $fetch("/cached/emotes/global", {
101
+ baseURL: providersURL.bttv,
102
+ method: "GET"
103
+ });
104
+ const [channelData, globalData] = await Promise.all([channelDataPromise, globalDataPromise]);
105
+ channel.push(...channelData.channelEmotes, ...channelData.sharedEmotes);
106
+ if (globalData) global.push(...globalData);
107
+ const normalizeData = (data) => {
108
+ if (!data?.length) return [];
109
+ return data.map((emote) => ({
110
+ animated: emote.animated,
111
+ id: emote.id,
112
+ images: [
113
+ {
114
+ url: `https://cdn.betterttv.net/emote/${emote.id}/1x`,
115
+ version: "1x"
116
+ },
117
+ {
118
+ url: `https://cdn.betterttv.net/emote/${emote.id}/2x`,
119
+ version: "2x"
120
+ },
121
+ {
122
+ url: `https://cdn.betterttv.net/emote/${emote.id}/3x`,
123
+ version: "3x"
124
+ }
125
+ ],
126
+ name: emote.code,
127
+ provider: "bttv"
128
+ }));
129
+ };
130
+ return {
131
+ channel: normalizeData(channel),
132
+ ...globals && { global: normalizeData(global) }
133
+ };
134
+ };
135
+ //#endregion
136
+ //#region src/providers/ffz.ts
137
+ /**
138
+ *
139
+ * @param twitchLogin Twitch channel login.
140
+ * @param {boolean} options.globals Include global Twitch emotes in the response. Defaults to `true`.
141
+ * @returns
142
+ */
143
+ const getFfzEmotes = async (channelLogin, options) => {
144
+ channelLogin = channelLogin.toLowerCase();
145
+ const { globals = true } = options ?? {};
146
+ const channelId = await getTwitchIdByLogin(channelLogin);
147
+ const channel = [];
148
+ const global = [];
149
+ const channelDataPromise = $fetch(`/room/id/${channelId}`, {
150
+ baseURL: providersURL.ffz,
151
+ method: "GET"
152
+ });
153
+ let globalDataPromise;
154
+ if (globals) globalDataPromise = $fetch("/set/global", {
155
+ baseURL: providersURL.ffz,
156
+ method: "GET"
157
+ });
158
+ const [channelData, globalData] = await Promise.all([channelDataPromise, globalDataPromise]);
159
+ channel.push(...channelData.sets[channelData.room.set].emoticons);
160
+ if (globalData) global.push(...globalData.default_sets.flatMap((setId) => globalData.sets[setId].emoticons));
161
+ const normalizeData = (data) => {
162
+ if (!data?.length) return [];
163
+ return data.map((emote) => {
164
+ const images = Object.keys(emote.urls).map((key) => ({
165
+ url: emote.urls[key],
166
+ version: key
167
+ }));
168
+ return {
169
+ animated: false,
170
+ id: emote.id,
171
+ images,
172
+ name: emote.name,
173
+ provider: "ffz"
174
+ };
175
+ });
176
+ };
177
+ return {
178
+ channel: normalizeData(channel),
179
+ ...globals && { global: normalizeData(global) }
180
+ };
181
+ };
182
+ //#endregion
183
+ //#region src/providers/twitch.ts
184
+ /**
185
+ *
186
+ * @param twitchLogin Twitch channel login.
187
+ * @param {boolean} options.globals Include global Twitch emotes in the response. Defaults to `true`.
188
+ * @returns
189
+ */
190
+ const getTwitchEmotes = async (channelLogin, options) => {
191
+ channelLogin = channelLogin.toLowerCase();
192
+ const { globals = true } = options ?? {};
193
+ const emotesFields = [
194
+ "id",
195
+ "token",
196
+ "assetType"
197
+ ];
198
+ const globalQuery = {
199
+ operation: "emoteSet",
200
+ variables: { id: {
201
+ value: "0",
202
+ type: "ID!"
203
+ } },
204
+ fields: [{ emotes: emotesFields }]
205
+ };
206
+ const channelQuery = {
207
+ operation: "subscriptionProduct",
208
+ variables: { productName: {
209
+ value: channelLogin,
210
+ type: "String!"
211
+ } },
212
+ fields: [{ emotes: emotesFields }]
213
+ };
214
+ const toQuery = [];
215
+ if (globals) toQuery.push(globalQuery);
216
+ toQuery.push(channelQuery);
217
+ const { data } = await $fetch(providersURL.twitch, {
218
+ method: "POST",
219
+ headers: {
220
+ "Client-ID": "kimne78kx3ncx6brgo4mv6wki5h1ko",
221
+ "Content-Type": "application/json"
222
+ },
223
+ body: gqlQuery(toQuery)
224
+ });
225
+ const normalizeData = (data) => {
226
+ if (!data?.length) return [];
227
+ return data.map((emote) => ({
228
+ animated: emote.assetType === "ANIMATED",
229
+ id: emote.id,
230
+ images: [
231
+ {
232
+ url: `https://static-cdn.jtvnw.net/emoticons/v1/${emote.id}/1.0`,
233
+ version: "1.0"
234
+ },
235
+ {
236
+ url: `https://static-cdn.jtvnw.net/emoticons/v1/${emote.id}/2.0`,
237
+ version: "2.0"
238
+ },
239
+ {
240
+ url: `https://static-cdn.jtvnw.net/emoticons/v1/${emote.id}/3.0`,
241
+ version: "3.0"
242
+ }
243
+ ],
244
+ name: emote.token,
245
+ provider: "twitch"
246
+ }));
247
+ };
248
+ return {
249
+ channel: normalizeData(data?.subscriptionProduct?.emotes),
250
+ ...globals && { global: normalizeData(data?.emoteSet?.emotes) }
251
+ };
252
+ };
253
+ //#endregion
254
+ //#region src/index.ts
255
+ /**
256
+ *
257
+ * @param channelLogin
258
+ * @param options.bttv Get emotes from BetterTTV if `true`. Defaults to `false`.
259
+ * @param options.ffz Get emotes from FrankerFaceZ if `true`. Defaults to `false`.
260
+ * @param options.sevenTV Get emotes from 7TV if `true`. Defaults to `false`.
261
+ * @param options.twitch Get emotes from Twitch if `true`. Defaults to `false`.
262
+ * @param options.globals Include global emotes in the response. Defaults to `true`.
263
+ * @returns
264
+ */
265
+ const getStreamerEmotes = async (channelLogin, options) => {
266
+ if (!Object.keys(options).length) throw new Error("At least one provider must be enabled");
267
+ const { bttv, ffz, sevenTV, twitch } = options;
268
+ const data = {};
269
+ 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 });
272
+ if (ffz) ffzPromise = getFfzEmotes(channelLogin, { globals: typeof ffz === "boolean" ? true : ffz?.globals });
273
+ if (sevenTV) sevenTvPromise = get7tvEmotes(channelLogin, { globals: typeof sevenTV === "boolean" ? true : sevenTV?.globals });
274
+ if (twitch) twitchPromise = getTwitchEmotes(channelLogin, { globals: typeof twitch === "boolean" ? true : twitch?.globals });
275
+ const [bttvEmotes, ffzEmotes, sevenTvEmotes, twitchEmotes] = await Promise.all([
276
+ bttvPromise,
277
+ ffzPromise,
278
+ sevenTvPromise,
279
+ twitchPromise
280
+ ]);
281
+ if (bttv) data.bttv = bttvEmotes;
282
+ if (ffz) data.ffz = ffzEmotes;
283
+ if (sevenTV) data.sevenTV = sevenTvEmotes;
284
+ if (twitch) data.twitch = twitchEmotes;
285
+ return data;
286
+ };
287
+ //#endregion
288
+ export { getStreamerEmotes };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "streamer-emotes",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "description": "A library to get Twitch, BTTV, FFZ and 7TV emotes for a given Twitch channel.",
6
+ "keywords": [
7
+ "streamer",
8
+ "emotes",
9
+ "twitch",
10
+ "bttv",
11
+ "ffz",
12
+ "7tv"
13
+ ],
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/ahmedrangel/streamer-emotes.git"
18
+ },
19
+ "homepage": "https://github.com/ahmedrangel/streamer-emotes",
20
+ "author": {
21
+ "name": "Ahmed Rangel",
22
+ "email": "ahmedrangel@outlook.com",
23
+ "url": "https://ahmedrangel.com"
24
+ },
25
+ "scripts": {
26
+ "build": "obuild",
27
+ "dev": "node playground/index.ts",
28
+ "lint": "eslint",
29
+ "test:types": "tsc --noEmit"
30
+ },
31
+ "main": "./dist/index.mjs",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.mts",
35
+ "default": "./dist/index.mjs"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist"
40
+ ],
41
+ "dependencies": {
42
+ "gql-payload": "^2.1.0",
43
+ "ofetch": "^2.0.0-alpha.3"
44
+ },
45
+ "devDependencies": {
46
+ "@eslint/compat": "^2.0.3",
47
+ "@stylistic/eslint-plugin": "^5.10.0",
48
+ "@types/node": "^25.5.0",
49
+ "@typescript-eslint/eslint-plugin": "^8.57.0",
50
+ "@typescript-eslint/parser": "^8.57.0",
51
+ "changelogen": "^0.6.2",
52
+ "eslint": "^10.0.3",
53
+ "eslint-plugin-import-x": "^4.16.2",
54
+ "obuild": "^0.4.32",
55
+ "typescript": "^5.9.3"
56
+ },
57
+ "packageManager": "pnpm@10.32.1"
58
+ }