فهرست منبع

add aliases and alternate form sections to characters

Kylie Jo Swistak 4 سال پیش
والد
کامیت
aed8ca6a2f
6فایلهای تغییر یافته به همراه103 افزوده شده و 5 حذف شده
  1. 10 1
      app/carousels/member.rb
  2. 27 1
      app/carousels/user.rb
  3. 18 0
      app/commands/member.rb
  4. 37 1
      app/embeds/character.rb
  5. 9 1
      app/models/characters.rb
  6. 2 1
      lib/emoji.rb

+ 10 - 1
app/carousels/member.rb

@@ -6,6 +6,7 @@ class CharacterCarousel < Carousel
       Emoji::NOTEBOOK => 'journal',
       Emoji::BAGS => 'bags',
       Emoji::FAMILY => 'family',
+      Emoji::SPY => 'forms',
       Emoji::BUST => 'user'
     }
   end
@@ -34,7 +35,15 @@ class CharacterCarousel < Carousel
 
       # Transition into a UserCarousel
       event.message.delete_all_reactions
-      UserCarousel.transition(event, carousel, user)
+      UserCarousel.transition_user(event, carousel, user)
+    when 'forms'
+      # Find User
+      character = Character.find(carousel.char_id)
+      base_char = character.alt_form ? Character.find(character.alt_form) : character
+
+      # Transition into a UserCarousel
+      event.message.delete_all_reactions
+      UserCarousel.transition_character(event, carousel, base_char)
     when 'all', 'bags', 'family'
       # Fetch the corresponding emoji, and remove non-bot reactions
       emoji = sections.key(section)

+ 27 - 1
app/carousels/user.rb

@@ -16,7 +16,7 @@ class UserCarousel < Carousel
     CharacterCarousel.transition(event, carousel, character)
   end
 
-  def self.transition(event, carousel, user)
+  def self.transition_user(event, carousel, user)
     # Character array
     all_chars = Character.where(user_id: user.id).order(:rating)
 
@@ -48,4 +48,30 @@ class UserCarousel < Carousel
       embed: user_char_embed(all_chars, member, sfw)
     )
   end
+
+  def self.transition_character(event, carousel, character)
+    # Character array
+    chars = [ character ]
+    chars.concat( Character.where(alt_form: character.id) )
+
+    # Update carousel to reflect new information
+    carousel.update(
+      char_id: nil,
+      image_id: nil,
+      landmark_id: nil,
+      options: chars.map{ |c| c.id },
+      journal_page: nil
+    )
+
+    # Array of section reactions and an X
+    user_reactions = Emoji::NUMBERS.take(chars.length)
+    user_reactions.push(Emoji::CROSS)
+
+    # Update reply
+    BotResponse.new(
+      carousel: carousel,
+      reactions: user_reactions,
+      embed: character_embed(character: character, event: event, section: 'forms')
+    )
+  end
 end

+ 18 - 0
app/commands/member.rb

@@ -79,6 +79,8 @@ class MemberCommand < BaseCommand
         else
           character = Character.where.not(active: 'Deleted')
             .where('name ilike ?', name)
+            .or(Character.where.not(active: 'Deleted')
+            .where('? = any(aliases)', name))
           raise 'Character not found!' if character.empty?
         end
 
@@ -165,6 +167,22 @@ class MemberCommand < BaseCommand
         carousel: journal,
         reactions: JournalCarousel.sections.map{ |k,v| k }.push(Emoji::CROSS)
       )
