| View previous topic :: View next topic |
| Author |
Message |
psychic Voice
Joined: 02 Sep 2008 Posts: 5
|
Posted: Tue Sep 02, 2008 11:10 am Post subject: newchanban issue |
|
|
This is a part of my tcl which is not working and I get this error wrong # args: should be "putlog text"
| Code: |
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? |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Sep 02, 2008 1:06 pm Post subject: |
|
|
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: | ...
proc command {nick host hand text} {
set tlist [split $text]
set cmd [lindex $tlist 0]
...
} |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
psychic Voice
Joined: 02 Sep 2008 Posts: 5
|
Posted: Tue Sep 02, 2008 1:53 pm Post subject: |
|
|
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: | 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? |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Sep 02, 2008 2:03 pm Post subject: |
|
|
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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
psychic Voice
Joined: 02 Sep 2008 Posts: 5
|
Posted: Tue Sep 02, 2008 2:11 pm Post subject: |
|
|
| 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) |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Sep 02, 2008 2:27 pm Post subject: |
|
|
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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Tue Sep 02, 2008 7:40 pm Post subject: |
|
|
| Code: | 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. _________________ speechles' eggdrop tcl archive
Last edited by speechles on Tue Sep 02, 2008 7:44 pm; edited 1 time in total |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Sep 02, 2008 7:44 pm Post subject: |
|
|
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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
psychic Voice
Joined: 02 Sep 2008 Posts: 5
|
Posted: Tue Sep 02, 2008 10:24 pm Post subject: |
|
|
Thanks all, I got it all working and much better now. Thanks to the guys on IRCNet #Eggdrop!
Thanks all! |
|
| Back to top |
|
 |
|