@mkody/twitch-emoticons 3.0.0-beta.6 → 3.0.0-beta.7
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/README.md +10 -3
- package/dist/TwitchEmoticons.cjs +6 -1
- package/dist/TwitchEmoticons.esm.min.js +5 -3
- package/dist/TwitchEmoticons.esm.min.js.map +3 -3
- package/dist/TwitchEmoticons.min.js +5 -3
- package/dist/TwitchEmoticons.min.js.map +3 -3
- package/package.json +9 -16
- package/src/struct/EmoteParser.js +3 -0
- package/src/struct/SevenTVEmote.js +2 -2
- package/src/util/Constants.js +2 -0
- package/typings/index.d.cts +2 -0
- package/typings/index.d.ts +2 -0
package/README.md
CHANGED
|
@@ -25,9 +25,11 @@ Gets Twitch, BTTV, FFZ and 7TV emotes as well as parsing text to emotes!
|
|
|
25
25
|
- The defaults for `EmoteParser` changed to use the `html` template, and it does not require `:colons:` by default (using `/([^\s]+)/g` to match non-whitespaces).
|
|
26
26
|
- The default `html` template does not have `twitch-emote-{size}` anymore in its `class` attribute.
|
|
27
27
|
*The `size` is inconsistent between the different sources, so it cannot be reliably used.*
|
|
28
|
+
- The `EmoteParser` now has an `allowNSFW` option, set to `false` by default.
|
|
29
|
+
*This prevents rendering "NSFW" emotes using `EmoteParser.parse()`, which is a flag currently only available to emotes from 7TV when they are flagged "Sexual"/"Twitch disallowed" or they are unlisted.*
|
|
28
30
|
- If you somehow used `EmoteFetcher.globalChannel`, it has now been removed.
|
|
29
31
|
*Directly use `EmoteFetcher.channels.get(null)` instead.*
|
|
30
|
-
- The `EmoteFetcher.fetchSevenTVEmotes()`, `Emote.toLink()`, and `
|
|
32
|
+
- The `EmoteFetcher.fetchSevenTVEmotes()`, `Emote.toLink()`, and `EmoteParser.parse()` methods now have their options as an object.
|
|
31
33
|
- `fetcher.fetchSevenTVEmotes(null, { format: 'avif' })` - The first parameter is still the Twitch user ID (or `null` for global).
|
|
32
34
|
- `emote.toLink({ size: 1, forceStatic: true, themeMode: 'light' })`
|
|
33
35
|
- `parser.parse('Kappa', { size: 2, forceStatic: true, themeMode: 'dark' })` - The first parameter is still the input text.
|
|
@@ -202,7 +204,7 @@ method to… get a link!
|
|
|
202
204
|
> - `.modifier` (boolean, emote effects, should be hidden)
|
|
203
205
|
> - 7TV:
|
|
204
206
|
> - `.zeroWidth` (boolean, can overlay an another emote)
|
|
205
|
-
> - `.nsfw` (boolean, flagged "Sexual"
|
|
207
|
+
> - `.nsfw` (boolean, flagged "Sexual"/"Twitch disallowed" or unlisted)
|
|
206
208
|
|
|
207
209
|
|
|
208
210
|
### Parse strings to include emotes with `EmoteParser`
|
|
@@ -217,6 +219,9 @@ const parser = new EmoteParser(
|
|
|
217
219
|
|
|
218
220
|
// The second parameter is an *optional* object with settings.
|
|
219
221
|
{
|
|
222
|
+
// Allow, or explicitly disallow, rendering emotes we flag as "NSFW" (7TV only)
|
|
223
|
+
allowNSFW, // <boolean> - Default: false
|
|
224
|
+
|
|
220
225
|
// What output should be used when you parse messages? There are two ways to set that up:
|
|
221
226
|
// Option 1: Use one of the provided templates:
|
|
222
227
|
// - 'html': `<img alt="{name}" title="{name}" class="twitch-emote" src="{link}">`
|
|
@@ -337,6 +342,8 @@ const fetcher = new EmoteFetcher({
|
|
|
337
342
|
twitchThemeMode: 'dark',
|
|
338
343
|
})
|
|
339
344
|
const parser = new EmoteParser(fetcher, {
|
|
345
|
+
// Allow NSFW/unlisted emotes from 7TV
|
|
346
|
+
allowNSFW: true,
|
|
340
347
|
// Custom HTML format
|
|
341
348
|
template: `
|
|
342
349
|
<img
|
|
@@ -348,7 +355,7 @@ const parser = new EmoteParser(fetcher, {
|
|
|
348
355
|
data-overlay="{is-zero-width}"
|
|
349
356
|
data-nsfw="{is-nsfw}"
|
|
350
357
|
>`,
|
|
351
|
-
// Matches words (like \w)
|
|
358
|
+
// Matches words (like \w) and dashes
|
|
352
359
|
match: /([a-zA-Z0-9_\-]+)/g,
|
|
353
360
|
})
|
|
354
361
|
|
package/dist/TwitchEmoticons.cjs
CHANGED
|
@@ -118,6 +118,7 @@ var Constants_default = {
|
|
|
118
118
|
name
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
listed
|
|
121
122
|
owner {
|
|
122
123
|
display_name
|
|
123
124
|
}
|
|
@@ -143,6 +144,7 @@ var Constants_default = {
|
|
|
143
144
|
name
|
|
144
145
|
}
|
|
145
146
|
}
|
|
147
|
+
listed
|
|
146
148
|
owner {
|
|
147
149
|
display_name
|
|
148
150
|
}
|
|
@@ -485,7 +487,7 @@ var SevenTVEmote = class _SevenTVEmote extends Emote_default {
|
|
|
485
487
|
this.imageType = this.channel.format;
|
|
486
488
|
this.animated = Boolean(data.data.animated);
|
|
487
489
|
this.zeroWidth = (data.flags & ActiveEmoteFlags.ZeroWidth) !== 0 || (data.data.flags & EmoteFlags.ZeroWidth) !== 0;
|
|
488
|
-
this.nsfw = (data.data.flags & EmoteFlags.Sexual) !== 0 || (data.data.flags & EmoteFlags.TwitchDisallowed) !== 0;
|
|
490
|
+
this.nsfw = (data.data.flags & EmoteFlags.Sexual) !== 0 || (data.data.flags & EmoteFlags.TwitchDisallowed) !== 0 || data.data.listed === false;
|
|
489
491
|
}
|
|
490
492
|
/**
|
|
491
493
|
* Gets the image link of the emote.
|
|
@@ -945,6 +947,7 @@ var EmoteParser = class {
|
|
|
945
947
|
* A parser to replace text with emotes.
|
|
946
948
|
* @param {EmoteFetcher} fetcher - The {@linkcode EmoteFetcher} to use the cache of.
|
|
947
949
|
* @param {object} [options={}] - Options for the parser.
|
|
950
|
+
* @param {boolean} [options.allowNSFW=false] - Only for 7TV: allow usage of NSFW/unlisted emotes.
|
|
948
951
|
* @param {string} [options.template=''] - The template to be used.
|
|
949
952
|
* The strings that can be interpolated are:
|
|
950
953
|
* - `{link}` The link of the emote.
|
|
@@ -960,6 +963,7 @@ var EmoteParser = class {
|
|
|
960
963
|
constructor(fetcher, options = {}) {
|
|
961
964
|
this.fetcher = fetcher;
|
|
962
965
|
this.options = {
|
|
966
|
+
allowNSFW: false,
|
|
963
967
|
template: "",
|
|
964
968
|
type: "html",
|
|
965
969
|
match: /([^\s]+)/g,
|
|
@@ -1016,6 +1020,7 @@ var EmoteParser = class {
|
|
|
1016
1020
|
const emote = this.fetcher.emotes.get(id);
|
|
1017
1021
|
if (!emote) return matched;
|
|
1018
1022
|
if (emote.modifier) return "";
|
|
1023
|
+
if (emote.nsfw && !this.options.allowNSFW) return matched;
|
|
1019
1024
|
const template = this.options.template || Constants_default.Templates[this.options.type];
|
|
1020
1025
|
const link = emote.toLink({ size, forceStatic, themeMode });
|
|
1021
1026
|
const res = template.replaceAll("{link}", link).replaceAll("{name}", emote.code).replaceAll("{size}", size).replaceAll("{creator}", emote.ownerName || "global").replaceAll("{is-animated}", emote.animated ? "true" : "false").replaceAll("{is-zero-width}", emote.zeroWidth ? "true" : "false").replaceAll("{is-nsfw}", emote.nsfw ? "true" : "false");
|