class SardonyxRing::Handlers::MessageHandler

Attributes

pattern[R]

Public Class Methods

new(pattern, callback) click to toggle source
# File lib/sardonyx_ring/handlers/message_handler.rb, line 6
def initialize(pattern, callback)
  @pattern = pattern
  @callback = callback
end

Public Instance Methods

match(message) click to toggle source
# File lib/sardonyx_ring/handlers/message_handler.rb, line 18
def match(message)
  case @pattern
  when String
    @pattern if message.text == @pattern
  when Regexp
    message.text&.match(@pattern)
  end
end
run(app, message_event, match = nil) click to toggle source
# File lib/sardonyx_ring/handlers/message_handler.rb, line 13
def run(app, message_event, match = nil)
  args = [message_event, match].slice(0, @callback.arity)
  @callback.bind(app).call(*args)
end