matchup.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 primary type image, or raise exception if none is found
  15. raise "No type given" unless primary
  16. file = "images/Type #{primary.capitalize}.png"
  17. # If a secondary type is given, append images for each
  18. if secondary
  19. file_2 = "images/Type #{secondary.capitalize}.png"
  20. append_image(file, file_2, 'images/Type Double.png')
  21. file = 'images/Type Double.png'
  22. end
  23. # Raise an error if the File does not exist, or return
  24. raise 'Unknown Type!' unless File.exists?(file)
  25. BotResponse.new(destination: event.channel.id, file: file)
  26. rescue StandardError => e
  27. error_embed(e.message)
  28. end
  29. end
  30. def self.example_command(event=nil)
  31. case ['primary', 'secondary'].sample
  32. when 'primary'
  33. [Type.where.not(name: 'Unknown').order('RANDOM()').first.name]
  34. when 'secondary'
  35. type = Type.where.not(name: 'Unknown').order('RANDOM()').take(2)
  36. type.map(&:name)
  37. end
  38. end
  39. end