image_app.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. # Update image and find character
  21. image = ImageController.edit_image(app)
  22. character = Character.find(image.char_id)
  23. # Determine appropriate channel
  24. channel = image.rating == 'NSFW' ? ENV['CHAR_NSFW_CH'] : ENV['CHAT_CH']
  25. reply = BotResponse.new(
  26. destination: channel,
  27. text: "Good News, <@#{character.user_id}>! Your image was approved!",
  28. embed: character_embed(
  29. character: character,
  30. event: event,
  31. section: 'image',
  32. image: image
  33. )
  34. )
  35. # Delete app and reply
  36. event.message.delete
  37. reply
  38. end
  39. def self.deny(event)
  40. # Create App Rejection
  41. reply = BotResponse.new(
  42. embed: reject_app_embed(app, :image),
  43. reactions: ImgApp::REJECT_MESSAGES.map{ |k,v| k }
  44. )
  45. # Delete app, and reply
  46. event.message.delete
  47. reply
  48. end
  49. end