character_app.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. admin_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. member = event.server.member(UID.match(app.description)[1])
  25. # Save character and default image
  26. character = CharacterController.edit_character(app)
  27. ImageController.default_image(app.thumbnail&.url, character.id, character.rating)
  28. # Determine appropriate channel
  29. channel = case character.rating
  30. when /sfw/i then ENV['CHAR_CH']
  31. when /nsfw/i then ENV['CHAR_NSFW_CH']
  32. when /hidden/i then member.dm
  33. end
  34. # Create reply
  35. reply = BotResponse.new(
  36. destination: channel,
  37. text: "Good News, <@#{character.user_id}>! Your character was approved!",
  38. embed: character_embed(character: character, event: event)
  39. )
  40. # Delete app from approval channel, and reply
  41. event.message.delete
  42. reply
  43. end
  44. def self.deny(event)
  45. # Save the application
  46. app = event.message.embeds.first
  47. # Create App Rejection
  48. reply = BotResponse.new(
  49. embed: reject_app_embed(app, :character),
  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. # Save the application
  58. app = event.message.embeds.first
  59. # Create link embed
  60. reply = BotResponse.new(
  61. destination: event.channel.id,
  62. embed: self_edit_embed(app.footer.text, Url::CHARACTER),
  63. timer: 35
  64. )
  65. # Delete app and reply
  66. event.message.delete
  67. reply
  68. end
  69. end