Sent-ts and tmi-sent-ts tags?

I’ve been developing an irc backend using sockets, and I’ve noticed that occasionally I’ll receive a message that looks something like the following:

@color={COLOR};display-name={DISPLAY_NAME};emotes={EMOTES};sent-ts={A_BUNCH_OF_NUMBERS};subscriber={SUB};tmi-sent-ts={A_BUNCH_OF_NUMBERS};turbo={TURBO};user-type={TYPE} :{USER}!{USER}@{USER}.tmi.twitch.tv PRIVMSG #{CHANNEL} :{MESSAGE}

And nowhere in the IRC documentation can I find a reference to either the “sent-ts” or the “tmi-sent-ts” tags, so I was wondering what they were.

Could it possibly be a timestamp? How are the numbers formatted?

An example would be:

@color=#0000FF;display-name=DongerinoCopyPasta;emotes=356:0-5,36-41;sent-ts=1437250120418;subscriber=0;tmi-sent-ts=1437250120654;turbo=0;user-type= :dongerinocopypasta!dongerinocopypasta@dongerinocopypasta.tmi.twitch.tv PRIVMSG #imaqtpie :{msg}

And it only happens occasionally: pic of output

Edit: Pic

From what I can tell, these are unix timestamps in milliseconds. sent-ts is equivalent to Sat, 18 Jul 2015 20:08:40 GMT and tmi-sent-ts is basically the same thing but off by a few milliseconds. I suppose this can be useful for checking ping but I’ve no clue why TMI would be sending these.

Edit: Also, this is what I used to convert them. Neat thing about this site is that it will tell you if it’s a timestamp in milliseconds.

Also, I don’t know what language you’re using for your bot if that’s what you’re even making, but this is what I use for BotOnFire to parse that metadata and turn it into a JavaScript object. Sorry for the mess as it’s compiled CoffeeScript

parseUserData = function(string) {
      var splitDataArray, toReturn;
      toReturn = {};
      splitDataArray = string.split(';');
      splitDataArray.forEach((function(_this) {
        return function(item) {
          var key, kvSplit, value;
          kvSplit = item.split('=');
          key = kvSplit[0];
          value = kvSplit[1];
          return toReturn[key] = value;
        };
      })(this));
      return toReturn;
    };

Code released under CC BY 4.0
Author: Josh Ferrara (http://ferrara.space)

And here’s an example:

Edit: Also one last tip, don’t rely on display-name for the users name. Sometimes TMI will not include it, which to be honest, isn’t that surprising.

Thanks for all the help :heart:

This means that the user hasn’t “picked” a display name

That code is missing handling for escaped characters, such as space, in tag values. Empty display-name tag is expected and documented. (As Barry already said, it’ll be empty when the user has never set it, like the color tag.)

I was only using that code to grab sub/turbo/user-type status’ so I never worried or encountered any escaping issues, but I’ll take that into consideration.

I find it laughable that @scjosh released code under a copyright… I mean really? lol wow.

Feel free to use this for whatever:

function parseTags(message) {
    message = message.trim() + ' ';
    var firstSpace = message.indexOf(' ');
    var rawTags = message
                  .slice(message.charAt(0) === '@' ? 1 : 0, firstSpace)
                  .split(';');
    var tags = {};
    for (var i = 0; i < rawTags.length; i++) {
        var tag = rawTags[i];
        var firstEquals = tag.indexOf('=');
        var key = tag.slice(0, firstEquals);
        var value = tag.slice(firstEquals + 1);
        if(firstEquals === -1) {
            tags[key] = true;
        } else if(/^[0-9]+$/.test(value)) {
            tags[key] = parseInt(value);
        } else {
            value = value
                    .replace(/\\:/g, ';')
                    .replace(/\\s/g, ' ')
                    .replace(/\\\\/g, '\\')
                    .replace(/\\r/g, '\r')
                    .replace(/\\n/g, '\n');
            tags[key] = value;
        }
    }
    return tags;
}

It should cover all cases as outlined in the IRCv3 documentation at http://ircv3.net/specs/core/message-tags-3.2.html

2 Likes

Use this license @night ?

             DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
                    Version 2, December 2004 

 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> 

 Everyone is permitted to copy and distribute verbatim or modified 
 copies of this license document, and changing it is allowed as long 
 as the name is changed. 

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 

  0. You just DO WHAT THE FUCK YOU WANT TO.

Source: http://www.wtfpl.net/about/

It’s wrong to release open source code under an open source license? That’s the first time I’ve heard that…

And here I thought that the Twitch dev community was much more mature…I mean we’re all just trying to help - no need for the destructive criticism.

I’m poking fun of the fact that you took a lot of time to paste your copyright over a 15 line code snippet, even coloring it red in an image for extra importance. Is your 15 lines of code even worth that copyright? Would you be the guy who adds his copyright to a single line var a = b;? Generally people copyright an entire project, or at least a somewhat larger and unique script. You could probably look at my script and see enough similarities to wonder why you’d bother copyrighting yours. There’s only so many ways to code something as specific as splitting a string into an key value object.

We’re trying to help people here, you’re right. That’s why I posted a better solution with no strings attached.

I’m poking fun of the fact that you took a lot of time to paste your copyright over a 15 line code snippet, even coloring it red in an image for extra importance.

The red is a result of using Greenshot to add the text - it’s the default color and styling.

As for the copyright, CC BY 4.0 just asks that you attribute for the code and don’t claim it as your own. A quick google search would’ve yielded that.

Would you be the guy who adds his copyright to a single line var a = b;?

No, and assuming that about someone is quite irrational.

We’re trying to help people here, you’re right. That’s why I posted a better solution with no strings attached.

So then don’t prefix your solution with a snarky comment, rather, “Here’s my solution that takes into account x, y, and z and this is why it’s better.” It’s not hard to have a civil discussion.

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