| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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
- maj = majority(event)
- 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
- end
- def self.approve(event)
- # Save app
- app = event.message.embeds.first
- # Update image and find character
- image = ImageController.edit_image(app)
- character = Character.find(image.char_id)
- # Determine appropriate channel
- channel = image.category == 'NSFW' ? ENV['CHAR_NSFW_CH'] : ENV['CHAR_CH']
- reply = BotResponse.new(
- destination: channel,
- text: "Good News, <@#{character.user_id}>! Your image was approved!",
- embed: character_embed(
- character: character,
- event: event,
- section: 'image',
- image: image
- )
- )
- # Delete app and reply
- event.message.delete
- reply
- end
- def self.deny(event)
- # Create App Rejection
- reply = BotResponse.new(
- embed: reject_app(event.message.embeds.first, :image),
- reactions: ImgApp::REJECT_MESSAGES.map{ |k,v| k }.push(Emoji::CHECK)
- )
- # Delete app, and reply
- event.message.delete
- reply
- end
- end
|