@mkody/twitch-emoticons 2.4.1 → 2.6.0
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/.jsdoc.json +5 -0
- package/LICENSE +1 -0
- package/README.md +85 -13
- package/docs/BTTVEmote.html +87 -37
- package/docs/Channel.html +165 -42
- package/docs/Collection.html +42 -36
- package/docs/Emote.html +58 -25
- package/docs/EmoteFetcher.html +2694 -2075
- package/docs/EmoteParser.html +39 -20
- package/docs/FFZEmote.html +91 -37
- package/docs/SevenTV.html +1191 -0
- package/docs/SevenTVEmote.html +1318 -0
- package/docs/TwitchEmote.html +85 -37
- package/docs/index.html +201 -133
- package/docs/scripts/collapse.js +19 -0
- package/docs/scripts/commonNav.js +28 -0
- package/docs/scripts/search.js +16 -0
- package/docs/struct_BTTVEmote.js.html +5 -2
- package/docs/struct_Channel.js.html +21 -10
- package/docs/struct_Emote.js.html +6 -3
- package/docs/struct_EmoteFetcher.js.html +168 -109
- package/docs/struct_EmoteParser.js.html +5 -2
- package/docs/struct_FFZEmote.js.html +5 -2
- package/docs/struct_SevenTVEmote.js.html +135 -0
- package/docs/struct_TwitchEmote.js.html +5 -2
- package/docs/styles/jsdoc.css +13 -2
- package/docs/styles/prettify.css +1 -0
- package/docs/util_Collection.js.html +5 -2
- package/package.json +19 -16
- package/src/index.js +4 -3
- package/src/struct/Channel.js +16 -8
- package/src/struct/Emote.js +1 -1
- package/src/struct/EmoteFetcher.js +96 -40
- package/src/struct/SevenTVEmote.js +63 -0
- package/src/util/Constants.js +6 -2
- package/test/index.js +82 -19
- package/typings/index.d.ts +35 -18
- package/typings/test.ts +0 -24
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const Emote = require('./Emote');
|
|
2
|
+
const Constants = require('../util/Constants');
|
|
3
|
+
|
|
4
|
+
/** @extends Emote */
|
|
5
|
+
class SevenTVEmote extends Emote {
|
|
6
|
+
/**
|
|
7
|
+
* A 7TV emote.
|
|
8
|
+
* @param {Channel} channel - Channel this emote belongs to.
|
|
9
|
+
* @param {string} id - ID of the emote.
|
|
10
|
+
* @param {data} data - The raw emote data.
|
|
11
|
+
*/
|
|
12
|
+
constructor(channel, id, data) {
|
|
13
|
+
super(channel, id, data);
|
|
14
|
+
this.type = '7tv';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The channel of this emote's creator.
|
|
19
|
+
* Not guaranteed to contain the emote, or be cached.
|
|
20
|
+
* @readonly
|
|
21
|
+
* @type {?Channel}
|
|
22
|
+
*/
|
|
23
|
+
get owner() {
|
|
24
|
+
return this.fetcher.channels.get(this.ownerName);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_setup(data) {
|
|
28
|
+
super._setup(data);
|
|
29
|
+
this.code = data.name;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The name of the emote creator's channel.
|
|
33
|
+
* @type {string}
|
|
34
|
+
*/
|
|
35
|
+
this.ownerName = data.owner.display_name;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Available image sizes.
|
|
39
|
+
* @type {string[]}
|
|
40
|
+
*/
|
|
41
|
+
this.sizes = data.host.files
|
|
42
|
+
.filter(el => el.format === this.channel.format.toUpperCase())
|
|
43
|
+
.map(el => el.name);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The image type of the emote.
|
|
47
|
+
* @type {string}
|
|
48
|
+
*/
|
|
49
|
+
this.imageType = this.channel.format;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Gets the image link of the emote.
|
|
54
|
+
* @param {number} size - The size of the image.
|
|
55
|
+
* @returns {string}
|
|
56
|
+
*/
|
|
57
|
+
toLink(size = 0) {
|
|
58
|
+
size = this.sizes[size];
|
|
59
|
+
return Constants.SEVENTV.CDN(this.id, size); // eslint-disable-line new-cap
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = SevenTVEmote;
|
package/src/util/Constants.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
Twitch: {
|
|
3
|
-
CDN: (id, size) => `https://static-cdn.jtvnw.net/emoticons/
|
|
3
|
+
CDN: (id, size) => `https://static-cdn.jtvnw.net/emoticons/v2/${id}/default/dark/${size + 1}.0`
|
|
4
4
|
},
|
|
5
5
|
BTTV: {
|
|
6
6
|
Global: 'https://api.betterttv.net/3/cached/emotes/global',
|
|
7
7
|
Channel: id => `https://api.betterttv.net/3/cached/users/twitch/${id}`,
|
|
8
8
|
CDN: (id, size) => `https://cdn.betterttv.net/emote/${id}/${size + 1}x`
|
|
9
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
|
+
},
|
|
10
15
|
FFZ: {
|
|
11
16
|
Channel: id => `https://api.frankerfacez.com/v1/room/id/${id}`,
|
|
12
|
-
ChannelName: name => `https://api.frankerfacez.com/v1/room/${name}`,
|
|
13
17
|
CDN: (id, size) => `https://cdn.frankerfacez.com/emote/${id}/${size}`
|
|
14
18
|
},
|
|
15
19
|
Templates: {
|
package/test/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const { env } = require('process');
|
|
|
5
5
|
const { EmoteFetcher, EmoteParser } = require('../src/index.js');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* If environement variables are set, test Twitch fetching.
|
|
8
|
+
* If environement variables are set, test Twitch fetching and parsing.
|
|
9
9
|
*
|
|
10
10
|
* Tests:
|
|
11
11
|
* - Fetch emotes
|
|
@@ -28,12 +28,12 @@ if (env.TWITCH_ID !== undefined && env.TWITCH_SECRET !== undefined) {
|
|
|
28
28
|
twitchFetcher.fetchTwitchEmotes(56648155)
|
|
29
29
|
]).then(() => {
|
|
30
30
|
const kappa = twitchFetcher.emotes.get('Kappa');
|
|
31
|
-
assert.strictEqual(kappa.toLink(2), 'https://static-cdn.jtvnw.net/emoticons/
|
|
31
|
+
assert.strictEqual(kappa.toLink(2), 'https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/3.0');
|
|
32
32
|
|
|
33
33
|
const text = twitchParser.parse(':CoolCat:\n:tppD:');
|
|
34
34
|
assert.strictEqual(text, [
|
|
35
|
-
'',
|
|
36
|
+
''
|
|
37
37
|
].join('\n'));
|
|
38
38
|
}).then(() => {
|
|
39
39
|
console.log('Twitch emotes test was successful.');
|
|
@@ -61,43 +61,106 @@ try {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
+
* Test BetterTTV fetching and parsing.
|
|
65
|
+
*
|
|
64
66
|
* Tests:
|
|
65
67
|
* - Fetch emotes
|
|
66
68
|
* - BTTV Global
|
|
67
69
|
* - BTTV Channel (twitchplayspokemon)
|
|
68
|
-
* - FFZ via user name (sylux98)
|
|
69
|
-
* - FFZ via user ID (shizuka_natsume)
|
|
70
|
-
*
|
|
71
70
|
* - Parse to Markdown
|
|
72
71
|
* - BTTV Global emote (SourPls)
|
|
73
72
|
* - BTTV Channel emote (tppUrn)
|
|
74
73
|
* - BTTV Shared emote (MODS)
|
|
75
|
-
* - FFZ emote from user name (AWOOO)
|
|
76
|
-
* - FFZ emote from user ID (SanaeSip)
|
|
77
74
|
*/
|
|
78
|
-
const
|
|
79
|
-
const
|
|
75
|
+
const bttvFetcher = new EmoteFetcher();
|
|
76
|
+
const bttvParser = new EmoteParser(bttvFetcher, {
|
|
80
77
|
type: 'markdown',
|
|
81
78
|
match: /:(.+?):/g
|
|
82
79
|
});
|
|
83
80
|
|
|
84
81
|
Promise.all([
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
fetcher.fetchFFZEmotes('sylux98'),
|
|
88
|
-
fetcher.fetchFFZEmotes(13638332)
|
|
82
|
+
bttvFetcher.fetchBTTVEmotes(),
|
|
83
|
+
bttvFetcher.fetchBTTVEmotes(56648155)
|
|
89
84
|
]).then(() => {
|
|
90
|
-
const text =
|
|
85
|
+
const text = bttvParser.parse(':SourPls:\n:tppUrn:\n:MODS:');
|
|
91
86
|
assert.strictEqual(text, [
|
|
92
87
|
'',
|
|
93
88
|
'',
|
|
94
|
-
''
|
|
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 Channel (sylux98)
|
|
105
|
+
* - FFZ Channel (shizuka_natsume)
|
|
106
|
+
* - Parse to Markdown
|
|
107
|
+
* - FFZ emote from user name (AWOOO)
|
|
108
|
+
* - FFZ emote from user ID (SanaeSip)
|
|
109
|
+
*/
|
|
110
|
+
const ffzFetcher = new EmoteFetcher();
|
|
111
|
+
const ffzParser = new EmoteParser(ffzFetcher, {
|
|
112
|
+
type: 'markdown',
|
|
113
|
+
match: /:(.+?):/g
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
Promise.all([
|
|
117
|
+
ffzFetcher.fetchFFZEmotes(21490561),
|
|
118
|
+
ffzFetcher.fetchFFZEmotes(13638332)
|
|
119
|
+
]).then(() => {
|
|
120
|
+
const text = ffzParser.parse(':AWOOO:\n:SanaeSip:');
|
|
121
|
+
assert.strictEqual(text, [
|
|
95
122
|
'',
|
|
96
123
|
''
|
|
97
124
|
].join('\n'));
|
|
98
125
|
}).then(() => {
|
|
99
|
-
console.log('
|
|
126
|
+
console.log('FFZ emotes test was successful.');
|
|
127
|
+
}).catch(err => {
|
|
128
|
+
console.error('FFZ emotes test failed!');
|
|
129
|
+
console.error(err);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Test 7TV fetching and parsing.
|
|
134
|
+
*
|
|
135
|
+
* Tests:
|
|
136
|
+
* - Fetch emotes
|
|
137
|
+
* - 7TV Global (in AVIF format)
|
|
138
|
+
* - 7TV Channel (0kody)
|
|
139
|
+
* - Parse to Markdown
|
|
140
|
+
* - 7TV Global emote (EZ)
|
|
141
|
+
* - 7TV Global emote (Clap)
|
|
142
|
+
* - 7TV Channel emote (modCheck)
|
|
143
|
+
*/
|
|
144
|
+
const sevenFetcher = new EmoteFetcher();
|
|
145
|
+
const sevenParser = new EmoteParser(sevenFetcher, {
|
|
146
|
+
type: 'markdown',
|
|
147
|
+
match: /:(.+?):/g
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
Promise.all([
|
|
151
|
+
sevenFetcher.fetchSevenTVEmotes(null, 'avif'),
|
|
152
|
+
sevenFetcher.fetchSevenTVEmotes(44317909)
|
|
153
|
+
]).then(() => {
|
|
154
|
+
const text = sevenParser.parse(':EZ:\n:Clap:\n:modCheck:');
|
|
155
|
+
assert.strictEqual(text, [
|
|
156
|
+
'',
|
|
157
|
+
'',
|
|
158
|
+
''
|
|
159
|
+
].join('\n'));
|
|
160
|
+
}).then(() => {
|
|
161
|
+
console.log('7TV emotes test was successful.');
|
|
100
162
|
}).catch(err => {
|
|
101
|
-
console.error('
|
|
163
|
+
console.error('7TV emotes test failed!');
|
|
164
|
+
console.error('(Note that they might be different during certain events like Halloween.)');
|
|
102
165
|
console.error(err);
|
|
103
166
|
});
|
package/typings/index.d.ts
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
declare module '@mkody/twitch-emoticons' {
|
|
2
|
-
export class BTTVEmote extends Emote {
|
|
3
|
-
public constructor(channel: Channel, id: string, data: any);
|
|
4
|
-
|
|
5
|
-
public ownerName: string;
|
|
6
|
-
public imageType: string;
|
|
7
|
-
public readonly owner?: Channel;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
2
|
export class Channel {
|
|
11
|
-
public constructor(fetcher: EmoteFetcher,
|
|
3
|
+
public constructor(fetcher: EmoteFetcher, id: number);
|
|
12
4
|
|
|
13
5
|
public fetcher: EmoteFetcher;
|
|
14
|
-
public
|
|
6
|
+
public id: number;
|
|
15
7
|
public emotes: Collection<string, Emote>;
|
|
16
8
|
|
|
17
9
|
public fetchBTTVEmotes(): Promise<Collection<string, BTTVEmote>>;
|
|
18
10
|
public fetchFFZEmotes(): Promise<Collection<string, FFZEmote>>;
|
|
11
|
+
public fetchSevenTVEmotes(): Promise<Collection<string, SevenTVEmote>>;
|
|
19
12
|
}
|
|
20
13
|
|
|
21
14
|
export abstract class Emote {
|
|
@@ -24,10 +17,8 @@ declare module '@mkody/twitch-emoticons' {
|
|
|
24
17
|
public fetcher: EmoteFetcher;
|
|
25
18
|
public channel: Channel;
|
|
26
19
|
public id: string;
|
|
27
|
-
public type: 'twitch' | 'bttv' | 'ffz';
|
|
20
|
+
public type: 'twitch' | 'bttv' | 'ffz' | '7tv';
|
|
28
21
|
public code: string;
|
|
29
|
-
|
|
30
|
-
public toLink(size: number): string;
|
|
31
22
|
}
|
|
32
23
|
|
|
33
24
|
export class EmoteFetcher {
|
|
@@ -38,19 +29,40 @@ declare module '@mkody/twitch-emoticons' {
|
|
|
38
29
|
|
|
39
30
|
public fetchTwitchEmotes(id?: number): Promise<Collection<string, TwitchEmote>>;
|
|
40
31
|
public fetchBTTVEmotes(id?: number): Promise<Collection<string, BTTVEmote>>;
|
|
41
|
-
public fetchFFZEmotes(id: number
|
|
32
|
+
public fetchFFZEmotes(id: number): Promise<Collection<string, FFZEmote>>;
|
|
33
|
+
public fetchSevenTVEmotes(id?: number, format?: 'webp' | 'avif'): Promise<Collection<string, SevenTVEmote>>;
|
|
42
34
|
}
|
|
43
35
|
|
|
44
36
|
export class EmoteParser {
|
|
45
37
|
public constructor(fetcher: EmoteFetcher, options: {
|
|
46
38
|
template?: string,
|
|
47
39
|
type?: string,
|
|
48
|
-
match?: RegExp
|
|
40
|
+
match?: RegExp
|
|
49
41
|
});
|
|
50
42
|
|
|
51
43
|
public parse(text: string, size?: number): string;
|
|
52
44
|
}
|
|
53
45
|
|
|
46
|
+
export class TwitchEmote extends Emote {
|
|
47
|
+
public constructor(channel: Channel, id: string, data: object);
|
|
48
|
+
|
|
49
|
+
public set?: string;
|
|
50
|
+
public imageType: string;
|
|
51
|
+
public readonly owner: Channel;
|
|
52
|
+
|
|
53
|
+
public toLink(size: number): string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class BTTVEmote extends Emote {
|
|
57
|
+
public constructor(channel: Channel, id: string, data: any);
|
|
58
|
+
|
|
59
|
+
public ownerName: string;
|
|
60
|
+
public imageType: string;
|
|
61
|
+
public readonly owner?: Channel;
|
|
62
|
+
|
|
63
|
+
public toLink(size: number): string;
|
|
64
|
+
}
|
|
65
|
+
|
|
54
66
|
export class FFZEmote extends Emote {
|
|
55
67
|
public constructor(channel: Channel, id: string, data: object);
|
|
56
68
|
|
|
@@ -58,14 +70,19 @@ declare module '@mkody/twitch-emoticons' {
|
|
|
58
70
|
public sizes: string[];
|
|
59
71
|
public imageType: string;
|
|
60
72
|
public readonly owner?: Channel;
|
|
73
|
+
|
|
74
|
+
public toLink(size: number): string;
|
|
61
75
|
}
|
|
62
76
|
|
|
63
|
-
export class
|
|
77
|
+
export class SevenTVEmote extends Emote {
|
|
64
78
|
public constructor(channel: Channel, id: string, data: object);
|
|
65
79
|
|
|
66
|
-
public
|
|
80
|
+
public ownerName: string;
|
|
81
|
+
public sizes: string[];
|
|
67
82
|
public imageType: string;
|
|
68
|
-
public readonly owner
|
|
83
|
+
public readonly owner?: Channel;
|
|
84
|
+
|
|
85
|
+
public toLink(size: number): string;
|
|
69
86
|
}
|
|
70
87
|
|
|
71
88
|
export class Collection<K, V> extends Map<K, V> {
|
package/typings/test.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/// <reference path='index.d.ts' />
|
|
2
|
-
|
|
3
|
-
import { EmoteFetcher, EmoteParser, TwitchEmote } from 'twitch-emoticons';
|
|
4
|
-
|
|
5
|
-
const fetcher = new EmoteFetcher();
|
|
6
|
-
const parser = new EmoteParser(fetcher, {
|
|
7
|
-
type: 'markdown',
|
|
8
|
-
match: /:(.+?):/g
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
Promise.all([
|
|
12
|
-
fetcher.fetchTwitchEmotes(),
|
|
13
|
-
fetcher.fetchBTTVEmotes(),
|
|
14
|
-
fetcher.fetchBTTVEmotes('11computer'),
|
|
15
|
-
fetcher.fetchFFZEmotes('sylux98')
|
|
16
|
-
]).then(() => {
|
|
17
|
-
const kappa = fetcher.emotes.get('Kappa');
|
|
18
|
-
if (kappa instanceof TwitchEmote) {
|
|
19
|
-
console.log(kappa.description);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const parsed = parser.parse('Hello world :Kappa:');
|
|
23
|
-
console.log(parsed);
|
|
24
|
-
});
|