character.rb 5.9 KB

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