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.

Help with this bad command kick script

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
mcdarby
Halfop
Posts: 69
Joined: Tue Jul 16, 2002 7:46 pm
Location: Bangor, Pennsylvania
Contact:

Help with this bad command kick script

Post by mcdarby »

Hey there, I was trying to write a TCL script for my bot to kick on any of the listed commands being entered by anyone in any of the two channels I was trying to set it up in. This is what I have for a script, and when I tested it, the bot doesn't do anything in response.

Code: Select all

set bancomm(chans) "#Fuzzy #ForestHaven"

set bancomm(comms) "!find @find !list @list !packs @packs !search @search !warezlist @warezlist !xdcclist @xdcclist"

set bancomm(chans) [string tolower $bancomm(chans)]
set bancomm(comms) [string tolower $bancomm(comms)]
foreach chan $bancomm(chans) {bind pubm -|- "$chan $bancomm(comms)" pub:bancomms}
proc pub:bancomms {nick host hand chan arg} {
    putserv "KICK $chan $nick The command you just entered is not allowed here due to it being commonly used by art and software pirates to find out whether or not a server hosts file archieves. Continuing to enter it will result in you being banned from the channel. You have been warned."
}
Any idea what I may have done wrong?[/code]
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

Try:

Code: Select all

set bancomm(chans) "#Fuzzy #ForestHaven"

set bancomm(comms) "!find @find !list @list !packs @packs !search @search !warezlist @warezlist !xdcclist @xdcclist"

bind pubm -|- {*} pub:bancomms

