mIRC Home    About    Download    Register    News    Help

Topic Options
#264511 - 09/12/18 11:16 PM Simple One Man Spam Prevention Bot
TroyL Offline
Babel fish

Registered: 04/12/18
Posts: 52
Can anyone please provide me with a code that automatically times someone out after a certain amount of messages is sent within a set amount of seconds on Twitch.

Top
#264513 - 10/12/18 02:28 AM Re: Simple One Man Spam Prevention Bot [Re: TroyL]
maroon Offline
Hoopy frood

Registered: 12/01/04
Posts: 1139
Here's something to flag someone saying something 5 times in 300 seconds. Change those variables to the values you want. (There's 2 places with the 300)

I don't use twitch, so you'll need to fill in the blank for what command does the 'time out'.

This works by creating a hashtable item each time someone says something, that has a lifetime of the value you set as %timeframe. After doing that, it counts how many not-expired items still alive.

This assumes you don't have a channel name having a "!" in it.

Code:
on *:TEXT:*:#*:{ $flood_counter }
on *:ACTION:*:#*:{ $flood_counter }
on *:NICK:{
  var %table flood , %timeframe 300 , %wilditem $+(*!,$fulladdress)
  while ($hfind(%table,%wilditem,1,w)) {
    hdel %table $v1
    hadd -u $+ %timeframe %table $puttok($v1,$newnick,3,33)
  }
}


alias flood_counter {
  var %timeframe 300 , %max.messages 5 , %table flood
  if (!$hget(%table)) { hmake %table 101 | hadd %table counter 1 }
  var %counter $hget(%table,counter) | hinc %table counter 1
  var %item $+(%counter,!,$chan,!,$fulladdress) , %wilditem $+(*!,$chan,!,$fulladdress)
  hadd -u $+ %timeframe %table %item | var %msg_count $hfind(%table,%wilditem,0,w)
  echo -s debug message: $nick has %msg_count messages in the last %timeframe seconds. You can delete this line
  if (%msg_count >= %max.messages) {
    echo -s action to take against $nick in $chan goes inside these brackets. This is where the time-out command goes
  }
}



Edited by maroon (10/12/18 03:30 AM)

Top
#264521 - 10/12/18 10:56 PM Re: Simple One Man Spam Prevention Bot [Re: maroon]
TroyL Offline
Babel fish

Registered: 04/12/18
Posts: 52
Thank you so much this works perfectly!

Top
#264606 - 20/12/18 05:19 AM Re: Simple One Man Spam Prevention Bot [Re: TroyL]
maroon Offline
Hoopy frood

Registered: 12/01/04
Posts: 1139
Replying to the other thread here, since it's modifying the code of this thread.
https://forums.mirc.com/ubbthreads.php/topics/264596/Re:_Twitch_Commands_Help#Post264596

I combined the 2 tasks in the same event handlers. The code for each task is kept in separate groups of lines.

The %timeframe2 variable should be defined as the same number in both places it's used, ditto for %table1 and %table2. As with the flood counter, I'm resetting the clock when they change their nick instead of continuing with the existing time countdown.

I also modified the TEXT and ACTION events with the @ prefix, which prevents the event from triggering unless you have OP level in that channel. If that doesn't apply to twitch, you can delete the @ from those lines.

As before, I leave it up to you to code the action you're taking against the offender.

Code:
on @*:TEXT:*:#*:{ noop $flood_counter $repeat_counter($1-)   }
on @*:ACTION:*:#*:{ noop $flood_counter $repeat_counter($1-) }
on *:NICK:{
  var %table flood , %timeframe 300 , %wilditem $+(*!,$fulladdress)
  while ($hfind(%table,%wilditem,1,w)) {
    hdel %table $v1
    hadd -u $+ %timeframe %table $puttok($v1,$newnick,3,33)
  }

  var %timeframe2 300 , %table1 repeat.text , %table2 repeat.count , %wilditem $+(*!,$fulladdress)
  while ($hfind(%table1,%wilditem,1,w)) {
    var %a $puttok($v1,$newnick,2,33)
    hadd -u $+ %timeframe2 %table1 %a $hget(%table1,$v1)
    hadd -u $+ %timeframe2 %table2 %a $hget(%table2,$v1)
    hdel %table1 $v1
    hdel %table2 $v1
  }

}

alias -l repeat_counter {
  var %timeframe2 300 , %kill.at.repeats 3 , %table1 repeat.text , %table2 repeat.count
  var %text $lower($strip($1))

  if (!$hget(%table1)) { hmake %table1 101 }
  if (!$hget(%table2)) { hmake %table2 101 }
  var %item $+($chan,!,$fulladdress)
  var %a $hget(%table1,%item)
  if ((%a == $null) || (%a != %text)) {
    hadd -u $+ %timeframe2 %table1 %item %text
    hadd -u $+ %timeframe2 %table2 %item 1
    return
  }

  var %secs $hget(%table1,%item).unset | if (!%secs) var %secs %timeframe2
  hinc -u $+ %timeframe2 %table2 %item
  var %count $hget(%table2,%item)

  if (%count >= %kill.at.repeats) {
    echo 4 -a $nick has repeated %count times within %timeframe2 seconds. Action goes in here
  }

}