+    elsif section&.match(/(alt(ernate)?)?\s?forms?/i)
+      chars = []
+      if character.alt_form
+        chars.push( Character.find(character.alt_form) )
+      else
+        chars.push(character)
+      end
+
+      # Add forms
+      chars.concat( Character.where(alt_form: chars.first.id) )
+
+      BotResponse.new(
+        embed: embed,
+        carousel: chars.map{ |c| c.id },
+        reactions: Emoji::NUMBERS.take(chars.length).push(Emoji::CROSS)
+      )
     else
       BotResponse.new(
         embed: embed,

+ 37 - 1
app/embeds/character.rb

@@ -23,6 +23,7 @@ def character_embed(character:, event:, section: nil, image: nil, journal: nil)
   case section
   when /all/i, /default/i, nil
     embed.description = character.personality if character.personality
+    fields = char_alias(character, fields)
     fields = char_type(character, fields)
     fields = char_status(character, fields)
     fields = char_bio(character, fields)
@@ -30,6 +31,7 @@ def character_embed(character:, event:, section: nil, image: nil, journal: nil)
     fields = char_dm_notes(character, fields, event)
   when /bio/i
     embed.description = character.personality if character.personality
+    fields = char_alias(character, fields)
     fields = char_bio(character, fields)
     fields = char_dm_notes(character, fields, event)
   when /types?/i
@@ -58,6 +60,8 @@ def character_embed(character:, event:, section: nil, image: nil, journal: nil)
     fields = char_inv(character, fields)
   when /journal/i
     fields = char_journal(character, fields, journal)
+  when /forms?/i, /alt(ernate)?\sforms?/i
+    fields = alt_form_embed(character, fields)
   end
 
   # Add fields to embed
@@ -68,6 +72,14 @@ def character_embed(character:, event:, section: nil, image: nil, journal: nil)
   author_footer(embed, member, footer_info)
 end
 
+def char_alias(char, fields)
+  fields.push(
+    { name: 'Known Aliases', value: char.aliases.join(', ') }
+  )if char.aliases
+
+  fields
+end
+
 def char_bio(char, fields)
   # Find the appropriate teams
   char_teams = CharTeam.where(char_id: char.id, active: true).map(&:team_id)
@@ -335,7 +347,7 @@ def user_char_embed(chars, member, nsfw=nil)
 
   active.each.with_index do |char, i|
     name = nsfw && char.rating == 'NSFW' ?
-      "#{i+1} || #{char.name} ||" : "#{i+1} #{char.name}"
+      "#{Emoji::NUMBERS[i]} || #{char.name} ||" : "#{Emoji::NUMBERS[i]} #{char.name}"
     fields.push({
       name: name,
       value: "#{char.species} -- #{char.types}"
@@ -383,6 +395,30 @@ def dup_char_embed(chars, name)
   )
 end
 
+def alt_form_embed(char, fields)
+  # Find Base Character Form
+  chars = []
+  if char.alt_form
+    chars.push( Character.find(char.alt_form) )
+  else
+    chars.push(char)
+  end
+
+  # Add forms
+  chars.concat( Character.where(alt_form: chars.first.id) )
+
+  # Display forms
+  chars.each.with_index do |char, i|
+    fields.push({
+      name: "#{Emoji::NUMBERS[i]} #{char.name}",
+      value: "#{char.species} -- #{char.types}"
+    })
+  end
+
+  # return fields
+  fields
+end
+
 def image_list_embed(character, event)
   # Find the author, if they're a member, or in DMs use the event's author
   if event.server

+ 9 - 1
app/models/characters.rb

@@ -33,6 +33,7 @@ class Character < ActiveRecord::Base
   def self.from_form(app)
     key_mapping = {
       "Characters Name" => "name",
+      "Aliases" => "aliases",
       "Species" => "species",
       "Shiny" => "shiny",
       "Type" => "types",
@@ -55,12 +56,14 @@ class Character < ActiveRecord::Base
       "Rating" => "rating",
       "Current Location" => "location",
       "DM Notes" => "dm_notes",
+      "Base Form ID" => "alt_form",
       "Edit Key (ignore)" => "edit_url",
     }
 
     hash = {
       "user_id" => nil,
       "name" => nil,
+      "aliases" => nil,
       "species" => nil,
       "shiny" => nil,
       "types" => nil,
@@ -84,13 +87,16 @@ class Character < ActiveRecord::Base
       "rumors" => nil,
       "hometown" => nil,
       "warnings" => nil,
-      "rating" => nil
+      "rating" => nil,
+      "alt_form" => nil,
     }
 
     user_id = UID.match(app.description)
     active = case app.title
              when /Personal Character/
                'Active'
+             when /Alternate Form/
+               'Alternate Form'
              when /NPC/
                'NPC'
              when /Archived Character/
@@ -116,6 +122,8 @@ class Character < ActiveRecord::Base
 
       if db_column == 'shiny'
         hash[db_column] = field.value.match(/yes/i) ? true : false
+      elsif db_column == 'aliases'
+        hash[db_column] = field.value.split(/\s?(\||,)\s?/)
       else
         hash[db_column] = field.value
       end

+ 2 - 1
lib/emoji.rb

@@ -81,6 +81,7 @@ module Emoji
   BUST = "👤"
   WIZARD = "🧙"
   TALK = "🗣️"
+  SPY = "🕵️"
 
   GHOST = "👻"
   FISH = "🐟"
@@ -94,7 +95,7 @@ module Emoji
 
   CHAR_APP = [SPEECH_BUBBLE, PICTURE, BOOKS, NOTE, QUESTION, PEOPLE, WIZARD]
   IMG_APP = [DOG, KEY, FLAG, PAGE, BOOKS, VULGAR]
-  MEMBER = [EYES, PICTURE, NOTEBOOK, BAGS, FAMILY, BUST, CROSS]
+  MEMBER = [EYES, PICTURE, NOTEBOOK, BAGS, FAMILY, SPY, BUST, CROSS]
   LANDMARK = [BOOKS, SKULL, MAP, HOUSES, PEOPLE, CROSS]
 
   APPLICATION = [Y, N, CRAYON, CROSS]