reactivate_app.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. # Create App Rejection
  47. reply = BotResponse.new(
  48. embed: reject_app(event.message.embeds.first, :reactivation),
  49. reactions: CharApp::REJECT_MESSAGES.map{ |k,v| k }.push(Emoji::CHECK)
  50. )
  51. # Delete app, and reply
  52. event.message.delete
  53. reply
  54. end
  55. def self.edit(event)
  56. app = event.message.embeds.first
  57. # Find Character
  58. character = Character.find(app.footer.text.match(/\|\s(\d+)$/)[1])
  59. # Create link embed
  60. reply = BotResponse.new(
  61. destination: event.channel.id,
  62. embed: self_edit_embed(character.edit_url, Url::CHARACTER),
  63. timer: 35
  64. )
  65. # Delete app and reply
  66. event.message.delete
  67. reply
  68. end
  69. end