image_app.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. require './app/app_forms/app_form.rb'
  2. class ImageApplication < ApplicationForm
  3. def self.process
  4. @process ||= Application.new('Image Application') do |event|
  5. # Calculate majority, and check votes
  6. maj = majority(event)
  7. reactions = event.message.reactions
  8. if reactions[Emoji::Y]&.count.to_i > maj && star(event)
  9. approve(event)
  10. elsif reactions[Emoji::N]&.count.to_i > maj
  11. deny(event)
  12. elsif reactions[Emoji::CROSS]&.count.to_i > 1
  13. remove(event)
  14. end
  15. rescue StandardError => e
  16. error_embed(e.message)
  17. end
  18. end
  19. def self.approve(event)
  20. # Save app
  21. app = event.message.embeds.first
  22. # Update image and find character
  23. image = ImageController.edit_image(app)
  24. character = Character.find(image.char_id)
  25. # Determine appropriate channel
  26. channel = image.category == 'NSFW' ? ENV['CHAR_NSFW_CH'] : ENV['CHAR_CH']
  27. reply = BotResponse.new(
  28. destination: channel,
  29. text: "Good News, <@#{character.user_id}>! Your image was approved!",
  30. embed: character_embed(
  31. character: character,
  32. event: event,
  33. section: 'image',
  34. image: image
  35. )
  36. )
  37. # Delete app and reply
  38. event.message.delete
  39. reply
  40. end
  41. def self.deny(event)
  42. # Create App Rejection
  43. reply = BotResponse.new(
  44. embed: reject_app(event.message.embeds.first, :image),
  45. reactions: ImgApp::REJECT_MESSAGES.map{ |k,v| k }.push(Emoji::CHECK)
  46. )
  47. # Delete app, and reply
  48. event.message.delete
  49. reply
  50. end
  51. end