| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- def character_embed(char:, img: nil, user:, color:, section: nil)
- fields = []
- user_name = user ? "#{user.name}##{user.tag}" : "Unknown User"
- footer_text = "#{user_name} | #{char.active}"
- footer_text += " | #{char.rating}" if char.rating
- footer_text += " | #{img.category} " if section == :image
- navigate = "React to Navigate"
- footer_text += " | #{navigate}" unless section.nil?
- embed = Embed.new(
- footer: {
- text: footer_text
- },
- title: char.name,
- color: color,
- )
- case section
- when :all, nil
- embed.description = char.personality if char.personality
- fields = char_type(char, fields)
- fields = char_status(char, fields)
- fields = char_bio(char, fields)
- fields = char_rumors(char, fields)
- when :default
- embed.description = navigate
- fields = char_sections(fields)
- when :bio
- embed.description = char.personality if char.personality
- fields = char_bio(char, fields)
- when :type
- fields = char_type(char, fields)
- when :status
- fields = char_status(char, fields)
- when :rumors
- fields = char_rumors(char, fields)
- when :image
- if img
- embed.title =
- "#{char.name} | #{img.keyword}" unless img.keyword == 'Default'
- embed.image = { url: img.url }
- else
- embed.description = "No character images found!"
- end
- end
- embed.thumbnail = { url: img.url } if img && section != :image
- embed.fields = fields
- embed.footer.icon_url = user.avatar_url if user
- embed
- end
- def char_bio(char, fields)
- fields.push(
- { name: 'Hometown', value: char.hometown, inline: true }
- )if char.hometown
- fields.push(
- { name: 'Location', value: char.location, inline: true }
- )if char.location
- fields.push(
- { name: 'Likes', value: char.likes }
- )if char.likes
- fields.push(
- { name: 'Dislikes', value: char.dislikes }
- )if char.dislikes
- fields.push(
- { name: 'Backstory', value: char.backstory }
- )if char.backstory
- fields.push(
- { name: 'Other', value: char.other }
- )if char.other
- fields.push(
- { name: 'DM Notes', value: char.dm_notes }
- )if char.dm_notes
- fields
- end
- def char_type(char, fields)
- fields.push(
- { name: 'Species', value: char.species, inline: true }
- )if char.species
- fields.push(
- { name: 'Type', value: char.types, inline: true }
- )if char.types
- if char.attacks
- attacks = char.attacks
- attacks = attacks.gsub(/\s?\|\s?/, "\n")
- fields.push({ name: 'Attacks', value: attacks })
- end
- fields
- end
- def char_rumors(char, fields)
- fields.push(
- { name: 'Warnings', value: char.warnings }
- )if char.warnings
- if char.rumors
- rumors = char.rumors.split(/\s?\|\s?/)
- rumors = rumors.shuffle
- rumors = rumors.join("\n")
- fields.push({ name: 'Rumors', value: rumors })
- end
- fields
- end
- def char_status(char, fields)
- fields.push(
- { name: 'Age', value: char.age, inline: true }
- )if char.age
- fields.push(
- { name: 'Gender', value: char.gender, inline: true }
- )if char.gender
- fields.push(
- { name: 'Weight', value: char.weight, inline: true }
- )if char.weight
- fields.push(
- { name: 'Height', value: char.height, inline: true }
- )if char.height
- fields.push(
- { name: 'Sexual Orientation', value: char.orientation, inline: true }
- )if char.orientation
- fields.push(
- { name: 'Relationship Status', value: char.relationship, inline: true }
- )if char.relationship
- fields
- end
- def char_sections(fields)
- CharCarousel::REACTIONS.map do |emoji, message|
- fields.push({
- name: emoji,
- value: message,
- inline: true
- })
- end
- fields
- end
- def char_list_embed(chars, user = nil)
- fields = []
- active = []
- npcs = []
- chars.each do |char|
- case char.active
- when 'Active'
- active.push char.name
- when 'NPC'
- npcs.push char.name
- end
- end
- fields.push({
- name: 'Active Characters',
- value: active.join(", ")
- })if active.length > 0
- fields.push({
- name: 'NPCs',
- value: npcs.join(", ")
- })if npcs.length > 0
- embed = Embed.new(
- title: 'Registered Characters',
- fields: fields
- )
- if user
- user_name = user.nickname || user.name
- embed.color = user.color.combined
- embed.title = "#{user_name}'s Characters"
- end
- embed
- end
- def user_char_embed(chars, user)
- fields = []
- active = []
- npcs = []
- user_name = user.nickname || user.name
- chars.each do |char|
- case char.active
- when 'Active'
- active.push char
- when 'NPC'
- npcs.push char.name
- end
- end
- active.each.with_index do |char, i|
- fields.push({
- name: "#{i+1} #{char.name}",
- value: "#{char.species} -- #{char.types}"
- })
- end
- unless npcs.empty?
- fields.push({ name: "#{user_name}'s NPCs", value: npcs.join(", ") })
- end
- embed = Embed.new(
- title: "#{user_name}'s Characters",
- description: "Click on the corresponding reaction to view the character",
- fields: fields
- )
- embed.color = user.color.combined if user.color
- embed
- end
- def dup_char_embed(chars, name)
- fields = []
- chars.each.with_index do |char, i|
- fields.push({
- name: "#{Emoji::NUMBERS[i]}: #{char.species}",
- value: "Created by <@#{char.user_id}>"
- })
- end
- Embed.new(
- title: "Which #{name}?",
- description: "Click on the corresponding reaction to pick",
- fields: fields
- )
- end
- def char_image_embed(char, image, user, color)
- footer = "#{user.name}##{user.tag} | #{char.active}" +
- " | #{image.category}"
- Embed.new(
- footer: {
- icon_url: user.avatar_url,
- text: footer
- },
- title: "#{char.name} | #{image.keyword}",
- color: color,
- image: {
- url: image.url
- }
- )
- end
- def image_list_embed(char, images, user, color)
- desc = ""
- images.each do |img|
- desc += "[#{img.keyword}](#{img.url})\n" unless img.keyword == 'Default'
- end
- Embed.new(
- title: char.name,
- description: desc,
- color: color,
- footer: {
- icon_url: user.avatar_url,
- text: "#{user.name}##{user.tag} | #{char.active}"
- }
- )
- end
|