Class: Rubord::CommandRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/rubord/models/commands/registry.rb

Instance Method Summary collapse

Constructor Details

#initializeCommandRegistry

Returns a new instance of CommandRegistry.



3
4
5
# File 'lib/rubord/models/commands/registry.rb', line 3

def initialize
  @commands = {}
end

Instance Method Details

#allObject



20
21
22
# File 'lib/rubord/models/commands/registry.rb', line 20

def all
  @commands.values.freeze
end

#get(name) ⇒ Object



16
17
18
# File 'lib/rubord/models/commands/registry.rb', line 16

def get(name)
  @commands.find{ |_, c| c.name == name || c.aliases.include?(name)}&.last
end

#register(klass, client, logCommands = true) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/rubord/models/commands/registry.rb', line 7

def register(klass, client, logCommands = true)
  name = klass.command_name
  raise "Command missing name" unless name
  
  @commands[name] = klass.new(client)
  
  Rubord::Logger.success "[Rubord:Commands] Registered command: #{name}" if logCommands
end