Class: Aide::ActionContext
- Inherits:
-
Object
- Object
- Aide::ActionContext
- Defined in:
- lib/aide/actioncontext.rb
Overview
This class is used to provide an execution context for processing messages. It houses all the attributes and helper methods that are to be exposed to the blocks that are passed in to Aide via the Aide::Dsl.with method. These contexts are created and destroyed on a per-message basis, so all attribute values refer to the message that is currently being processed.
Instance Attribute Summary collapse
-
#bot ⇒ Object
Aide::Bot - The bot instance that received and is acting on this message.
-
#from ⇒ Object
String - The Jabber address from which the message was sent.
-
#message ⇒ Object
String - The text of the message, minus the portion that was matched by the bot.
-
#text ⇒ Object
String - The full text of the message, including the portion that was matched by the bot.
-
#to ⇒ Object
String - The Jabber address to which the message was sent.
-
#type ⇒ Object
Symbol - The type of the message (e.g. :chat, :group, etc.).
Instance Method Summary collapse
-
#respond(msg) ⇒ Object
Sends a message back to the jabber id that sent the original message.
-
#send(msg, rec) ⇒ Object
Sends a message to the specified jabber id.
Instance Attribute Details
#bot ⇒ Object
Aide::Bot - The bot instance that received and is acting on this message.
24 25 26 |
# File 'lib/aide/actioncontext.rb', line 24 def bot @bot end |
#from ⇒ Object
String - The Jabber address from which the message was sent.
11 12 13 |
# File 'lib/aide/actioncontext.rb', line 11 def from @from end |
#message ⇒ Object
String - The text of the message, minus the portion that was matched by the bot.
16 17 18 |
# File 'lib/aide/actioncontext.rb', line 16 def @message end |
#text ⇒ Object
String - The full text of the message, including the portion that was matched by the bot.
19 20 21 |
# File 'lib/aide/actioncontext.rb', line 19 def text @text end |
#to ⇒ Object
String - The Jabber address to which the message was sent.
13 14 15 |
# File 'lib/aide/actioncontext.rb', line 13 def to @to end |
#type ⇒ Object
Symbol - The type of the message (e.g. :chat, :group, etc.)
21 22 23 |
# File 'lib/aide/actioncontext.rb', line 21 def type @type end |
Instance Method Details
#respond(msg) ⇒ Object
Sends a message back to the jabber id that sent the original message.
Parameters:
-
msg: String. The text of the message to send.
31 32 33 |
# File 'lib/aide/actioncontext.rb', line 31 def respond(msg) send(msg, from) end |
#send(msg, rec) ⇒ Object
Sends a message to the specified jabber id.
Parameters:
-
msg: String. The text of the message to send.
-
rec: String. The jabber id to send the message to.
41 42 43 44 45 46 |
# File 'lib/aide/actioncontext.rb', line 41 def send(msg, rec) response = Jabber::Message.new(rec, msg) response.type = :chat bot.send(response) end |