landmark.rb 1016 B

123456789101112131415161718192021222324252627282930313233343536
  1. class LandmarkCarousel < Carousel
  2. def self.sections
  3. {
  4. Emoji::BOOKS => 'history',
  5. Emoji::SKULL => 'warning',
  6. Emoji::MAP => 'map',
  7. Emoji::HOUSES => 'layout',
  8. Emoji::PEOPLE => 'npc'
  9. }
  10. end
  11. def self.update_embed(event, carousel)
  12. # Save reactions and determine section
  13. reactions = event.message.reactions
  14. section = sections.filter{ |k,v| reactions[k]&.count.to_i > 1 }.values.first
  15. # Close the embed if that is chosen
  16. return carousel.close(event) if reactions[Emoji::CROSS]&.count.to_i > 1
  17. # Fetch the corresponding emoji, and remove non-bot reactions
  18. emoji = sections.key(section)
  19. event.message.reacted_with(emoji).each do |r|
  20. event.message.delete_reaction(r.id, emoji) unless r.current_bot?
  21. end
  22. # Update landmark with new section
  23. BotResponse.new(
  24. carousel: carousel,
  25. embed: landmark_embed(
  26. lm: Landmark.find(carousel.landmark_id),
  27. section: section,
  28. event: event
  29. )
  30. )
  31. end
  32. end