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.

newchanban issue

Help for those learning Tcl or writing their own scripts.
Post Reply
p
psychic
Voice
Posts: 5
Joined: Tue Sep 02, 2008 11:07 am

newchanban issue

Post by psychic »

This is a part of my tcl which is not working and I get this error wrong # args: should be "putlog text"

Code: Select all


Here's the requested code from the pastebin:

Wrap Lines   Use Line Numbers

bind msg -|fpm command command
proc command {nick uhost hand args} {
 global botnick 
 set thechan "#chan"
 set passed_data [lrange [lindex $args 0] 0 end]
 set arg1 [lindex [lindex $args 0] 0]
 set cmd  [lindex [lindex $args 0] 0] 
 set arg2 [lindex [lindex $args 0] 1]
 set arg3 [lindex [lindex $args 0] 2]
 set arg4 [lindex [lindex $args 0] 3]
 if { $cmd == "addban"} {
    newchanban $thechan $arg2 $nick $arg4 $arg3
 }
/msg botnickname command addban <host> <ban time in days or any format> <ban reason>
to set add a ban to the bots banlist (like .+ban .....)

Could somebody help me please correct my syntax?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

That error is not related to the posted code. Look for some part of your script that contains putlog, as this is where the error most likely is located.

A few notes on the code in question however;
I see no reason for the use of the special argument "args". Especially since you only retrieve the first argument (lindex $args 0). Considder using something different, such as text.
Secondly, your use of lrange, as well as further use of lindex is flawed, as the "list" actually is a string. Please considder using split to convert the string to a list prior any list operations..

I will post a partial example on how you should use list commands, and how to implement the proc with normal arguments, rather than using the special "args".

Code: Select all

...
proc command {nick host hand text} {
 set tlist [split $text]
 set cmd [lindex $tlist 0]
 ...
}
NML_375
p
psychic
Voice
Posts: 5
Joined: Tue Sep 02, 2008 11:07 am

Post by psychic »

I am afraid this didn't really help me much, I still can't do it.
All I wish to do is something like if { $cmd == "addban"} { newchanban $arg2 (host) $arg4 (duration in days) $arg3 (ban message) }

Code: Select all

bind msg -|m command syntcmd
proc syntcmd {nick uhost hand args} {
	global botnick 
	set cmdchan "#test"
	set passed_data [lrange [lindex $args 0] 0 end]
	set arg1 [lindex [lindex $args 0] 0]
	set cmd  [lindex [lindex $args 0] 0] 
	set arg2 [lindex [lindex $args 0] 1]
	set arg3 [lindex [lindex $args 0] 2]
	set arg4 [lindex [lindex $args 0] 3]
	set the_msg [lrange [lindex $args 0] 2 end]
	set isgood 0
	if { $cmd == "addban"} {
		set isgood 1    
		newchanban $thechan $arg2 $nick $arg4 $arg3
	}
	putlog "blah_blah: command was: $cmd issued by: $nick directed toward: $arg2"
	if { $isgood == "0"} {
		putlog "WARNING from docmd: bad command processing for - "
		putlog $passed_data 
		return 0
	}
}
Make more sense now?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Still, none of those putlogs are responsible for that error of yours.. That error is elsewhere in your script.

=====

A quick rule of thumb, do not use the name "args" for any argument name in your procs. This is a special name, which has some extended features and caveats. Unless you are an advanced coder, you will have no use for those features, and the caveats are such that you need that [lindex $args 0] whenever you try to process the last argument.

Next, there are two fundamentally different data types in tcl. These are strings, and lists. Only use list-commands such as lindex, lrange, etc. on lists, never strings. If you need to "convert" a string into a list, use the command split. At the same time, don't use lists when a command expects a string.
NML_375
p
psychic
Voice
Posts: 5
Joined: Tue Sep 02, 2008 11:07 am

Post by psychic »

Alright, but can we focus a bit on the "newchanban" thingy? Can you tell me a correct syntax of using newchanban here? I mean in my code. ( I did change $args to a different name too)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Syntax for newchanban seems pretty much ok:
"newchanban <channel> <ban> <creator> <comment> ?lifetime? ?options?"

So, assuming arg2, arg3, and arg4 has been properly set, that part should work like a charm.
NML_375
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

set passed_data [lrange [lindex $args 0] 0 end]
putlog $passed_data
There is your error. You use lrange incorrectly, and passed_data becomes a list. When you try to putlog this list, it causes dilemma. Using putlog "$passed_data" with double quotes encapsulating the list variable is a way to fix it. You can also try a putlog [join $passed_data], but it doesn't corrected the flawed list/string relationships. You will see curly braces denoting list fields. Perhaps consider the lessons learned from nml375 concerning lists vs strings and vice versa.
Last edited by speechles on Tue Sep 02, 2008 7:44 pm, edited 1 time in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Messing up lists and strings is indeed a problem within this script, but it will not cause the error mentioned in the original post. Regardless of the type of data, it's still one single parameter, so putlog would not complain 'bout number of parameters.
NML_375
p
psychic
Voice
Posts: 5
Joined: Tue Sep 02, 2008 11:07 am

Post by psychic »

Thanks all, I got it all working and much better now. Thanks to the guys on IRCNet #Eggdrop!

Thanks all!
Post Reply