alias -l flood_counter {
  var %timeframe 300 , %max.messages 5 , %table flood
  if (!$hget(%table)) { hmake %table 101 | hadd %table counter 1 }
  var %counter $hget(%table,counter) | hinc %table counter 1
  var %item $+(%counter,!,$chan,!,$fulladdress) , %wilditem $+(*!,$chan,!,$fulladdress)
  hadd -u $+ %timeframe %table %item | var %msg_count $hfind(%table,%wilditem,0,w)
  echo -s debug message: $nick has %msg_count messages in the last %timeframe seconds
  if (%msg_count >= %max.messages) {
    echo 4 -s action to take against $nick in $chan goes inside these brackets
  }
}


Top
#264612 - 20/12/18 10:15 PM Re: Simple One Man Spam Prevention Bot [Re: maroon]
TroyL Offline
Babel fish

Registered: 04/12/18
Posts: 52
Thank you this worked. Another thing i've been wondering is how do i limit how many letter or emotes they type. Because some people come into a chat and spam stupid long paragraphs so i was wondering how i could limit that?

Top
#264613 - 20/12/18 10:59 PM Re: Simple One Man Spam Prevention Bot [Re: TroyL]
maroon Offline
Hoopy frood

Registered: 12/01/04
Posts: 1139
$len($1-) would be the length of the message, including spaces and color codes, but with multiple spaces trimmed out. Using $parms instead of $1- counts all the extra spaces padding they might use.

For your flooding monitor, you could have messages count as more-than-one message if they meet some of your flags, such as being too long.

If you're wanting to flag certain kind of text, that would depend on what you mean by emotes. Are you talking about doing things like ":)" or using emoji characters that are visible only in certain fonts like "Segoi UI Symbol" where this shows the black cat emoji:

Code:
//echo -a $chr(55357) $+ $chr(56369)

Top
#264619 - 21/12/18 05:37 AM Re: Simple One Man Spam Prevention Bot [Re: maroon]
TroyL Offline
Babel fish

Registered: 04/12/18
Posts: 52
Could you kindly provide me with a code for the long paragraph protection please? smile

Top
#264621 - 21/12/18 06:04 AM Re: Simple One Man Spam Prevention Bot [Re: TroyL]
maroon Offline
Hoopy frood

Registered: 12/01/04
Posts: 1139
What kind of protection do you have in mind? You didn't say what kind of count-extra you had in mind for someone typing long messages. If you're blocking 3 messages in N seconds, and if someone types a really long message, should that possibly be enough 'points' to cause someone to be banned (or whatever action you're taking against them)?

Depending on how you want to do things, there would be different ways to accomplish it. For example, if you want the points to be (length of message / 100) with a minimum of 1, that would require putting the 'points' into each hashtable item, then looping through all the hashtable items to count all the points. Or if you want messages longer than a specific threshhold to count as if a 2nd message, then it would just add a 2nd hashtable item for those messages.

Top
#264626 - 21/12/18 05:49 PM Re: Simple One Man Spam Prevention Bot [Re: maroon]
TroyL Offline
Babel fish

Registered: 04/12/18
Posts: 52
Ya basically i just want it to flag down long messages and time them out. I would say after 60 letters it should time them out.

Top
#264627 - 21/12/18 07:40 PM Re: Simple One Man Spam Prevention Bot [Re: TroyL]
maroon Offline
Hoopy frood

Registered: 12/01/04
Posts: 1139
if you want to timeout someone because of too many messages, or also because of their first long message, change:

Code:
from:
if (%msg_count >= %max.messages) {
to:
if ((%msg_count >= %max.messages) || ($len($eventparms) >= 60)) {


$eventparms works in v7.53 or higher. For earlier versions, you would need to call this alias like $flood_counter($1-) instead of $flood_counter then replace $eventparms with $1-

I'd find myself timed out in your channel, because 60 seems too short.

Top
#264629 - 21/12/18 08:57 PM Re: Simple One Man Spam Prevention Bot [Re: maroon]
TroyL Offline
Babel fish

Registered: 04/12/18
Posts: 52
Ya i dont know why i said 60 lol. But thanks for all the help!

Update: It isnt working can i have a full script for this?

Top
#264630 - 22/12/18 06:25 AM Re: Simple One Man Spam Prevention Bot [Re: TroyL]
maroon Offline
Hoopy frood

Registered: 12/01/04
Posts: 1139
If you correctly replaced that line with the new line, the only reason it shouldn't work is

* If you have this below another :TEXT: event in the same script, the higher script line event can stop the lower one from being seen.

* if you tried to use $eventparms prior to version 7.53
* the @ prefix on the :TEXT: and :ACTION: lines is causing the event to ignore you if you don't have @op status. If twitch doesn't require Op status to take the quieting action, you can remove the @ prefix from those lines. You can also add debug lines to a script to see which lines are being seen.

echo -s debug: line $scriptline

at the top of the alias tells whether the alias is even being seen, by whether the echo displays to the status window.

Top