@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.
- 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/docs/BTTVEmote.html +1319 -1319
- package/docs/Channel.html +823 -823
- package/docs/Collection.html +797 -797
- package/docs/Emote.html +801 -801
- package/docs/EmoteFetcher.html +2946 -2946
- package/docs/EmoteParser.html +811 -811
- package/docs/FFZEmote.html +1473 -1473
- package/docs/SevenTV.html +1190 -1190
- package/docs/SevenTVEmote.html +1395 -1395
- package/docs/TwitchEmote.html +1315 -1315
- package/docs/index.html +206 -206
- package/docs/struct_BTTVEmote.js.html +132 -132
- package/docs/struct_Channel.js.html +127 -127
- package/docs/struct_Emote.js.html +138 -138
- package/docs/struct_EmoteFetcher.js.html +395 -399
- package/docs/struct_EmoteParser.js.html +153 -153
- package/docs/struct_FFZEmote.js.html +146 -146
- package/docs/struct_SevenTVEmote.js.html +141 -141
- package/docs/struct_TwitchEmote.js.html +130 -130
- package/docs/util_Collection.js.html +150 -150
- package/package.json +57 -57
- package/src/index.js +12 -12
- package/src/struct/BTTVEmote.js +60 -60
- package/src/struct/Channel.js +55 -55
- package/src/struct/Emote.js +66 -66
- package/src/struct/EmoteFetcher.js +323 -327
- package/src/struct/EmoteParser.js +81 -81
- package/src/struct/FFZEmote.js +74 -74
- package/src/struct/SevenTVEmote.js +69 -69
- package/src/struct/TwitchEmote.js +58 -58
- package/src/util/Collection.js +78 -78
- package/src/util/Constants.js +31 -31
- package/test/index.js +174 -174
- package/typings/index.d.ts +98 -98
package/src/util/Collection.js
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An extended Map with utility methods.
|
|
3
|
-
* @class Collection
|
|
4
|
-
*/
|
|
5
|
-
class Collection extends Map {
|
|
6
|
-
/**
|
|
7
|
-
* Finds first matching value by property or function.
|
|
8
|
-
* Same as `Array#find`.
|
|
9
|
-
* @param {string|Function} propOrFunc - Property or function to test.
|
|
10
|
-
* @param {any} [value] - Value to find.
|
|
11
|
-
* @returns {any}
|
|
12
|
-
*/
|
|
13
|
-
find(propOrFunc, value) {
|
|
14
|
-
if (typeof propOrFunc === 'string') {
|
|
15
|
-
if (typeof value === 'undefined') return null;
|
|
16
|
-
for (const item of this.values()) {
|
|
17
|
-
if (item[propOrFunc] === value) return item;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (typeof propOrFunc === 'function') {
|
|
24
|
-
let i = 0;
|
|
25
|
-
for (const item of this.values()) {
|
|
26
|
-
if (propOrFunc(item, i, this)) return item;
|
|
27
|
-
i++;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Filters cache by function.
|
|
38
|
-
* Same as `Array#filter`.
|
|
39
|
-
* @param {Function} func - Function to test.
|
|
40
|
-
* @param {any} [thisArg] - The context for the function.
|
|
41
|
-
* @returns {Collection}
|
|
42
|
-
*/
|
|
43
|
-
filter(func, thisArg) {
|
|
44
|
-
if (thisArg) func = func.bind(thisArg);
|
|
45
|
-
|
|
46
|
-
const results = new this.constructor();
|
|
47
|
-
|
|
48
|
-
let i = 0;
|
|
49
|
-
for (const [key, item] of this) {
|
|
50
|
-
if (func(item, i, this)) results.set(key, item);
|
|
51
|
-
i++;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return results;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Maps cache by function.
|
|
59
|
-
* Same as `Array#map`.
|
|
60
|
-
* @param {Function} func - Function to use.
|
|
61
|
-
* @param {any} [thisArg] - The context for the function.
|
|
62
|
-
* @returns {any[]}
|
|
63
|
-
*/
|
|
64
|
-
map(func, thisArg) {
|
|
65
|
-
if (thisArg) func = func.bind(thisArg);
|
|
66
|
-
|
|
67
|
-
const array = new Array(this.size);
|
|
68
|
-
let i = 0;
|
|
69
|
-
for (const item of this.values()) {
|
|
70
|
-
array[i] = func(item, i, this);
|
|
71
|
-
i++;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return array;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
module.exports = Collection;
|
|
1
|
+
/**
|
|
2
|
+
* An extended Map with utility methods.
|
|
3
|
+
* @class Collection
|
|
4
|
+
*/
|
|
5
|
+
class Collection extends Map {
|
|
6
|
+
/**
|
|
7
|
+
* Finds first matching value by property or function.
|
|
8
|
+
* Same as `Array#find`.
|
|
9
|
+
* @param {string|Function} propOrFunc - Property or function to test.
|
|
10
|
+
* @param {any} [value] - Value to find.
|
|
11
|
+
* @returns {any}
|
|
12
|
+
*/
|
|
13
|
+
find(propOrFunc, value) {
|
|
14
|
+
if (typeof propOrFunc === 'string') {
|
|
15
|
+
if (typeof value === 'undefined') return null;
|
|
16
|
+
for (const item of this.values()) {
|
|
17
|
+
if (item[propOrFunc] === value) return item;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof propOrFunc === 'function') {
|
|
24
|
+
let i = 0;
|
|
25
|
+
for (const item of this.values()) {
|
|
26
|
+
if (propOrFunc(item, i, this)) return item;
|
|
27
|
+
i++;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Filters cache by function.
|
|
38
|
+
* Same as `Array#filter`.
|
|
39
|
+
* @param {Function} func - Function to test.
|
|
40
|
+
* @param {any} [thisArg] - The context for the function.
|
|
41
|
+
* @returns {Collection}
|
|
42
|
+
*/
|
|
43
|
+
filter(func, thisArg) {
|
|
44
|
+
if (thisArg) func = func.bind(thisArg);
|
|
45
|
+
|
|
46
|
+
const results = new this.constructor();
|
|
47
|
+
|
|
48
|
+
let i = 0;
|
|
49
|
+
for (const [key, item] of this) {
|
|
50
|
+
if (func(item, i, this)) results.set(key, item);
|
|
51
|
+
i++;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return results;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Maps cache by function.
|
|
59
|
+
* Same as `Array#map`.
|
|
60
|
+
* @param {Function} func - Function to use.
|
|
61
|
+
* @param {any} [thisArg] - The context for the function.
|
|
62
|
+
* @returns {any[]}
|
|
63
|
+
*/
|
|
64
|
+
map(func, thisArg) {
|
|
65
|
+
if (thisArg) func = func.bind(thisArg);
|
|
66
|
+
|
|
67
|
+
const array = new Array(this.size);
|
|
68
|
+
let i = 0;
|
|
69
|
+
for (const item of this.values()) {
|
|
70
|
+
array[i] = func(item, i, this);
|
|
71
|
+
i++;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return array;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = Collection;
|
package/src/util/Constants.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
Twitch: {
|
|
3
|
-
CDN: (id, size) => `https://static-cdn.jtvnw.net/emoticons/v2/${id}/default/dark/${size + 1}.0`
|
|
4
|
-
},
|
|
5
|
-
BTTV: {
|
|
6
|
-
Global: 'https://api.betterttv.net/3/cached/emotes/global',
|
|
7
|
-
Channel: id => `https://api.betterttv.net/3/cached/users/twitch/${id}`,
|
|
8
|
-
CDN: (id, size) => `https://cdn.betterttv.net/emote/${id}/${size + 1}x.webp`
|
|
9
|
-
},
|
|
10
|
-
SevenTV: {
|
|
11
|
-
Global: 'https://7tv.io/v3/emote-sets/global',
|
|
12
|
-
Channel: id => `https://7tv.io/v3/users/twitch/${id}`,
|
|
13
|
-
CDN: (id, size) => `https://cdn.7tv.app/emote/${id}/${size}`
|
|
14
|
-
},
|
|
15
|
-
FFZ: {
|
|
16
|
-
sets: {
|
|
17
|
-
Global: 3,
|
|
18
|
-
Modifiers: 1532818
|
|
19
|
-
},
|
|
20
|
-
Set: id => `https://api.frankerfacez.com/v1/set/${id}`,
|
|
21
|
-
Channel: id => `https://api.frankerfacez.com/v1/room/id/${id}`,
|
|
22
|
-
CDN: (id, size) => `https://cdn.frankerfacez.com/emote/${id}/${size}`,
|
|
23
|
-
CDNAnimated: (id, size) => `https://cdn.frankerfacez.com/emote/${id}/animated/${size}.webp`
|
|
24
|
-
},
|
|
25
|
-
Templates: {
|
|
26
|
-
html: '<img alt="{name}" title="{name}" class="twitch-emote twitch-emote-{size}" src="{link}">',
|
|
27
|
-
markdown: '',
|
|
28
|
-
bbcode: '[img]{link}[/img]',
|
|
29
|
-
plain: '{link}'
|
|
30
|
-
}
|
|
31
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
Twitch: {
|
|
3
|
+
CDN: (id, size) => `https://static-cdn.jtvnw.net/emoticons/v2/${id}/default/dark/${size + 1}.0`
|
|
4
|
+
},
|
|
5
|
+
BTTV: {
|
|
6
|
+
Global: 'https://api.betterttv.net/3/cached/emotes/global',
|
|
7
|
+
Channel: id => `https://api.betterttv.net/3/cached/users/twitch/${id}`,
|
|
8
|
+
CDN: (id, size) => `https://cdn.betterttv.net/emote/${id}/${size + 1}x.webp`
|
|
9
|
+
},
|
|
10
|
+
SevenTV: {
|
|
11
|
+
Global: 'https://7tv.io/v3/emote-sets/global',
|
|
12
|
+
Channel: id => `https://7tv.io/v3/users/twitch/${id}`,
|
|
13
|
+
CDN: (id, size) => `https://cdn.7tv.app/emote/${id}/${size}`
|
|
14
|
+
},
|
|
15
|
+
FFZ: {
|
|
16
|
+
sets: {
|
|
17
|
+
Global: 3,
|
|
18
|
+
Modifiers: 1532818
|
|
19
|
+
},
|
|
20
|
+
Set: id => `https://api.frankerfacez.com/v1/set/${id}`,
|
|
21
|
+
Channel: id => `https://api.frankerfacez.com/v1/room/id/${id}`,
|
|
22
|
+
CDN: (id, size) => `https://cdn.frankerfacez.com/emote/${id}/${size}`,
|
|
23
|
+
CDNAnimated: (id, size) => `https://cdn.frankerfacez.com/emote/${id}/animated/${size}.webp`
|
|
24
|
+
},
|
|
25
|
+
Templates: {
|
|
26
|
+
html: '<img alt="{name}" title="{name}" class="twitch-emote twitch-emote-{size}" src="{link}">',
|
|
27
|
+
markdown: '',
|
|
28
|
+
bbcode: '[img]{link}[/img]',
|
|
29
|
+
plain: '{link}'
|
|
30
|
+
}
|
|
31
|
+
};
|
package/test/index.js
CHANGED
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
const { env } = require('process');
|
|
5
|
-
const { EmoteFetcher, EmoteParser } = require('../src/index.js');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* If environement variables are set, test Twitch fetching and parsing.
|
|
9
|
-
*
|
|
10
|
-
* Tests:
|
|
11
|
-
* - Fetch emotes
|
|
12
|
-
* - Twitch Global
|
|
13
|
-
* - Twitch Channel (twitchplayspokemon)
|
|
14
|
-
* - Link to Kappa
|
|
15
|
-
* - Parse to Markdown
|
|
16
|
-
* - Twitch Global emote (CoolCat)
|
|
17
|
-
* - Twitch Channel emote (tppD)
|
|
18
|
-
*/
|
|
19
|
-
if (env.TWITCH_ID !== undefined && env.TWITCH_SECRET !== undefined) {
|
|
20
|
-
const twitchFetcher = new EmoteFetcher(env.TWITCH_ID, env.TWITCH_SECRET);
|
|
21
|
-
const twitchParser = new EmoteParser(twitchFetcher, {
|
|
22
|
-
type: 'markdown',
|
|
23
|
-
match: /:(.+?):/g
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
Promise.all([
|
|
27
|
-
twitchFetcher.fetchTwitchEmotes(),
|
|
28
|
-
twitchFetcher.fetchTwitchEmotes(56648155)
|
|
29
|
-
]).then(() => {
|
|
30
|
-
const kappa = twitchFetcher.emotes.get('Kappa');
|
|
31
|
-
assert.strictEqual(kappa.toLink(2), 'https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/3.0');
|
|
32
|
-
|
|
33
|
-
const text = twitchParser.parse(':CoolCat:\n:tppD:');
|
|
34
|
-
assert.strictEqual(text, [
|
|
35
|
-
'',
|
|
36
|
-
''
|
|
37
|
-
].join('\n'));
|
|
38
|
-
}).then(() => {
|
|
39
|
-
console.log('Twitch emotes test was successful.');
|
|
40
|
-
}).catch(err => {
|
|
41
|
-
console.error('Twitch emotes test failed!');
|
|
42
|
-
console.error(err);
|
|
43
|
-
});
|
|
44
|
-
} else {
|
|
45
|
-
console.log('Notice: Twitch client id/secret missing.');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/*
|
|
49
|
-
* Code should throw if we try to fetch Twitch emotes without a Client ID and Secret
|
|
50
|
-
*/
|
|
51
|
-
const twitchFaultyFetcher = new EmoteFetcher();
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
assert.throws(() => {
|
|
55
|
-
twitchFaultyFetcher.fetchTwitchEmotes();
|
|
56
|
-
}, new Error('Client id or client secret not provided.'));
|
|
57
|
-
console.log('Twitch emotes test (without API keys) was successful.');
|
|
58
|
-
} catch (err) {
|
|
59
|
-
console.error('Twitch emotes test (without API keys) failed!');
|
|
60
|
-
console.error(err);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Test BetterTTV fetching and parsing.
|
|
65
|
-
*
|
|
66
|
-
* Tests:
|
|
67
|
-
* - Fetch emotes
|
|
68
|
-
* - BTTV Global
|
|
69
|
-
* - BTTV Channel (twitchplayspokemon)
|
|
70
|
-
* - Parse to Markdown
|
|
71
|
-
* - BTTV Global emote (SourPls)
|
|
72
|
-
* - BTTV Channel emote (tppUrn)
|
|
73
|
-
* - BTTV Shared emote (MODS)
|
|
74
|
-
*/
|
|
75
|
-
const bttvFetcher = new EmoteFetcher();
|
|
76
|
-
const bttvParser = new EmoteParser(bttvFetcher, {
|
|
77
|
-
type: 'markdown',
|
|
78
|
-
match: /:(.+?):/g
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
Promise.all([
|
|
82
|
-
bttvFetcher.fetchBTTVEmotes(),
|
|
83
|
-
bttvFetcher.fetchBTTVEmotes(56648155)
|
|
84
|
-
]).then(() => {
|
|
85
|
-
const text = bttvParser.parse(':SourPls:\n:tppUrn:\n:MODS:');
|
|
86
|
-
assert.strictEqual(text, [
|
|
87
|
-
'',
|
|
88
|
-
'',
|
|
89
|
-
''
|
|
90
|
-
].join('\n'));
|
|
91
|
-
}).then(() => {
|
|
92
|
-
console.log('BTTV emotes test was successful.');
|
|
93
|
-
}).catch(err => {
|
|
94
|
-
console.error('BTTV emotes test failed!');
|
|
95
|
-
console.error(err);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Test FrankerFaceZ fetching and parsing.
|
|
101
|
-
*
|
|
102
|
-
* Tests:
|
|
103
|
-
* - Fetch emotes
|
|
104
|
-
* - FFZ Global
|
|
105
|
-
* - FFZ Channel (0kody)
|
|
106
|
-
* - FFZ Channel (shizuka_natsume)
|
|
107
|
-
* - Parse to Markdown
|
|
108
|
-
* - FFZ Global emote (CatBag)
|
|
109
|
-
* - FFZ Channel emote (5Head)
|
|
110
|
-
* - FFZ Channel animated emote (MikuSway)
|
|
111
|
-
* - FFZ Channel emote (SanaeSip)
|
|
112
|
-
* - FFZ modifier (ffzHyper)
|
|
113
|
-
*/
|
|
114
|
-
const ffzFetcher = new EmoteFetcher();
|
|
115
|
-
const ffzParser = new EmoteParser(ffzFetcher, {
|
|
116
|
-
type: 'markdown',
|
|
117
|
-
match: /:(.+?):/g
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
Promise.all([
|
|
121
|
-
ffzFetcher.fetchFFZEmotes(),
|
|
122
|
-
ffzFetcher.fetchFFZEmotes(44317909),
|
|
123
|
-
ffzFetcher.fetchFFZEmotes(13638332)
|
|
124
|
-
]).then(() => {
|
|
125
|
-
const text = ffzParser.parse(':CatBag:\n:5Head:\n:MikuSway:\n:SanaeSip: :ffzHyper:');
|
|
126
|
-
assert.strictEqual(text, [
|
|
127
|
-
'',
|
|
128
|
-
'',
|
|
129
|
-
'',
|
|
130
|
-
// Note the trailing space as ffZHyper is removed but not the space before
|
|
131
|
-
' '
|
|
132
|
-
].join('\n'));
|
|
133
|
-
}).then(() => {
|
|
134
|
-
console.log('FFZ emotes test was successful.');
|
|
135
|
-
}).catch(err => {
|
|
136
|
-
console.error('FFZ emotes test failed!');
|
|
137
|
-
console.error(err);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Test 7TV fetching and parsing.
|
|
142
|
-
*
|
|
143
|
-
* Tests:
|
|
144
|
-
* - Fetch emotes
|
|
145
|
-
* - 7TV Global (in AVIF format)
|
|
146
|
-
* - 7TV Channel (0kody)
|
|
147
|
-
* - Parse to Markdown
|
|
148
|
-
* - 7TV Global emote (EZ)
|
|
149
|
-
* - 7TV Global emote (Clap)
|
|
150
|
-
* - 7TV Channel emote (modCheck)
|
|
151
|
-
*/
|
|
152
|
-
const sevenFetcher = new EmoteFetcher();
|
|
153
|
-
const sevenParser = new EmoteParser(sevenFetcher, {
|
|
154
|
-
type: 'markdown',
|
|
155
|
-
match: /:(.+?):/g
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
Promise.all([
|
|
159
|
-
sevenFetcher.fetchSevenTVEmotes(null, 'avif'),
|
|
160
|
-
sevenFetcher.fetchSevenTVEmotes(44317909)
|
|
161
|
-
]).then(() => {
|
|
162
|
-
const text = sevenParser.parse(':EZ:\n:Clap:\n:modCheck:');
|
|
163
|
-
assert.strictEqual(text, [
|
|
164
|
-
'',
|
|
165
|
-
'',
|
|
166
|
-
''
|
|
167
|
-
].join('\n'));
|
|
168
|
-
}).then(() => {
|
|
169
|
-
console.log('7TV emotes test was successful.');
|
|
170
|
-
}).catch(err => {
|
|
171
|
-
console.error('7TV emotes test failed!');
|
|
172
|
-
console.error('(Note that they might be different during certain events like Halloween.)');
|
|
173
|
-
console.error(err);
|
|
174
|
-
});
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
const { env } = require('process');
|
|
5
|
+
const { EmoteFetcher, EmoteParser } = require('../src/index.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* If environement variables are set, test Twitch fetching and parsing.
|
|
9
|
+
*
|
|
10
|
+
* Tests:
|
|
11
|
+
* - Fetch emotes
|
|
12
|
+
* - Twitch Global
|
|
13
|
+
* - Twitch Channel (twitchplayspokemon)
|
|
14
|
+
* - Link to Kappa
|
|
15
|
+
* - Parse to Markdown
|
|
16
|
+
* - Twitch Global emote (CoolCat)
|
|
17
|
+
* - Twitch Channel emote (tppD)
|
|
18
|
+
*/
|
|
19
|
+
if (env.TWITCH_ID !== undefined && env.TWITCH_SECRET !== undefined) {
|
|
20
|
+
const twitchFetcher = new EmoteFetcher(env.TWITCH_ID, env.TWITCH_SECRET);
|
|
21
|
+
const twitchParser = new EmoteParser(twitchFetcher, {
|
|
22
|
+
type: 'markdown',
|
|
23
|
+
match: /:(.+?):/g
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
Promise.all([
|
|
27
|
+
twitchFetcher.fetchTwitchEmotes(),
|
|
28
|
+
twitchFetcher.fetchTwitchEmotes(56648155)
|
|
29
|
+
]).then(() => {
|
|
30
|
+
const kappa = twitchFetcher.emotes.get('Kappa');
|
|
31
|
+
assert.strictEqual(kappa.toLink(2), 'https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/3.0');
|
|
32
|
+
|
|
33
|
+
const text = twitchParser.parse(':CoolCat:\n:tppD:');
|
|
34
|
+
assert.strictEqual(text, [
|
|
35
|
+
'',
|
|
36
|
+
''
|
|
37
|
+
].join('\n'));
|
|
38
|
+
}).then(() => {
|
|
39
|
+
console.log('Twitch emotes test was successful.');
|
|
40
|
+
}).catch(err => {
|
|
41
|
+
console.error('Twitch emotes test failed!');
|
|
42
|
+
console.error(err);
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
console.log('Notice: Twitch client id/secret missing.');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* Code should throw if we try to fetch Twitch emotes without a Client ID and Secret
|
|
50
|
+
*/
|
|
51
|
+
const twitchFaultyFetcher = new EmoteFetcher();
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
assert.throws(() => {
|
|
55
|
+
twitchFaultyFetcher.fetchTwitchEmotes();
|
|
56
|
+
}, new Error('Client id or client secret not provided.'));
|
|
57
|
+
console.log('Twitch emotes test (without API keys) was successful.');
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.error('Twitch emotes test (without API keys) failed!');
|
|
60
|
+
console.error(err);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Test BetterTTV fetching and parsing.
|
|
65
|
+
*
|
|
66
|
+
* Tests:
|
|
67
|
+
* - Fetch emotes
|
|
68
|
+
* - BTTV Global
|
|
69
|
+
* - BTTV Channel (twitchplayspokemon)
|
|
70
|
+
* - Parse to Markdown
|
|
71
|
+
* - BTTV Global emote (SourPls)
|
|
72
|
+
* - BTTV Channel emote (tppUrn)
|
|
73
|
+
* - BTTV Shared emote (MODS)
|
|
74
|
+
*/
|
|
75
|
+
const bttvFetcher = new EmoteFetcher();
|
|
76
|
+
const bttvParser = new EmoteParser(bttvFetcher, {
|
|
77
|
+
type: 'markdown',
|
|
78
|
+
match: /:(.+?):/g
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
Promise.all([
|
|
82
|
+
bttvFetcher.fetchBTTVEmotes(),
|
|
83
|
+
bttvFetcher.fetchBTTVEmotes(56648155)
|
|
84
|
+
]).then(() => {
|
|
85
|
+
const text = bttvParser.parse(':SourPls:\n:tppUrn:\n:MODS:');
|
|
86
|
+
assert.strictEqual(text, [
|
|
87
|
+
'',
|
|
88
|
+
'',
|
|
89
|
+
''
|
|
90
|
+
].join('\n'));
|
|
91
|
+
}).then(() => {
|
|
92
|
+
console.log('BTTV emotes test was successful.');
|
|
93
|
+
}).catch(err => {
|
|
94
|
+
console.error('BTTV emotes test failed!');
|
|
95
|
+
console.error(err);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Test FrankerFaceZ fetching and parsing.
|
|
101
|
+
*
|
|
102
|
+
* Tests:
|
|
103
|
+
* - Fetch emotes
|
|
104
|
+
* - FFZ Global
|
|
105
|
+
* - FFZ Channel (0kody)
|
|
106
|
+
* - FFZ Channel (shizuka_natsume)
|
|
107
|
+
* - Parse to Markdown
|
|
108
|
+
* - FFZ Global emote (CatBag)
|
|
109
|
+
* - FFZ Channel emote (5Head)
|
|
110
|
+
* - FFZ Channel animated emote (MikuSway)
|
|
111
|
+
* - FFZ Channel emote (SanaeSip)
|
|
112
|
+
* - FFZ modifier (ffzHyper)
|
|
113
|
+
*/
|
|
114
|
+
const ffzFetcher = new EmoteFetcher();
|
|
115
|
+
const ffzParser = new EmoteParser(ffzFetcher, {
|
|
116
|
+
type: 'markdown',
|
|
117
|
+
match: /:(.+?):/g
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
Promise.all([
|
|
121
|
+
ffzFetcher.fetchFFZEmotes(),
|
|
122
|
+
ffzFetcher.fetchFFZEmotes(44317909),
|
|
123
|
+
ffzFetcher.fetchFFZEmotes(13638332)
|
|
124
|
+
]).then(() => {
|
|
125
|
+
const text = ffzParser.parse(':CatBag:\n:5Head:\n:MikuSway:\n:SanaeSip: :ffzHyper:');
|
|
126
|
+
assert.strictEqual(text, [
|
|
127
|
+
'',
|
|
128
|
+
'',
|
|
129
|
+
'',
|
|
130
|
+
// Note the trailing space as ffZHyper is removed but not the space before
|
|
131
|
+
' '
|
|
132
|
+
].join('\n'));
|
|
133
|
+
}).then(() => {
|
|
134
|
+
console.log('FFZ emotes test was successful.');
|
|
135
|
+
}).catch(err => {
|
|
136
|
+
console.error('FFZ emotes test failed!');
|
|
137
|
+
console.error(err);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Test 7TV fetching and parsing.
|
|
142
|
+
*
|
|
143
|
+
* Tests:
|
|
144
|
+
* - Fetch emotes
|
|
145
|
+
* - 7TV Global (in AVIF format)
|
|
146
|
+
* - 7TV Channel (0kody)
|
|
147
|
+
* - Parse to Markdown
|
|
148
|
+
* - 7TV Global emote (EZ)
|
|
149
|
+
* - 7TV Global emote (Clap)
|
|
150
|
+
* - 7TV Channel emote (modCheck)
|
|
151
|
+
*/
|
|
152
|
+
const sevenFetcher = new EmoteFetcher();
|
|
153
|
+
const sevenParser = new EmoteParser(sevenFetcher, {
|
|
154
|
+
type: 'markdown',
|
|
155
|
+
match: /:(.+?):/g
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
Promise.all([
|
|
159
|
+
sevenFetcher.fetchSevenTVEmotes(null, 'avif'),
|
|
160
|
+
sevenFetcher.fetchSevenTVEmotes(44317909)
|
|
161
|
+
]).then(() => {
|
|
162
|
+
const text = sevenParser.parse(':EZ:\n:Clap:\n:modCheck:');
|
|
163
|
+
assert.strictEqual(text, [
|
|
164
|
+
'',
|
|
165
|
+
'',
|
|
166
|
+
''
|
|
167
|
+
].join('\n'));
|
|
168
|
+
}).then(() => {
|
|
169
|
+
console.log('7TV emotes test was successful.');
|
|
170
|
+
}).catch(err => {
|
|
171
|
+
console.error('7TV emotes test failed!');
|
|
172
|
+
console.error('(Note that they might be different during certain events like Halloween.)');
|
|
173
|
+
console.error(err);
|
|
174
|
+
});
|