status.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. class StatusCommand < BaseCommand
  2. def self.opts
  3. {
  4. usage: {
  5. name: "Searches for a status by its name. If none is specified, " +
  6. "R0ry displays a list of all statuses"
  7. }
  8. }
  9. end
  10. def self.cmd
  11. desc = "Update or edit statuses"
  12. @cmd ||= Command.new(:status, desc, opts) do |event, name, effect, flag|
  13. if effect
  14. # Update or create status, returns embed
  15. StatusController.update_status(name, effect, flag) if Util::Roles.admin?(event.author)
  16. else
  17. # Find Status, if specified
  18. status = Status.find_by('name ilike ?', name) if name
  19. # Display Status or Status List
  20. embed = status ? status_details(status) : status_list
  21. embed
  22. end
  23. rescue ActiveRecord::RecordNotFound => e
  24. error_embed(e.message)
  25. rescue StandardError => e
  26. error_embed(e.message)
  27. end
  28. end
  29. def self.example_command(event=nil)
  30. case ['', 'name'].sample
  31. when ''
  32. []
  33. when 'name'
  34. [Status.order('RANDOM()').first.name]
  35. end
  36. end
  37. def self.admin_opts
  38. {
  39. usage: {
  40. name: "The name given to the status",
  41. effect: "The effect to display on a user.",
  42. flag: "Indicates if the effect stacks, default is true"
  43. }
  44. }
  45. end
  46. end