landmark.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. ['history', 'warning', 'map', 'layout', 'npc'].sample]
  55. end
  56. end
  57. end