Class: Robut::PM

Inherits:
Presence show all
Defined in:
lib/robut/pm.rb

Instance Attribute Summary

Attributes inherited from Presence

#connection

Instance Method Summary collapse

Methods inherited from Presence

#handle_message

Constructor Details

#initialize(connection, rooms) ⇒ PM

Returns a new instance of PM.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/robut/pm.rb', line 3

def initialize(connection, rooms)
  # Add the callback from direct messages. Turns out the
  # on_private_message callback doesn't do what it sounds like, so I
  # have to go a little deeper into xmpp4r to get this working.
  self.connection = connection
  connection.client.add_message_callback(200, self) do |message|
    from_room = rooms.any? {|room| room.muc.from_room?(message.from)}
    if !from_room && message.type == :chat && message.body
      time = Time.now # TODO: get real timestamp? Doesn't seem like
                      # jabber gives it to us
      sender_jid = message.from
      plugins = Robut::Plugin.plugins.map { |p| p.new(self, sender_jid) }
      handle_message(plugins, time, connection.roster[sender_jid].iname, message.body)
      true
    else
      false
    end
  end
end

Instance Method Details

#reply(message, to) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/robut/pm.rb', line 23

def reply(message, to)
  unless to.kind_of?(Jabber::JID)
    to = find_jid_by_name(to)
  end

  msg = Jabber::Message.new(to, message)
  msg.type = :chat
  connection.client.send(msg)
end