Using Bind msg and Bind Pub for one Proc

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
ComputerTech
Master
Posts: 400
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Using Bind msg and Bind Pub for one Proc

Post by ComputerTech »

Is it possible to let Bind Msg and Bind Pub use the same proc?

Like

Code: Select all

bind pub - !blah blah:blah

bind msg - blah blah:blah

proc blah:blah {nick host hand chan text} { 
putserv "PRIVMSG $chan :blah"
}
but somehow remove the variable "text" in the proc when using bind msg?

Thanks in advanced :D
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1384
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

No, you can't. In msg, you don't have the channel.
You can just do the following to "translate" pub to msg:

Code: Select all

bind pub - !blah pub:blah
bind msg - !blah blah

proc pub:blah {nick uhost handle chan text} {
   blah $nick $uhost $handle $text
}

proc blah {nick uhost handle text} {
   putserv "PRIVMSG $nick :hello"
}
Or you can do the other way, but you'll have to force msg to be something like "!blah #chan hello pple":

Code: Select all

bind pub - !blah blah
bind msg - !blah msg:blah

proc blah {nick uhost handle chan text} {
   putserv "PRIVMSG $chan :$text"
}

proc msg:blah {nick uhost handle text} {
   set chan [join [lindex [split $text] 0]]
   # check that $chan is really a channel or exit
   set msg [join [lrange [split $text] 1 end]]
   blah $nick $uhost $handle $chan $msg
}
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Re: Using Bind msg and Bind Pub for one Proc

Post by willyw »

ComputerTech wrote: ...
but somehow remove the variable "text" in the proc when using bind msg?

When calling the proc with a bind msg, how is it going to know what channel to post in? Is it fixed?.... just one channel?... and thus you can hard code it?

In other words: Need more info.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
Post Reply