Determine if someone is an active chatter

I’m building a twitch bot mostly for fun but also in the hopes that I can use it at least for a decent period of time in my streams.

I’m using node.js and the awesome tmijs.org TMI module for the bot connection.

I’m trying to build a currency system and I have most of it in place, but what I really want to try to work through is someway of figuring out if someone is actively chatting or not. I don’t want people to just sit in my chat and say nothing and just rack up points. I want people to be actively chatting.

Since I know this isn’t a forum for one language I won’t post any code but if you want to see my current code you can find it here

The basic theory of what I’m trying to do is basically every say 5 minutes I check the current list of viewers in chat and compare that to the list of viewers from 5 minutes ago, and for each list I basically make a new list that only includes people that are in both lists. At this point I would loop over each and update my database for that person with the new number of minutes they’ve been watching and their new currency level.

It’s somewhere here I think I would need to somehow figure out if that person is an active chatter or not. I’m just not sure what the best way of doing that is.

My first thought is to for each chat message save that username and the timestamp of the chat message into an object and each time that person chats again update the timestamp to the new time, and then when the loop goes to add currency to that user it can look in the object for the users username and see if the timestamp from the last chat message is within say 10 minutes and if it’s not it will skip adding currency to that person.

My forethought is I worry about having to manage a large object for potentially hundreds of users one day and I’m not sure if my bot can handle that.

If anyone has any tips on even just a theory of how I might do this I would love to hear your thoughts.

Yes your code can handle that many users. I have a nodejs bot that stores 33000 records of about 1 timestamp in length so it should handle it fine.

I would go with the “store last timestamp of user” method and reward those of the “less than 5 minutes” which would mean you don’t need to fetch the chatters list as all. Since you are only monitoring activity and not presence.

1 Like

Hundreds of usernames and timestamps might seem like much, but really isn’t. Since it is only important to gather if a user has posted it’s latest message within a given time frame, the list would only have to contain recent posters and discard the old. Even on the biggest channels I don’t think that would take much resources.

In an associative array I would use username as the key and timestamp as the value. Each time a user posts, an assignment of their username would either assign or overwrite your previous timestamp.

Checking is as simple as iterating over the list and discard each user key with a timestamp that is too old. The remaining keys are all the active chatters within your time frame.

Edit: Use the delete operator to remove keys, so that the list won’t keep growing

1 Like

Thanks for the info, I know nodejs can handle quite a bit, but I’ve never really done any indepth nodejs development so I want to make sure I do things right so I can let nodejs to the heavy lifting. It’s good to hear that yours is handling it well.

I code in a few languages… just storing an array of username/timestamps is literally fluff all in terms of memory footprint…

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