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.
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."
}
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."
}
#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."
}
}
}
@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:
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:
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."
}
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."
}
}
}
@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)