bot_response.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 Fable
  43. Carousel.create(message_id: message.id, fable_id: @carousel.id)
  44. when JournalEntry
  45. Carousel.create(message_id: message.id, char_id: @carousel.char_id, journal_page: 1)
  46. when CharImage
  47. Carousel.create(
  48. message_id: message.id,
  49. image_id: @carousel.id
  50. )
  51. when Array
  52. Carousel.create(message_id: message.id, options: @carousel)
  53. when String
  54. Carousel.create(message_id: message.id)
  55. end
  56. # React
  57. @reactions.each do |reaction|
  58. message.react(reaction)
  59. end
  60. end
  61. end