team_app.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. require './app/app_forms/app_form.rb'
  2. class TeamApplication < ApplicationForm
  3. def self.process
  4. @process ||= Application.new('Team Application') do |event|
  5. # Calculate majority, and check votes
  6. maj = majority(event)
  7. reactions = event.message.reactions
  8. if reactions[Emoji::Y]&.count.to_i > maj && star(event)
  9. approve(event)
  10. elsif reactions[Emoji::N]&.count.to_i > maj
  11. deny(event)
  12. elsif reactions[Emoji::Cross]&.count.to_i > 1
  13. remove(event)
  14. end
  15. rescue StandardError => e
  16. admin_error_embed(e.message)
  17. end
  18. end
  19. def self.approve(event)
  20. # Save the application
  21. app = event.message.embeds.first
  22. # Create Role
  23. role = event.server.create_role(
  24. name: app.title,
  25. colour: 3447003,
  26. hoist: true,
  27. mentionable: true,
  28. reason: 'New Team'
  29. )
  30. # Sort the Team above Clubs
  31. role.sort_above(ENV['TEAM_ROLE'])
  32. # Create Channel
  33. channel = event.server.create_channel(
  34. app.title,
  35. parent: ENV['TEAM_CAT'],
  36. permission_overwrites: [
  37. { id: event.server.everyone_role.id, deny: 1024 },
  38. { id: role.id, allow: 1024 }
  39. ]
  40. )
  41. # Create new team
  42. team = Team.create(
  43. name: app.title,
  44. description: app.description,
  45. role: role.id.to_s,
  46. channel: channel.id.to_s
  47. )
  48. reply = BotResponse.new(
  49. destination: ENV['TEAM_CH'],
  50. embed: message_embed(
  51. "#{team.name} was approved!",
  52. "Request to join with ```pkmn-team #{team.name} | apply | character_name```"
  53. )
  54. )
  55. event.message.delete
  56. reply
  57. end
  58. def self.deny(event)
  59. event.message.delete
  60. end
  61. end