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.

get executed command

Help for those learning Tcl or writing their own scripts.
Post Reply
r
romb
Voice
Posts: 2
Joined: Wed Oct 17, 2007 8:34 pm

get executed command

Post by romb »

hello all!
i am need get command executed by user on channel.
example:

Code: Select all

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
User avatar
YooHoo
Owner
Posts: 939
Joined: Thu Feb 13, 2003 10:07 pm
Location: Redwood Coast

Re: get executed command

Post by YooHoo »

romb wrote:hello all!
i am need get command executed by user on channel.
example:

Code: Select all

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?
r
romb
Voice
Posts: 2
Joined: Wed Oct 17, 2007 8:34 pm

Post by romb »

user on channel types !command1 or !command2 or !command3
and in function i gets command1 or command2 or command3
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

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: Select all

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"?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

A more generic way of doing it would be to use the "lastbind" global variable:

Code: Select all

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
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

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 :P

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: Select all

# 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"?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
Post Reply