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 little question about "string" cmd

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 little question about "string" cmd

Post by Riddler »

Hello guy's,

I have a little problem with a string ... How do I set a "except" on a DCC CHAT string so that I wont get banned (when I`m trying to connect through partyline with the bot ) :( ?

I wanna except form banning only the ctcp key's "ACTION" and "DCC CHAT" .... for the rest, I want them banned :!:

:arrow: The Code

Code: Select all

bind ctcp -|- * s:do:ctcp

proc s:do:ctcp { nick uhost handle target key args } {
 global botnick work_chan
   if {[string tolower $key]=="action"} {return 0}
   if {[string tolower $key]=="dcc*chat"} {return 0}
     putserv "PRIVMSG $work_chan :.2days *!*@[lindex [split $uhost @] 1] Drones/BOT's are banned."
}

Any little help pls, thanks !
I am a man of few words, but many riddles
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

looks like nobody knows :!: :shock:
I am a man of few words, but many riddles
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

  1. "key" will never contain a white space
  2. the == operand doesn't support wildcards, you must use string match to do so.
  3. consider using string equal -nocase to begin with, when comparing string ignoring the case.
  4. if the key is "dcc" the keyword "chat" will be in [lindex $args 0].
  5. You can put them all into one if statement, if you use them in a statement like:

    Code: Select all

    ![string equal -nocase $key "action"] && !([string equal -nocase $key "dcc"] && [string equal -nocase [lindex $args 0] "chat"])
    which should be true, in case you want them to be banned.
PS: you might want to rename "args" to "arg", because "args" might screw the lindex or require it to be doubled. I am currently not that familiar with the ctcp bind, but I suppose it might be that way.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

ok, still not working :!:

Error:
(02:08:03) <@EGG> !ATENTIE!: Posibil SPAM prin CTCP de la Nickname [ident@hostname.users.undernet.org]: DCC CHAT chat 1380788232 1024
This message is not suppose to show, beacuse I`ve added the hostmask in to a except string :(

Code

Code: Select all

### CONFIG ###

set spamdet(chat) "#channel"

set spamdet(except) {
 "*!*@hostname.users.undernet.org"
 "*!*@username.users.undernet.org"
}


### CODE ####

setudef flag spamdetective

bind ctcp -|- * s:do:ctcp

proc s:do:ctcp { nick uhost handle target key args } {
 global botnick spamdet
   set sms [lindex $args 0]
     if {[string match *$uhost* $spamdet(except)]} { return 0 }
      if {![string equal -nocase $key "action"] && !([string equal -nocase $key "dcc"] && [string equal -nocase [lindex $args 0] "chat"])} {
        putserv "PRIVMSG $spamdet(chat) :\002!ATENTIE!\002: Posibil SPAM prin\002 CTCP \002de la\0032 $nick \003\[$uhost\]: $key $sms "
      }
}

putlog "Loaded spamdet.tcl"
Some more help ?!
I am a man of few words, but many riddles
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Considder converting spamdet(except) to a list and use a foreach loop to match each list-item against the hostmask, rather than using a "string match" on the whole content.

If the list of hosts is stored in "hostlist", you could use something like this:

Code: Select all

foreach host $hostlist {
 if {[string match $host "$nick!$uhost"]} {return 0}
}
NML_375
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

That's it nml375 :D , it's working 8)
I`ve improve the code with some more facility's and run a cross a little issue with the utimer comand :? ...

The Problem:
(02:44:58) * Parts: EGG (id@domain.name) (looking for clues...)
(02:44:58) * Joins: EGG (id@domain.name)
(...)
(02:49:58) * Parts: EGG (id@domain.name) (looking for clues...)
(02:49:58) * Joins: EGG (id@domain.name)
(...)
and so on...
The thing is that the bot is not following the $spamdet(gt) ( time to stay gone from the channel ) .... the actual part/join is within that second :shock:

The extended code:

Code: Select all

### CONFIG ### 

# main channel
set spamdet(mc) "#main_channel" 

# alert channel
set spamdet(ac) "#alert_channel"

# cycle time [minutes]
set spamdet(ct) "5"

# gone time form the maine channel [seconds]
set spamdet(gt) "40"

# part message
set spamdet(pm) "looking for clues..."

# except from beeing banned
set spamdet(except) { 
 "*!*@hostname.users.undernet.org" 
 "*!*@username.users.undernet.org" 
} 

### CODE #### 

bind ctcp -|- * s:do:ctcp 

global spamdet
timer $spamdet(ct) s:cycle

proc s:cycle {} {
 global botnick spamdet
   putserv "PART $spamdet(mc) :$spamdet(pm)"
   utimer $spamdet(gt) [list putserv "JOIN $spamdet(mc)"]
   timer $spamdet(ct) s:cycle
}

proc s:do:ctcp { nick uhost handle target key args } {
 global botnick spamdet
  foreach host $spamdet(except) {
    if {[string match $host "$nick!$uhost"]} {return 0}
  }
  if {![string equal -nocase $key "action"] && !([string equal -nocase $key "dcc"] && [string equal -nocase [lindex $args 0] "chat"])} {
     set sms [lindex $args 0]
     putserv "PRIVMSG $spamdet(ac) :\002!ATENTIE!\002: Posibil SPAM prin\002 CTCP \002de la\0032 $nick \003\[$uhost\]: $key $sms "
     putserv "PRIVMSG $spamdet(mc) :.d 14 *!*@[lindex [split $uhost @] 1] Drones/BOT's are banned."
  }
}

foreach checkutimer [utimers] {
  if {[string match *cycle* [lindex $checkutimer 1]]} {
  killutimer [lindex $checkutimer 2]
  }
}

putlog "Loaded spamdet.tcl"
What could be the problem ?! :idea:
I am a man of few words, but many riddles
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Your bot will automatically rejoin any channel it is supposed to monitor, should it leave the channel for any other reason then the channel being either set +inactive or removed from the channel-list.

Rather than using putserv "PART ...", considder using something like this:

Code: Select all

   channel set $spamdet(mc) +inactive
   utimer $spamdet(gt) [list channel set $spamdet(mc) -inactive]
NML_375
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

Thanks nml375, the script works great :D
I am a man of few words, but many riddles
Post Reply