Procházet zdrojové kódy

update inactive to archived

Kylie Jo Swistak před 5 roky
rodič
revize
8214dbe05d
3 změnil soubory, kde provedl 136 přidání a 17 odebrání
  1. 10 10
      app/responses/character.rb
  2. 8 0
      app/responses/reject.rb
  3. 118 7
      bot.rb

+ 10 - 10
app/responses/character.rb

@@ -207,13 +207,13 @@ end
 def char_list_embed(chars, user = nil)
   fields = []
   active = []
-  inactive= []
+  archived = []
   owned_npcs = []
   unowned_npcs = []
 
   list = {
     "Active Guild Members" => active,
-    "Former Guild Members" => inactive,
+    "Archived Guild Members" => archived,
     "NPCs" => owned_npcs,
     "Public NPCs" => unowned_npcs
   }
@@ -222,8 +222,8 @@ def char_list_embed(chars, user = nil)
     case char.active
     when 'Active'
       active.push char.name
-    when 'Inactive'
-      inactive.push char.name
+    when 'Archived'
+      archived.push char.name
     when 'NPC'
       owned_npcs.push char.name if char.user_id != 'Public'
       unowned_npcs.push char.name if char.user_id == 'Public'
@@ -261,7 +261,7 @@ end
 def user_char_embed(chars, user)
   fields = []
   active = []
-  inactive = []
+  archived = []
   npcs = []
   user_name = user&.nickname || user&.name
 
@@ -269,8 +269,8 @@ def user_char_embed(chars, user)
     case char.active
     when 'Active'
       active.push char
-    when 'Inactive'
-      inactive.push char.name
+    when 'Archived'
+      archived.push char.name
     when 'NPC'
       npcs.push char.name
     end
@@ -283,10 +283,10 @@ def user_char_embed(chars, user)
     })
   end
 
-  unless inactive.empty?
+  unless archived.empty?
     fields.push({
-      name: "#{user_name}'s Inactive Characters",
-      value: inactive.join(", ")
+      name: "#{user_name}'s Archived Characters",
+      value: archived.join(", ")
     })
   end
 

+ 8 - 0
app/responses/reject.rb

@@ -141,3 +141,11 @@ def self_edit_embed(app, form)
     description: "[Edit the Application](#{form}#{app.footer.text})"
   )
 end
+
+def char_reactive(form, edit_url)
+  Embed.new(
+    title: "Your reactivation request has been declined!",
+    color: ERROR,
+    description: "[Edit the Application](#{form}#{edit_url})"
+  )
+end

+ 118 - 7
bot.rb

@@ -292,7 +292,12 @@ app = Command.new(:app, desc, opts) do |event, name, status|
     else
       Character.where(user_id: user.id).find_by(name: name) if name
     end
-  active = status.match(/(in)?active/i) if status
+  active = case status
+           when /inactive/i, /archive/i
+             false
+           when /active/i
+             true
+           end
 
   case
   when flag
@@ -322,22 +327,49 @@ app = Command.new(:app, desc, opts) do |event, name, status|
   when name && !character
     app_not_found_embed(user_name, name)
 
-  when status && active && character
-    if active[1].nil?
+  when status && character
+    if active
       uid = character.user_id
       user_allowed = (User.find_by(id: uid).level / 10) + 1
       user_allowed = user_allowed + 1 if user.roles.map(&:name).include?('Nitro Booster')
       active_chars = Character.where(user_id: uid, active: 'Active')
 
-      allowed = active_chars.count < user_allowed && character.active == 'Inactive'
+      allowed = active_chars.count < user_allowed && character.active == 'Archived'
     else
       allowed = true
     end
 
-    if allowed
-      character.update!(active: active[0].capitalize)
+    if allowed && active
+      # create re-approval character embed
+      img = CharImage.where(char_id: character.id).find_by(keyword: 'Default')
+      color = CharacterController.type_color(character)
+
+      app = character_embed(
+        char: character,
+        img: img,
+        section: :default,
+        user: user,
+        color: color,
+        event: event
+      )
+
+      app.author = { name: "Reactivation Application [#{character.id}]" }
+      msg = bot.send_message(ENV['APP_CH'], "", false, app)
+      msg.react(Emoji::Y)
+      msg.react(Emoji::N)
+      msg.react(Emoji::CRAYON)
+      msg.react(Emoji::CROSS)
+
+      #character.update!(active: active[0].capitalize)
+      #character.reload
+      #success_embed("Successfully updated #{name} to be #{active[0].downcase}")
+    elsif allowed && !active
+      character.update!(active: 'Archived')
       character.reload
-      success_embed("Successfully updated #{name} to be #{active[0].downcase}")
+
+      embed = success_embed("Successfully archived #{name}")
+      bot.send_message(ENV['APP_CH'], "", false, embed)
+      embed
     else
       error_embed(
         "You're not allowed to do that!",
@@ -1091,6 +1123,12 @@ bot.reaction_add do |event|
       m = event.server.roles.find{ |r| r.id == ENV['ADMINS'].to_i }.members
       maj = m.count > 2 ? m.count/2.0 : 2
       :landmark_application
+    when /Reactivation\sApplication/
+      m = event.server.roles.find{ |r| r.id == ENV['ADMINS'].to_i }.members
+      maj = m.count > 2 ? m.count/2.0 : 2
+
+      maj = 1
+      :reactivation
     else
       if event.server == nil
         :new_app
@@ -1227,6 +1265,79 @@ bot.reaction_add do |event|
       self_edit_embed(app, Url::CHARACTER)
     )
 
+  when [:reactivation, :yes]
+    ch_id = app.author.name.match(/\[(\d)+\]/)
+    char = Character.find(ch_id[1])
+
+    img = CharImage.where(char_id: char.id).find_by(keyword: 'Default')
+    color = CharacterController.type_color(char)
+    user = case char.user_id
+           when /server/i
+             char.user_id
+           else
+             event.server.member(char.user_id.to_i)
+           end
+
+    channel = case char.rating
+              when /nsfw/i
+                ENV['CHAR_NSFW_CH']
+              when /hidden/i
+                user.dm&.id
+              else
+                ENV['CHAR_CH']
+              end
+
+    char.update(active: 'Active')
+    char.reload
+
+    embed = character_embed(
+      char: char,
+      img: img,
+      user: user,
+      color: color,
+      event: event
+    )if char
+
+    if embed
+      bot.send_message(
+        channel.to_i,
+        "Good news, <@#{char.user_id}>! Your character was approved",
+        false,
+        embed
+      )
+      event.message.delete
+    else
+      event.respond(
+        "",
+        admin_error_embed("Something went wrong when saving application")
+      )
+    end
+  when [:reactivation, :no]
+    ch_id = app.author.name.match(/\[(\d)+\]/)
+    char = Character.find(ch_id[1])
+
+    user = event.server.member(char.user_id)
+    embed = char_reactive(Url::CHARACTER, char.edit_url)
+
+    event.message.delete
+    bot.send_temporary_message(event.channel.id, "", 5, false, embed)
+    bot.send_message(user.dm.id, "", false, embed)
+  when [:reactivation, :cross]
+    event.message.delete
+
+  when [:reactivation, :crayon]
+    ch_id = app.author.name.match(/\[(\d)+\]/)
+    char = Character.find(ch_id[1])
+
+    event.message.delete
+    bot.send_temporary_message(
+      event.channel.id,
+      "",
+      35,
+      false,
+      char_reactive(Url::CHARACTER, char.edit_url)
+    )
+
   when [:landmark_application, :yes]
     uid = UID.match(app.description)
     user =