Class: Commandorobo::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/commandorobo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, permissions, description, invokers, bot)
    @name = name
    @code = code
    @permissions = permissions
    @description = description
    @invokers = invokers.nil? ? [name] : invokers
 @bot = bot
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



89
90
91
# File 'lib/commandorobo.rb', line 89

def code
  @code
end

#descriptionObject (readonly)

Returns the value of attribute description.



89
90
91
# File 'lib/commandorobo.rb', line 89

def description
  @description
end

#invokersObject (readonly)

Returns the value of attribute invokers.



89
90
91
# File 'lib/commandorobo.rb', line 89

def invokers
  @invokers
end

#nameObject (readonly)

Returns the value of attribute name.



89
90
91
# File 'lib/commandorobo.rb', line 89

def name
  @name
end

#permissionsObject (readonly)

Returns the value of attribute permissions.



89
90
91
# File 'lib/commandorobo.rb', line 89

def permissions
  @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.author.id)
        else
            perms[p] = event.author.permission?(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