Class: Lita::Handlers::TaskScheduler

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/task_scheduler.rb

Instance Method Summary collapse

Instance Method Details

#rebroadcast(payload) ⇒ Object



8
9
10
11
12
# File 'lib/lita/handlers/task_scheduler.rb', line 8

def rebroadcast(payload)
  serialized = serialize_message(payload)

  resend(serialized)
end

#resend(serialized) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lita/handlers/task_scheduler.rb', line 14

def resend(serialized)
  user = Lita::User.new(serialized.fetch(:user_name))
  room = Lita::Room.new(serialized.fetch(:room_name))
  source = Lita::Source.new(user: user, room: room)

  newmsg = Lita::Message.new(
    robot,
    "#{robot.name} double #{rand(1..100)}",
    source
  )

  robot.receive newmsg
end

#serialize_message(payload) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/lita/handlers/task_scheduler.rb', line 28

def serialize_message(payload)
  msg = payload.fetch(:message)

  {
    user_name: msg.user.name,
    room_name: msg.source.room,
    body: msg.body
  }
end