character.rb 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. def character_embed(char:, img: nil, user:, color:, section: nil)
  2. fields = []
  3. user_name = user ? "#{user.name}##{user.tag}" : "Unknown User"
  4. footer_text = "#{user_name} | #{char.active}"
  5. footer_text += " | #{char.rating}" if char.rating
  6. footer_text += " | #{img.category} " if section == :image
  7. navigate = "React to Navigate"
  8. footer_text += " | #{navigate}" unless section.nil?
  9. embed = Embed.new(
  10. footer: {
  11. text: footer_text
  12. },
  13. title: char.name,
  14. color: color,
  15. )
  16. case section
  17. when :all, nil
  18. embed.description = char.personality if char.personality
  19. fields = char_type(char, fields)
  20. fields = char_status(char, fields)
  21. fields = char_bio(char, fields)
  22. fields = char_rumors(char, fields)
  23. when :default
  24. embed.description = navigate
  25. fields = char_sections(fields)
  26. when :bio
  27. embed.description = char.personality if char.personality
  28. fields = char_bio(char, fields)
  29. when :type
  30. fields = char_type(char, fields)
  31. when :status
  32. fields = char_status(char, fields)
  33. when :rumors
  34. fields = char_rumors(char, fields)
  35. when :image
  36. if img
  37. embed.title =
  38. "#{char.name} | #{img.keyword}" unless img.keyword == 'Default'
  39. embed.image = { url: img.url }
  40. else
  41. embed.description = "No character images found!"
  42. end
  43. when :bags
  44. bags = Inventory.where(char_id: char.id)
  45. fields = char_inv(bags, fields)
  46. end
  47. embed.thumbnail = { url: img.url } if img && section != :image
  48. embed.fields = fields
  49. embed.footer.icon_url = user.avatar_url if user
  50. embed
  51. end
  52. def char_bio(char, fields)
  53. fields.push(
  54. { name: 'Hometown', value: char.hometown, inline: true }
  55. )if char.hometown
  56. fields.push(
  57. { name: 'Location', value: char.location, inline: true }
  58. )if char.location
  59. fields.push(
  60. { name: 'Likes', value: char.likes }
  61. )if char.likes
  62. fields.push(
  63. { name: 'Dislikes', value: char.dislikes }
  64. )if char.dislikes
  65. fields.push(
  66. { name: 'Backstory', value: char.backstory }
  67. )if char.backstory
  68. fields.push(
  69. { name: 'Other', value: char.other }
  70. )if char.other
  71. fields.push(
  72. { name: 'DM Notes', value: char.dm_notes }
  73. )if char.dm_notes
  74. fields
  75. end
  76. def char_type(char, fields)
  77. fields.push(
  78. { name: 'Species', value: char.species, inline: true }
  79. )if char.species
  80. fields.push(
  81. { name: 'Type', value: char.types, inline: true }
  82. )if char.types
  83. if char.attacks
  84. attacks = char.attacks
  85. attacks = attacks.gsub(/\s?\|\s?/, "\n")
  86. fields.push({ name: 'Attacks', value: attacks })
  87. end
  88. fields
  89. end
  90. def char_rumors(char, fields)
  91. fields.push(
  92. { name: 'Warnings', value: char.warnings }
  93. )if char.warnings
  94. if char.rumors
  95. rumors = char.rumors.split(/\s?\|\s?/)
  96. rumors = rumors.shuffle
  97. rumors = rumors.join("\n")
  98. fields.push({ name: 'Rumors', value: rumors })
  99. end
  100. fields
  101. end
  102. def char_status(char, fields)
  103. fields.push(
  104. { name: 'Age', value: char.age, inline: true }
  105. )if char.age
  106. fields.push(
  107. { name: 'Gender', value: char.gender, inline: true }
  108. )if char.gender
  109. fields.push(
  110. { name: 'Weight', value: char.weight, inline: true }
  111. )if char.weight
  112. fields.push(
  113. { name: 'Height', value: char.height, inline: true }
  114. )if char.height
  115. fields.push(
  116. { name: 'Sexual Orientation', value: char.orientation, inline: true }
  117. )if char.orientation
  118. fields.push(
  119. { name: 'Relationship Status', value: char.relationship, inline: true }
  120. )if char.relationship
  121. fields
  122. end
  123. def char_inv(bags, fields)
  124. inv = []
  125. bags.each do |line|
  126. item = Item.find(line.item_id)
  127. inv_line = line.amount > 1 ? "#{item.name} [#{line.amount}]" : item.name
  128. inv.push(inv_line)
  129. end
  130. fields.push({ name: "Bags", value: inv.join("\n"), inline: true })
  131. end
  132. def char_sections(fields)
  133. CharCarousel::REACTIONS.map do |emoji, message|
  134. fields.push({
  135. name: emoji,
  136. value: message,
  137. inline: true
  138. })
  139. end
  140. fields
  141. end
  142. def char_list_embed(chars, user = nil)
  143. fields = []
  144. active = []
  145. npcs = []
  146. chars.each do |char|
  147. case char.active
  148. when 'Active'
  149. active.push char.name
  150. when 'NPC'
  151. npcs.push char.name
  152. end
  153. end
  154. fields.push({
  155. name: 'Active Characters',
  156. value: active.join(", ")
  157. })if active.length > 0
  158. fields.push({
  159. name: 'NPCs',
  160. value: npcs.join(", ")
  161. })if npcs.length > 0
  162. embed = Embed.new(
  163. title: 'Registered Characters',
  164. fields: fields
  165. )
  166. if user
  167. user_name = user.nickname || user.name
  168. embed.color = user.color.combined
  169. embed.title = "#{user_name}'s Characters"
  170. end
  171. embed
  172. end
  173. def user_char_embed(chars, user)
  174. fields = []
  175. active = []
  176. npcs = []
  177. user_name = user.nickname || user.name
  178. chars.each do |char|
  179. case char.active
  180. when 'Active'
  181. active.push char
  182. when 'NPC'
  183. npcs.push char.name
  184. end
  185. end
  186. active.each.with_index do |char, i|
  187. fields.push({
  188. name: "#{i+1} #{char.name}",
  189. value: "#{char.species} -- #{char.types}"
  190. })
  191. end
  192. unless npcs.empty?
  193. fields.push({ name: "#{user_name}'s NPCs", value: npcs.join(", ") })
  194. end
  195. embed = Embed.new(
  196. title: "#{user_name}'s Characters",
  197. description: "Click on the corresponding reaction to view the character",
  198. fields: fields
  199. )
  200. embed.color = user.color.combined if user.color
  201. embed
  202. end
  203. def dup_char_embed(chars, name)
  204. fields = []
  205. chars.each.with_index do |char, i|
  206. fields.push({
  207. name: "#{Emoji::NUMBERS[i]}: #{char.species}",
  208. value: "Created by <@#{char.user_id}>"
  209. })
  210. end
  211. Embed.new(
  212. title: "Which #{name}?",
  213. description: "Click on the corresponding reaction to pick",
  214. fields: fields
  215. )
  216. end
  217. def char_image_embed(char, image, user, color)
  218. footer = "#{user.name}##{user.tag} | #{char.active}" +
  219. " | #{image.category}"
  220. Embed.new(
  221. footer: {
  222. icon_url: user.avatar_url,
  223. text: footer
  224. },
  225. title: "#{char.name} | #{image.keyword}",
  226. color: color,
  227. image: {
  228. url: image.url
  229. }
  230. )
  231. end
  232. def image_list_embed(char, images, user, color)
  233. desc = ""
  234. images.each do |img|
  235. desc += "[#{img.keyword}](#{img.url})\n" unless img.keyword == 'Default'
  236. end
  237. Embed.new(
  238. title: char.name,
  239. description: desc,
  240. color: color,
  241. footer: {
  242. icon_url: user.avatar_url,
  243. text: "#{user.name}##{user.tag} | #{char.active}"
  244. }
  245. )
  246. end