cure.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. require './app/commands/base_command.rb'
  2. class CureCommand < BaseCommand
  3. def self.opts
  4. {
  5. usage: {
  6. character: "Searches for the character by name, can only cure your own characters",
  7. status: "Searches for a status effect by name",
  8. amount: "Removes a percentage amount of the status, should only be used if status is stackable",
  9. }
  10. }
  11. end
  12. def self.cmd
  13. desc = "Cure characters of afflicted statuses"
  14. @cmd ||= Command.new(:cure, desc, opts) do |event, name, status, amount|
  15. # Find the Character and Status
  16. character = Character.restricted_find(name, event.author, ['Archived'])
  17. status = Status.find_by!('name ilike ?', status) unless status.match(/all/i)
  18. raise 'Amount must be a positive number' if amount.to_i < 1
  19. # Update Status, and reload
  20. StatusController.update_char_status(character, status, 0 - amount.to_i)
  21. character.reload
  22. # Create character embed, and reply
  23. BotResponse.new(
  24. embed: character_embed(character: character, event: event, section: :status)
  25. )
  26. rescue ActiveRecord::RecordNotFound => e
  27. error_embed(e.message)
  28. rescue StandardError => e
  29. error_embed(e.message)
  30. end
  31. end
  32. def self.example_command(event=nil)
  33. case ['unstackable', 'stackable'].sample
  34. when 'unstackable'
  35. [Character.where(active: 'Active').order('RANDOM()').first.name,
  36. Status.where(amount: false).order('RANDOM()').first.name]
  37. when 'stackable'
  38. [Character.where(active: 'Active').order('RANDOM()').first.name,
  39. Status.where(amount: true).order('RANDOM()').first.name,
  40. rand(1 .. 100)]
  41. end
  42. end
  43. end