egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

counting digits and if it exceeds threshold set mute

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
simo
Owner


Joined: 22 Mar 2015
Posts: 653

PostPosted: Yesterday at 1:37 pm    Post subject: counting digits and if it exceeds threshold set mute Reply with quote

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
View user's profile Send private message
CrazyCat
Owner


Joined: 13 Jan 2002
Posts: 859
Location: France

PostPosted: Yesterday at 7:05 pm    Post subject: Reply with quote

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
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 653

PostPosted: Today at 7:33 am    Post subject: Reply with quote

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
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 653

PostPosted: Today at 7:51 am    Post subject: Reply with quote

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
View user's profile Send private message
CrazyCat
Owner


Joined: 13 Jan 2002
Posts: 859
Location: France

PostPosted: Today at 8:08 am    Post subject: Reply with quote

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
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 653

PostPosted: Today at 8:54 am    Post subject: Reply with quote

that seems to do it excellent thanks CC much apriciated
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber