JTV 2 Receiving Messages

As I’ve been shown by @BatedUrGonnaDie and @george in a recent post, you can request meta data on the same line. Examples of the format is shown in the aforementioned post.

If you want to use regex to handle these I just wrote a quick regex that only handles PRIVMSG (since matching to all the available messages would create a monster bigger than the one below:)

@color=(#[0-9A-F]+)?;emotes=([\d:\-\/,]+)?;subscriber=([01]);turbo=([01]);user_type=([a-z_]+)?\s:([_a-z0-9]+)![_a-z0-9]+@[_a-z0-9]+\.tmi\.twitch\.tv\sPRIVMSG\s#([_a-z0-9]+)\s:([^\r\n]+)

The regex has 8 capture groups:

$1: the color hex code
$2: the emotes by image_id:start_index-end_index
$3: subscriber status (0 or 1)
$4: turbo status (0 or 1)
$5: user type (staff, admin, global_mod or mod)
$6: username
$7: channel
$8: message

But again, monsters like these are the reason I stay away from regex and parse the messages manually :wink:

EDIT: The above regex doesn’t work with unexpected tags, as requested below. Modify as needed.

1 Like