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.
87 88 89 |
# File 'lib/async/matrix/application_service/bot.rb', line 87 def initialize(client) @client = client end |
Instance Method Details
#client ⇒ Object
120 121 122 |
# File 'lib/async/matrix/application_service/bot.rb', line 120 def client @client end |
#execute(event, &block) ⇒ Object
91 92 93 94 |
# File 'lib/async/matrix/application_service/bot.rb', line 91 def execute(event, &block) @event = event instance_exec(event, &block) end |
#join_room(room_id) ⇒ Object
108 109 110 |
# File 'lib/async/matrix/application_service/bot.rb', line 108 def join_room(room_id) @client.join_room(room_id) end |
#leave_room(room_id) ⇒ Object
112 113 114 |
# File 'lib/async/matrix/application_service/bot.rb', line 112 def leave_room(room_id) @client.leave_room(room_id) end |
#send_html(room_id, html, plaintext = nil) ⇒ Object
100 101 102 |
# File 'lib/async/matrix/application_service/bot.rb', line 100 def send_html(room_id, html, plaintext = nil) @client.send_html(room_id, html, plaintext) end |
#send_notice(room_id, text) ⇒ Object
104 105 106 |
# File 'lib/async/matrix/application_service/bot.rb', line 104 def send_notice(room_id, text) @client.send_notice(room_id, text) end |
#send_text(room_id, text) ⇒ Object
96 97 98 |
# File 'lib/async/matrix/application_service/bot.rb', line 96 def send_text(room_id, text) @client.send_text(room_id, text) end |
#set_display_name(name, user_id = nil) ⇒ Object
116 117 118 |
# File 'lib/async/matrix/application_service/bot.rb', line 116 def set_display_name(name, user_id = nil) @client.set_display_name(name, user_id) end |