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.

A big problem

Help for those learning Tcl or writing their own scripts.
Post Reply
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

A big problem

Post by Riddler »

Heya guys, I have a issue with a tcl I`m trying to upgrade...

Here is the code

Code: Select all

# color.tcl

set color(chan) "#chan"

set color(kickmsg) "NO colors allowed here!"

set color(bantime) "60"

### END CFG ###

bind pubm - * s:color

proc s:color {nick uhost hand chan text} {
 global botnick color
  if {[matchattr $hand of|of $chan] || [isop $nick $chan] || [isvoice $nick $chan]}  { return 0 }
  if {(([lsearch -exact [string tolower $color(chan)] [string tolower $chan]] != -1) || ($color(chan) == "*")) && (![matchattr $hand b]) && ($nick != $botnick)} {
    if {[string match *\003* $text]} {
      if {[regexp {(?i)(http://|www\.|\s#\w|^#\w)} $text]} {
        return 1
      } else {
        ban $nick $uhost $hand $chan $text
      }
      return 0
     }
  }
}

proc ban {nick uhost hand chan text} {
 global botnick color
   set ban "*!*@[lindex [split $uhost @] 1]"
   newchanban $chan $ban color $color(kickmsg) $color(bantime)
   putquick "KICK $chan $nick :$color(kickmsg)"
   return 1
}

putlog "color.tcl loaded!"
So here is the main idea ... as the code show's I`m trying to make this tcl ban only users who use color text only, and will NOT ban those type of text that contain channel/web advertise. ( because that job is done by another code...)

Now the problem:
(05:19:29) * Joins: teste1 (~test@127.0.0.1)
(05:19:35) <teste1> #test
(05:19:35) * |EGG sets mode: +b *!*@127.0.0.1
(05:19:35) * teste1 was kicked by |EGG (NO colors allowed here!)
This is not the way I want the code to work!! When the user typed "#test" (with the red color) the reaction should be null ( return 1 )

This is the wright way for this code to work
(05:29:29) * Joins: teste1 (~test@127.0.0.1)
(05:29:35) <teste1> #test
..... no banning ( the above text normaly will activate the chan/web advertise script )
(05:29:46) <teste1> color test
(05:29:46) * |EGG sets mode: +b *!*@127.0.0.1
(05:29:46) * teste1 was kicked by |EGG (NO colors allowed here!)
..... do the ban ( corect order )
What's the bug ?! :?: :!: :arrow:

Any ideas how to fix it ? .... ( hope so :? )
I am a man of few words, but many riddles
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

Try changing

Code: Select all

 if {[regexp {(?i)(http://|www\.|\s#\w|^#\w)} $text]} {
  return 1
 } else {
  ban $nick $uhost $hand $chan $text
 }
   return 0
}
to

Code: Select all

 if {[regexp {(?i)(http://|www\.|\s#\w|^#\w)} $text]} {return 0} else {ban "$nick $uhost $hand $chan $text"; return 1}; return
}
Am not good with regexp but i think thats the reutrn's sorted out.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

The code is pretty much fine, the regular expression however is flawed.
You expect the first character to be a #, not the \003 color control-code. Also, I fail to see the purpose of the (?i) entity in your expression.

Keep in mind that ^ means start of word, so the expression "^#\w" will only match when # is the very first character in the word, not when the first character is a \003 (which is what you used for testing). One easy workaround might be to use the stripcodes command to remove any and all control-codes before running the regular expression.
NML_375
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

First off all, thanks for your replys
Second,
nml375 wrote:You expect the first character to be a #, not the \003 color control-code.
nml375, I`m not expecting for every user who wants to make a advertise with colors, bolds or underlines to start there advertise with # and then the \003 | \037 | \002 .... I tryin to make a if statement so that this script will ban *ONLY* simple text that contain \003 , \037 or \002.
nml375 wrote:Keep in mind that ^ means start of word, so the expression "^#\w" will only match when # is the very first character in the word, not when the first character is a \003 (which is what you used for testing).
I`ve tryed to remove the "^#\w" and leave only this part:

Code: Select all

if {[regexp {(?i)(http://|www\.|\s#\w)} $text]}
This si the result (including TCL_no_TK's suggestion):
<teste22> mmmm test
* |EGG sets mode: +b *!*@127.0.0.1
* teste22 was kicked by |EGG (NO colors allowed here!)
<@me> .tcl killchanban #channels *!*@127.0.0.1
<@|EGG> OK: 1 - 0.029 ms
* |tester sets mode: -b *!*@X101.DSL02.lipetsk.ru
* Joins: teste22 (~test@127.0.0.1)
<teste22> mmmm #test
* |EGG sets mode: +b *!*@127.0.0.1
* teste22 was kicked by |EGG (NO colors allowed here!)
<@me> .tcl killchanban #channels *!*@127.0.0.1
<@|EGG> OK: 1 - 0.031 ms
<teste22> mmmm http://test.ro
* |EGG sets mode: +b *!*@127.0.0.1
* teste22 was kicked by |EGG (NO colors allowed here!)
.... now the user gets ban if he types #|http:// or any type of channel/web advertise

I`ll try to fing other ways in the code for the bot NOT to ban ( with this script ) users who use in there messages #* | http://* | ftp://* | www.*
I am a man of few words, but many riddles
Post Reply