@mkody/twitch-emoticons 2.5.0 → 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.
@@ -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;
@@ -7,9 +7,13 @@ module.exports = {
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
@@ -101,8 +101,8 @@ Promise.all([
101
101
  *
102
102
  * Tests:
103
103
  * - Fetch emotes
104
- * - FFZ via user name (sylux98)
105
- * - FFZ via user ID (shizuka_natsume)
104
+ * - FFZ Channel (sylux98)
105
+ * - FFZ Channel (shizuka_natsume)
106
106
  * - Parse to Markdown
107
107
  * - FFZ emote from user name (AWOOO)
108
108
  * - FFZ emote from user ID (SanaeSip)
@@ -114,7 +114,7 @@ const ffzParser = new EmoteParser(ffzFetcher, {
114
114
  });
115
115
 
116
116
  Promise.all([
117
- ffzFetcher.fetchFFZEmotes('sylux98'),
117
+ ffzFetcher.fetchFFZEmotes(21490561),
118
118
  ffzFetcher.fetchFFZEmotes(13638332)
119
119
  ]).then(() => {
120
120
  const text = ffzParser.parse(':AWOOO:\n:SanaeSip:');
@@ -128,3 +128,39 @@ Promise.all([
128
128
  console.error('FFZ emotes test failed!');
129
129
  console.error(err);
130
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
+ '![EZ](https://cdn.7tv.app/emote/60dd13426ef5a66f4134f804/1x.avif "EZ")',
157
+ '![Clap](https://cdn.7tv.app/emote/603cb71c73d7a5001441f995/1x.avif "Clap")',
158
+ '![modCheck](https://cdn.7tv.app/emote/60abf171870d317bef23d399/1x.webp "modCheck")'
159
+ ].join('\n'));
160
+ }).then(() => {
161
+ console.log('7TV emotes test was successful.');
162
+ }).catch(err => {
163
+ console.error('7TV emotes test failed!');
164
+ console.error('(Note that they might be different during certain events like Halloween.)');
165
+ console.error(err);
166
+ });
@@ -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, name: string);
3
+ public constructor(fetcher: EmoteFetcher, id: number);
12
4
 
13
5
  public fetcher: EmoteFetcher;
14
- public name: string;
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 | string): Promise<Collection<string, FFZEmote>>;
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 TwitchEmote extends Emote {
77
+ export class SevenTVEmote extends Emote {
64
78
  public constructor(channel: Channel, id: string, data: object);
65
79
 
66
- public set?: string;
80
+ public ownerName: string;
81
+ public sizes: string[];
67
82
  public imageType: string;
68
- public readonly owner: Channel;
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
- });