Code: Select all
set con(f2c) {blah blah blah}
set con(c2f) {blah blah blah}
foreach cmd [array names con] {
bind pub - !$cmd [list pub_handler $cmd]
bind msg - !$cmd [list msg_handler $cmd]
bind dcc - $cmd [list dcc_handler $cmd]
}
proc pub_handler {cmd nick uhost hand chan text} {
global con
# con($cmd) is the entry for this thing
}
proc msg_handler {cmd nick uhost hand text} {
global con
# con($cmd) is the entry for this thing
}
...
Code: Select all
foreach cmd [array names con] {
bind dcc - $cmd [list con_form $cmd d]
bind msg - !$cmd [list con_form $cmd m]
bind pub - !$cmd [list con_form $cmd p]
}
proc con_form {cmd method args} {
if {$method == "p"} {set dest [lindex $args 4]} <-- channel
if {$method == "m"} {set dest [lindex $args 0]} <-- nick
if {$method == "d"} {set dest [lindex $args 1]} <-- idx
set arg [lindex $args end]
...
}
Code: Select all
proc newalg {args} {
global con
set cmd [lindex $args 0]
set text [join [lrange $args 1 end]]
regsub -all x $text { ($arg) }
# For extra points, regsub x**y and x^y to pow(x,y)
set con($cmd) $text
}
newalg square x * x
newalg cuberoot pow(x, 1/3)
...