reject.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. MSG = "Please resubmit when you've addressed the issues!\n"
  2. FTR = "If you have any questions, feel free to ask a Guildmaster"
  3. def reject_app(app, opts)
  4. embed = Embed.new(
  5. title: app.title,
  6. description: app.description,
  7. color: ERROR,
  8. author: {
  9. name: app.author.name.gsub('Application', 'Rejection'),
  10. icon_url: app.author.icon_url
  11. },
  12. footer: { text: app.footer.text }
  13. )
  14. fields = case opts
  15. when :character
  16. reject_fields(CharApp::REJECT_MESSAGES)
  17. when :image
  18. reject_fields(ImgApp::REJECT_MESSAGES)
  19. when :landmark
  20. reject_fields(LmApp::REJECT_MESSAGES)
  21. when :reactivation
  22. # Find Character
  23. character = Character.find(app.footer.text.match(/\|\s(\d+)$/)[1])
  24. # Set embed up correctly
  25. embed.title = character.name
  26. embed.description = "<@#{character.user_id}>"
  27. embed.footer = { text: character.edit_url }
  28. embed.author = { name: 'Character Rejection' }
  29. reject_fields(CharApp::REJECT_MESSAGES)
  30. end
  31. # Add one last field and update embed
  32. fields.push({ name: Emoji::CHECK, value: "Indicates you are finished" })
  33. embed.fields = fields
  34. embed
  35. end
  36. def reject_fields(message_hash)
  37. fields = []
  38. message_hash.map do |emoji, message|
  39. fields.push({
  40. name: emoji,
  41. value: "#{message}\n#{CharApp::INLINE_SPACE}",
  42. inline: true
  43. })
  44. end
  45. end
  46. def rejected_app(event, opts)
  47. # Save the app and the reactions
  48. app = event.message.embeds.first
  49. reactions = event.message.reactions
  50. # Fill out the selected messages in accordance with the form
  51. fields =
  52. case opts
  53. when :character
  54. [{
  55. name: "Messages from the admin:",
  56. value: selected_messages(reactions, CharApp::REJECT_MESSAGES).
  57. join("\n") || 'No messages given'
  58. },{
  59. name: MSG,
  60. value: "[Edit Your Application](#{URL::CHARACTER}" +
  61. "#{app.footer.text})"
  62. }]
  63. when :image
  64. [{
  65. name: "Messages from the admin:",
  66. value: selected_messages(reactions, ImgApp::REJECT_MESSAGES).
  67. join("\n") || 'No messages given'
  68. }]
  69. when :landmark
  70. [{
  71. name: "Messages from the admin:",
  72. value: selected_messages(reactions, LmApp::REJECT_MESSAGES).
  73. join("\n") || 'No messages given'
  74. },{
  75. name: MSG,
  76. value: "[Edit Your Application](#{URL::LANDMARK}" +
  77. "#{app.footer.text})"
  78. }]
  79. end
  80. # Populate embed and return
  81. Embed.new(
  82. title: "Your application has been rejected!",
  83. description: app.title,
  84. color: ERROR,
  85. footer: { text: FTR },
  86. fields: fields
  87. )
  88. end
  89. def selected_messages(reactions, hash)
  90. messages = []
  91. hash.each do |emoji, message|
  92. messages.push(message) if reactions[emoji]&.count.to_i > 1
  93. end
  94. messages
  95. end
  96. def self_edit_embed(edit_url, form)
  97. Embed.new(
  98. title: "Don't forget to resubmit!",
  99. color: ERROR,
  100. description: "[Edit the Application](#{form}#{edit_url})"
  101. )
  102. end