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.

annoy check

Help for those learning Tcl or writing their own scripts.
Post Reply
T
Torrevado
Op
Posts: 101
Joined: Wed Aug 02, 2006 6:29 pm

annoy check

Post by Torrevado »

Hi, I'm trying to modify channel protection script by gozzip. What I want is to add some chars like "annoying". I did it this way, but it doesn't work:

Code: Select all

if {($letter == "?") || ($letter == "!") || ($letter == "$") || ($letter == "_") || ($letter == "*") || ($letter == "%") || ($letter == "¿") || ($letter == "¡") || ($letter == "ñ") || ($letter == "á") || ($letter == "é") || ($letter == "í") || ($letter == "ó") || ($letter == "ú") || ($letter == "[") || ($letter == "]") || ($letter == "{") || ($letter == "}") || ($letter == "<") || ($letter == ">") || ($letter == "|") || ($letter == "ç") || ($letter == ".") || ($letter == "¨")} {incr annoy; incr total_annoy}
Entire proccess (original one) is:

Code: Select all

set annoy_count(z:z) 0
set annoy_triggered(z:z) 0


##CHECK_ANNOY
proc check_annoy {nick uhost hand chan text} {

 #load some global variables
 global chanpro annoy_count annoy_triggered botnick annoy_ban_type
 
 #set the annoy variables
 set annoy 0
 set total_annoy 0
 set triggered 0
 
 #check if annoy-check is disabled, if so - return
 if {!$chanpro(annoy)} {return 0}

 #check if other bot is actually typing the word <- Added to fix bugs
 if {[matchattr $hand +b]} {return 0}

 #check each char with a loop
 foreach word [split $text] { 
    foreach letter [split $word ""] {
       if {($letter == "?") || ($letter == "!") || ($letter == "$") || ($letter == "_") || ($letter == "*") || ($letter == "%")} {incr annoy; incr total_annoy}
    }
    
    #checks if the length of the annoy is huge enough
    if {$annoy >= $chanpro(annoy_length)} {break} {set annoy 0}
 }
 
 #set some vars again
 set total_string [expr [string length $text] - [regsub -all -- " " $text * *]]
 set percent [expr $total_annoy.0 / $total_string * 100]

 #check if the annoy was big enough
 if {$annoy >= $chanpro(annoy_length)} {
    set triggered 1
 } 

 #check if the percentage was big enough, and string was long enough to count
 if {$total_string >= $chanpro(annoy_minimum) && $percent >= $chanpro(annoy_percent)} {
    set triggered 1
 }
 
 #check if we got a trigger
 if {!$triggered} {
    return 0
 }


 ##now, proceed to the actual actions the bot will take
 ##create a timer for the violation, kick/ban..
   
 #checks if the user is an op, if so check if protect_ops is enabled
 if {([matchattr $hand o|o $chan] || [isop $nick $chan]) && $chanpro(protect_ops)} {
    putserv "[subst $chanpro(op_method)] :[subst $chanpro(op_annoy)]"
    return 0
 }
 
 #check if the dude has triggered before
 if {![info exists annoy_count($uhost:$chan)]} {
    set annoy_count($uhost:$chan) 0
 }
   
 #increase the variable thar tracks number of offences
 incr annoy_count($uhost:$chan)
   
 #check if we allready have a timer set, and kill it if so (prevent error msgs and bad timers)
 if {[info exists annoy_triggered($uhost:$chan)]} {killtimer $annoy_triggered($uhost:$chan); list unset annoy_triggered($uhost:$chan)}
   
 #set our timer, bound to a variable..
 set annoy_triggered($uhost:$chan) [timer $chanpro(remember) [list unset annoy_count($uhost:$chan)]]
 timer $chanpro(remember) [list unset annoy_triggered($uhost:$chan)]
   
 #check what offencenr this was, and act from it
 if {$annoy_count($uhost:$chan) == 1} {putserv "[subst $chanpro(warning_method)] :[subst $chanpro(warn_annoy)]"}
 if {$annoy_count($uhost:$chan) == 2} {putserv "KICK $chan $nick :[subst $chanpro(kick_annoy)]"}
 if {$annoy_count($uhost:$chan) == 3} {
    set bmask [annoy:masktype $nick!$uhost $annoy_ban_type]
    newchanban $chan $bmask $botnick [subst $chanpro(ban_annoy)] $chanpro(ban_time_annoy)
    putserv "KICK $chan $nick :[subst $chanpro(ban_annoy)]"
    set annoy_count($uhost:$chan) 2
    putloglev o * "*** Kickban $nick from $chan for doing $chanpro(ban_annoy)"
 }

} ;#end proc
Thanks :)
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

what a long IF :P

try to escape these two chars:

Code: Select all

($letter == "[") || ($letter == "]")
this should be like this:

Code: Select all

($letter == "\[") || ($letter == "\]")
:>
T
Torrevado
Op
Posts: 101
Joined: Wed Aug 02, 2006 6:29 pm

Post by Torrevado »

Thanks, it fixed "[", "]", "{" and "}" chars, but nothing to do with others (¿ ¡ á é í ó ú ñ ...etc) :(
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

hmm, its working for me:

Code: Select all

[tomekk@zonk]:/home/temp# ./test.tcl ç
passed
Maybe your channel code page is diffrent from bot code page, don't know.
I don't think so that can be because code page is wrong.

Write some simple script with one "if" and one special char like "ç" and test it.

like:

Code: Select all

bind pub - !test test_proc
proc test_proc {n u h c a} {
      set char "ç"
      if {$char == $a} {
          putquick "PRIVMSG $c :working...."
      }
}
and run "!test ç" (or some other special char, exept [ ] {} ! ? etc, use some language special char)

:>
T
Torrevado
Op
Posts: 101
Joined: Wed Aug 02, 2006 6:29 pm

Post by Torrevado »

This test script works with all standard chars, even [ ] { }, but not with my language special chars like ç, ñ, ¿, á ...etc

I guess what happens is what you said, but I don't know what does it exactly mean, and if it can be fixed
tomekk wrote:Maybe your channel code page is diffrent from bot code page, don't know.
I don't think so that can be because code page is wrong.
I'm lost in Space :cry:
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

Torrevado wrote:This test script works with all standard chars, even [ ] { }, but not with my language special chars like ç, ñ, ¿, á ...etc

I guess what happens is what you said, but I don't know what does it exactly mean, and if it can be fixed
tomekk wrote:Maybe your channel code page is diffrent from bot code page, don't know.
I don't think so that can be because code page is wrong.
I'm lost in Space :cry:
Sometimes problems with code page are rly crazy, I had once a problem with code page in one polish script with special polish UTF chars, but anyway

U want to allow only ASCII chars, like abcde ABCD etc etc, [] ! {} all without special language char?

U can always check letter ASCII code, if it is bigger than 127 then you know that is some other char, f.e. special language char.

http://www.asciitable.com/

little code which can be helpful:

Code: Select all

set char "á"
scan $char "%c" int
puts $int
This will return "225" (cause á code is 225) and this is biggerr than 127 then this is not "normal" char.

Or try to do this i normal way, find char unicode code or some other code page and test it.

Try it.
Post Reply