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: 1107
Joined: Sun Mar 22, 2015 2:41 pm

counting digits and if it exceeds threshold set mute

Post by simo »

i was wondering is there was an easier way to count the digits used in a sentence and counted untill threshold has been reached within time frame
while without having to loop thru all words in a the sentence over and over in other words if a nick wich has digits in it is mentioned the tcl should not count that

using this at the moment:

Code: Select all

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

bind pubm - * check:whatsapp

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


	if {[botisop $chan] || [isop $nick $chan] ||  [ishalfop $nick $chan] ||  [matchattr $hand +bfmo|fmo $chan] || [isvoice $nick $chan]} {return}


	global whatsapp
	set chan [string tolower $chan]
	set text [string map [list \017 ""] [stripcodes abcgru $text]]
	set text [string tolower $text]
	set length [regexp -all {[0-9]} [stripcodes * $text]]

	foreach user [split $text] {
		if {[onchan $user $chan]} { return 0 }
	}

	if {[info exists whatsapp($chan:$nick)]} {  incr length $whatsapp($chan:$nick)  }

	if {[regexp {[0-9]{1,}} [stripcodes * $text]]} {

		if {($length >= $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
		}

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

		if {[regexp {[0-9]{1,}} [stripcodes * $text]]} { set whatsapp($chan:$nick) $length }
		return 0
	}
}


i think this part is cpu intensive looping in each sentence over and over or is that not the case ?
foreach user [split $text] {
if {[onchan $user $chan]} { return 0 }
}
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Trying to understand...
You want to count digits in text lines, but only if they are not in a mentionned nick ?

To remove the nicks from a line, use the ldiff proc:

Code: Select all

proc ldiff {list1 list2 {option -exact}} {
   if {$option ne "-nocase"} { set option -exact }
   return [lmap x $list1 {expr {[lsearch $option $list2 $x] < 0 ? $x : [continue]}}]
}
To use it, replace your foreach loop with:

Code: Select all

set users [split [chanlist $chan]]
set text [join [ldiff [split $text] $users]]
Note that your foreach loop stops if a nick is in the line, I don't think it's what you really want to do.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks for your reply CC i tried that and it still seem to execute when nick with more than threshold digits is mentioned in sentence

Code: Select all

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

bind pubm - * check:whatsapp

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


   if {[botisop $chan] || [isop $nick $chan] ||  [ishalfop $nick $chan] ||  [matchattr $hand +bfmo|fmo $chan] || [isvoice $nick $chan]} {return}


   global whatsapp
   set chan [string tolower $chan]
   set text [string map [list \017 ""] [stripcodes abcgru $text]]
   set text [string tolower $text]

   set users [split [chanlist $chan]]
   set text [join [ldiff [split $text] $users]]
   set length [regexp -all {[0-9]} [stripcodes * $text]]

   if {[info exists whatsapp($chan:$nick)]} {  incr length $whatsapp($chan:$nick)  }

   if {[regexp {[0-9]{1,}} [stripcodes * $text]]} {

      if {($length >= $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
      }

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

      if {[regexp {[0-9]{1,}} [stripcodes * $text]]} { set whatsapp($chan:$nick) $length }
      return 0
   }
}


proc ldiff {list1 list2 {option -exact}} {
   if {$option ne "-nocase"} { set option -exact }
   return [lmap x $list1 {expr {[lsearch $option $list2 $x] < 0 ? $x : [continue]}}]
}
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

CrazyCat wrote:Trying to understand...
You want to count digits in text lines, but only if they are not in a mentionned nick ?

To remove the nicks from a line, use the ldiff proc:

Code: Select all

proc ldiff {list1 list2 {option -exact}} {
   if {$option ne "-nocase"} { set option -exact }
   return [lmap x $list1 {expr {[lsearch $option $list2 $x] < 0 ? $x : [continue]}}]
}
To use it, replace your foreach loop with:

Code: Select all

set users [split [chanlist $chan]]
set text [join [ldiff [split $text] $users]]
Note that your foreach loop stops if a nick is in the line, I don't think it's what you really want to do.

