landmark.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. def landmark_embed(lm:, user: nil, section: nil, event: nil)
  2. fields = []
  3. icon = nil
  4. user_name = case user
  5. when /Server/i
  6. icon = event.server.icon_url if event
  7. 'Server Owned'
  8. when nil
  9. icon = UNKNOWN_USER_IMG
  10. 'Unknown Creator'
  11. else
  12. icon = user.avatar_url
  13. "#{user.name}##{user.tag}"
  14. end
  15. r = Region.find(lm.region)
  16. plm = Landmark.find(lm.location) if lm.location
  17. npcs = []
  18. npc_list = LandmarkNpcs.where(landmark_id: lm.id)
  19. npc_list.each do |lmnpc|
  20. npc = Character.find(lmnpc.character_id)
  21. npcs.push "#{npc.name} - #{npc.species}"
  22. end
  23. inhabitants = npcs.empty? ? 'No known inhabitants' : npcs.join("\n")
  24. embed = Embed.new(
  25. footer: {
  26. text: "#{user_name} | #{lm.category} | #{lm.rating}"
  27. },
  28. title: lm.name
  29. )
  30. case section
  31. when :history, nil
  32. embed.description = lm.description
  33. embed.thumbnail = { url: lm.url } if lm.url
  34. fields.push({name: 'Location', value: plm.name, inline: true}) if lm.location
  35. fields.push({name: 'Region', value: r.name, inline: true}) if r
  36. fields.push({name: 'History', value: lm.history}) if lm.history
  37. fields.push({name: 'Folk Lore', value: lm.folk_lore}) if lm.folk_lore
  38. when :warning
  39. embed.description = lm.description
  40. embed.thumbnail = { url: lm.w_url } if lm.w_url
  41. fields.push({name: 'Kinks', value: lm.kink.join("\n")}) if lm.kink
  42. fields.push({name: 'Warning', value: lm.warning}) if lm.warning
  43. when :map
  44. if lm.map_url
  45. embed.image = { url: lm.map_url }
  46. else
  47. embed.description = 'No Map Data'
  48. end
  49. when :layout
  50. if lm.layout_url
  51. embed.image = { url: lm.layout_url }
  52. else
  53. embed.description = 'No Layout Data'
  54. end
  55. when :npcs
  56. embed.description = lm.description
  57. embed.thumbnail = { url: lm.url } if lm.url
  58. fields.push({name: 'NPC Residents', value: inhabitants})
  59. end
  60. embed.fields = fields
  61. embed.footer.icon_url = icon
  62. embed
  63. end
  64. def landmark_list
  65. fields = []
  66. rs = Region.all
  67. rs.each do |r|
  68. lms = Landmark.where(region: r.id)
  69. fields.push({ name: r.name, value: lms.map(&:name).join("\n") }) unless lms.empty?
  70. end
  71. Embed.new(
  72. title: 'Places of Interest',
  73. fields: fields
  74. )
  75. end