How to identify and response to BTTV/FFZ/Twitch emotes?

What you have done is extract the emotes from the Tags.

What you see here is

25: the ID of the Emote
12-16: the start and inclusive end of hte word in the message

So for example:

this is a test message Kappa

The result PRIVMSG is

@badge-info=;badges=broadcaster/1,ambassador/1;client-nonce=2cd194239f124f00447463975c5ace63;color=#033700;display-name=BarryCarlyon;emotes=25:23-27;flags=;id=c91c56af-d738-46f1-9690-3cf95b0475c5;mod=0;room-id=15185913;subscriber=0;tmi-sent-ts=1624272189424;turbo=0;user-id=15185913;user-type= :barrycarlyon!barrycarlyon@barrycarlyon.tmi.twitch.tv PRIVMSG #barrycarlyon :this is a test message Kappa

This gives the emite tags of

emotes=25:23-27

So emote 25 is located at character 23 thru 27 (inclusive)

Splitting the message into characters

[“t”, “h”, “i”, “s”, " ", “i”, “s”, " ", “a”, " ", “t”, “e”, “s”, “t”, " ", “m”, “e”, “s”, “s”, “a”, “g”, “e”, " ", “K”, “a”, “p”, “p”, “a”]

So

Items:

IDX character
23 K
24 a
25 p
26 p
27 a

So you can use something like substring in javascript

let start = 23;
let end = 27;
let emote_word = input.substring(start,(end+1));

And emote_word is then Kappa

BTTV/FFZ emotes don’t generate an emotes tag response, so you’d probably be looking at regex to detect those and using their respective API’s to obtain a list of emotes in order to regex against.

1 Like