This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

counting digits and if it exceeds threshold set mute

Help for those learning Tcl or writing their own scripts.
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

if only we could compare nicks from nicklist with the $text and if any nick is in $text with a partial wildcard of only : on the right of nick if found like nick1763: or somenick: to strip the : and send to the section that removes nicks from $text to leave the rest to gather digit count
User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Ok, that's not the same proc than before, you change the way it works.

But why don't you keep the regsub given by SpiKe^^ (or mine, they are quite the same) to just clean $text of non-alphanum chars ?
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Code: Select all

set nkls [chanlist $chan]
set tmptx ""
set text [stripcodes c $text]
foreach word [split $text] {
  set word [string trimright $word ":"]
  if {[lsearch -nocase $nkls $word] == -1} { append tmptx "$word " }
}
set digitcount [regsub -all {[[:digit:]]} $tmptx "" tmptx]

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

tested that last code u posted spike^^ and it seems to do exactly what we had in mind ill test some more thanks so far
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

CrazyCat wrote:Ok, that's not the same proc than before, you change the way it works.

But why don't you keep the regsub given by SpiKe^^ (or mine, they are quite the same) to just clean $text of non-alphanum chars ?
because many web clients like mibbit , irccloud and perhaps others that postfix mentioned nicks with a : making it no longer correspond with the nicks in the gathered nicklist and therefor not removed and counted with the digits having it triggering a lot of false alarms

thanks CC much apreciated as always
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Tested it some more in an active channel and got no false alarms it seems to do exactly as expected excellent work

Thank spike^^ and cc much appreciated
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

I like this slightly cleaned up version.

Code: Select all

set whatsapp(maxlength) 5
set whatsapp(unsettime) 20

bind pubm - * 112345check:whatsapp


proc 112345check:whatsapp {nick host hand chan text} {
   global whatsapp

   set text [stripcodes c $text]
   if {![string match {*[0-9]*} $text]} {  return 0  }

   set nkls [chanlist $chan]
   set tmptx ""
   foreach word [split $text] {
      set word [string trimright $word ":"]
      if {[lsearch -nocase -exact $nkls $word] == -1} { append tmptx "$word " }
   } 
   set digitcount [regexp -all {\d} $tmptx]
   #putserv "PRIVMSG #test :$digitcount"

   if {$digitcount == 0} {  return 0  }
   if {[info exists whatsapp($chan:$nick)]} {  incr digitcount $whatsapp($chan:$nick)  }

   if {($digitcount >= $whatsapp(maxlength))} {
      set chost [getchanhost $nick $chan]
      set bmask m:[maskhost "$nick!$chost" 2]
      pushmode $chan +b $bmask
      after [expr {5*1000*1}] [list pushmode $chan -b $bmask]

      #putserv "PRIVMSG $nick :you have been temporary mutebanned due to: excessive digits in your sentences"
      putserv "NOTICE $nick :you have been temporary mutebanned due to: excessive digits in your sentences"
      array unset whatsapp $chan:$nick
      return 0
   }

   if {![info exists whatsapp($chan:$nick)]} {
      utimer $whatsapp(unsettime) [list array unset whatsapp $chan:$nick]
   }
   set whatsapp($chan:$nick) $digitcount
   return 0
}

=> NOTE: This code has been update to reflect the fix below:) <=
Last edited by SpiKe^^ on Mon Nov 08, 2021 11:16 am, edited 3 times in total.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Tested this and it doesn't seem to trigger and no errors
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

when i replaced
set digitcount [regexp -all {/d} $tmptx]


with :
set digitcount [regsub -all {[[:digit:]]} $tmptx "" tmptx]

it seems working again
User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Little typo from SpiKe^^. It's \d and not /d :)
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

oh yea true didnt see that, that seemed to fix it thanks CC
and thanks spike^^ for the cleanup of the code
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Ooops.

Thanks for the fix CrazyCat and simo.

Edited the above post to reflect that fix...
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i found another bug for example if a nick [Guest]12345 is on channel
and gets typed its not removed from $text and gets counted with the digits
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Try replacing this line in the script...

Code: Select all

if {[lsearch -nocase $nkls $word] == -1} { append tmptx "$word " }
with this updated line...

Code: Select all

if {[lsearch -nocase -exact $nkls $word] == -1} { append tmptx "$word " }
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

that seems to have fixed it thanks spike^^
Post Reply