Class: Discordrb::Commands::Command
- Inherits:
-
Object
- Object
- Discordrb::Commands::Command
- Defined in:
- lib/discordrb/commands/parser.rb
Overview
Command that can be called in a chain
Instance Attribute Summary collapse
-
#attributes ⇒ Hash
readonly
The attributes the command was initialized with.
-
#name ⇒ Symbol
readonly
The name of this command.
Instance Method Summary collapse
-
#call(event, arguments, chained = false, check_permissions = true) ⇒ String
Calls this command and executes the code inside.
Instance Attribute Details
#attributes ⇒ Hash (readonly)
Returns the attributes the command was initialized with.
7 8 9 |
# File 'lib/discordrb/commands/parser.rb', line 7 def attributes @attributes end |
#name ⇒ Symbol (readonly)
Returns the name of this command.
10 11 12 |
# File 'lib/discordrb/commands/parser.rb', line 10 def name @name end |
Instance Method Details
#call(event, arguments, chained = false, check_permissions = true) ⇒ String
Calls this command and executes the code inside.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/discordrb/commands/parser.rb', line 73 def call(event, arguments, chained = false, = true) if arguments.length < @attributes[:min_args] event.respond "Too few arguments for command `#{name}`!" event.respond "Usage: `#{@attributes[:usage]}`" if @attributes[:usage] return end if @attributes[:max_args] >= 0 && arguments.length > @attributes[:max_args] event.respond "Too many arguments for command `#{name}`!" event.respond "Usage: `#{@attributes[:usage]}`" if @attributes[:usage] return end unless @attributes[:chain_usable] if chained event.respond "Command `#{name}` cannot be used in a command chain!" return end end if rate_limited = event.bot.rate_limited?(@attributes[:bucket], event.) if @attributes[:bucket] && rate_limited if @attributes[:rate_limit_message] event.respond @attributes[:rate_limit_message].gsub('%time%', rate_limited.round(2).to_s) end return end end result = @block.call(event, *arguments) event.drain_into(result) rescue LocalJumpError # occurs when breaking nil end |