Prechádzať zdrojové kódy

fix level up images, and allow embed pasting into offices

Kylie Jo Swistak 5 rokov pred
rodič
commit
e85c015f44

+ 23 - 0
app/app_forms/app_form.rb

@@ -11,6 +11,24 @@ class ApplicationForm
     raise 'NYI'
   end
 
+  def self.check_votes(event, maj)
+    reactions = event.message.reactions
+
+    if reactions[Emoji::Y]&.count.to_i > maj && star(event)
+      approve(event)
+    elsif reactions[Emoji::N]&.count.to_i > maj
+      reject(event)
+    elsif reactions[Emoji::CRAYON]&.count.to_i > 1
+      edit(event)
+    elsif reactions[Emoji::CROSS]&.count.to_i > 1
+      remove(event)
+    elsif reactions[Emoji::GHOST]&.count.to_i > 0
+      to_office(event, ENV['MIZU_CH'])
+    elsif reactions[Emoji::FISH]&.count.to_i > 0
+      to_office(event, ENV['NEIRO_CH'])
+    end
+  end
+
   def self.approve
     raise 'NYI'
   end
@@ -40,4 +58,9 @@ class ApplicationForm
       event.message&.delete unless member.current_bot?
     end
   end
+
+  def self.to_office(event, office)
+    app = Embed.convert(event.message.embeds.first)
+    BotResponse.new(destination: office, embed: app)
+  end
 end

+ 1 - 10
app/app_forms/character_app.rb

@@ -5,17 +5,8 @@ class CharacterApplication < ApplicationForm
     @process ||= Application.new('Character Application') do |event|
       # Calculate majority, and check votes
       maj = majority(event)
+      check_votes(event, maj)
 
-      reactions = event.message.reactions
-      if reactions[Emoji::Y]&.count.to_i > maj && star(event)
-        approve(event)
-      elsif reactions[Emoji::N]&.count.to_i > maj
-        deny(event)
-      elsif reactions[Emoji::CRAYON]&.count.to_i > 1
-        edit(event)
-      elsif reactions[Emoji::CROSS]&.count.to_i > 1
-        remove(event)
-      end
     rescue StandardError => e
       error_embed(e.message)
     end

+ 5 - 9
app/app_forms/confirm_archive.rb

@@ -3,15 +3,11 @@ require './app/app_forms/app_form.rb'
 class ConfirmArchive < ApplicationForm
   def self.process
     @process ||= Application.new('Team Alert') do |event|
-      # Check reactions
-      reactions = event.message.reactions
-      if reactions[Emoji::Y]&.count.to_i > 1
-        approve(event)
-      elsif reactions[Emoji::N]&.count.to_i > 1
-        deny(event)
-      end
-    #rescue StandardError => e
-      #error_embed(e.message)
+      # Check votes
+      check_votes(event, 1)
+
+    rescue StandardError => e
+      error_embed(e.message)
     end
   end
 

+ 4 - 12
app/app_forms/fable_app.rb

@@ -3,20 +3,12 @@ require './app/app_forms/app_form.rb'
 class FableApplication < ApplicationForm
   def self.process
     @process||= Application.new('Fable Application') do |event|
-      # Calculate majority
+      # Calculate majority, and check votes
       maj = majority(event)
+      check_votes(event, maj)
 
-      # Check votes
-      reactions = event.message.reactions
-      if reactions[Emoji::Y]&.count.to_i > maj && star(event)
-        approve(event)
-      elsif reactions[Emoji::N]&.count.to_i > maj
-        deny(event)
-      elsif reactions[Emoji::CRAYON]&.count.to_i > 1
-        edit(event)
-      elsif reactions[Emoji::CROSS]&.count.to_i > 1
-        remove(event)
-      end
+    rescue StandardError => e
+      error_embed(e.message)
     end
   end
 

+ 2 - 9
app/app_forms/image_app.rb

@@ -3,17 +3,10 @@ require './app/app_forms/app_form.rb'
 class ImageApplication < ApplicationForm
   def self.process
     @process ||= Application.new('Image Application') do |event|
-      # Calculate majority, and check votes
+      # Calculate majority
       maj = majority(event)
+      check_votes(event, maj)
 
-      reactions = event.message.reactions
-      if reactions[Emoji::Y]&.count.to_i > maj && star(event)
-        approve(event)
-      elsif reactions[Emoji::N]&.count.to_i > maj
-        deny(event)
-      elsif reactions[Emoji::CROSS]&.count.to_i > 1
-        remove(event)
-      end
     rescue StandardError => e
       error_embed(e.message)
     end

+ 1 - 11
app/app_forms/item_app.rb

@@ -5,18 +5,8 @@ class ItemApplication < ApplicationForm
     @process ||= Application.new('Item Application') do |event|
       # Calculate majority
       maj = majority(event)
+      check_votes(event, maj)
 
-      # Check votes
-      reactions = event.message.reactions
-      if reactions[Emoji::Y]&.count.to_i > maj && star(event)
-        approve(event)
-      elsif reactions[Emoji::N]&.count.to_i > maj
-        deny(event)
-      elsif reactions[Emoji::CRAYON]&.count.to_i > 1
-        edit(event)
-      elsif reactions[Emoji::CROSS]&.count.to_i > 1
-        remove(event)
-      end
     rescue StandardError => e
       error_embed(e.message)
     end

