Class: Commandorobo::Command
- Inherits:
-
Object
- Object
- Commandorobo::Command
- Defined in:
- lib/commandorobo.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#invokers ⇒ Object
readonly
Returns the value of attribute invokers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
Instance Method Summary collapse
-
#initialize(name, code, permissions, description, invokers, bot) ⇒ Command
constructor
A new instance of Command.
- #invoke(event, args) ⇒ Object
- #perm_check(event) ⇒ Object
Constructor Details
#initialize(name, code, permissions, description, invokers, bot) ⇒ Command
Returns a new instance of Command.
90 91 92 93 94 95 96 97 |
# File 'lib/commandorobo.rb', line 90 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 ⇒ Object (readonly)
Returns the value of attribute code.
89 90 91 |
# File 'lib/commandorobo.rb', line 89 def code @code end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
89 90 91 |
# File 'lib/commandorobo.rb', line 89 def description @description end |
#invokers ⇒ Object (readonly)
Returns the value of attribute invokers.
89 90 91 |
# File 'lib/commandorobo.rb', line 89 def invokers @invokers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
89 90 91 |
# File 'lib/commandorobo.rb', line 89 def name @name end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
89 90 91 |
# File 'lib/commandorobo.rb', line 89 def @permissions end |
Instance Method Details
#invoke(event, args) ⇒ Object
99 100 101 |
# File 'lib/commandorobo.rb', line 99 def invoke(event, args) @code.call(event, args) end |
#perm_check(event) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/commandorobo.rb', line 103 def perm_check(event) perms = {} @permissions.each do |p| if p == :bot_owner perms[p] = @bot.config['owner'].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 |