Ver Fonte

complete cleanup and rebase

Kylie Jo Swistak há 6 anos atrás
pai
commit
e31a63f60b

+ 1 - 1
app/models/char_app_responses.rb → app/models/char_app.rb

@@ -1,7 +1,7 @@
 # frozen_string_literal: true
 require_relative '../../lib/emoji.rb'
 
-module CharAppResponses
+module CharApp
   GRAMMAR = "Please check your grammar and\ncapitalization"
   UNITS = "Please specify your units in\nImperial or Metric"
   IMAGE = "Your image is inappropriate for\ndefault use"

+ 2 - 2
app/models/char_images.rb

@@ -29,9 +29,9 @@ class CharImage < ActiveRecord::Base
     hash
   end
 
-  def self.to_form(name, species, id, keyword, category, url)
+  def self.to_form(name, species, id, keyword, category, url, user_id)
     form =
-      "_New Character Image_:\n\n>>> " +
+      "_New Character Image_:\nSubmitted by: <@#{user_id}>\n\n>>> " +
       "**Character**: #{name}\n**Species**: #{species}\n" +
       "**Character ID**: #{id}\n**Keyword**: #{keyword}\n" +
       "**Category**: #{category}\n**URL**: #{url}"

+ 22 - 0
app/models/img_app.rb

@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+require_relative '../../lib/emoji.rb'
+
+module ImgApp
+  SPECIES = "Your image contradicts your\ncharacters species"
+  KEYWORD = "Your keyword is invalid or\nmisleading"
+  CATEGORY = "Your image category is\nincorrectly flagged"
+  URL = "Your image url is incorrect,\nplease check for the `.png` etc.."
+  LORE = "Your image is conflicting\nwith server lore"
+  VULGAR = "Your image or keyword is too\nvulgar, or contradicts server rules"
+  INLINE_SPACE = "------------------------------------"
+
+  REJECT_MESSAGES = {
+    Emoji::DOG => SPECIES,
+    Emoji::KEY => KEYWORD,
+    Emoji::FLAG => CATEGORY,
+    Emoji::PAGE => URL,
+    Emoji::BOOKS => LORE,
+    Emoji::VULGAR => VULGAR
+  }
+end
+

+ 0 - 14
app/responses/application_responses.rb

@@ -20,17 +20,3 @@ def unknown_member(event)
   event.message.delete
   event.respond(content)
 end
-
-def reject_app(event, embed)
-  content = event.message.content
-  event.message.delete
-  reject = event.send_embed(content, embed)
-
-  Emoji::APP_SECTIONS.each do |reaction|
-    reject.react(reaction)
-  end
-
-  reject.react(Emoji::CHECK)
-  reject.react(Emoji::CROSS)
-  reject.react(Emoji::CRAYON)
-end

+ 3 - 4
app/responses/character.rb

@@ -92,16 +92,15 @@ def char_image_embed(char, image, user, color)
 end
 
 def image_list_embed(char, images, user, color)
-  fields = []
-
+  desc = ""
   images.each do |img|
