Class: CommandBot::Command

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

Overview

Stores command handler.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: '', aliases: [], data: {}) {|bot, arguments, options, other| ... } ⇒ Command

Initalize new command.

Yield Parameters:

  • bot (Bot)
  • arguments (Array<String>)
  • options (Hash<String, String>)
  • other (Array<void>)

Yield Returns:

  • (void)


15
16
17
18
19
20
21
# File 'lib/command_bot/command.rb', line 15

def initialize(name: '', aliases: [], data: {}, &handler)
  @name = name
  @aliases = aliases
  @data = data

  @handler = handler
end

Instance Attribute Details

#aliasesArray<String> (readonly)



27
28
29
# File 'lib/command_bot/command.rb', line 27

def aliases
  @aliases
end

#dataHash (readonly)



30
31
32
# File 'lib/command_bot/command.rb', line 30

def data
  @data
end

#handlerProc (readonly)



33
34
35
# File 'lib/command_bot/command.rb', line 33

def handler
  @handler
end

#nameString (readonly)



24
25
26
# File 'lib/command_bot/command.rb', line 24

def name
  @name
end

Instance Method Details

#all_aliasesArray<String>



36
37
38
# File 'lib/command_bot/command.rb', line 36

def all_aliases
  aliases + [name]
end

#name_matches?(*names) ⇒ Boolean



42
43
44
# File 'lib/command_bot/command.rb', line 42

def name_matches?(*names)
  all_aliases.any? { |a| names.include?(a) }
end