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.

common command with multiple variants/subcommands ?

Old posts that have not been replied to for several years.
Locked
k
kain
Halfop
Posts: 91
Joined: Fri Mar 15, 2002 8:00 pm
Contact:

common command with multiple variants/subcommands ?

Post by kain »

Hi,
Heres what im trying to do. ive got it going one way but i'd like to know if theres a better way of doing it.

I want to add a common command "add" which has 4 subcommands "owner/master/op/voice" followed by "nick/handle"
it would work something like this:

pub:
<kain> add owner person
<bot> Person is now a channel owner on #channel!
the same would work for master/op/voice
the second common command is "del" with subcommands "owner/master/op/voice" followed by "nick/handle"
the final one is the same as "add" but if the nick isnt on the channel you can use "add hand owner <handle>"
ive almost got it working but i wanted to know if there is a better way to add a common command and a list of subcommands which would be bound, rather than having a long list.
any help / ideas would be great :)
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

There is no way to sub-bind in eggdrop.

You would have to bind the "add" command, and then filter what is being said within the script, using either switch of if-elseif-else statments.

EG

bind pub n|n add pub:add:command
proc pub:add:command {nick uh hand chan arg} {
switch -exact -- [lindex [split [string tolower $arg]] 0] {
"owner" { chattr [lindex [split $arg] 1] +n $chan }
"master { chattr [lindex [split $arg] 1] +m $chan }
"op" {chattr [lindex [split $arg] 1] +o $chan }
"handle" {
switch -exact -- [lindex [split [string tolower $arg]] 1] {
"owner" {blah}
"master" {blah}
}
}
}
[/code]
k
kain
Halfop
Posts: 91
Joined: Fri Mar 15, 2002 8:00 pm
Contact:

Post by kain »

ahh, thats what i was doing, the switch anyway, have a look at this code, some of it might look a bit weird/wrong, which it probably is, but its part of a much larger script(which works), i'll try and include everything.

Code: Select all

   set add_pubcmd {
      "add"
      "del"
   }
   switch $add_pubcmd {
               "add" {
                  if {[lindex ${origtext} 0]=="owner"} {
                     pub_add_owner [lindex [split ${origtext} " "] 1] $chan $nick
                  }
               
               }
               
               "del" {
                  if {[lindex ${origtext} 0]=="owner"} {
                     pub_del_owner [lindex [split ${origtext} " "] 1] $chan $nick
                  }
               
               }
bind pub n|- owner pub_add_owner
proc pub_add_owner {nick host hand chan arg} {
  if { $arg == "" } {
    putserv "NOTICE $nick :Usage: add owner <handle>"
    return
  }
  chattr $arg |+n $chan
  putserv "PRIVMSG $chan :$nick is now a channel owner for $chan!"
  putloglev c $chan "($nick!$host) $hand $chan <<ADD OWNER>> $arg"
}
bind pub n|- owner pub_del_owner
proc pub_del_owner {nick host hand chan arg} {
    if { $arg == "" } {
    putserv "NOTICE $nick :Usage: del owner <handle>"
    return
  }
    if { ![validuser $arg] } {
    putserv "NOTICE $nick :Error: invalid handle."
    return
  }
  chattr $arg |-n $chan
  putserv "NOTICE $nick :Removed $arg as owner on $chan."
  putloglev c $chan "($nick!$host) $hand $chan <<DEL OWNER>> $arg"
}
its probably obvious that im no tcl god lol, but i try :-?
thanks again ppslim
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

An easy way to do subcommands would be to use the pubm bind, since it allows you to do more than one word. For instance:

Code: Select all

bind pubm n "add op *" pub_add_op
bind pubm n "add master" pub_add_master
bind pubm n "add owner *" pub_add_owner

proc pub_add_op {nick uhost hand chan text} {
  ...
}
This looks a lot easier than that switch statement heh.
k
kain
Halfop
Posts: 91
Joined: Fri Mar 15, 2002 8:00 pm
Contact:

Post by kain »

wow that looks so simple.
i'll try both and run each one for a week, see if i get any problems.
thanks both
k
kain
Halfop
Posts: 91
Joined: Fri Mar 15, 2002 8:00 pm
Contact:

Post by kain »

ppslim:
when i tried your code out i got this:

Code: Select all

Tcl error [pub:add:command]: list element in quotes followed by "op"" instead of space
maybe regsub would work?
k
kain
Halfop
Posts: 91
Joined: Fri Mar 15, 2002 8:00 pm
Contact:

Post by kain »

forgot to add:
i get that same error when trying any of the commands owner/master/op/voice
k
kain
Halfop
Posts: 91
Joined: Fri Mar 15, 2002 8:00 pm
Contact:

Post by kain »

i tried a few things and i still get that error, was looking good too :-?
Locked