コード例 #1
0
  def checkActions(self, text):
    """
    Checks to see if text triggered any actions.  Any resulting 
    actions will get added as an InputEvent to the queue.

    @param text: the data coming from the mud to check for triggers
    @type  text: string
    """
    # FIXME - make sure this works even when lines are broken up.

    actionlist = self._actionlist
    if not actionlist:
      actionlist = [x for x in list(self._actions.values()) if x[6] not in self._disabled]
      actionlist.sort(key = lambda x:x[3])
      self._actionlist = actionlist

    colorline = utils.filter_cm(text)
    nocolorline = ansi.filter_ansi(colorline)

    # go through all the lines in the data and see if we have
    # any matches
    for (action, actioncompiled, response, color, priority, onetime, tag) in actionlist:
      if color:
        match = actioncompiled.search(colorline)
        line = colorline
      else:
        match = actioncompiled.search(nocolorline)
        line = nocolorline

      if match:
        # for every match we figure out what the expanded response
        # is and add it as an InputEvent in the queue.  the reason
        # we do a series of separate events rather than one big
        # event with ; separators is due to possible issues with 
        # braces and such in malformed responses.

        # get variables from the action
        actionvars = get_ordered_vars(action)

        # fill in values for all the variables in the match
        varvals = {}
        for i in range(len(actionvars)):
          varvals[actionvars[i]] = match.group(i+1)

        # add special variables
        varvals['a'] = line.replace(';', '_')
            
        # fill in response variables from those that
        # matched on the trigger
        response = utils.expand_vars(response, varvals)

        # event.InputEvent(response, internal=1, ses=self._ses).enqueue()
        try:
          exported.lyntin_command(response, internal=1, session=self._ses)
        except:
          exported.write_traceback()

        if onetime and action in self._actions:
          del self._actions[action]
          self._actionlist = None           # invalidate the list
コード例 #2
0
 def expand_command(self, ses, text):
   t = utils.expand_vars(text, session.Session.global_vars)
   return utils.expand_vars(t, ses._vars)
コード例 #3
0
 def expand(self, ses, text):
   t = utils.expand_vars(text, session.Session.global_vars)
   t = utils.expand_vars(t, ses._vars)
   return utils.denest_vars(t, {})
コード例 #4
0
ファイル: action.py プロジェクト: OSadovy/lyntin
  def checkActions(self, text):
    """
    Checks to see if text triggered any actions.  Any resulting 
    actions will get added as an InputEvent to the queue.

    @param text: the data coming from the mud to check for triggers
    @type  text: string
    """
    # FIXME - make sure this works even when lines are broken up.

    actionlist = self._actionlist
    if not actionlist:
      actionlist = filter(lambda x: not self._disabled.has_key(x[6]),
                          self._actions.values())
      actionlist.sort(key=lambda i: i[3])
      self._actionlist = actionlist

    colorline = utils.filter_cm(text)
    nocolorline = ansi.filter_ansi(colorline)

    # go through all the lines in the data and see if we have
    # any matches
    for (action, actioncompiled, response, color, priority, onetime, tag) in actionlist:
      if color:
        match = actioncompiled.search(colorline)
        line = colorline
      else:
        match = actioncompiled.search(nocolorline)
        line = nocolorline

      if match:
        # for every match we figure out what the expanded response
        # is and add it as an InputEvent in the queue.  the reason
        # we do a series of separate events rather than one big
        # event with ; separators is due to possible issues with 
        # braces and such in malformed responses.

        # fill in values for all the variables in the match
        varvals = {}
        if match.lastindex is not None:
          if action.startswith('r['):
            for i in xrange(match.lastindex):
              varvals[str(i+1)] = match.group(i+1)
          else:
            # get variables from the action
            actionvars = get_ordered_vars(action)
            for i in xrange(len(actionvars)):
              varvals[actionvars[i]] = match.group(i+1)

        # add special variables
        varvals['a'] = line.replace(';', '_')
            
        # fill in response variables from those that
        # matched on the trigger
        response = utils.expand_vars(response, varvals)

        # event.InputEvent(response, internal=1, ses=self._ses).enqueue()
        try:
          exported.lyntin_command(response, internal=1, session=self._ses)
        except:
          exported.write_traceback()

        if onetime and self._actions.has_key(action):
          del self._actions[action]
          self._actionlist = None           # invalidate the list
コード例 #5
0
ファイル: lyntinunittest.py プロジェクト: OSadovy/lyntin
 def testExpandVars(self):
   """tests lyntin.utils.expand_vars"""
   from lyntin.utils import expand_vars
   for i in range(0, len(self.t)):
     c, s = self.t[i]
     self.assertEquals(expand_vars(c, self.varmap), s, "test %d" % i)
コード例 #6
0
ファイル: variable.py プロジェクト: OSadovy/lyntin
 def expand_command(self, ses, text):
     t = utils.expand_vars(text, session.Session.global_vars)
     return utils.expand_vars(t, ses._vars)
コード例 #7
0
ファイル: variable.py プロジェクト: OSadovy/lyntin
 def expand(self, ses, text):
     t = utils.expand_vars(text, session.Session.global_vars)
     t = utils.expand_vars(t, ses._vars)
     return utils.denest_vars(t, {})
コード例 #8
0
 def testExpandVars(self):
     """tests lyntin.utils.expand_vars"""
     from lyntin.utils import expand_vars
     for i in range(0, len(self.t)):
         c, s = self.t[i]
         self.assertEquals(expand_vars(c, self.varmap), s, "test %d" % i)