proc pun:bancomms {nickname hostname handle channel text} {
  if {[lsearch -exact [string tolower $bancomm(chans)] [string tolower $channel] == -1} { return }
  set command [lindex [split $text] 0]
  if {[lsearch -exact [string tolower $bancomm(comms)] [string tolower $command]] == -1} { return }
  putserv "KICK $channel $nickname :The command you just entered '$command' is not allowed here due to it being commonly used by art and software pirates to find out whether or not a server hosts file archieves. Continuing to enter it will result in you being banned from the channel. You have been warned."
}
Not Tested.
r0t3n @ #r0t3n @ Quakenet
A
Azeem
Voice
Posts: 14
Joined: Tue Sep 26, 2006 2:37 pm

Post by Azeem »

Code: Select all

#Number of channels..
set channels "#Channel1 #channel2"
#Command to ban..
set bancommands {
 "!find"
"@find"
"!list"
"@list"
"!packs"
"@packs"
"!search"
"@search"
"!warezlist"
"@warezlist"
"!xdcclist"
"@xdcclist"
}

bind pubm -|- * pub:bancomms
proc pub:bancomms {nick host hand chan arg} {
global bancommands channels
set command [string tolower [lindex $arg 0]]
foreach badcom [string tolower $bancommands] {
 if {([string match -nocase *$badcom* $command]) && ([lsearch -exact [string tolower $channels] [string tolower $chan] ] != -1)} {

   putserv "KICK $chan $nick :The command you just entered is not allowed here due to it being commonly used by art and software pirates to find out whether or not a server hosts file archieves. Continuing to enter it will result in you being banned from the channel. You have been warned."
   }
  }
}
Try it tested working..
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

@Azeem:
Unfortunately, that code is flawed, as you are using list commands on strings. What makes matters worse is that you use them on unchecked strings supplied by random users. Should any user in your channel write something containing characters such as (but not limited to) "{[]}", that code will start behaving very badly. Also, lsearch would generally be faster than iterating through the whole list of "badwords", especially if you keep it sorted.

@Tosser^^:
Nice code, you should however use something like this when building the channel and badwords lists:

Code: Select all

set bancomm(chans) [list #Fuzzy #ForestHaven]
set bancomm(comms) [list !find @find .....]
Also a suggestion, change the mask of the binding from "*" to "% !*" and "% @*" to enhance performance slightly
NML_375
User avatar
mcdarby
Halfop
Posts: 69
Joined: Tue Jul 16, 2002 7:46 pm
Location: Bangor, Pennsylvania
Contact:

Post by mcdarby »

@nml375:

You mean change that bind from

Code: Select all

bind pubm -|- {*} pub:bancomms
to

Code: Select all

bind pubm -|- {% !* and % @*} pub:bancomms
?

Well, I would think that

Code: Select all

bind pubm -|- {% *} pub:bancomms
might be better there.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

@mcdarby:
Nope, if it was'nt clear enough; this is what I intended:

Code: Select all

bind pubm -|- "% !*" pub:bancomms
bind pubm -|- "% @*" pub:bancomms
Replacing "*" with "% *" would be quite pointless...
NML_375
User avatar
mcdarby
Halfop
Posts: 69
Joined: Tue Jul 16, 2002 7:46 pm
Location: Bangor, Pennsylvania
Contact:

Post by mcdarby »

Okay, I just tested Tosser's script, where I have this

Code: Select all

set badcomm(chans) "#Fuzzy #ForestHaven"

set badcomm(comms) "!find @find !list @list !packs @packs !search @search !warezlist @warezlist !xdcclist @xdcclist"

bind pubm -|- "% !*" pub:badcommands
bind pubm -|- "% @*" pub:badcommands

proc pub:badcommands {nickname hostname handle channel text} {
  if {[lsearch -exact [string tolower $badcomm(chans)] [string tolower $channel]] == -1} { return }
  set command [lindex [split $text] 0]
  if {[lsearch -exact [string tolower $badcomm(comms)] [string tolower $command]] == -1} { return }
  putserv "KICK $channel $nickname :The command you just entered '$command' is not allowed here due to it being commonly used by art and software pirates to find out whether or not a server hosts file archieves. Continuing to enter it will result in you being banned from the channel. You have been warned."
}
And I was getting a TCL error that is the following:

Code: Select all

<BOT> [20:25] Tcl error [pub:badcommands]: can't read "badcomm(chans)": no such variable
And .set errInfo shows that following:

Code: Select all

<BOT> [20:25] #McDarby# set errorInfo
<BOT> Currently: can't read "badcomm(chans)": no such variable
<BOT> Currently:     while executing
<BOT> Currently: "string tolower $badcomm(chans)"
<BOT> Currently:     (procedure "pub:badcommands" line 2)
<BOT> Currently:     invoked from within
<BOT> Currently: "pub:badcommands $_pubm1 $_pubm2 $_pubm3 $_pubm4 $_pubm5"
Which I can't seem to find what is wrong now
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

Use:

Code: Select all

set badcomm(chans) "[list #Fuzzy #ForestHaven]"

set badcomm(comms) "[list !find @find !list @list !packs @packs !search @search !warezlist @warezlist !xdcclist @xdcclist]"

bind pubm -|- "% !*" pub:badcommands
bind pubm -|- "% @*" pub:badcommands

proc pub:badcommands {nickname hostname handle channel text} {
  global badcomm
  if {[lsearch -exact [string tolower $badcomm(chans)] [string tolower $channel]] == -1} { return }
  set command [lindex [split $text] 0]
  if {[lsearch -exact [string tolower $badcomm(comms)] [string tolower $command]] == -1} { return }
  putserv "KICK $channel $nickname :The command you just entered '$command' is not allowed here due to it being commonly used by art and software pirates to find out whether or not a server hosts file archieves. Continuing to enter it will result in you being banned from the channel. You have been warned."
}
r0t3n @ #r0t3n @ Quakenet
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Why would you use " " around
  • ?

    You need to start writing cleaner code tosser.

    Code: Select all

    set badcomm(chans) [list #Fuzzy #ForestHaven]
    
    set badcomm(comms) [list !find @find !list @list !packs @packs !search @search !warezlist @warezlist !xdcclist @xdcclist]
    
    bind pubm -|- "% !*" pub:badcommands
    bind pubm -|- "% @*" pub:badcommands
    
    proc pub:badcommands {nickname hostname handle channel text} {
      global badcomm
      if {[lsearch -exact [string tolower $badcomm(chans)] [string tolower $channel]] >= 0} {
        set command [lindex [split $text] 0]
        if {[lsearch -exact [string tolower $badcomm(comms)] [string tolower $command]] >= 0} {
          putserv "KICK $channel $nickname :The command you just entered '$command' is not allowed here due to it being commonly used by art and software pirates to find out whether or not a server hosts file archieves. Continuing to enter it will result in you being banned from the channel. You have been warned."
        }
      }
    }
A
Azeem
Voice
Posts: 14
Joined: Tue Sep 26, 2006 2:37 pm

Post by Azeem »

Ohk..thanks for highlighting b/w do u know any solution to it..am a n00b in tcl .. :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

@Azeem:
If you're referring to the use of list-commands; Make sure it's a list and not a string. If nessecary, convert the string to a list.
You'll probably want to read up on these commands:
list, split, join, lappend, lindex, lrange (and a few other list-commands)
NML_375
A
Azeem
Voice
Posts: 14
Joined: Tue Sep 26, 2006 2:37 pm

Post by Azeem »

Thanks for Helping :)
Post Reply