IRC Bot Phrase Counter Help

Hey there, I decided to make a fun little bot for personal use on some CS:GO streams.

During profesional games, whenever a great play happens the chat loves to spam VAC, so I wanted to make a bot where upon request it begins a counter of all the times VAC is said in chat. Once the counter is stopped by a command, it shows the number of times VAC was said, divided by the amount of seconds the timer was active for.

Basically, a kind of VAC/s counter!

I need advice on how to make this counter however, thanks for the help :^)!

This depends on your bots programming language, you better ask those lang forums.

You could keep it running constantly, then you never have to start/stop a timer.

If you’re looking for advice on methodology:

One simple way is to make an array of 60 buckets (positive integer values) for a 1 second granulation, then just count the occurrences of ‘VAC’ in each message and dump it in the appropriate bucket. Then when the count-per-minute is called for, add up all the buckets.

Or for each message you could count the occurrences, then push the count (plus a timestamp) onto an array. When the count is called for, start iterating backwards and adding up all the ones that are 1 minute or newer and throwing out the rest. You’d want to do some simple garbage collecting, like throwing out everything older than 1 minute once the array reaches a certain size, or throwing out the old ones once every few minutes, or throwing the out ones each time a new one is added.

Or keep it running for any amount of time, not necessarily a minute.

I’m sure people have come up with some pretty efficient and creative ways of counting the occurrences-per-minute in Twitch chat, but these are ways I’ve used to do it.

If you’re looking for language-specific answers though, you might have better luck in a forum for that language.

@OurFlagIsMined Your method is for displaying the number of VACs per minute at any time, and it’s a good way of doing it. @Jadester requested a counter of all the VACs during a timer that would be manually set and stopped, then getting the VACs per second of that whole duration.

This is done as simply as increasing a counter each time “VAC” is found in a message, then dividing this number by the difference in seconds between stop and start time.

But frankly, I think VACs per minute is more useful.

edit, improved VAC/min counter:

Each time “VAC” is encountered, add a timestamp to a list container. Also iterate from the back of the list and remove timestamps older than one minute. At any time the VAC per minute is requested, remove timestamps older than one minute again and return the size of the list container.

Hey there folks, after browsing around some msl forums I made something that somewhat works

on *:text:*:#: {
  if ($1 == vac) { inc %vac.times }
  elseif ($1 == >vaccount) { msg $chan VAC has been been spammed %vac.times times in the last %pers.times seconds, or more precisely $calc(%vac.times / %pers.times) VACs/second. | .timerVac off | %vac.times = 0 | %pers.times = 0  }
  elseif ($1 == >vacstart) { %vac.times = 0 | %pers.times = 0 | .timerVac 0 1 inc %pers.times | .msg $chan VAC/second count started, type >vaccount for results $+ . }
  elseif ($1 == >debug) msg $chan vac: %vac.times pers: %pers.times $+ .
}

Basically the way this works is that whenever “vac” is said in chat it is always incrementing the %vac.times variable by one. This is kind of contrary to what I originally asked, but I used a work around later. Whenever >vacstart is said it resets the %vac.times variable as well as a new %pers.times variable. It also begins a new timer that after every 1 second increments the %pers.times variable, which is what keeps track of the seconds.

When the count is finished, a user types >vaccount and it displays the raw data of numer of times VAC was said, number of seconds that had passed, then divides those values together to show the VAC/second count. It also ends the timer and resets the variables!

Thanks for your guys suggestions, glad I got this working.

Basically the way this works is that whenever “vac” is said in chat it is always incrementing the %vac.times variable by one.

Actually you’re wrong. That code only checks the first word. Also if you type it twice or even more, it only adds one to the counter. That way is meaningless to have a code.

Having a timer to increase %pers.times makes absolutely no sense. You can set a var with the time it started and then when you want it to stop, you subtract both.

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