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.

I need help with binding multiple commands to one proc

Help for those learning Tcl or writing their own scripts.
Post Reply
t
terron
Voice
Posts: 3
Joined: Mon Oct 11, 2010 2:22 am

I need help with binding multiple commands to one proc

Post by terron »

I have a bind,

Code: Select all

 bind pub - !sysinfo pub:syscmd
What I'd like to do is something like this:

Code: Select all

bind pub - !sysinfo pub:syscmd(sysinfo)
bind pub - !date pub:syscmd(date)
etc
So that I can have just one proc for the command rather than having to copy/paste it (and keep the code synced when I want to make changes) for each command I add.

Is this possible?

Additionally, it'd be great if there was some way to only have one bind with some sort of boolean to only match the specific commands I want to add and then reference the matched text in the command, but I can't find anything in the reference manuals. Something like

Code: Select all

bind pub - !{sysinfo|date} pub:syscmd($matchedtext}
but I can't find that in the manual either.

Any help would be greatly appreciated. Thanks
[/code]
t
thommey
Halfop
Posts: 76
Joined: Tue Apr 01, 2008 2:59 pm

Post by thommey »

If you need an additional static parameter, use this:

Code: Select all

bind pub - !sysinfo "myproc sysinfo"
bind pub - !bla "myproc bla"
proc myproc {param nick host hand chan text} {
# $param is now either "sysinfo" or "bla"
}
If you want to know which bindmask (trigger for bind pub) matched, do this:

Code: Select all

bind pub - !sysinfo myproc
bind pub - !bla myproc
proc myproc {nick host hand chan text} {
# $::lastbind contains either "!sysinfo" or "!bla" here
}
If you want a generic bind and do the matching yourself, use a bind type that supports wildcards instead of pub/msg (resp. pubm/msgm)

Code: Select all

# % is a one word wildcards and stands for channel here
bind pubm - "% *" myproc
proc myproc {nick host hand chan text} {
# $text contains the full text including !bla/!sysinfo as first word
}
The last thing you suggest is not possible. However, it just seems to be a shortcut to binding all commands to the respective proc, which you could just do with a loop

Code: Select all

set trigger !
foreach cmd {sysinfo bla uptime foobar} {
bind pub - ${trigger}$cmd "myproc $cmd"
}
here's the reference manual explaining bind types
Post Reply