Class: Cinch::Commands::Help
- Inherits:
-
Object
- Object
- Cinch::Commands::Help
- Includes:
- Cinch::Commands
- Defined in:
- lib/cinch/commands/help.rb
Overview
Generic !help command that lists all commands.
Constant Summary
Constants included from Cinch::Commands
Instance Method Summary collapse
-
#commands_named(name) ⇒ Array<Command>
protected
Finds all commands with a similar name.
-
#each_command {|command| ... } ⇒ Enumerator
protected
Enumerates over every command.
-
#help(m, command = nil) ⇒ Object
Displays a list of commands or the help information for a specific command.
Methods included from Cinch::Commands
Instance Method Details
#commands_named(name) ⇒ Array<Command> (protected)
Finds all commands with a similar name.
89 90 91 |
# File 'lib/cinch/commands/help.rb', line 89 def commands_named(name) each_command.select { |command| command.name == name } end |
#each_command {|command| ... } ⇒ Enumerator (protected)
Enumerates over every command.
70 71 72 73 74 75 76 77 78 |
# File 'lib/cinch/commands/help.rb', line 70 def each_command(&block) return enum_for(__method__) unless block_given? bot.config.plugins.plugins.each do |plugin| if plugin < Cinch::Commands plugin.commands.each(&block) end end end |
#help(m, command = nil) ⇒ Object
Displays a list of commands or the help information for a specific command.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cinch/commands/help.rb', line 35 def help(m,command=nil) if command found = commands_named(command) if found.empty? m.reply "help: Unknown command #{command.dump}" else # print all usages found.each { |cmd| m.reply cmd.usage } # print the description of the first command m.reply '' m.reply found.first.description end else each_command do |cmd| m.reply "#{cmd.usage} - #{cmd.summary}" end end end |