Class: Commandorobo::Command
- Inherits:
 - 
      Object
      
        
- Object
 - Commandorobo::Command
 
 
- Defined in:
 - lib/commandorobo.rb
 
Overview
Class that represents a command.
Instance Attribute Summary collapse
- 
  
    
      #code  ⇒ Block 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The code to execute when the command fires.
 - 
  
    
      #description  ⇒ String 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The description for the command.
 - 
  
    
      #invokers  ⇒ Array 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The invokers for the command.
 - 
  
    
      #name  ⇒ Symbol 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The name of the command.
 - 
  
    
      #permissions  ⇒ Array 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The permissions required to execute the command.
 
Instance Method Summary collapse
- 
  
    
      #initialize(name, code, permissions, description, invokers, bot)  ⇒ Command 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Command.
 - 
  
    
      #invoke(event, args)  ⇒ nil 
    
    
  
  
  
  
  
  
  
  
  
    
Invokes the command.
 - 
  
    
      #perm_check(event)  ⇒ true, Commandorobo::NoPermission 
    
    
  
  
  
  
  
  
  
  
  
    
Checks permissions for a command.
 
Constructor Details
#initialize(name, code, permissions, description, invokers, bot) ⇒ Command
Returns a new instance of Command.
      118 119 120 121 122 123 124 125  | 
    
      # File 'lib/commandorobo.rb', line 118 def initialize(name, code, , description, invokers, bot) @name = name @code = code @permissions = @description = description @invokers = invokers.nil? ? [name] : invokers @bot = bot end  | 
  
Instance Attribute Details
#code ⇒ Block (readonly)
The code to execute when the command fires.
      115 116 117  | 
    
      # File 'lib/commandorobo.rb', line 115 def code @code end  | 
  
#description ⇒ String (readonly)
The description for the command.
      115 116 117  | 
    
      # File 'lib/commandorobo.rb', line 115 def description @description end  | 
  
#invokers ⇒ Array
The invokers for the command.
      115 116 117  | 
    
      # File 'lib/commandorobo.rb', line 115 def invokers @invokers end  | 
  
#name ⇒ Symbol (readonly)
The name of the command.
      115 116 117  | 
    
      # File 'lib/commandorobo.rb', line 115 def name @name end  | 
  
#permissions ⇒ Array (readonly)
The permissions required to execute the command.
      115 116 117  | 
    
      # File 'lib/commandorobo.rb', line 115 def @permissions end  | 
  
Instance Method Details
#invoke(event, args) ⇒ nil
Invokes the command.
      131 132 133  | 
    
      # File 'lib/commandorobo.rb', line 131 def invoke(event, args) @code.call(event, args) end  | 
  
#perm_check(event) ⇒ true, Commandorobo::NoPermission
Checks permissions for a command.
      138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158  | 
    
      # File 'lib/commandorobo.rb', line 138 def perm_check(event) perms = {} @permissions.each do |p| if p == :bot_owner perms[p] = @bot.owners.include?(event..id) else perms[p] = event..(p) end end if !perms.values.all? noperms = [] perms.keys.each do |p| if !perms[p] noperms << p end end Commandorobo::NoPermission.new(noperms) else true end end  |