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

I’m still quiet new to coding but was interested to make my own twitch bot for witch I used tmi.js and faced a problem. I can’t identify any emotes! I’m not really sure but what I wanna do is should look like this

var emotes = new Set()
  axios
    .get(
      ''//May be some sort of api witch allows to check if emote listed on channel
    )
    .then(response => emotes.add(/*emotes from Twitch/BTTV/FFZ*/+" "))
  if (message.startsWith('!emotecheck')){
    if(emotes.indexOf(message.toLowerCase())>=0){
      client.say(channel, emotes + 'found in your messages')
//if message was "!emotes hi! Kappa how bttvNice are you? ZreknarF " it should response with "Kappa bttvNice ZreknarF found in your message"
    }
  }

I was only able to check if any of default twitch emotes was in message but was not able to identify actual text of an emote

if (message.startsWith('!emotecheck')&&tags.emotes!==null){
    client.say(channel, "Your message has one of default twitch emotes")
  }

If I try to log for emotes it only shows

emotes:{25: Array(1)}
 25:(1) ['12-16']
  0:'12-16'
  length:1
  __proto__:Array(0)
 __proto__:Object

Thanks in advance!

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

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.