fable_app.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require './app/app_forms/app_form.rb'
  2. class FableApplication < ApplicationForm
  3. def self.process
  4. @process||= Application.new('Fable Application') do |event|
  5. # Calculate majority, and check votes
  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 the application
  14. app = event.message.embeds.first
  15. # Save fable
  16. fable = FableController.edit_fable(app)
  17. reply = BotResponse.new(
  18. destination: ENV['FABLE_CH'],
  19. text: "Good News, <@#{fable.user_id}>! Your fable was published!",
  20. embed: fable_embed(fable, event)
  21. )
  22. event.message.delete
  23. reply
  24. end
  25. def self.deny(event)
  26. reply = BotResponse.new(
  27. embed: reject_app(event.message.embeds.first, :fable),
  28. reactions: FableApp::REJECT_MESSAGES.map{ |k,v| k }.push(Emoji::CHECK)
  29. )
  30. # Delete message and reply
  31. event.message.delete
  32. reply
  33. end
  34. def self.edit(event)
  35. # Save the application
  36. app = event.message.embeds.first
  37. reply = BotResponse.new(
  38. destination: event.channel.id,
  39. embed: self_edit_embed(app.footer.text, Url::FABLE),
  40. timer: 35
  41. )
  42. # Delete app and reply
  43. event.message.delete
  44. reply
  45. end
  46. end