Class: Async::Matrix::ApplicationService::Bot::Handler
- Inherits:
-
Object
- Object
- Async::Matrix::ApplicationService::Bot::Handler
- Defined in:
- lib/async/matrix/application_service/bot.rb
Overview
Internal handler object produced by the #on DSL method. Conforms to the Dispatcher duck-type: #event_types, #call.
Instance Attribute Summary collapse
-
#event_types ⇒ Object
readonly
Returns the value of attribute event_types.
Instance Method Summary collapse
- #call(event) ⇒ Object
-
#initialize(bot:, event_types:, msgtype:, not_from:, block:) ⇒ Handler
constructor
A new instance of Handler.
Constructor Details
#initialize(bot:, event_types:, msgtype:, not_from:, block:) ⇒ Handler
Returns a new instance of Handler.
68 69 70 71 72 73 74 |
# File 'lib/async/matrix/application_service/bot.rb', line 68 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_types ⇒ Object (readonly)
Returns the value of attribute event_types.
66 67 68 |
# File 'lib/async/matrix/application_service/bot.rb', line 66 def event_types @event_types end |
Instance Method Details
#call(event) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/async/matrix/application_service/bot.rb', line 76 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 |