item_app.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. require './app/app_forms/app_form.rb'
  2. class ItemApplication < ApplicationForm
  3. def self.process
  4. @process ||= Application.new('Item Application') do |event|
  5. # Calculate majority
  6. maj = majority(event)
  7. # Check votes
  8. reactions = event.message.reactions
  9. if reactions[Emoji::Y]&.count.to_i > maj && star(event)
  10. approve(event)
  11. elsif reactions[Emoji::N]&.count.to_i > maj
  12. deny(event)
  13. elsif reactions[Emoji::Crayon]&.count.to_i > 1
  14. edit(event)
  15. elsif reactions[Emoji::Cross]&.count.to_i > 1
  16. remove(event)
  17. end
  18. rescue StandardError => e
  19. admin_error_embed(e.message)
  20. end
  21. end
  22. def self.approve(event)
  23. # Save the application
  24. app = event.message.embeds.first
  25. # Save item
  26. item = ItemController.edit_landmark(app)
  27. reply = BotResponse.new(
  28. destination: ENV['LM_CH'],
  29. text: "Good News, <@#{item.user_id}>! Your landmark was approved!",
  30. embed: item_embed(item, event)
  31. )
  32. event.message.delete
  33. reply
  34. end
  35. def self.deny(event)
  36. # Save the application
  37. app = event.message.embeds.first
  38. reply = BotResponse.new(
  39. embed: reject_app_embed(app, :item),
  40. reactions: ItemApp::REJECT_MESSAGES.map{ |k,v| k }
  41. )
  42. # Delete message and reply
  43. event.message.delete
  44. reply
  45. end
  46. def self.edit(event)
  47. # Save the application
  48. app = event.message.embeds.first
  49. reply = BotResponse.new(
  50. destination: event.channel.id,
  51. embed: self_edit_embed(app.footer.text, Url::ITEM),
  52. timer: 35
  53. )
  54. # Delete app and reply
  55. event.message.delete
  56. reply
  57. end
  58. end