raffle.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. require './app/commands/base_command.rb'
  2. class RaffleCommand < BaseCommand
  3. def self.opts
  4. {
  5. usage: {
  6. participats: "Chooses a random winner from a list of names. " +
  7. "Also accepts everyone and here to pull names from server members"
  8. }
  9. }
  10. end
  11. def self.cmd
  12. desc = "Creates a raffle and picks a winner"
  13. @cmd ||= Command.new(:raffle, desc, opts) do |event, participant|
  14. # Collect participants
  15. participants =
  16. case participant
  17. when /^everyone$/i
  18. event.server.members
  19. when /^here$/i
  20. event.message.channel.users
  21. else
  22. participant.split(/\s?,\s?/)
  23. end
  24. # Pick winner and format
  25. winner = participants.sample
  26. results = winner&.id ? "<@#{winner.id}>" : winner.capitalize
  27. # Reply
  28. Embed.new(description: "#{results} has won the raffle!")
  29. rescue StandardError => e
  30. error_embed(e.message)
  31. end
  32. end
  33. def self.example_command(event=nil)
  34. list = [
  35. 'Neiro, Mizu, Lunick, Alina, Viewer, Vul',
  36. 'Cecil, Aster, Zel, Rezi, Vern, Sarah, Bernie',
  37. 'Apple, Cherry, Strawberry, Lemon, Chocolate',
  38. 'Eevee, Vaporeon, Flareon, Jolteon, Espeon, Umbreon, Glaceon, Leafeon, Sylveon',
  39. 'Sword, Sheild, Gun, Bomb, Tank, Fighter Jet'
  40. ].sample
  41. [ ['everyone'], ['here'], [list] ].sample
  42. end
  43. end