guild.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. class GuildCarousel < Carousel
  2. def self.update_embed(event, carousel)
  3. # Save reactions and determine section
  4. reactions = event.message.reactions
  5. reaction = Emoji::NUMBERS.filter{ |n| reactions[n]&.count.to_i > 1 }.first
  6. list_index = Emoji::NUMBERS.index(reaction)
  7. # Close if X is chosen
  8. return carousel.close(event) if reactions[Emoji::CROSS]&.count.to_i > 1
  9. embed =
  10. case list_index
  11. when 0
  12. char_list_embed(
  13. Character.where(active: 'Active').order(:name),
  14. 'active',
  15. Type.all
  16. )
  17. when 1
  18. char_list_embed(
  19. Character.where(active: 'Archived').order(:name),
  20. 'archived',
  21. Type.all
  22. )
  23. when 2
  24. char_list_embed(
  25. Character.select('characters.*, COALESCE(r.name, r2.name) AS region')
  26. .joins('LEFT OUTER JOIN landmarks l on l.name = characters.location')
  27. .joins('LEFT OUTER JOIN regions r on r.id = l.region')
  28. .joins('LEFT OUTER JOIN regions r2 on characters.location = r2.name')
  29. .where(active: 'NPC').order(:name),
  30. 'npc',
  31. Region.all
  32. )
  33. when 3
  34. adoptables = Character.where(user_id: 'Public').order(:name)
  35. specials = Character.where.not(special: nil).order(:name)
  36. char_list_embed(specials + adoptables, 'special')
  37. end
  38. # Remove reaction
  39. if reaction
  40. event.message.reacted_with(reaction).each do |r|
  41. event.message.delete_reaction(r.id, reaction) unless r.current_bot?
  42. end
  43. end
  44. BotResponse.new(carousel: carousel, embed: embed) if embed
  45. end
  46. end