-    fields.push({name: img.keyword, value: img.url})
+    desc += "[#{img.keyword}](#{img.url})\n" unless img.keyword == 'Default'
   end
 
   Embed.new(
     title: char.name,
+    description: desc,
     color: color,
-    fields: fields,
     footer: {
       icon_url: user.avatar_url,
       text: "#{user.name}##{user.tag} | #{char.active}"

+ 7 - 10
app/responses/generic.rb

@@ -1,12 +1,9 @@
 def new_generic_embed(event, title, text)
-    name = event.author.nickname || event.author.name
+  chat_embed = Embed.new(
+    title:  title,
+    description: text
+  )
 
-    chat_embed = Embed.new(
-        title:  title,
-        description: text
-    )
-
-    chat_embed.color = event.author.color.combined
-
-    raffle = event.send_embed("", chat_embed)
-  end
+  chat_embed.color = event.author.color.combined
+  chat_embed
+end

+ 85 - 9
app/responses/reject.rb

@@ -1,12 +1,15 @@
+MSG = "Please resubmit when you've addressed the issues!\n"
+FTR = "If you have any questions, feel free to ask a Guildmaster"
+
 def reject_char_embed(app)
   image_url = /\*\*URL to the Character\'s Appearance\*\*\:\s(.*)/.match(app)
 
   fields = []
 
-  CharAppResponses::REJECT_MESSAGES.map do |emoji, message|
+  CharApp::REJECT_MESSAGES.map do |emoji, message|
     fields.push({
       name: emoji,
-      value: "#{message}\n#{CharAppResponses::INLINE_SPACE}",
+      value: "#{message}\n#{CharApp::INLINE_SPACE}",
       inline: true
     })
   end
@@ -35,16 +38,50 @@ def reject_char_embed(app)
   embed
 end
 
-def message_user_embed(event)
+def reject_img_embed(app)
+  img_url = /\*\*URL\*\*:\s(.*)/.match(app)
+  fields = []
+
+  ImgApp::REJECT_MESSAGES.map do |emoji, message|
+    fields.push({
+      name: emoji,
+      value: "#{message}\n#{ImgApp::INLINE_SPACE}",
+      inline: true
+    })
+  end
+
+  instructions =
+    "#{Emoji::CHECK} : Indicates you are ready to send the corresponding " +
+    "messages to the user\n" +
+    "#{Emoji::CROSS} : Indicates you want to dismiss this message and " +
+    "not send a message to the user\n"
+
+  fields.push({
+    name: "Submitting",
+    value: instructions
+  })
+
+  embed = Embed.new(
+    title: "**_APPLICATION REJECTED_**",
+    description: "Please indicate what message to forward to the user!",
+    color: Color::ERROR,
+    fields: fields
+  )
+
+  embed.thumbnail = { url: img_url[1] } if img_url
+  embed
+end
+
+def user_char_app(event)
   reactions = event.message.reactions
   content = event.message.content
 
   edit_url = Regex::EDIT_URL.match(content)
   description = ""
 
-  Emoji::APP_SECTIONS.each do |reaction|
+  Emoji::CHAR_APP.each do |reaction|
     if reactions[reaction].count > 1
-      m = CharAppResponses::REJECT_MESSAGES[reaction].gsub("\n", " ")
+      m = CharApp::REJECT_MESSAGES[reaction].gsub("\n", " ")
       description += "\n#{m}"
     end
   end
@@ -52,14 +89,53 @@ def message_user_embed(event)
   embed = Embed.new(
     title: "**Your application has been rejected!!**",
     color: Color::ERROR,
+    footer: {
+      text: FTR
+    },
     fields: [
       {
         name: "Listed reasons for rejection:",
         value: description
       },
       {
-        name: "You can edit your application and resubmit here:",
-        value: "#{Url::CHARACTER}#{edit_url[1]}"
+        name: MSG,
+        value: "[Edit Your Application](#{Url::CHARACTER}#{edit_url[1]})"
+      }
+    ]
+  )
+
+  embed
+end
+
+def user_img_app(event)
+  reactions = event.message.reactions
+  content = event.message.content
+
+  img_url = /\*\*URL\*\*:\s(.*)/.match(content)
+  description = ""
+
+  Emoji::IMG_APP.each do |reaction|
+    if reactions[reaction].count > 1
+      m = ImgApp::REJECT_MESSAGES[reaction].gsub("\n", " ")
+      description += "\n#{m}"
+    end
+  end
+
+  description += "\n\n#{MSG}"
+
+  embed = Embed.new(
+    title: "**Your application has been rejected!!**",
+    color: Color::ERROR,
+    thumbnail: {
+      url: img_url[1]
+    },
+    footer: {
+      text: FTR
+    },
+    fields: [
+      {
+        name: "Listed reasons for rejection:",
+        value: description
       }
     ]
   )
@@ -71,8 +147,8 @@ def self_edit_embed(content)
   edit_url = Regex::EDIT_URL.match(content)
 
   Embed.new(
-    title: "Please edit the user's application and resubmit!",
+    title: "Don't forget to resubmit!",
     color: Color::ERROR,
-    description: "#{Url::CHARACTER}#{edit_url[1]}"
+    description: "[Edit the Application](#{Url::CHARACTER}#{edit_url[1]})"
   )
 end

+ 11 - 0
app/responses/success.rb

@@ -10,3 +10,14 @@ def success_embed(message)
     }
   )
 end
+
+def message_embed(title, desc, img = nil)
+  Embed.new(
+    title: title,
+    description: desc,
+    color: SUCCESS_GREEN,
+    thumbnail: {
+      url: img || Image::HAPPY
+    }
+  )
+end

+ 59 - 7
bot.rb

