Class: Cinch::Commands::Help

Inherits:
Object
  • Object
show all
Includes:
Cinch::Commands, Plugin, KAG::Common
Defined in:
lib/commands/help.rb

Overview

Generic ‘!help` command that lists all commands.

Instance Method Summary collapse

Methods included from KAG::Common

#_h, #debug, #is_admin, #is_banned?, #reply, #send_channels_msg

Methods included from Cinch::Commands

included

Instance Method Details

#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
55
56
57
58
59
60
61
62
# File 'lib/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
      return if found.first.admin and !is_admin(m.user)

      msg = []
      # print all usages
      found.each do |cmd|
        msg << cmd.usage
      end
      # print the description of the first command
      desc = found.first.description.to_s
      msg = "\x0302#{msg.join(", ")}\x0314"+(desc != "" ? " - #{desc}" : " - #{found.first.summary.to_s}")
      m.user.send(msg)
    end
  else
    msg = []
    each_command do |cmd|
      #msg << "\x0302#{cmd.usage}\x0314: #{cmd.summary}" unless (cmd.admin and !is_admin(m.user))
      msg << "!"+cmd.usage
    end
    m.user.send(msg.join ", ")
  end
end