| View previous topic :: View next topic |
| Author |
Message |
romb Voice
Joined: 17 Oct 2007 Posts: 2
|
Posted: Wed Oct 17, 2007 8:48 pm Post subject: get executed command |
|
|
hello all!
i am need get command executed by user on channel.
example:
| Code: |
proc ::comm::detect { nick uhost hand chan rest } {
#what i need to write this for get command1 or command2 or command3
return 0
}
bind pub - "!command1" ::comm::detect
bind pub - "!command2" ::comm::detect
bind pub - "!command3" ::comm::detect
|
|
|
| Back to top |
|
 |
YooHoo Owner

Joined: 13 Feb 2003 Posts: 939 Location: Redwood Coast
|
Posted: Thu Oct 18, 2007 12:40 am Post subject: Re: get executed command |
|
|
| romb wrote: | hello all!
i am need get command executed by user on channel.
example:
| Code: |
proc ::comm::detect { nick uhost hand chan rest } {
#what i need to write this for get command1 or command2 or command3
return 0
}
bind pub - "!command1" ::comm::detect
bind pub - "!command2" ::comm::detect
bind pub - "!command3" ::comm::detect
|
| it would help if we knew what you were trying to accomplish...ergo, what command? _________________
Johoho's TCL for beginners
 |
|
| Back to top |
|
 |
romb Voice
Joined: 17 Oct 2007 Posts: 2
|
Posted: Thu Oct 18, 2007 3:50 am Post subject: |
|
|
user on channel types !command1 or !command2 or !command3
and in function i gets command1 or command2 or command3 |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Thu Oct 18, 2007 4:19 am Post subject: |
|
|
Sounds like you're looking for the global variable named 'lastbind'.
But then you'd have to update the proc if you change the binds... a way to get around this would be to add an argument to the code in your binds: | Code: | bind pub - !cmd1 {theProc 1}
bind pub - !cmd2 {theProc 2}
proc theProc {cmd nick uhost hand chan arg} {
# $cmd = 1 or 2 depending on what bind was used
}
|
_________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Oct 18, 2007 6:36 am Post subject: |
|
|
A more generic way of doing it would be to use the "lastbind" global variable:
| Code: | bind pub - !cmd1 theProc
proc theProc {nick host hand chan text} {
switch -- $::lastbind {
"!cmd1" {
#Cmd1
}
"!cmd2" {
#Cmd2
}
default {
#Unknown command, default action
}
}
} |
This also opens up possibilities of more advanced command matching, as switch permits both Glob:style and regular expression patterns. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Fri Oct 19, 2007 5:04 am Post subject: |
|
|
| nml375 wrote: | | A more generic way of doing it would be to use the "lastbind" global variable |
Well, I did mention lastbind in my first sentence... I don't know what's "more generic" about it though
My point was to avoid having to update the proc if the keywords change...and you could have several keywords triggering the same command without having to add words to the switch statement:
| Code: |
# internal command name to public trigger keyword mapping(s)
set pubcmd(start) {!start}
set pubcmd(stop) {!stop !abort !exit !avbryt !stopp}
# create the binds:
foreach {cmd keys} [array get pubcmd] {
foreach key $keys {
bind pub - $key [list pubcmd $cmd]
}
}
proc pubcmd {cmd nick uhost hand chan arg} {
switch -- $cmd {
"start" {...}
"stop" {...}
default {error "Configuration error (invalid command name from bind)"}
}
} |
_________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Fri Oct 19, 2007 1:13 pm Post subject: |
|
|
Must've been reading your post too quickly I suppose, my bad.
Advantages of using 'lastbind', imho, is the possibility of wildcard matching, no need to keep track of additional parameters when creating the binding (you can continue to use the same number of parameters as with any other binding of that kind). I also find it easier to use when adding/removing commands/functions to the triggers.
I guess my biggest consern with using added parameters, is to make sure users don't remove/forget the use of list. Last example of yours was nice tho. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|