matchup.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. require './app/commands/base_command.rb'
  2. class MatchupCommand < BaseCommand
  3. def self.opts
  4. {
  5. usage: {
  6. primary: "Searches for type by name, must be an official pokemon type",
  7. secondary: "Concats the second type to the first, and displays both"
  8. }
  9. }
  10. end
  11. def self.cmd
  12. desc = "Displays a chart of effectiveness for the given type"
  13. @cmd ||= Command.new(:matchup, desc, opts) do |event, primary, secondary|
  14. # Find the appropriate type images
  15. file = "images/Type #{primary.capitalize}.png"
  16. secondary_file = "images/Type #{secondary.capitalize}.png"
  17. # Combine if there are two
  18. if File.exists?(file) && File.exists?(secondary_file)
  19. append_image(file, secondary_file, 'images/Type Double.png')
  20. file = 'images/Type Double.png'
  21. end
  22. # Raise an error if the File does not exist, or return
  23. raise 'Unknown Type!' unless File.exists?(file)
  24. BotResponse.new(destination: event.channel.id, file: file)
  25. rescue StandardError => e
  26. error_embed(e.message)
  27. end
  28. end
  29. def self.example_command(event=nil)
  30. case ['primary', 'secondary'].sample
  31. when 'primary'
  32. [Type.where.not(name: 'Unknown').order('RANDOM()').first.name]
  33. when 'secondary'
  34. type = Type.where.not(name: 'Unknown').order('RANDOM()').take(2)
  35. type.map(&:name)
  36. end
  37. end
  38. end