Skip to content

Instantly share code, notes, and snippets.

@kocisov
Created April 22, 2017 09:23
Show Gist options
  • Save kocisov/d736b14380f925443f40a78026e12d8d to your computer and use it in GitHub Desktop.
Save kocisov/d736b14380f925443f40a78026e12d8d to your computer and use it in GitHub Desktop.
emoteParserLUL
import parse from 'twitch-emoji';
import bttv from './bttv.json'; // https://api.betterttv.net/emotes
// it's a mess, just... don't... please... save us
function emoteParser (msg) {
let _msg = msg;
msg.split(/\s+/).map(t => {
bttv.emotes.filter(emote => t === emote.regex).map(e => {
if (e.url && e.url.length > 0) {
_msg = msg.replace(
t,
`<img className="twitch-emoji" src="${e.url}" alt="">`
);
}
});
});
// also parse Twitch's global emotes (handled by twitch-emoji package)
return parse(_msg, {
emojiSize: 'small',
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment