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 

A little question about "string" cmd

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


Joined: 20 May 2007
Posts: 60
Location: Brasov, Romania

PostPosted: Wed Oct 31, 2007 12:34 am    Post subject: A little question about "string" cmd Reply with quote

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 ) Sad ?

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

Arrow The Code

Code:

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Riddler
Halfop


Joined: 20 May 2007
Posts: 60
Location: Brasov, Romania

PostPosted: Wed Oct 31, 2007 7:14 pm    Post subject: Reply with quote

looks like nobody knows Exclamation Shocked
_________________
I am a man of few words, but many riddles
Back to top
View user's profile Send private message Send e-mail Visit poster's website
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Wed Oct 31, 2007 7:18 pm    Post subject: Reply with quote

  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:
    ![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...
Back to top
View user's profile Send private message MSN Messenger
Riddler
Halfop


Joined: 20 May 2007
Posts: 60
Location: Brasov, Romania

PostPosted: Wed Oct 31, 2007 8:17 pm    Post subject: Reply with quote

ok, still not working Exclamation

Error:

Quote:
(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 Sad

Code

Code:

### 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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Oct 31, 2007 8:27 pm    Post subject: Reply with quote

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:
foreach host $hostlist {
 if {[string match $host "$nick!$uhost"]} {return 0}
}

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Riddler
Halfop


Joined: 20 May 2007
Posts: 60
Location: Brasov, Romania

PostPosted: Wed Oct 31, 2007 10:14 pm    Post subject: Reply with quote

That's it nml375 Very Happy , it's working Cool
I`ve improve the code with some more facility's and run a cross a little issue with the utimer comand Confused ...

The Problem:

Quote:
(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 Shocked

The extended code:

Code:
### 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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Thu Nov 01, 2007 8:49 am    Post subject: Reply with quote

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:
   channel set $spamdet(mc) +inactive
   utimer $spamdet(gt) [list channel set $spamdet(mc) -inactive]

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Riddler
Halfop


Joined: 20 May 2007
Posts: 60
Location: Brasov, Romania

PostPosted: Fri Nov 02, 2007 9:20 pm    Post subject: Reply with quote

Thanks nml375, the script works great Very Happy
_________________
I am a man of few words, but many riddles
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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