character_app.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. require './app/app_forms/app_form.rb'
  2. class CharacterApplication < ApplicationForm
  3. def self.process
  4. @process ||= Application.new('Character Application') do |event|
  5. # Calculate majority, and check votes
  6. maj = majority(event)
  7. reactions = event.message.reactions
  8. if reactions[Emoji::Y]&.count.to_i > maj && star(event)
  9. approve(event)
  10. elsif reactions[Emoji::N]&.count.to_i > maj
  11. deny(event)
  12. elsif reactions[Emoji::CRAYON]&.count.to_i > 1
  13. edit(event)
  14. elsif reactions[Emoji::CROSS]&.count.to_i > 1
  15. remove(event)
  16. end
  17. rescue StandardError => e
  18. error_embed(e.message)
  19. end
  20. end
  21. def self.approve(event)
  22. # Save the application, and member if they exist
  23. app = event.message.embeds.first
  24. user_id = app.description.match(UID)
  25. member = event.server.member(user_id[1])
  26. # Save character and default image
  27. character = CharacterController.edit_character(app)
  28. ImageController.default_image(app.thumbnail&.url, character.id, character.rating)
  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. # Save the application
  47. app = event.message.embeds.first
  48. # Create App Rejection
  49. reply = BotResponse.new(
  50. embed: reject_app_embed(app, :character),
  51. reactions: CharApp::REJECT_MESSAGES.map{ |k,v| k }
  52. )
  53. # Delete app, and reply
  54. event.message.delete
  55. reply
  56. end
  57. def self.edit(event)
  58. # Save the application
  59. app = event.message.embeds.first
  60. # Create link embed
  61. reply = BotResponse.new(
  62. destination: event.channel.id,
  63. embed: self_edit_embed(app.footer.text, Url::CHARACTER),
  64. timer: 35
  65. )
  66. # Delete app and reply
  67. event.message.delete
  68. reply
  69. end
  70. end