Browse Source

fix member command and navigation for nsfw characters

Kylie Jo Swistak 5 năm trước cách đây
mục cha
commit
500a2c9e26

+ 1 - 1
app/carousels/member.rb

@@ -12,7 +12,7 @@ class CharacterCarousel < Carousel
   def self.update_embed(event, carousel)
     # Save reactions and determine section
     reactions = event.message.reactions
-    section = sections.filter{ |k,v| reactions[k]&.count > 1 }.values.first
+    section = sections.filter{ |k,v| reactions[k]&.count.to_i > 1 }.values.first
 
     # Close if X is chosen
     return carousel.close(event) if reactions[Emoji::CROSS]&.count.to_i > 1

+ 9 - 4
app/carousels/user.rb

@@ -18,9 +18,14 @@ class UserCarousel < Carousel
 
   def self.transition(event, carousel, user)
     # Character array
-    all_chars = Character.where(active: 'Active', user_id: user.id).order(:rating)
-    sfw_chars = all_chars.filter{ |c| c.rating == 'SFW' }
-    chars = event.channel.nsfw? ? all_chars : sfw_chars
+    all_chars = Character.where(user_id: user.id).order(:rating)
+
+    # Handle nsfw chars in sfw channels
+    active_chars = all_chars.filter{ |c| c.active == 'Active' }
+    sfw_chars = active_chars.filter{ |c| c.rating == 'SFW' }
+
+    sfw = !event.channel.nsfw?
+    chars = sfw ? sfw_chars : active_chars
 
     # Update carousel to reflect new information
     carousel.update(
@@ -39,7 +44,7 @@ class UserCarousel < Carousel
     BotResponse.new(
       carousel: carousel,
       reactions: user_reactions,
-      embed: user_char_embed(chars, member)
+      embed: user_char_embed(all_chars, member, sfw)
     )
   end
 end

+ 9 - 3
app/commands/member.rb

@@ -39,11 +39,16 @@ class MemberCommand < BaseCommand
         characters = Character.where(user_id: UID.match(name)[1])
         active_chars = characters.filter{ |c| c.active == 'Active' }
 
+        # Handle sfw channels and nsfw characters
+        sfw = !event.channel.nsfw?
+        sfw_chars = active_chars.filter{ |c| c.rating == 'SFW' }
+        chars = sfw ? sfw_chars : active_chars
+
         # Generate embed and reply
         BotResponse.new(
-          embed: user_char_embed(characters, member),
+          embed: user_char_embed(characters, member, sfw),
           carousel: active_chars.map(&:id),
-          reactions: Emoji::NUMBERS.take(active_chars.count).push(Emoji::CROSS)
+          reactions: Emoji::NUMBERS.take(chars.count).push(Emoji::CROSS)
         )
 
       # Show Character List Embed
@@ -58,7 +63,8 @@ class MemberCommand < BaseCommand
         # Generate embed, and reply
         BotResponse.new(
           embed: char_list_embed(characters, 'active', types),
-          reactions: reactions.push(Emoji::CROSS)
+          reactions: reactions.push(Emoji::CROSS),
+          carousel: 'Guild'
         )
 
       # Show character embed

+ 7 - 5
app/embeds/character.rb

@@ -222,7 +222,7 @@ def char_list_embed(chars, group, sort = nil)
       list[s.name] = chars.map do |c|
         next unless c.types.split("/").first === s.name
         name = c.name
-        name = "~~#{name}~~" if c.rating&.match(/NSFW/i)
+        name = "|| #{name} ||" if c.rating&.match(/NSFW/i)
         name
       end.compact
     end
@@ -237,7 +237,7 @@ def char_list_embed(chars, group, sort = nil)
         next unless c.region == s.name
         name = c.name
         name = "*#{name}*" if c.user_id.match(/public/i)
-        name = "~~#{name}~~" if c.rating&.match(/NSFW/i)
+        name = "|| #{name} ||" if c.rating&.match(/NSFW/i)
         name
       end.compact
     end
@@ -247,7 +247,7 @@ def char_list_embed(chars, group, sort = nil)
       next unless c.region.nil?
       name = c.name
       name = "*#{name}*" if c.user_id.match(/public/i)
-      name = "~~#{name}~~" if c.rating&.match(/NSFW/i)
+      name = "|| #{name} ||" if c.rating&.match(/NSFW/i)
       name
     end.compact
 
@@ -317,9 +317,11 @@ def user_char_embed(chars, member, nsfw=nil)
   end
 
   active.each.with_index do |char, i|
+    name = nsfw && char.rating == 'NSFW' ?
+      "#{i+1} || #{char.name} ||" : "#{i+1} #{char.name}"
     fields.push({
-      name: "#{i+1} #{char.name}",
-      value: "#{'~~' if nsfw}#{char.species} -- #{char.types}#{'~~' if nsfw}"
+      name: name,
+      value: "#{char.species} -- #{char.types}"
     })
   end
 

+ 2 - 0
app/models/bot_response.rb

@@ -48,6 +48,8 @@ class BotResponse
       )
     when Array
       Carousel.create(message_id: message.id, options: @carousel)
+    when String
+      Carousel.create(message_id: message.id)
     end
 
     # React