reject.rb 3.3 KB

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