Class: Async::Matrix::ApplicationService::Bot::Context
- Inherits:
-
Object
- Object
- Async::Matrix::ApplicationService::Bot::Context
- Defined in:
- lib/async/matrix/application_service/bot.rb
Overview
Execution context for handler blocks. Provides helper methods so blocks can call send_notice, join_room, etc. directly without holding a reference to the client.
Instance Method Summary collapse
- #client ⇒ Object
- #execute(event, &block) ⇒ Object
-
#initialize(client) ⇒ Context
constructor
A new instance of Context.
- #join_room(room_id) ⇒ Object
- #leave_room(room_id) ⇒ Object
- #send_html(room_id, html, plaintext = nil) ⇒ Object
- #send_notice(room_id, text) ⇒ Object
- #send_text(room_id, text) ⇒ Object
- #set_display_name(name, user_id = nil) ⇒ Object
Constructor Details
#initialize(client) ⇒ Context
Returns a new instance of Context.
89 90 91 |
# File 'lib/async/matrix/application_service/bot.rb', line 89 def initialize(client) @client = client end |
Instance Method Details
#client ⇒ Object
122 123 124 |
# File 'lib/async/matrix/application_service/bot.rb', line 122 def client @client end |
#execute(event, &block) ⇒ Object
93 94 95 96 |
# File 'lib/async/matrix/application_service/bot.rb', line 93 def execute(event, &block) @event = event instance_exec(event, &block) end |
#join_room(room_id) ⇒ Object
110 111 112 |
# File 'lib/async/matrix/application_service/bot.rb', line 110 def join_room(room_id) @client.join_room(room_id) end |
#leave_room(room_id) ⇒ Object
114 115 116 |
# File 'lib/async/matrix/application_service/bot.rb', line 114 def leave_room(room_id) @client.leave_room(room_id) end |
#send_html(room_id, html, plaintext = nil) ⇒ Object
102 103 104 |
# File 'lib/async/matrix/application_service/bot.rb', line 102 def send_html(room_id, html, plaintext = nil) @client.send_html(room_id, html, plaintext) end |
#send_notice(room_id, text) ⇒ Object
106 107 108 |
# File 'lib/async/matrix/application_service/bot.rb', line 106 def send_notice(room_id, text) @client.send_notice(room_id, text) end |
#send_text(room_id, text) ⇒ Object
98 99 100 |
# File 'lib/async/matrix/application_service/bot.rb', line 98 def send_text(room_id, text) @client.send_text(room_id, text) end |
#set_display_name(name, user_id = nil) ⇒ Object
118 119 120 |
# File 'lib/async/matrix/application_service/bot.rb', line 118 def set_display_name(name, user_id = nil) @client.set_display_name(name, user_id) end |