landmark.rb 2.7 KB

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