landmark.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 = Character.where(location: lm.name)
  20. npc_list.each do |npc|
  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}"
  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. if !event.channel.nsfw? && lm.w_rating == 'NSFW'
  41. embed.thumbnail = { url: NO_GOLD }
  42. fields.push({name: 'Kinks', value: lm.kink.join("\n")}) if lm.kink
  43. fields.push({name: 'Warning', value: 'This warning is NSFW!'})
  44. else
  45. embed.thumbnail = { url: lm.w_url } if lm.w_url
  46. fields.push({name: 'Kinks', value: lm.kink.join("\n")}) if lm.kink
  47. fields.push({name: 'Warning', value: lm.warning}) if lm.warning
  48. end
  49. when :map
  50. if lm.map_url
  51. embed.image = { url: lm.map_url }
  52. else
  53. embed.description = 'No Map Data'
  54. end
  55. when :layout
  56. if lm.layout_url
  57. embed.image = { url: lm.layout_url }
  58. else
  59. embed.description = 'No Layout Data'
  60. end
  61. when :npcs
  62. embed.description = lm.description
  63. embed.thumbnail = { url: lm.url } if lm.url
  64. fields.push({name: 'NPC Residents', value: inhabitants})
  65. end
  66. embed.fields = fields
  67. embed.footer.icon_url = icon
  68. embed
  69. end
  70. def landmark_list
  71. fields = []
  72. rs = Region.all
  73. rs.each do |r|
  74. lms = Landmark.where(region: r.id)
  75. fields.push({ name: r.name, value: lms.map(&:name).join("\n"), inline: true}) unless lms.empty?
  76. end
  77. Embed.new(
  78. title: 'Places of Interest',
  79. fields: fields
  80. )
  81. end