reject.rb 2.9 KB

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