landmark_app.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require './app/app_forms/app_form.rb'
  2. class LandmarkApplication < ApplicationForm
  3. def self.process
  4. @process ||= Application.new('Landmark 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 the application
  14. app = event.message.embeds.first
  15. # Save landmark
  16. landmark = LandmarkController.edit_landmark(app)
  17. reply = BotResponse.new(
  18. destination: ENV['LM_CH'],
  19. text: "Good News, <@#{landmark.user_id}>! Your landmark was approved!",
  20. embed: landmark_embed(lm: landmark, event: 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, :landmark),
  28. reactions: LmApp::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::LANDMARK),
  40. timer: 35
  41. )
  42. # Delete app and reply
  43. event.message.delete
  44. reply
  45. end
  46. end