Class: Aide::ActionContext

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#botObject

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

#fromObject

String - The Jabber address from which the message was sent.



11
12
13
# File 'lib/aide/actioncontext.rb', line 11

def from
  @from
end

#messageObject

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
  @message
end

#textObject

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

#toObject

String - The Jabber address to which the message was sent.



13
14
15
# File 'lib/aide/actioncontext.rb', line 13

def to
  @to
end

#typeObject

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