landmark.rb 2.3 KB

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