raffle.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 = case winner
  27. when String then winner.capitalize
  28. else
  29. "<@#{winner.id}>"
  30. end
  31. # Reply
  32. Embed.new(description: "#{results} has won the raffle!")
  33. rescue StandardError => e
  34. error_embed(e.message)
  35. end
  36. end
  37. def self.example_command(event=nil)
  38. list = [
  39. 'Neiro, Mizu, Lunick, Alina, Viewer, Vul',
  40. 'Cecil, Aster, Zel, Rezi, Vern, Sarah, Bernie',
  41. 'Apple, Cherry, Strawberry, Lemon, Chocolate',
  42. 'Eevee, Vaporeon, Flareon, Jolteon, Espeon, Umbreon, Glaceon, Leafeon, Sylveon',
  43. 'Sword, Sheild, Gun, Bomb, Tank, Fighter Jet'
  44. ].sample
  45. [ ['everyone'], ['here'], [list] ].sample
  46. end
  47. end