bot_response.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. class BotResponse
  2. def initialize(destination: nil, text: "", embed: nil, timer: nil, file: nil, carousel: nil, reactions: [])
  3. @destination = destination
  4. @text = text
  5. @timer = timer
  6. @embed = embed
  7. @file = file
  8. @reactions = reactions
  9. @carousel = carousel
  10. end
  11. def call(event, bot)
  12. # Send message and embed(s)
  13. if @file
  14. message = bot.send_file(@destination, File.open(@file, 'r'))
  15. elsif @timer
  16. message = bot.send_temporary_message(
  17. @destination,
  18. @text,
  19. @timer,
  20. false,
  21. @embed
  22. )
  23. elsif @destination
  24. message = bot.send_message(
  25. @destination,
  26. @text,
  27. false,
  28. @embed
  29. )
  30. elsif !@carousel.is_a? Carousel
  31. message = event.send_embed(@text, @embed)
  32. end
  33. # Create/Update Carousel
  34. case @carousel
  35. when Carousel
  36. event.message.edit(@text, @embed)
  37. message = event.message
  38. when Character
  39. Carousel.create(message_id: message.id, char_id: @carousel.id)
  40. when Landmark
  41. Carousel.create(message_id: message.id, landmark_id: @carousel.id)
  42. when CharImage
  43. Carousel.create(
  44. message_id: message.id,
  45. image_id: @carousel.id
  46. )
  47. when Array
  48. Carousel.create(message_id: message.id, options: @carousel)
  49. end
  50. # React
  51. @reactions.each do |reaction|
  52. message.react(reaction)
  53. end
  54. end
  55. end