character.rb 5.8 KB

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