Class: Del::Robot

Inherits:
Object
  • Object
show all
Defined in:
lib/del/robot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration:) ⇒ Robot

Returns a new instance of Robot.



5
6
7
8
9
10
11
12
13
# File 'lib/del/robot.rb', line 5

def initialize(configuration:)
  @users = UserRepository.new
  @rooms = RoomRepository.new
  @connection = Connection.new(
    configuration: configuration,
    users: users,
    rooms: rooms,
  )
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



3
4
5
# File 'lib/del/robot.rb', line 3

def connection
  @connection
end

#roomsObject (readonly)

Returns the value of attribute rooms.



3
4
5
# File 'lib/del/robot.rb', line 3

def rooms
  @rooms
end

#usersObject (readonly)

Returns the value of attribute users.



3
4
5
# File 'lib/del/robot.rb', line 3

def users
  @users
end

Instance Method Details

#receive(message) ⇒ Object



22
23
24
25
# File 'lib/del/robot.rb', line 22

def receive(message)
  return if message.type == :error || message.body.nil?
  send_message(message.from, message.body)
end

#runObject



15
16
17
18
19
20
# File 'lib/del/robot.rb', line 15

def run
  connection.connect(self)
  sleep
rescue Interrupt
  connection.disconnect
end

#send_message(jid, message) ⇒ Object



27
28
29
# File 'lib/del/robot.rb', line 27

def send_message(jid, message)
  connection.deliver(jid, message)
end