your description is exactly what i needed to check for digitts in a sentence count them even over multiple lines and if threshold within timeframe is reached to set muteban

i tried it but it doesnt seem to remove the nick from the $text
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Normal, you make a string tolower on text, and ldiff use -exact by default.

Change the second line:

Code: Select all

set text [join [ldiff [split $text] $users "-nocase"]]
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

that seems to do it excellent thanks CC much apriciated
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

tested again and it accures if someone says like

Guest52474:
or any chars placed after the nick actually like Guest52474: :Guest52474 Guest52474. Guest52474) (Guest52474 and so on



it triggers while Guest52474 is a nick on channel


this is what i got so far:

Code: Select all

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

   global whatsapp
   set chan [string tolower $chan]
   set users [split [chanlist $chan]]
   set text [join [ldiffzizo [split $text] $users "-nocase"]]
   set text [string tolower $text]
   set length [regexp -all {[0-9]} [stripcodes * $text]]

   if {[info exists whatsapp($chan:$nick)]} {  incr length $whatsapp($chan:$nick)  }

   if {[regexp {[0-9]{1,}} [stripcodes * $text]]} {

      if {($length >= $whatsapp(maxlength))} {


         set chost [getchanhost $nick $chan]
         set bmask m:[maskhost "$nick!$chost" 2]
         pushmode $chan +b $bmask
         after [expr {1*1000*60}] [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
      }

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

      if {[regexp {[0-9]{1,}} [stripcodes * $text]]} { set whatsapp($chan:$nick) $length }
      return 0
   }
}

proc ldiffzizo {list1 list2 {option -exact}} {
   if {$option ne "-nocase"} { set option -exact }
   return [lmap x $list1 {expr {[lsearch $option $list2 $x] < 0 ? $x : [continue]}}]
}

it seems to need exact nick while our webclient is designed if someones nick is mentioned its send like this nick:

perhaps wildcard can be used so if a nick is mentioned to check for *nick* to get the nick regardless of a character placed in front or in the back of it
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

You can try to remove non-word chars from the line before checking it:
Add:

Code: Select all

regsub -all -- {\W} $text " " text
before the line:

Code: Select all

set text [join [ldiffzizo [split $text] $users "-nocase"]]
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

tested it that seems to do it thanks again CC much apriciated
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

tested again and found it doesnt strip all non alphanumeric characters
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

underscore (_) is a word character in regexp.

If another character is not stripped, give an example, I won't try to find which one is not stripped.

And if you want to strip the underscore too, replace \W with [^a-zA-Z0-9]
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Code: Select all

regsub -all -- {[^[:alnum:]]} $text "" text
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: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

that seems to work thanks Spike^^
thanks CC as well much apreciated all working well now
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

heres what im working with so far the nicks removal from $text is provided by spike^^ ive integrated that it all works fine but when nicks like Guest12345 are used in the manner of :

<somenick> Guest12345: hey how are you

it counts the digits of the mentioned nick as well

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 nkls [chanlist $chan]
  set tmptx ""
  foreach word [split $text] {  if {[lsearch -nocase $nkls $word] == -1} { append tmptx "$word " }   }
  set digitcount [regsub -all {[[:digit:]]} $tmptx "" tmptx]

   putserv "PRIVMSG #test :$digitcount"

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

   if {[regexp {[0-9]{1,}} [stripcodes * $text]]} {

      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
      }

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

      if {[regexp {[0-9]{1,}} [stripcodes * $text]]} { set whatsapp($chan:$nick) $digitcount }
      return 0
   }
}  


perhaps we need to add some workaround as basically issue is only with : as the network im using this on they use mibbit and mibbit tends to add postfix : if nicks are mentinoned
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

wildcard might not be a bad idea if its the only solution as we use minimum of 3 chars to be used in nick length

i tried using foreach word [split $text] { if {[lsearch -nocase *$nkls* $word] == -1} { append tmptx "$word " } }

didnt seem to check with wildcard
Post Reply