character.rb 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 char_image_embed(char, image, user, color)
  161. footer = "#{user.name}##{user.tag} | #{char.active}" +
  162. " | #{image.category}"
  163. Embed.new(
  164. footer: {
  165. icon_url: user.avatar_url,
  166. text: footer
  167. },
  168. title: "#{char.name} | #{image.keyword}",
  169. color: color,
  170. image: {
  171. url: image.url
  172. }
  173. )
  174. end
  175. def image_list_embed(char, images, user, color)
  176. desc = ""
  177. images.each do |img|
  178. desc += "[#{img.keyword}](#{img.url})\n" unless img.keyword == 'Default'
  179. end
  180. Embed.new(
  181. title: char.name,
  182. description: desc,
  183. color: color,
  184. footer: {
  185. icon_url: user.avatar_url,
  186. text: "#{user.name}##{user.tag} | #{char.active}"
  187. }
  188. )
  189. end