poll.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. require './app/commands/base_command.rb'
  2. class PollCommand < BaseCommand
  3. def self.opts
  4. {
  5. usage: {
  6. question: 'The Question for people to vote on',
  7. options: 'The answers to choose from, separated by commas. Each answer ' +
  8. 'will be assigned a cooresponding letter for users to vote with. Maxiumum 20 options'
  9. }
  10. }
  11. end
  12. def self.cmd
  13. desc = 'Creates a dynamic poll in any channel'
  14. @cmd ||= Command.new(:poll, desc, opts) do |event, question, options|
  15. # Split choices into an array
  16. choices = options.split(/\s?,\s?/)
  17. # Reply
  18. raise 'Need voting options!' if choices.empty?
  19. BotResponse.new(
  20. embed: new_poll(event, question, choices),
  21. reactions: Emoji::LETTERS.take(choices.count)
  22. )
  23. rescue StandardError => e
  24. error_embed(e.message)
  25. end
  26. end
  27. def self.example_command(_event=nil)
  28. [
  29. ["What's your favorite cake?", 'Chocolate, Red Velvet, Ice Cream, Cookie, The Cake is a lie'],
  30. ['Who would win in an Epic Rap Battle?', 'Alina, Aster, Cecil, Jaki, Kipper, Someone Else (#poll-chat-sfw)'],
  31. ['The best admin/moderator is..', 'Neiro, Mizu, Lunick, Alina, Viewer, Vul, R0ry, He who must not be named'],
  32. ['The best pokemon generation is', 'Kanto, Johto, Hoenn, Sinnoh, Unova, Kalos, Alola, Galar'],
  33. ['What is the answer to the ultimate question of life, the universe, and everything?', 'What?, 42']
  34. ].sample
  35. end
  36. end