reactivate_app.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. require './app/app_forms/app_form.rb'
  2. class ReactivationApplication < ApplicationForm
  3. def self.process
  4. @process ||= Application.new('Reactivation 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. app = event.message.embeds.first
  14. # Find Character
  15. character = Character.find(app.footer.text.match(/\|\s(\d+)$/)[1])
  16. # Reactivate and reload
  17. character.update(active: 'Active')
  18. character.reload
  19. # Determine appropriate channel
  20. channel = case character.rating
  21. when /sfw/i then ENV['CHAR_CH']
  22. when /nsfw/i then ENV['CHAR_NSFW_CH']
  23. when /hidden/i then member.dm
  24. end
  25. # Create reply
  26. reply = BotResponse.new(
  27. destination: channel,
  28. text: "Good News, <@#{character.user_id}>! your character was approved!",
  29. embed: character_embed(character: character, event: event)
  30. )
  31. # Delete app from approval channel, and reply
  32. event.message.delete
  33. reply
  34. end
  35. def self.deny(event)
  36. # Create App Rejection
  37. reply = BotResponse.new(
  38. embed: reject_app(event.message.embeds.first, :reactivation),
  39. reactions: CharApp::REJECT_MESSAGES.map{ |k,v| k }.push(Emoji::CHECK)
  40. )
  41. # Delete app, and reply
  42. event.message.delete
  43. reply
  44. end
  45. def self.edit(event)
  46. app = event.message.embeds.first
  47. # Find Character
  48. character = Character.find(app.footer.text.match(/\|\s(\d+)$/)[1])
  49. # Create link embed
  50. reply = BotResponse.new(
  51. destination: event.channel.id,
  52. embed: self_edit_embed(character.edit_url, Url::CHARACTER),
  53. timer: 35
  54. )
  55. # Delete app and reply
  56. event.message.delete
  57. reply
  58. end
  59. end