image_app.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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
  6. maj = majority(event)
  7. check_votes(event, maj)
  8. rescue StandardError => e
  9. error_embed(e.message)
  10. end
  11. end
  12. def self.approve(event)
  13. # Save app
  14. app = event.message.embeds.first
  15. # Update image and find character
  16. image = ImageController.edit_image(app)
  17. character = Character.find(image.char_id)
  18. # Determine appropriate channel
  19. channel = image.category == 'NSFW' ? ENV['CHAR_NSFW_CH'] : ENV['CHAR_CH']
  20. reply = BotResponse.new(
  21. destination: channel,
  22. text: "Good News, <@#{character.user_id}>! Your image was approved!",
  23. embed: character_embed(
  24. character: character,
  25. event: event,
  26. section: 'image',
  27. image: image
  28. )
  29. )
  30. # Delete app and reply
  31. event.message.delete
  32. reply
  33. end
  34. def self.deny(event)
  35. # Create App Rejection
  36. reply = BotResponse.new(
  37. embed: reject_app(event.message.embeds.first, :image),
  38. reactions: ImgApp::REJECT_MESSAGES.map{ |k,v| k }.push(Emoji::CHECK)
  39. )
  40. # Delete app, and reply
  41. event.message.delete
  42. reply
  43. end
  44. end