# -----------------------------------------------------------------
# --- file:        strigger
# --- date:        2 mar. 2002
# --- revised by:  Selim
# --- revised on:  3 mar. 2002
# --- author:      Frank Scherthan aka Taros
# --- email:       t.a.r.o.s@gmx.de
# --- mud name:    Tubmud
# --- mud ip/port: ?
# --- mud base:    LP
# --- comments:    strigger: an easy way to add trigger procs to the
# ---              session. (
# ---              Even good for highlighting text you receive from
# ---              the mud! ;)
# ---
# --- ex.:
# ---  strigger NAME REGEXP TODO
# ---   where NAME is a unique name for your trigger (needed for the action-system)
# ---   where REGEXP is any regular expression (RTFM ;) )
# ---   where TODO is the expression that should be done (=executed)
# ---
# --- if the mud sends the sting like '... died.' you take all from corpse
# ---  strigger die {.* died.*} {take all from corpse}
# ---
# --- if someone tells you something, it will be shown in green
# ---  strigger tell {.*tells you.*} {::smm::tag FGgreen}
# ---
# --- removes the tigger named 'die'
# ---  unstrigger die
#

::smm::showme "strigger loaded!"

::set regexp "reg"
::set todo "do"

::proc strigger {name _regexp _todo} {
    ::variable regexp
    ::variable todo

    ::set regexp $_regexp
    ::set todo $_todo

    ::proc $name {line} {
	::variable todo
	::variable regexp
	::if {[::regexp $regexp $line]} {
	    ::eval $todo
	}
    }

    ::smm::action::set $name 10
}

::proc unstrigger {name} {
    ::smm::action::unset $name
}