egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

get executed command

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
romb
Voice


Joined: 17 Oct 2007
Posts: 2

PostPosted: Wed Oct 17, 2007 8:48 pm    Post subject: get executed command Reply with quote

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
View user's profile Send private message
YooHoo
Owner


Joined: 13 Feb 2003
Posts: 939
Location: Redwood Coast

PostPosted: Thu Oct 18, 2007 12:40 am    Post subject: Re: get executed command Reply with quote

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?
_________________
Mr. Green
Johoho's TCL for beginners
Mr. Green
Back to top
View user's profile Send private message Send e-mail
romb
Voice


Joined: 17 Oct 2007
Posts: 2

PostPosted: Thu Oct 18, 2007 3:50 am    Post subject: Reply with quote

user on channel types !command1 or !command2 or !command3
and in function i gets command1 or command2 or command3
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Thu Oct 18, 2007 4:19 am    Post subject: Reply with quote

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
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Thu Oct 18, 2007 6:36 am    Post subject: Reply with quote

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
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Fri Oct 19, 2007 5:04 am    Post subject: Reply with quote

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 Razz

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
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Fri Oct 19, 2007 1:13 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber