Class: Del::Robot

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

Overview

A funky robo-sapien.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration: Del.configuration) ⇒ Robot

Returns a new instance of Robot.



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

def initialize(configuration: Del.configuration)
  @configuration = configuration
  @jid = configuration.jid
  @name = configuration.name
end

Instance Attribute Details

#jidObject (readonly)

Returns the value of attribute jid.



6
7
8
# File 'lib/del/robot.rb', line 6

def jid
  @jid
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/del/robot.rb', line 6

def name
  @name
end

Instance Method Details

#get_funky!(start_server: true) ⇒ Object



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

def get_funky!(start_server: true)
  Del.logger.info('🔥🔥🔥')
  xmpp_connection.connect(self)
  if start_server
    deltron = Del::Tron.new(self, configuration)
    socket_server.run(deltron)
  end
rescue Interrupt
  xmpp_connection.disconnect
end

#receive(message, source:) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/del/robot.rb', line 25

def receive(message, source:)
  return if source.from?(self)

  configuration.router.route(
    Message.new(message, robot: self, source: source)
  )
end

#send_message(jid, message) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/del/robot.rb', line 33

def send_message(jid, message)
  if user?(jid)
    xmpp_connection.deliver(jid, message)
  else
    xmpp_connection.deliver_to_room(jid, message)
  end
end