@mkody/twitch-emoticons 2.3.0 → 2.4.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 CHANGED
@@ -83,7 +83,6 @@
83
83
  "array-bracket-spacing": "error",
84
84
  "block-spacing": "error",
85
85
  "brace-style": ["error", "1tbs", { "allowSingleLine": true }],
86
- "capitalized-comments": ["error", "always", { "ignoreConsecutiveComments": true }],
87
86
  "comma-dangle": ["error", "never"],
88
87
  "comma-spacing": "error",
89
88
  "comma-style": "error",
@@ -9,7 +9,10 @@ jobs:
9
9
  - uses: actions/checkout@v2
10
10
  - uses: actions/setup-node@v2
11
11
  with:
12
- node-version: 12
12
+ node-version: 16
13
13
  - run: yarn
14
14
  - run: yarn lint
15
15
  - run: yarn test
16
+ env:
17
+ TWITCH_ID: ${{ secrets.TWITCH_ID }}
18
+ TWITCH_SECRET: ${{ secrets.TWITCH_SECRET }}
package/README.md CHANGED
@@ -8,6 +8,12 @@ You can use [this page to quickly grab it](https://s.kdy.ch/twitchid/).
8
8
 
9
9
  _FFZ still supports names, but usage of the ID is recommended._
10
10
 
11
+ ### About this fork's 2.4.0+
12
+ You now need to use the official Twitch API to get emotes. For this you need to provide your client id and client secret.
13
+ To get a client and secret create a Twitch app [here](https://dev.twitch.tv/console/apps/create), it's free.
14
+
15
+ If you are only using BetterTTV and FrankerFaceZ you don't need to provide anything as they are independent from the Twitch API.
16
+
11
17
  ### Install
12
18
  ```sh
13
19
  npm install @mkody/twitch-emoticons
@@ -18,9 +24,12 @@ yarn add @mkody/twitch-emoticons
18
24
  ### Example
19
25
 
20
26
  ```js
21
- const { EmoteFetcher, EmoteParser } = require('twitch-emoticons');
27
+ const { EmoteFetcher, EmoteParser } = require('@mkody/twitch-emoticons');
28
+
29
+ const clientId = '<your client id>';
30
+ const clientSecret = '<your client secret>';
22
31
 
23
- const fetcher = new EmoteFetcher();
32
+ const fetcher = new EmoteFetcher(clientId, clientSecret);
24
33
  const parser = new EmoteParser(fetcher, {
25
34
  type: 'markdown',
26
35
  match: /:(.+?):/g
@@ -45,6 +54,5 @@ fetcher.fetchTwitchEmotes(null).then(() => {
45
54
  - [Changelog](https://github.com/mkody/twitch-emoticons/releases)
46
55
 
47
56
  This library uses the following:
48
- - [Twitch Emotes API](https://twitchemotes.com/apidocs)
49
57
  - [BetterTTV API](https://betterttv.com/)
50
58
  - [FrankerFaceZ API](http://www.frankerfacez.com/developers)
@@ -71,7 +71,7 @@
71
71
 
72
72
  <dt class="tag-source">Source:</dt>
73
73
  <dd class="tag-source"><ul class="dummy"><li>
74
- <a href="struct_BTTVEmote.js.html">struct/BTTVEmote.js</a>, <a href="struct_BTTVEmote.js.html#line12">line 12</a>
74
+ <a href="struct_BTTVEmote.js.html">struct/BTTVEmote.js</a>, <a href="struct_BTTVEmote.js.html#line5">line 5</a>
75
75
  </li></ul></dd>
76
76
 
77
77
 
@@ -1179,7 +1179,7 @@ Will give the emote's name.</p>
1179
1179
  <br class="clear">
1180
1180
 
1181
1181
  <footer>
1182
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1182
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1183
1183
  </footer>
1184
1184
 
1185
1185
  <script>prettyPrint();</script>
package/docs/Channel.html CHANGED
@@ -688,7 +688,7 @@ For the global channel, the name will be null.</p>
688
688
  <br class="clear">
689
689
 
690
690
  <footer>
691
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
691
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
692
692
  </footer>
693
693
 
694
694
  <script>prettyPrint();</script>
@@ -779,7 +779,7 @@ Same as <code>Array#map</code>.</p>
779
779
  <br class="clear">
780
780
 
781
781
  <footer>
782
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
782
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
783
783
  </footer>
784
784
 
785
785
  <script>prettyPrint();</script>
package/docs/Emote.html CHANGED
@@ -756,7 +756,7 @@ Will give the emote's name.</p>
756
756
  <br class="clear">
757
757
 
758
758
  <footer>
759
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
759
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
760
760
  </footer>
761
761
 
762
762
  <script>prettyPrint();</script>
@@ -59,7 +59,7 @@
59
59
 
60
60
 
61
61
 
62
- <h4 class="name" id="EmoteFetcher"><span class="type-signature"></span>new EmoteFetcher<span class="signature">()</span><span class="type-signature"></span></h4>
62
+ <h4 class="name" id="EmoteFetcher"><span class="type-signature"></span>new EmoteFetcher<span class="signature">(clientId, clientSecret)</span><span class="type-signature"></span></h4>
63
63
 
64
64
 
65
65
 
@@ -71,7 +71,7 @@
71
71
 
72
72
  <dt class="tag-source">Source:</dt>
73
73
  <dd class="tag-source"><ul class="dummy"><li>
74
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line17">line 17</a>
74
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line21">line 21</a>
75
75
  </li></ul></dd>
76
76
 
77
77
 
@@ -124,6 +124,78 @@
124
124
 
125
125
 
126
126
 
127
+ <h5>Parameters:</h5>
128
+
129
+
130
+ <table class="params">
131
+ <thead>
132
+ <tr>
133
+
134
+ <th>Name</th>
135
+
136
+
137
+ <th>Type</th>
138
+
139
+
140
+
141
+
142
+
143
+ <th class="last">Description</th>
144
+ </tr>
145
+ </thead>
146
+
147
+ <tbody>
148
+
149
+
150
+ <tr>
151
+
152
+ <td class="name"><code>clientId</code></td>
153
+
154
+
155
+ <td class="type">
156
+
157
+
158
+ <span class="param-type">string</span>
159
+
160
+
161
+
162
+ </td>
163
+
164
+
165
+
166
+
167
+
168
+ <td class="description last"><p>The client id for the twitch api.</p></td>
169
+ </tr>
170
+
171
+
172
+
173
+ <tr>
174
+
175
+ <td class="name"><code>clientSecret</code></td>
176
+
177
+
178
+ <td class="type">
179
+
180
+
181
+ <span class="param-type">string</span>
182
+
183
+
184
+
185
+ </td>
186
+
187
+
188
+
189
+
190
+
191
+ <td class="description last"><p>The client secret for the twitch api.</p></td>
192
+ </tr>
193
+
194
+
195
+ </tbody>
196
+ </table>
197
+
198
+
127
199
 
128
200
 
129
201
 
@@ -162,6 +234,69 @@
162
234
 
163
235
 
164
236
 
237
+ <h4 class="name" id="apiClient"><span class="type-signature"></span>apiClient<span class="type-signature"></span></h4>
238
+
239
+
240
+
241
+
242
+
243
+ <dl class="details">
244
+
245
+
246
+ <dt class="tag-source">Source:</dt>
247
+ <dd class="tag-source"><ul class="dummy"><li>
248
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line28">line 28</a>
249
+ </li></ul></dd>
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+ </dl>
282
+
283
+
284
+
285
+
286
+
287
+ <div class="description usertext">
288
+ <p>Twitch api client.</p>
289
+ </div>
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
165
300
  <h4 class="name" id="channels"><span class="type-signature"></span>channels<span class="type-signature"> :<a href="Collection.html">Collection</a>.&lt;string, <a href="Channel.html">Channel</a>></span></h4>
166
301
 
167
302
 
@@ -173,7 +308,7 @@
173
308
 
174
309
  <dt class="tag-source">Source:</dt>
175
310
  <dd class="tag-source"><ul class="dummy"><li>
176
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line30">line 30</a>
311
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line43">line 43</a>
177
312
  </li></ul></dd>
178
313
 
179
314
 
@@ -247,7 +382,7 @@ Collectionped by name to Channel instance.</p>
247
382
 
248
383
  <dt class="tag-source">Source:</dt>
249
384
  <dd class="tag-source"><ul class="dummy"><li>
250
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line23">line 23</a>
385
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line36">line 36</a>
251
386
  </li></ul></dd>
252
387
 
253
388
 
@@ -321,7 +456,7 @@ Collectionped by emote code to Emote instance.</p>
321
456
 
322
457
  <dt class="tag-source">Source:</dt>
323
458
  <dd class="tag-source"><ul class="dummy"><li>
324
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line38">line 38</a>
459
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line51">line 51</a>
325
460
  </li></ul></dd>
326
461
 
327
462
 
@@ -404,7 +539,7 @@ Collectionped by emote code to Emote instance.</p>
404
539
 
405
540
  <dt class="tag-source">Source:</dt>
406
541
  <dd class="tag-source"><ul class="dummy"><li>
407
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line103">line 103</a>
542
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line120">line 120</a>
408
543
  </li></ul></dd>
409
544
 
410
545
 
@@ -581,7 +716,7 @@ Collectionped by emote code to Emote instance.</p>
581
716
 
582
717
  <dt class="tag-source">Source:</dt>
583
718
  <dd class="tag-source"><ul class="dummy"><li>
584
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line149">line 149</a>
719
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line166">line 166</a>
585
720
  </li></ul></dd>
586
721
 
587
722
 
@@ -758,7 +893,7 @@ Collectionped by emote code to Emote instance.</p>
758
893
 
759
894
  <dt class="tag-source">Source:</dt>
760
895
  <dd class="tag-source"><ul class="dummy"><li>
761
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line63">line 63</a>
896
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line80">line 80</a>
762
897
  </li></ul></dd>
763
898
 
764
899
 
@@ -935,7 +1070,7 @@ Collectionped by emote code to Emote instance.</p>
935
1070
 
936
1071
  <dt class="tag-source">Source:</dt>
937
1072
  <dd class="tag-source"><ul class="dummy"><li>
938
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line83">line 83</a>
1073
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line100">line 100</a>
939
1074
  </li></ul></dd>
940
1075
 
941
1076
 
@@ -1110,7 +1245,7 @@ Use <code>null</code> for the global emotes channel.</p>
1110
1245
 
1111
1246
  <dt class="tag-source">Source:</dt>
1112
1247
  <dd class="tag-source"><ul class="dummy"><li>
1113
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line122">line 122</a>
1248
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line139">line 139</a>
1114
1249
  </li></ul></dd>
1115
1250
 
1116
1251
 
@@ -1267,7 +1402,7 @@ Use <code>null</code> for the global emotes channel.</p>
1267
1402
 
1268
1403
  <dt class="tag-source">Source:</dt>
1269
1404
  <dd class="tag-source"><ul class="dummy"><li>
1270
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line48">line 48</a>
1405
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line61">line 61</a>
1271
1406
  </li></ul></dd>
1272
1407
 
1273
1408
 
@@ -1421,7 +1556,7 @@ Use <code>null</code> for the global emotes channel.</p>
1421
1556
 
1422
1557
  <dt class="tag-source">Source:</dt>
1423
1558
  <dd class="tag-source"><ul class="dummy"><li>
1424
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line184">line 184</a>
1559
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line201">line 201</a>
1425
1560
  </li></ul></dd>
1426
1561
 
1427
1562
 
@@ -1596,7 +1731,7 @@ Use <code>null</code> for the global emotes channel.</p>
1596
1731
 
1597
1732
  <dt class="tag-source">Source:</dt>
1598
1733
  <dd class="tag-source"><ul class="dummy"><li>
1599
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line199">line 199</a>
1734
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line216">line 216</a>
1600
1735
  </li></ul></dd>
1601
1736
 
1602
1737
 
@@ -1750,7 +1885,7 @@ Use <code>null</code> for the global emotes channel.</p>
1750
1885
 
1751
1886
  <dt class="tag-source">Source:</dt>
1752
1887
  <dd class="tag-source"><ul class="dummy"><li>
1753
- <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line168">line 168</a>
1888
+ <a href="struct_EmoteFetcher.js.html">struct/EmoteFetcher.js</a>, <a href="struct_EmoteFetcher.js.html#line185">line 185</a>
1754
1889
  </li></ul></dd>
1755
1890
 
1756
1891
 
@@ -1928,7 +2063,7 @@ Use <code>null</code> for the global emotes channel.</p>
1928
2063
  <br class="clear">
1929
2064
 
1930
2065
  <footer>
1931
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
2066
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1932
2067
  </footer>
1933
2068
 
1934
2069
  <script>prettyPrint();</script>
@@ -780,7 +780,7 @@ Must be a global regex, with one capture group for the emote code.</p></td>
780
780
  <br class="clear">
781
781
 
782
782
  <footer>
783
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
783
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
784
784
  </footer>
785
785
 
786
786
  <script>prettyPrint();</script>
@@ -71,7 +71,7 @@
71
71
 
72
72
  <dt class="tag-source">Source:</dt>
73
73
  <dd class="tag-source"><ul class="dummy"><li>
74
- <a href="struct_FFZEmote.js.html">struct/FFZEmote.js</a>, <a href="struct_FFZEmote.js.html#line12">line 12</a>
74
+ <a href="struct_FFZEmote.js.html">struct/FFZEmote.js</a>, <a href="struct_FFZEmote.js.html#line5">line 5</a>
75
75
  </li></ul></dd>
76
76
 
77
77
 
@@ -1251,7 +1251,7 @@ Will give the emote's name.</p>
1251
1251
  <br class="clear">
1252
1252
 
1253
1253
  <footer>
1254
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1254
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1255
1255
  </footer>
1256
1256
 
1257
1257
  <script>prettyPrint();</script>
@@ -71,7 +71,7 @@
71
71
 
72
72
  <dt class="tag-source">Source:</dt>
73
73
  <dd class="tag-source"><ul class="dummy"><li>
74
- <a href="struct_TwitchEmote.js.html">struct/TwitchEmote.js</a>, <a href="struct_TwitchEmote.js.html#line12">line 12</a>
74
+ <a href="struct_TwitchEmote.js.html">struct/TwitchEmote.js</a>, <a href="struct_TwitchEmote.js.html#line5">line 5</a>
75
75
  </li></ul></dd>
76
76
 
77
77
 
@@ -1177,7 +1177,7 @@ Will give the emote's name.</p>
1177
1177
  <br class="clear">
1178
1178
 
1179
1179
  <footer>
1180
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1180
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1181
1181
  </footer>
1182
1182
 
1183
1183
  <script>prettyPrint();</script>
package/docs/index.html CHANGED
@@ -59,15 +59,26 @@
59
59
  <section class="readme usertext">
60
60
  <article><h1>twitch-emoticons</h1>
61
61
  <p>Get a Twitch channel's Twitch emotes, BTTV emotes, and FFZ emotes!</p>
62
+ <h3>About this fork's 2.3.0+</h3>
63
+ <p>You must now use a Twitch user ID instead of the username to fetch user's emotes.<br>
64
+ You can use <a href="https://s.kdy.ch/twitchid/">this page to quickly grab it</a>.</p>
65
+ <p><em>FFZ still supports names, but usage of the ID is recommended.</em></p>
66
+ <h3>About this fork's 2.4.0+</h3>
67
+ <p>You now need to use the official Twitch API to get emotes. For this you need to provide your client id and client secret.<br>
68
+ To get a client and secret create a Twitch app <a href="https://dev.twitch.tv/console/apps/create">here</a>, it's free.</p>
69
+ <p>If you are only using BetterTTV and FrankerFaceZ you don't need to provide anything as they are independent from the Twitch API.</p>
62
70
  <h3>Install</h3>
63
71
  <pre class="prettyprint source lang-sh"><code>npm install @mkody/twitch-emoticons
64
72
  # or
65
73
  yarn add @mkody/twitch-emoticons
66
74
  </code></pre>
67
75
  <h3>Example</h3>
68
- <pre class="prettyprint source lang-js"><code>const { EmoteFetcher, EmoteParser } = require('twitch-emoticons');
76
+ <pre class="prettyprint source lang-js"><code>const { EmoteFetcher, EmoteParser } = require('@mkody/twitch-emoticons');
69
77
 
70
- const fetcher = new EmoteFetcher();
78
+ const clientId = '&lt;your client id>';
79
+ const clientSecret = '&lt;your client secret>';
80
+
81
+ const fetcher = new EmoteFetcher(clientId, clientSecret);
71
82
  const parser = new EmoteParser(fetcher, {
72
83
  type: 'markdown',
73
84
  match: /:(.+?):/g
@@ -89,7 +100,6 @@ fetcher.fetchTwitchEmotes(null).then(() => {
89
100
  <li><a href="https://github.com/mkody/twitch-emoticons">Github</a></li>
90
101
  <li><a href="https://mkody.github.io/twitch-emoticons/">Documentation</a></li>
91
102
  <li><a href="https://github.com/mkody/twitch-emoticons/releases">Changelog</a></li>
92
- <li><a href="https://s.kdy.ch/twitchid/">Grab a Twitch user's ID</a></li>
93
103
  </ul>
94
104
  <p>This library uses the following:</p>
95
105
  <ul>
@@ -111,7 +121,7 @@ fetcher.fetchTwitchEmotes(null).then(() => {
111
121
  <br class="clear">
112
122
 
113
123
  <footer>
114
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
124
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
115
125
  </footer>
116
126
 
117
127
  <script>prettyPrint();</script>
@@ -110,7 +110,7 @@ module.exports = BTTVEmote;
110
110
  <br class="clear">
111
111
 
112
112
  <footer>
113
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
113
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
114
114
  </footer>
115
115
 
116
116
  <script>prettyPrint();</script>
@@ -103,7 +103,7 @@ module.exports = Channel;
103
103
  <br class="clear">
104
104
 
105
105
  <footer>
106
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
106
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
107
107
  </footer>
108
108
 
109
109
  <script>prettyPrint();</script>
@@ -121,7 +121,7 @@ module.exports = Emote;
121
121
  <br class="clear">
122
122
 
123
123
  <footer>
124
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
124
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
125
125
  </footer>
126
126
 
127
127
  <script>prettyPrint();</script>
@@ -47,18 +47,31 @@ const Channel = require('./Channel');
47
47
  const Collection = require('../util/Collection');
48
48
  const Constants = require('../util/Constants');
49
49
  const FFZEmote = require('./FFZEmote');
50
- const request = require('request-promise');
50
+ const got = require('got');
51
51
  const TwitchEmote = require('./TwitchEmote');
52
+ const { ApiClient } = require('@twurple/api');
53
+ const { ClientCredentialsAuthProvider } = require('@twurple/auth');
52
54
 
53
55
  const options = {
54
- json: true
56
+ responseType: 'json'
55
57
  };
56
58
 
57
59
  class EmoteFetcher {
58
60
  /**
59
61
  * Fetches and caches emotes.
62
+ * @param {string} clientId The client id for the twitch api.
63
+ * @param {string} clientSecret The client secret for the twitch api.
60
64
  */
61
- constructor() {
65
+ constructor(clientId, clientSecret) {
66
+ if (clientId !== undefined &amp;&amp; clientSecret !== undefined) {
67
+ const authProvider = new ClientCredentialsAuthProvider(clientId, clientSecret);
68
+
69
+ /**
70
+ * Twitch api client.
71
+ */
72
+ this.apiClient = new ApiClient({ authProvider });
73
+ }
74
+
62
75
  /**
63
76
  * Cached emotes.
64
77
  * Collectionped by emote code to Emote instance.
@@ -90,11 +103,15 @@ class EmoteFetcher {
90
103
  * @returns {Promise&lt;Object[]>}
91
104
  */
92
105
  _getRawTwitchEmotes(id) {
93
- const endpoint = !id
94
- ? Constants.Twitch.Global
95
- : Constants.Twitch.Channel(id); // eslint-disable-line new-cap
106
+ if (!this.apiClient) {
107
+ throw new Error('Client id or client secret not provided.');
108
+ }
96
109
 
97
- return request({ uri: endpoint, ...options });
110
+ if (id) {
111
+ return this.apiClient.chat.getChannelEmotes(id);
112
+ } else {
113
+ return this.apiClient.chat.getGlobalEmotes();
114
+ }
98
115
  }
99
116
 
100
117
  /**
@@ -129,11 +146,11 @@ class EmoteFetcher {
129
146
  ? Constants.BTTV.Global
130
147
  : Constants.BTTV.Channel(id); // eslint-disable-line new-cap
131
148
 
132
- return request({ uri: endpoint, ...options }).then(body => {
149
+ return got(endpoint, options).then(req => {
133
150
  // Global emotes
134
- if (body instanceof Array) return body;
151
+ if (req.body instanceof Array) return req.body;
135
152
  // Channel emotes
136
- return [...body.channelEmotes, ...body.sharedEmotes];
153
+ return [...req.body.channelEmotes, ...req.body.sharedEmotes];
137
154
  });
138
155
  }
139
156
 
@@ -172,10 +189,10 @@ class EmoteFetcher {
172
189
  endpoint = Constants.FFZ.ChannelName(id); // eslint-disable-line new-cap
173
190
  }
174
191
 
175
- return request({ uri: endpoint, ...options }).then(body => {
192
+ return got(endpoint, options).then(req => {
176
193
  const emotes = [];
177
- for (const key of Object.keys(body.sets)) {
178
- const set = body.sets[key];
194
+ for (const key of Object.keys(req.body.sets)) {
195
+ const set = req.body.sets[key];
179
196
  emotes.push(...set.emoticons);
180
197
  }
181
198
 
@@ -211,11 +228,11 @@ class EmoteFetcher {
211
228
  */
212
229
  fetchTwitchEmotes(id = null) {
213
230
  return this._getRawTwitchEmotes(id).then(rawEmotes => {
214
- for (const data of rawEmotes.emotes) {
215
- this._cacheTwitchEmote(rawEmotes.channel_name, data);
231
+ for (const emote of rawEmotes) {
232
+ this._cacheTwitchEmote(id, { code: emote.name, id: emote.id });
216
233
  }
217
234
 
218
- return this.channels.get(rawEmotes.channel_name).emotes.filter(e => e.type === 'twitch');
235
+ return this.channels.get(id).emotes.filter(e => e.type === 'twitch');
219
236
  });
220
237
  }
221
238
 
@@ -266,7 +283,7 @@ module.exports = EmoteFetcher;
266
283
  <br class="clear">
267
284
 
268
285
  <footer>
269
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
286
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
270
287
  </footer>
271
288
 
272
289
  <script>prettyPrint();</script>
@@ -136,7 +136,7 @@ module.exports = EmoteParser;
136
136
  <br class="clear">
137
137
 
138
138
  <footer>
139
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
139
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
140
140
  </footer>
141
141
 
142
142
  <script>prettyPrint();</script>
@@ -117,7 +117,7 @@ module.exports = FFZEmote;
117
117
  <br class="clear">
118
118
 
119
119
  <footer>
120
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
120
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
121
121
  </footer>
122
122
 
123
123
  <script>prettyPrint();</script>
@@ -108,7 +108,7 @@ module.exports = TwitchEmote;
108
108
  <br class="clear">
109
109
 
110
110
  <footer>
111
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
111
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
112
112
  </footer>
113
113
 
114
114
  <script>prettyPrint();</script>
@@ -134,7 +134,7 @@ module.exports = Collection;
134
134
  <br class="clear">
135
135
 
136
136
  <footer>
137
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
137
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
138
138
  </footer>
139
139
 
140
140
  <script>prettyPrint();</script>
package/package.json CHANGED
@@ -1,49 +1,51 @@
1
1
  {
2
- "name": "@mkody/twitch-emoticons",
3
- "version": "2.3.0",
4
- "description": "Gets Twitch emotes and BTTV emotes, as well as parsing text to emotes!",
5
- "main": "src/index.js",
6
- "typings": "typings/index.d.ts",
7
- "keywords": [
8
- "emote",
9
- "emoticon",
10
- "emoji",
11
- "bttv",
12
- "better",
13
- "twitch",
14
- "tv",
15
- "parse"
16
- ],
17
- "author": "MKody <gh@kdy.ch> (André Fernandes)",
18
- "contrubutors": [
19
- "1Computer",
20
- "MKody"
21
- ],
22
- "license": "MIT",
23
- "dependencies": {
24
- "request": "^2.88.2",
25
- "request-promise": "^4.2.5"
26
- },
27
- "devDependencies": {
28
- "docdash": "^1.2.0",
29
- "eslint": "7.18.0",
30
- "jsdoc": "^3.6.6"
31
- },
32
- "scripts": {
33
- "docs": "jsdoc --configure .jsdoc.json --verbose --package ''",
34
- "test": "node test/index.js",
35
- "lint": "eslint ./src"
36
- },
37
- "repository": {
38
- "type": "git",
39
- "url": "git+https://github.com/mkody/twitch-emoticons.git"
40
- },
41
- "bugs": {
42
- "url": "https://github.com/mkody/twitch-emoticons/issues"
43
- },
44
- "homepage": "https://github.com/mkody/twitch-emoticons",
45
- "directories": {
46
- "doc": "docs",
47
- "test": "test"
48
- }
2
+ "name": "@mkody/twitch-emoticons",
3
+ "version": "2.4.1",
4
+ "description": "Gets Twitch emotes and BTTV emotes, as well as parsing text to emotes!",
5
+ "main": "src/index.js",
6
+ "typings": "typings/index.d.ts",
7
+ "keywords": [
8
+ "emote",
9
+ "emoticon",
10
+ "emoji",
11
+ "bttv",
12
+ "better",
13
+ "twitch",
14
+ "tv",
15
+ "parse"
16
+ ],
17
+ "author": "MKody <gh@kdy.ch> (André Fernandes)",
18
+ "contrubutors": [
19
+ "1Computer",
20
+ "Killusions",
21
+ "MKody"
22
+ ],
23
+ "license": "MIT",
24
+ "dependencies": {
25
+ "@twurple/api": "^5.0.5",
26
+ "@twurple/auth": "^5.0.5",
27
+ "got": "^11.8.2"
28
+ },
29
+ "devDependencies": {
30
+ "docdash": "^1.2.0",
31
+ "eslint": "^8.0.1",
32
+ "jsdoc": "^3.6.7"
33
+ },
34
+ "scripts": {
35
+ "docs": "jsdoc --configure .jsdoc.json --verbose --package ''",
36
+ "test": "node test/index.js",
37
+ "lint": "eslint ./src ./test"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/mkody/twitch-emoticons.git"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/mkody/twitch-emoticons/issues"
45
+ },
46
+ "homepage": "https://github.com/mkody/twitch-emoticons",
47
+ "directories": {
48
+ "doc": "docs",
49
+ "test": "test"
50
+ }
49
51
  }
@@ -3,18 +3,31 @@ const Channel = require('./Channel');
3
3
  const Collection = require('../util/Collection');
4
4
  const Constants = require('../util/Constants');
5
5
  const FFZEmote = require('./FFZEmote');
6
- const request = require('request-promise');
6
+ const got = require('got');
7
7
  const TwitchEmote = require('./TwitchEmote');
8
+ const { ApiClient } = require('@twurple/api');
9
+ const { ClientCredentialsAuthProvider } = require('@twurple/auth');
8
10
 
9
11
  const options = {
10
- json: true
12
+ responseType: 'json'
11
13
  };
12
14
 
13
15
  class EmoteFetcher {
14
16
  /**
15
17
  * Fetches and caches emotes.
18
+ * @param {string} clientId The client id for the twitch api.
19
+ * @param {string} clientSecret The client secret for the twitch api.
16
20
  */
17
- constructor() {
21
+ constructor(clientId, clientSecret) {
22
+ if (clientId !== undefined && clientSecret !== undefined) {
23
+ const authProvider = new ClientCredentialsAuthProvider(clientId, clientSecret);
24
+
25
+ /**
26
+ * Twitch api client.
27
+ */
28
+ this.apiClient = new ApiClient({ authProvider });
29
+ }
30
+
18
31
  /**
19
32
  * Cached emotes.
20
33
  * Collectionped by emote code to Emote instance.
@@ -46,11 +59,15 @@ class EmoteFetcher {
46
59
  * @returns {Promise<Object[]>}
47
60
  */
48
61
  _getRawTwitchEmotes(id) {
49
- const endpoint = !id
50
- ? Constants.Twitch.Global
51
- : Constants.Twitch.Channel(id); // eslint-disable-line new-cap
62
+ if (!this.apiClient) {
63
+ throw new Error('Client id or client secret not provided.');
64
+ }
52
65
 
53
- return request({ uri: endpoint, ...options });
66
+ if (id) {
67
+ return this.apiClient.chat.getChannelEmotes(id);
68
+ } else {
69
+ return this.apiClient.chat.getGlobalEmotes();
70
+ }
54
71
  }
55
72
 
56
73
  /**
@@ -85,11 +102,11 @@ class EmoteFetcher {
85
102
  ? Constants.BTTV.Global
86
103
  : Constants.BTTV.Channel(id); // eslint-disable-line new-cap
87
104
 
88
- return request({ uri: endpoint, ...options }).then(body => {
105
+ return got(endpoint, options).then(req => {
89
106
  // Global emotes
90
- if (body instanceof Array) return body;
107
+ if (req.body instanceof Array) return req.body;
91
108
  // Channel emotes
92
- return [...body.channelEmotes, ...body.sharedEmotes];
109
+ return [...req.body.channelEmotes, ...req.body.sharedEmotes];
93
110
  });
94
111
  }
95
112
 
@@ -128,10 +145,10 @@ class EmoteFetcher {
128
145
  endpoint = Constants.FFZ.ChannelName(id); // eslint-disable-line new-cap
129
146
  }
130
147
 
131
- return request({ uri: endpoint, ...options }).then(body => {
148
+ return got(endpoint, options).then(req => {
132
149
  const emotes = [];
133
- for (const key of Object.keys(body.sets)) {
134
- const set = body.sets[key];
150
+ for (const key of Object.keys(req.body.sets)) {
151
+ const set = req.body.sets[key];
135
152
  emotes.push(...set.emoticons);
136
153
  }
137
154
 
@@ -167,11 +184,11 @@ class EmoteFetcher {
167
184
  */
168
185
  fetchTwitchEmotes(id = null) {
169
186
  return this._getRawTwitchEmotes(id).then(rawEmotes => {
170
- for (const data of rawEmotes.emotes) {
171
- this._cacheTwitchEmote(rawEmotes.channel_name, data);
187
+ for (const emote of rawEmotes) {
188
+ this._cacheTwitchEmote(id, { code: emote.name, id: emote.id });
172
189
  }
173
190
 
174
- return this.channels.get(rawEmotes.channel_name).emotes.filter(e => e.type === 'twitch');
191
+ return this.channels.get(id).emotes.filter(e => e.type === 'twitch');
175
192
  });
176
193
  }
177
194
 
@@ -1,7 +1,5 @@
1
1
  module.exports = {
2
2
  Twitch: {
3
- Global: 'https://api.twitchemotes.com/api/v4/channels/0',
4
- Channel: id => `https://api.twitchemotes.com/api/v4/channels/${id}`,
5
3
  CDN: (id, size) => `https://static-cdn.jtvnw.net/emoticons/v1/${id}/${size + 1}.0`
6
4
  },
7
5
  BTTV: {
package/test/index.js CHANGED
@@ -1,48 +1,103 @@
1
1
  /* eslint-disable no-console */
2
2
 
3
3
  const assert = require('assert');
4
+ const { env } = require('process');
4
5
  const { EmoteFetcher, EmoteParser } = require('../src/index.js');
5
6
 
6
- const fetcher = new EmoteFetcher();
7
- const parser = new EmoteParser(fetcher, {
8
- type: 'markdown',
9
- match: /:(.+?):/g
10
- });
11
-
12
7
  /**
8
+ * If environement variables are set, test Twitch fetching.
9
+ *
13
10
  * Tests:
11
+ * - Fetch emotes
12
+ * - Twitch Global
13
+ * - Twitch Channel (twitchplayspokemon)
14
14
  * - Link to Kappa
15
15
  * - Parse to Markdown
16
- * - Global Twitch emote (CoolCat)
17
- * - User Twitch emote (tppD)
18
- * - Global BTTV emote (SourPls)
19
- * - Channel BTTV emote (tppUrn)
20
- * - Shared BTTV emote (MODS)
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/v1/25/3.0');
32
+
33
+ const text = twitchParser.parse(':CoolCat:\n:tppD:');
34
+ assert.strictEqual(text, [
35
+ '![CoolCat](https://static-cdn.jtvnw.net/emoticons/v1/58127/1.0 "CoolCat")',
36
+ '![tppD](https://static-cdn.jtvnw.net/emoticons/v1/307609315/1.0 "tppD")'
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
+ * Tests:
65
+ * - Fetch emotes
66
+ * - BTTV Global
67
+ * - BTTV Channel (twitchplayspokemon)
68
+ * - FFZ via user name (sylux98)
69
+ * - FFZ via user ID (shizuka_natsume)
70
+ *
71
+ * - Parse to Markdown
72
+ * - BTTV Global emote (SourPls)
73
+ * - BTTV Channel emote (tppUrn)
74
+ * - BTTV Shared emote (MODS)
21
75
  * - FFZ emote from user name (AWOOO)
22
- * - FFZ emote from user ID (AWOOO)
76
+ * - FFZ emote from user ID (SanaeSip)
23
77
  */
78
+ const fetcher = new EmoteFetcher();
79
+ const parser = new EmoteParser(fetcher, {
80
+ type: 'markdown',
81
+ match: /:(.+?):/g
82
+ });
83
+
24
84
  Promise.all([
25
- fetcher.fetchTwitchEmotes(),
26
- fetcher.fetchTwitchEmotes(56648155),
27
85
  fetcher.fetchBTTVEmotes(),
28
86
  fetcher.fetchBTTVEmotes(56648155),
29
87
  fetcher.fetchFFZEmotes('sylux98'),
30
88
  fetcher.fetchFFZEmotes(13638332)
31
89
  ]).then(() => {
32
- const kappa = fetcher.emotes.get('Kappa');
33
- assert.strictEqual(kappa.toLink(2), 'https://static-cdn.jtvnw.net/emoticons/v1/25/3.0');
34
-
35
- const text = parser.parse(':CoolCat:\n:tppD:\n:SourPls:\n:tppUrn:\n:MODS:\n:AWOOO:\n:SanaeSip:');
90
+ const text = parser.parse(':SourPls:\n:tppUrn:\n:MODS:\n:AWOOO:\n:SanaeSip:');
36
91
  assert.strictEqual(text, [
37
- '![CoolCat](https://static-cdn.jtvnw.net/emoticons/v1/58127/1.0 "CoolCat")',
38
- '![tppD](https://static-cdn.jtvnw.net/emoticons/v1/303132934/1.0 "tppD")',
39
92
  '![SourPls](https://cdn.betterttv.net/emote/566ca38765dbbdab32ec0560/1x "SourPls")',
40
93
  '![tppUrn](https://cdn.betterttv.net/emote/5f5f7d5f68d9d86c020e8672/1x "tppUrn")',
41
94
  '![MODS](https://cdn.betterttv.net/emote/5f2c4f9e65fe924464ef6d61/1x "MODS")',
42
95
  '![AWOOO](https://cdn.frankerfacez.com/emote/67/1 "AWOOO")',
43
96
  '![SanaeSip](https://cdn.frankerfacez.com/emote/305078/1 "SanaeSip")'
44
97
  ].join('\n'));
98
+ }).then(() => {
99
+ console.log('BTTV/FFZ emotes test was successful.');
45
100
  }).catch(err => {
46
- console.error('Test failed!');
101
+ console.error('BTTV/FFZ emotes test failed!');
47
102
  console.error(err);
48
103
  });
@@ -31,6 +31,8 @@ declare module '@mkody/twitch-emoticons' {
31
31
  }
32
32
 
33
33
  export class EmoteFetcher {
34
+ public constructor(clientId?: string, clientSecret?: string);
35
+
34
36
  public emotes: Collection<string, Emote>;
35
37
  public channels: Collection<string, Channel>;
36
38