Class: Cinch::Commands::Help

Inherits:
Object
  • Object
show all
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

VERSION

Instance Method Summary collapse

Methods included from Cinch::Commands

included

Instance Method Details

#commands_named(name) ⇒ Array<Command> (protected)

Finds all commands with a similar name.

Parameters:

  • name (String)

    The name to search for.

Returns:

  • (Array<Command>)

    The commands with the matching 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.

Yields:

  • (command)

    The given block will be passed every command.

Yield Parameters:

Returns:

  • (Enumerator)

    If no block is given, an Enumerator will be returned.



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.

Parameters:

  • The (Cinch::Message)

    message that invoked !help.

  • command (String) (defaults to: nil)

    The specific command to list help information for.



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