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 

help with a simple Bot Query Kick Bug (SOLVED)

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


Joined: 28 Apr 2007
Posts: 28

PostPosted: Sun Apr 29, 2007 10:21 am    Post subject: help with a simple Bot Query Kick Bug (SOLVED) Reply with quote

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

Quote:

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)
_________________
let he who is without stone cast the first sin


Last edited by masheen on Sun Apr 29, 2007 8:37 pm; edited 2 times in total
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Apr 29, 2007 10:42 am    Post subject: Reply with quote

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:
#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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
masheen
Voice


Joined: 28 Apr 2007
Posts: 28

PostPosted: Sun Apr 29, 2007 12:38 pm    Post subject: Reply with quote

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

sori about this. its fixed
Quote:
Secondly, tcl is newline terminated, and "else" is not a separate command, but a parameter to "if"..

got his one thanks. Smile
Quote:
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.
Quote:
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. Smile pls bear with me.
_________________
let he who is without stone cast the first sin
Back to top
View user's profile Send private message
YooHoo
Owner


Joined: 13 Feb 2003
Posts: 939
Location: Redwood Coast

PostPosted: Sun Apr 29, 2007 1:57 pm    Post subject: Reply with quote

you might wanna bind the message to some flags, ya think? Kinda looks like anyone could use this code to kick anyone else...
_________________
Mr. Green
Johoho's TCL for beginners
Mr. Green
Back to top
View user's profile Send private message Send e-mail
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Apr 29, 2007 3:09 pm    Post subject: Reply with quote

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:
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:
#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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
masheen
Voice


Joined: 28 Apr 2007
Posts: 28

PostPosted: Sun Apr 29, 2007 8:37 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
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