IRCv3 Tag Logic?

I am writing an IRC class to process the incoming messages from Twitch. I am running into issues when Twitch sends a malformed message.

Here are some examples:

This one list no channel.

:twitch_username! PART

I have no idea what this was suppose to be.


This one missed the channel and message.

@color=#0D4200;display-name=TWITCH_UserNaME;emotes=25:0-4,12-16/1902:6-10;mod=0;subscriber=0;turbo=1;user-id=1337;user-type=global_mod :twitch_username! PRIVMSG

I get a few of these incomplete responses and it’s messing with my logic.
Currently I am checking the start of a message to determine if it’s “:” or “@” then I start breaking down the message to it’s parts(channel, message type, tags, sender, etc…), of course if a message is malformed and missing a part it results in an errors for trying to access an index that doesn’t exist.
So my question is to fellow programmers, how do you handle these?
Is there a sound logic to processing these responses?

I haven’t noticed any “malformed messages” from Twitch… How are you reading from the connection and parsing the message? A message might not fit in your buffer, especially if your buffer is small but otherwise as well, so you should be listening until you hit \r\n before parsing the IRC message.

It parses 99% of data just fine. I have hundreds of bots online at any given time and out of those hundreds of bots parsing thousands of lines I only see this error on rare occasions. My issue is I haven’t found a good way proceed when this does occur. I’m just trying to determine a uniform way of identifying the IRC responses so I can throw away malformed responses when they don’t fit the uniform.

Wondering how other people done it.

This isn’t the first time I’ve heard this complaint but it would be the first time the cause wasn’t improper reading from the connection.

If Twitch really isn’t sending the whole message, there’s not much you can do except drop processing the message when the necessary information is missing, but it would be a problem for Twitch to fix.

I’m not very savvy with the communication. I’m only editing the data parsing to be compatible with Twitch tags. The IRC client is in c# and from what I can understand it’s using .NET’s NetworkStream. I never see /r/n and I am monitoring the raw data coming out of that stream.

I’d say you just get partial messages. Use a buffer to store data received from Twitch before processing.

Example from my bot (NodeJS):

this.sock.on('data', function(data) {
  this.buf += data.toString();
  if (this.buf.indexOf(this.lineTerminator) >= 0) {
    var lines = this.buf.split(this.lineTerminator);

    for (var i = 0; i < lines.length - 1; i++) {

    // put back any partial lines into the buffer
    this.buf = lines[lines.length - 1];

(lineTerminator is “\r\n”.)

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