reactivate_app.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 Save application
  6. maj = majority(event)
  7. # Check votes
  8. reactions = event.message.reactions
  9. if reactions[Emoji::Y]&.count.to_i > maj && star(event)
  10. approve(event)
  11. elsif reactions[Emoji::N]&count.to_i > maj
  12. deny(event)
  13. elsif reactions[Emoji::CRAYON]&count.to_i > maj
  14. edit(event)
  15. elsif reactions[Emoji::Cross]&.count.to_i > 1
  16. remove(event)
  17. end
  18. #rescue StandardError => e
  19. #error_embed(e.message)
  20. end
  21. end
  22. def self.approve(event)
  23. app = event.message.embeds.first
  24. # Find Character
  25. character = Character.find(app.footer.text.match(/\|\s(\d+)$/)[1])
  26. # Reactivate and reload
  27. character.update(active: 'Active')
  28. character.reload
  29. # Determine appropriate channel
  30. channel = case character.rating
  31. when /sfw/i then ENV['CHAR_CH']
  32. when /nsfw/i then ENV['CHAR_NSFW_CH']
  33. when /hidden/i then member.dm
  34. end
  35. # Create reply
  36. reply = BotResponse.new(
  37. destination: channel,
  38. text: "Good News, <@#{character.user_id}>! your character was approved!",
  39. embed: character_embed(character: character, event: event)
  40. )
  41. # Delete app from approval channel, and reply
  42. event.message.delete
  43. reply
  44. end
  45. def self.deny(event)
  46. app = event.message.embeds.first
  47. # Create App Rejection
  48. reply = BotResponse.new(
  49. embed: reject_app_embed(app, :reactivation),
  50. reactions: CharApp::REJECT_MESSAGES.map{ |k,v| k }
  51. )
  52. # Delete app, and reply
  53. event.message.delete
  54. reply
  55. end
  56. def self.edit(event)
  57. app = event.message.embeds.first
  58. # Find Character
  59. character = Character.find(app.footer.text.match(/\|\s(\d+)$/)[1])
  60. # Create link embed
  61. reply = BotResponse.new(
  62. destination: event.channel.id,
  63. embed: self_edit_embed(character.edit_url, Url::CHARACTER),
  64. timer: 35
  65. )
  66. # Delete app and reply
  67. event.message.delete
  68. reply
  69. end
  70. end