landmark.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. require './app/commands/base_command.rb'
  2. class LandmarkCommand < BaseCommand
  3. def self.opts
  4. {
  5. # Nav consists of reaction sections and descriptions
  6. nav: {
  7. history: [Emoji::BOOKS, 'Learn about the history and folklore'],
  8. warning: [Emoji::SKULL, 'Learn about the areas dangers'],
  9. map: [Emoji::MAP, 'See the area on the map of Zaplana'],
  10. layout: [Emoji::HOUSES, 'View a local map of the area'],
  11. npc: [Emoji::PEOPLE, 'See the NPC residents you might meet']
  12. },
  13. # Usage has each option, in order with instructions, and a real example
  14. usage: {
  15. name:
  16. 'Searches landmarks for the specified name. ' +
  17. 'If no name is given, R0ry will show a list of all landmarks',
  18. section:
  19. 'Skips to the specified section, can use any section listed in ' +
  20. 'navigation. If no section is given, R0ry will default to history'
  21. }
  22. }
  23. end
  24. def self.cmd
  25. desc = 'Learn all about the various places in Zaplana!'
  26. @cmd ||= Command.new(:landmark, desc, opts) do |event, name, section|
  27. if name
  28. # Find landmark, case insensitive
  29. landmark = Landmark.find_by!('name ilike ?', name)
  30. # Reply with landmark display
  31. BotResponse.new(
  32. embed: landmark_embed(lm: landmark, section: section, event: event),
  33. carousel: landmark,
  34. reactions: LandmarkCarousel.sections.map { |k, _v| k }.push(Emoji::CROSS)
  35. )
  36. else
  37. # Reply with landmark list display
  38. landmark_list
  39. end
  40. rescue ActiveRecord::RecordNotFound => e
  41. error_embed('Record Not Found!', e.message)
  42. rescue StandardError => e
  43. error_embed(e.message)
  44. end
  45. end
  46. def self.example_command(_event=nil)
  47. case ['', 'name', 'section'].sample
  48. when ''
  49. []
  50. when 'name'
  51. [Landmark.order('RANDOM()').first.name]
  52. when 'section'
  53. [Landmark.order('RANDOM()').first.name,
  54. %w[history warning map layout npc].sample]
  55. end
  56. end
  57. end