@@ -150,8 +150,12 @@ poll = Command.new(:poll, desc, opts) do |event, question, options|
   end
 end
 
-opts = { "participants" => "May accept Everyone, Here, or a comma seperated list of names"}
-raffle = Command.new(:raffle, "Creates a raffle and picks a winner", opts) do |event, participant|
+opts = {
+  "participants" =>
+  "Accepts Everyone, Here, or a comma seperated list of names"
+}
+desc = "Creates a raffle and picks a winner"
+raffle = Command.new(:raffle, desc, opts) do |event, participant|
   participants =
     case participant
     when /^everyone$/i
@@ -172,7 +176,7 @@ raffle = Command.new(:raffle, "Creates a raffle and picks a winner", opts) do |e
     end
 
     if winner_name
-      new_generic_embed(event, "Raffle Results!", "Winner: " + winner_name)
+      message_embed("Raffle Results!", "Winner: #{winner_name}")
     else
       command_error_embed("There was an error creating your raffle!", raffle)
     end
@@ -193,9 +197,21 @@ image = Command.new(:image, desc, opts) do |event, name, keyword, tag, url|
   img = CharImage.find_by(keyword: keyword) if keyword
 
   case
+  when /^Default$/i.match(keyword)
+    error_embed(
+      "Cannot update Default here!",
+      "Use `pkmn-app character` to edit your default image in your form"
+    )
   when char && keyword && url && tag && tag.match(/(n)?sfw/i)
-    img_app =
-      CharImage.to_form(char.name, char.species, char.id, keyword, tag, url)
+    img_app = CharImage.to_form(
+      char.name,
+      char.species,
+      char.id,
+      keyword,
+      tag,
+      url,
+      user.id
+    )
 
     approval = bot.send_message(Channel::APPROVAL, img_app, false, nil)
     approval.react(Emoji::Y)
@@ -340,11 +356,23 @@ bot.reaction_add do |event|
       )
     end
   when [:character_application, :no]
-    reject_app(event, reject_char_embed(content))
+    content = event.message.content
+    embed = reject_char_embed(content)
+
+    event.message.delete
+    reject = event.send_embed(content, embed)
+
+    Emoji::CHAR_APP.each do |reaction|
+      reject.react(reaction)
+    end
+
+    reject.react(Emoji::CHECK)
+    reject.react(Emoji::CROSS)
+    reject.react(Emoji::CRAYON)
 
   when [:character_rejection, :check]
     user = event.server.member(Regex::UID.match(content)[1])
-    embed = message_user_embed(event)
+    embed = user_char_app(event)
 
     event.message.delete
     bot.send_temporary_message(event.channel.id, "", 5, false, embed)
@@ -384,6 +412,30 @@ bot.reaction_add do |event|
                 Channel::CHARACTER_NSFW
               end
     bot.send_message(channel, "Image Approved!", false, embed)
+  when [:image_application, :no]
+    content = event.message.content
+    embed = reject_img_embed(content)
+
+    event.message.delete
+    reject = event.send_embed(content, embed)
+
+    Emoji::IMG_APP.each do |reaction|
+      reject.react(reaction)
+    end
+
+    reject.react(Emoji::CHECK)
+    reject.react(Emoji::CROSS)
+
+  when [:image_application, :check]
+    user = event.server.member(Regex::UID.match(content)[1])
+    embed = user_img_app(event)
+
+    event.message.delete
+    bot.send_temporary_message(event.channel.id, "", 5, false, embed)
+    bot.send_message(user.dm.id, "", false, embed)
+  when [:image_application, :cross]
+    event.message.delete
+
   end
 end
 

+ 6 - 1
lib/emoji.rb

@@ -41,7 +41,12 @@ module Emoji
   VULGAR = "🖕"
   CRAYON = "🖍"
   PHONE = "📱"
+  DOG = "🐶"
+  KEY = "🔑"
+  PAGE = "📄"
+  FLAG = "🚩"
 
   LETTERS = [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z]
-  APP_SECTIONS = [SPEECH_BUBBLE, SCALE, PICTURE, BOOKS, BABY, SKULL, VULGAR, NOTE]
+  CHAR_APP = [SPEECH_BUBBLE, SCALE, PICTURE, BOOKS, BABY, SKULL, VULGAR, NOTE]
+  IMG_APP = [DOG, KEY, FLAG, PAGE, BOOKS, VULGAR]
 end