reject.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.fields[1].value || 'Unknown Character',
  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. message_hash.map{ |e,m| { name: e, value: m, inline: true } }
  38. end
  39. def rejected_app(event, opts)
  40. # Save the app and the reactions
  41. app = event.message.embeds.first
  42. reactions = event.message.reactions
  43. # Fill out the selected messages in accordance with the form
  44. fields =
  45. case opts
  46. when :character
  47. [{
  48. name: "Messages from the admin:",
  49. value: selected_messages(reactions, CharApp::REJECT_MESSAGES).
  50. join("\n") || 'No messages given'
  51. },{
  52. name: MSG,
  53. value: "[Edit Your Application](#{Url::CHARACTER}" +
  54. "#{app.footer.text})"
  55. }]
  56. when :image
  57. [{
  58. name: "Messages from the admin:",
  59. value: selected_messages(reactions, ImgApp::REJECT_MESSAGES).
  60. join("\n") || 'No messages given'
  61. }]
  62. when :landmark
  63. [{
  64. name: "Messages from the admin:",
  65. value: selected_messages(reactions, LmApp::REJECT_MESSAGES).
  66. join("\n") || 'No messages given'
  67. },{
  68. name: MSG,
  69. value: "[Edit Your Application](#{URL::LANDMARK}" +
  70. "#{app.footer.text})"
  71. }]
  72. end
  73. # Populate embed and return
  74. Embed.new(
  75. title: "Your application has been rejected!",
  76. description: app.title,
  77. color: ERROR,
  78. footer: { text: FTR },
  79. fields: fields
  80. )
  81. end
  82. def selected_messages(reactions, hash)
  83. messages = []
  84. hash.each do |emoji, message|
  85. messages.push(message) if reactions[emoji]&.count.to_i > 1
  86. end
  87. messages
  88. end
  89. def self_edit_embed(edit_url, form)
  90. Embed.new(
  91. title: "Don't forget to resubmit!",
  92. color: ERROR,
  93. description: "[Edit the Application](#{form}#{edit_url})"
  94. )
  95. end