regexp triggers

Bug #416111 reported by odbrazen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
leanlyn
Fix Committed
Undecided
Unassigned

Bug Description

We need a simple one-line way to add triggers. This is possible now, [see basiccommands.ReMatchTrig] but not full featured. One possibility is cribbing the syntax from lyntin. Another is populating the interactive interpreter namespace with helper functions (I like this solution better) eg/
  @add_trig('^\w falls down dead', 'loot corpse')
would expand to
  def add_trig(re_text, send_text):
    sess = engine.sessions[0] # current session
    trig = catcher.REMatch(re_text, listen=1)
    def send_text(dummy):
      sess.to_mud(send_text + "\n")
    trig.add_callback(send_text)
    sess.icatch(trig) # add the catcher to the incoming text stream

Since commands starting with '@' use the python interactive interpreter we wouldn't have to do any parsing by hand. Also, the syntax is familiar to anyone that knows python (and/or it teaches python to people who don't know it).

Tags: beta
Revision history for this message
odbrazen (odbrazen) wrote :

to add a trigger
@trigger('your regexp here', 'this gets executed as if typed in the entry box', listen=1, no_ansi=True)
the options are passed to the catcher.REMatch.__init__ so for one-shot triggers include count=1, for muffles use muffle=True, etc

added the '#triggers ' command which can be used to list/delete triggers created with the @trigger command.

Changed in leanlyn:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.