| View previous topic :: View next topic |
| Author |
Message |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Fri Oct 22, 2021 1:37 pm Post subject: counting digits and if it exceeds threshold set mute |
|
|
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: |
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 ?
| Quote: |
foreach user [split $text] {
if {[onchan $user $chan]} { return 0 }
} |
|
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Fri Oct 22, 2021 7:05 pm Post subject: |
|
|
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: | 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: | 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. _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Sat Oct 23, 2021 7:33 am Post subject: |
|
|
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: |
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]}}]
} |
|
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Sat Oct 23, 2021 7:51 am Post subject: |
|
|
| 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: | 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: | 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 |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Sat Oct 23, 2021 8:08 am Post subject: |
|
|
Normal, you make a string tolower on text, and ldiff use -exact by default.
Change the second line:
| Code: | | set text [join [ldiff [split $text] $users "-nocase"]] |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Sat Oct 23, 2021 8:54 am Post subject: |
|
|
| that seems to do it excellent thanks CC much apriciated |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Mon Nov 01, 2021 9:15 am Post subject: |
|
|
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: |
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 |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Mon Nov 01, 2021 11:06 am Post subject: |
|
|
You can try to remove non-word chars from the line before checking it:
Add:
| Code: | | regsub -all -- {\W} $text " " text |
before the line:
| Code: | | set text [join [ldiffzizo [split $text] $users "-nocase"]] |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Mon Nov 01, 2021 11:28 am Post subject: |
|
|
| tested it that seems to do it thanks again CC much apriciated |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Mon Nov 01, 2021 12:31 pm Post subject: |
|
|
| tested again and found it doesnt strip all non alphanumeric characters |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Mon Nov 01, 2021 7:25 pm Post subject: |
|
|
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] _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Mon Nov 01, 2021 8:44 pm Post subject: |
|
|
| Code: | | 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
. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Tue Nov 02, 2021 8:34 am Post subject: |
|
|
that seems to work thanks Spike^^
thanks CC as well much apreciated all working well now |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Fri Nov 05, 2021 9:54 am Post subject: |
|
|
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: |
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 |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Fri Nov 05, 2021 10:05 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
|