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 a simple Bot Query Kick Bug (SOLVED)

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
masheen
Voice
Posts: 28
Joined: Sat Apr 28, 2007 1:14 pm

help with a simple Bot Query Kick Bug (SOLVED)

Post by masheen »

hi guys... m just starting out with TCL so pls bear if i am wasting ur time. can anybody point out why dis script simpy does nothing? its a script that i use to PM the bot to kick sum1 in a channel he is opped in
bind msg - !k kick

proc kick {nick host hand arg} {
set knick [lindex $arg 1]
set uchan [lindex $arg 0]
set kmsg [lrange $arg 2 end]
if {$knick == adzuBOT} { putserv "NOTICE $nick :no can do!" }
if {[isop adzuBOT $uchan] && [onchan $knick $uchan]} {
if {$nick == "masheen"} {
if {$kmsg == ""} {
putquick "KICK $chan $knick :Requested by $nick (OSX)
}
else {
putquick "KICK $chan $knick :$kmsg 14(7OSX14)"
}
}
return 0
}
}
on IRC i made a /msg <botnick> !b #chan nick on a bot using exactly the same logic as above and was working fine... can anyone point out the error why the bot simply just does nothing with this one? or maybe fix it for me pls? thanks in advance to anyone who would bother sharing a little time to help out people not as good with TCL programming as me. ^_^ (and sori if the script is not properly indented as i cant seem to get it right using quotes ehehe)
Last edited by masheen on Sun Apr 29, 2007 8:37 pm, edited 2 times in total.
let he who is without stone cast the first sin
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Well, first off, don't use caps in topic... EVER!!!

Secondly, tcl is newline terminated, and "else" is not a separate command, but a parameter to "if"..

Code: Select all

#This will work:
if {...} {
...
} else {
...
}

#However, this will not
if {...} {
...
}
else {
...
}
Third, you really should not use list commands such as lindex and lrange on strings, either build proper list using the "list" command, or use "split" to convert a string to a list.
Also be aware that lindex will return the item stored at the specified offset in the list, while lrange will return a list with the subset selected. You'll most likely like to convert the output from lrange back to a string; "join" is the trick here.

Fourth, you'd really be better of using "string equal" for comparing strings, rather than using "blah == $blah". The latter can produce some unexpected results in rare conditions.

Also, if you use the code-tags rather than the quote-tags, the code is alittle easier to read...
NML_375
User avatar
masheen
Voice
Posts: 28
Joined: Sat Apr 28, 2007 1:14 pm

Post by masheen »

Well, first off, don't use caps in topic... EVER!!!
sori about this. its fixed
Secondly, tcl is newline terminated, and "else" is not a separate command, but a parameter to "if"..
got his one thanks. :)
Third, you really should not use list commands such as lindex and lrange on strings, either build proper list using the "list" command, or use "split" to convert a string to a list.
Also be aware that lindex will return the item stored at the specified offset in the list, while lrange will return a list with the subset selected. You'll most likely like to convert the output from lrange back to a string; "join" is the trick here.
m a bit confused with this one? can u give me a line of code that explains this? i am better off understanding this with a code.
Fourth, you'd really be better of using "string equal" for comparing strings, rather than using "blah == $blah". The latter can produce some unexpected results in rare conditions.
um by string equals u mean sumthing like this? [onchan $nick $chan]. m a bit lost with tcl terms sori. again i understand better with a line of code.

lastly thanks very much for the help and for the additional help u may still give. :) pls bear with me.
let he who is without stone cast the first sin
User avatar
YooHoo
Owner
Posts: 939
Joined: Thu Feb 13, 2003 10:07 pm
Location: Redwood Coast

Post by YooHoo »

you might wanna bind the message to some flags, ya think? Kinda looks like anyone could use this code to kick anyone else...
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Think of lists as a kind of psuedo-array, or a serialized array. Whitespace-characters are generally used to separate list entities, although any item may contain whitespace characters themselves - requiring some special encapsulation. You might wish to investigate the example below, and also observe the contents of the different variables. Also try some (inappropriate) list commands such as lindex and lrange on $mystring and observe how it might not produce the output you expected.

Code: Select all

set mystring "This is a string { of various } words and{ special characters"
#convert the string to a properly structured list, treating space " " as a field-separator.
set mylist [split $mystring " "]
#Now retrieve a single item from the list, in this case "string"
set myword [lindex $mylist 3]
#Also retrieve a subset of the list
set mysublist [lrange $mylist 5 6]
#and convert it to a string (where each list-item will now be separated by a space " ")
set mysubstring [join $mysublist " "]
As for the string equal part; no, I'm not referring to the onchan tests, they look just fine. However, considder these two examples:

Code: Select all

#Bad way of doing it, may produce unexpected results in some rare conditions:
if {$somestring == "someword"} {...

#A better way of doing it:
if {[string equal $somestring "someword"]} {...
NML_375
User avatar
masheen
Voice
Posts: 28
Joined: Sat Apr 28, 2007 1:14 pm

Post by masheen »

ok thanks for the fast reply guys. will try the advice you guys gave. hope all things go smoothly this time. cheers!
let he who is without stone cast the first sin
Post Reply