Class: Async::Matrix::ApplicationService::Bot::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/async/matrix/application_service/bot.rb

Overview

Internal handler object produced by the #on DSL method. Conforms to the TransactionHandler duck-type: #event_types, #call.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bot:, event_types:, msgtype:, not_from:, block:) ⇒ Handler

Returns a new instance of Handler.



66
67
68
69
70
71
72
# File 'lib/async/matrix/application_service/bot.rb', line 66

def initialize(bot:, event_types:, msgtype:, not_from:, block:)
  @bot         = bot
  @event_types = event_types
  @msgtype     = msgtype
  @not_from    = not_from
  @block       = block
end

Instance Attribute Details

#event_typesObject (readonly)

Returns the value of attribute event_types.



64
65
66
# File 'lib/async/matrix/application_service/bot.rb', line 64

def event_types
  @event_types
end

Instance Method Details

#call(event) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/async/matrix/application_service/bot.rb', line 74

def call(event)
  return if @msgtype  && event.content&.msgtype != @msgtype
  return if @not_from == :self && event.sender == @bot.client.config.bot_mxid

  # Execute the block in a context that has helper methods
  Context.new(@bot.client).execute(event, &@block)
end