Class: Robut::Room

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

Overview

Handles connections and responses to different rooms.

Instance Attribute Summary collapse

Attributes inherited from Presence

#connection

Instance Method Summary collapse

Methods inherited from Presence

#handle_message

Constructor Details

#initialize(connection, room_name) ⇒ Room

Returns a new instance of Room.



10
11
12
13
14
# File 'lib/robut/room.rb', line 10

def initialize(connection, room_name)
  self.muc        = Jabber::MUC::SimpleMUCClient.new(connection.client)
  self.connection = connection
  self.name       = room_name
end

Instance Attribute Details

#mucObject

The MUC that wraps the Jabber Chat protocol.



5
6
7
# File 'lib/robut/room.rb', line 5

def muc
  @muc
end

#nameObject

The room jid



8
9
10
# File 'lib/robut/room.rb', line 8

def name
  @name
end

Instance Method Details

#joinObject



16
17
18
19
20
21
22
23
24
# File 'lib/robut/room.rb', line 16

def join
  # Add the callback from messages that occur inside the room
  muc.on_message do |time, nick, message|
    plugins = Robut::Plugin.plugins.map { |p| p.new(self) }
    handle_message(plugins, time, nick, message, name)
  end

  muc.join(self.name + '/' + connection.config.nick)
end

#reply(message, to) ⇒ Object

Send message to the room we’re currently connected to



27
28
29
# File 'lib/robut/room.rb', line 27

def reply(message, to)
  muc.send(Jabber::Message.new(muc.room, message))
end