lib/rubo/robot.rb
# Adds a Listener that attempts to match incoming messages directed
# at the # robot based on a Regex.
# All regexes treat patterns like they begin with a '^'
#
# @param regex [Regexp] A Regex that determines
#   if the callback should be called.
# @yield [message] A Function that is called with a Response object.
# @yieldparam message [Response]
# @return [void]
Adds a Listener that attempts to match incoming messages directed
at the # robot based on a Regex.
All regexes treat patterns like they begin with a '^'
Adds a Listener that attempts to match incoming messages directed at the # robot based on a Regex . All regexes treat patterns like they begin with a ' ^ '
def respond(regex, &block)
      pattern = regex.source
      options = regex.options
      if pattern[0] == '^'
        logger.warn \
          "Anchors don't work well with respond, perhaps you want to use 'hear'"
        logger.warn "The regex in question was #{regex}"
      end
      name = self.name.to_s.gsub(/[-\[\]{}()*+?.,\\^$|#\s]/, '\\$&')
      regex = (
        if self.alias_name
          alias_name = self.alias_name.to_s.gsub(
            /[-\[\]{}()*+?.,\\^$|#\s]/,
            '\\$&'
          )
          Regexp.new(
            "^[@]?(?:#{alias_name}[:,]?|#{name}[:,]?)\\s*(?:#{pattern})",
            options
          )
        else
          Regexp.new("^[@]?#{name}[:,]?\\s*(?:#{pattern})", options)
        end
      )
      @listeners << TextListener.new(self, regex, &block)
    end
def respond ( regex , & block ) pattern = regex . source options = regex . options if pattern [ 0 ] == '^' logger . warn "Anchors don't work well with respond, perhaps you want to use 'hear'" logger . warn "The regex in question was #{regex}" end name = self . name . to_s . gsub ( / [- \[ \] {}()*+?., \\ ^$|# \s ] / , '\\$&' ) regex = ( if self . alias_name alias_name = self . alias_name . to_s . gsub ( / [- \[ \] {}()*+?., \\ ^$|# \s ] / , '\\$&' ) Regexp . new ( "^[@]?(?:#{alias_name}[:,]?|#{name}[:,]?)\\s*(?:#{pattern})" , options ) else Regexp . new ( "^[@]?#{name}[:,]?\\s*(?:#{pattern})" , options ) end ) @listeners << TextListener . new ( self , regex , & block ) end
Adds a Listener that attempts to match incoming messages directed
at the # robot based on a Regex.
Adds a Listener that attempts to match incoming messages directed at the # robot based on a Regex .
None
void
regex
A Regex that determines if the callback should be called.
A Regex that determines if the callback should be called .
block
<not_specific>
]
<not_specific>
A Function that is called with a Response object.
A Function that is called with a Response object .
<not_specific>
None