+ 1 - 11
app/app_forms/landmark_app.rb

@@ -5,18 +5,8 @@ class LandmarkApplication < ApplicationForm
     @process ||= Application.new('Landmark Application') do |event|
       # Calculate majority
       maj = majority(event)
+      check_votes(event, maj)
 
-      # Check votes
-      reactions = event.message.reactions
-      if reactions[Emoji::Y]&.count.to_i > maj && star(event)
-        approve(event)
-      elsif reactions[Emoji::N]&.count.to_i > maj
-        deny(event)
-      elsif reactions[Emoji::CRAYON]&.count.to_i > 1
-        edit(event)
-      elsif reactions[Emoji::CROSS]&.count.to_i > 1
-        remove(event)
-      end
     rescue StandardError => e
       error_embed(e.message)
     end

+ 4 - 14
app/app_forms/reactivate_app.rb

@@ -3,22 +3,12 @@ require './app/app_forms/app_form.rb'
 class ReactivationApplication < ApplicationForm
   def self.process
     @process ||= Application.new('Reactivation Application') do |event|
-      # Calculate majority and Save application
+      # Calculate majority and check votes
       maj = majority(event)
+      check_votes(event, maj)
 
-      # Check votes
-      reactions = event.message.reactions
-      if reactions[Emoji::Y]&.count.to_i > maj && star(event)
-        approve(event)
-      elsif reactions[Emoji::N]&.count.to_i > maj
-        deny(event)
-      elsif reactions[Emoji::CRAYON]&.count.to_i > maj
-        edit(event)
-      elsif reactions[Emoji::CROSS]&.count.to_i > 1
-        remove(event)
-      end
-    #rescue StandardError => e
-      #error_embed(e.message)
+    rescue StandardError => e
+      error_embed(e.message)
     end
   end
 

+ 2 - 9
app/app_forms/team_app.rb

@@ -3,17 +3,10 @@ require './app/app_forms/app_form.rb'
 class TeamApplication < ApplicationForm
   def self.process
     @process ||= Application.new('Team Application') do |event|
-      # Calculate majority, and check votes
+      # Calculate majority and check votes
       maj = majority(event)
-      reactions = event.message.reactions
+      check_votes(event, maj)
 
-      if reactions[Emoji::Y]&.count.to_i > maj && star(event)
-        approve(event)
-      elsif reactions[Emoji::N]&.count.to_i > maj
-        deny(event)
-      elsif reactions[Emoji::CROSS]&.count.to_i > 1
-        remove(event)
-      end
     rescue StandardError => e
       error_embed(e.message)
     end

+ 1 - 6
app/app_forms/team_join_app.rb

@@ -5,13 +5,8 @@ class TeamJoinApplication < ApplicationForm
     @process ||= Application.new('Team Join Request') do |event|
       # Calculate majority and check votes
       maj = majority(event)
-      reactions = event.message.reactions
+      check_votes(event, maj)
 
-      if reactions[Emoji::Y]&.count.to_i > maj
-        approve(event)
-      elsif reactions[Emoji::N]&.count.to_i > maj
-        deny(event)
-      end
     rescue StandardError => e
       error_embed(e.message)
     end

+ 30 - 0
app/models/embed.rb

@@ -88,4 +88,34 @@ class Embed
     hex = color.to_s.sub(/\A#/, '0x')
     Integer(hex)
   end
+
+  def self.convert(discord_embed)
+    fields = []
+    discord_embed.fields.each do |field|
+      fields.push({ name: field.name, value: field.value })
+    end
+
+    embed = Embed.new(
+      title: discord_embed.title,
+      description: discord_embed.description,
+      url: discord_embed.url,
+      color: discord_embed.color&.combined,
+      timestamp: discord_embed.timestamp
+    )
+
+    embed.footer = {
+      icon_url: discord_embed.footer.icon_url,
+      text: discord_embed.footer.text
+    } if discord_embed.footer
+    embed.thumbnail = { url: discord_embed.thumbnail.url } if discord_embed.thumbnail
+    embed.image = { url: discord_embed.image.url } if discord_embed.image
+    embed.author = {
+      icon_url: discord_embed.author.icon_url,
+      name: discord_embed.author.name,
+      url: discord_embed.author.url,
+    } if discord_embed.author
+    embed.fields = fields if fields
+
+    embed
+  end
 end

+ 1 - 1
app/models/users.rb

@@ -73,7 +73,7 @@ class User < ActiveRecord::Base
     n = Nature.find(nature)
 
     stats = stat_calc(n.up_stat, n.down_stat)
-    img = stat_image(self, member, stats) if member
+    img = UsersController.stat_image(self, member, stats) if member
 
     self.update(stats)
     self.reload

+ 3 - 0
lib/emoji.rb

@@ -82,6 +82,9 @@ module Emoji
   WIZARD = "🧙"
   TALK = "🗣️"
 
+  GHOST = "👻"
+  FISH = "🐟"
+
 
   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]
   NUMBERS = [ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN]