twitch-emoticons
Gets Twitch, BTTV, FFZ and 7TV emotes as well as parsing text to emotes!
Migrating from upstream
You must now use a Twitch user ID instead of the username to fetch user's emotes.
You can use this page to quickly grab it.
To fetch Twitch emotes you need to get a client and secret from Twitch here, it's free.
If you are only using BetterTTV, FrankerFaceZ and 7TV you don't need to provide Twitch app keys as they are independent from the Twitch API.
Install
npm install @mkody/twitch-emoticons
yarn add @mkody/twitch-emoticons
Examples
Basic Twitch emote parsing
import TwitchEmoticons from '@mkody/twitch-emoticons';
const { EmoteFetcher, EmoteParser } = TwitchEmoticons;
const { EmoteFetcher, EmoteParser } = require('@mkody/twitch-emoticons');
const clientId = '<your client id>';
const clientSecret = '<your client secret>';
const fetcher = new EmoteFetcher(clientId, clientSecret);
const parser = new EmoteParser(fetcher, {
type: 'markdown',
match: /:(.+?):/g
});
fetcher.fetchTwitchEmotes(null).then(() => {
const kappa = fetcher.emotes.get('Kappa').toLink();
console.log(kappa);
const text = 'Hello :CoolCat:!';
const parsed = parser.parse(text);
console.log(parsed);
});
All providers, global + channel, custom template and match pattern
const { EmoteFetcher, EmoteParser } = require('@mkody/twitch-emoticons');
const channelId = 44317909;
const clientId = '<your client id>';
const clientSecret = '<your client secret>';
const fetcher = new EmoteFetcher(clientId, clientSecret);
const parser = new EmoteParser(fetcher, {
template: '<img class="emote" alt="{name}" src="{link}">',
match: /(\w+)+?/g
});
Promise.all([
fetcher.fetchTwitchEmotes(),
fetcher.fetchTwitchEmotes(channelId),
fetcher.fetchBTTVEmotes(),
fetcher.fetchBTTVEmotes(channelId),
fetcher.fetchSevenTVEmotes(),
fetcher.fetchSevenTVEmotes(channelId),
fetcher.fetchFFZEmotes(),
fetcher.fetchFFZEmotes(channelId)
]).then(() => {
const globalEmotes = parser.parse('EZ Clap way too easy LUL now for the last boss monkaS LaterSooner');
console.log(globalEmotes);
const channelEmotes = parser.parse('KEKW that was 3Head TeriPoint');
console.log(channelEmotes);
}).catch(err => {
console.error('Error loading emotes...');
console.error(err);
});
7TV formats
7TV v3 delivers emotes in either WEBP or AVIF.
By default we'll return WEBP emotes but you can override this.
const { EmoteFetcher } = require('@mkody/twitch-emoticons');
const fetcher = new EmoteFetcher();
fetcher.fetchSevenTVEmotes(null, 'avif');
fetcher.fetchSevenTVEmotes(44317909);
fetcher.fetchSevenTVEmotes(44317909, 'webp');
fetcher.fetchSevenTVEmotes(24377667, 'avif');
Links
This library uses the following: