Trap ^C and shut down cleanly
[dcbot.git] / plugins / help.rb
blob1b600602f20efe9d785b01491ca045835bb2e882
1 class HelpPlugin < PluginBase
2   def self.cmd_help(socket, sender, isprivate, args)
3     args.strip!
4     if args.blank? or not PluginBase.has_command?(args) then
5       if not args.blank? then
6         socket.sendPrivateMessage(sender, "Unknown command '#{args}'.")
7       end
8       socket.sendPrivateMessage(sender, "Available commands are:")
9       PluginBase.commands.each do |cmd|
10         if PluginBase.has_command_help?(cmd) then
11           socket.sendPrivateMessage(sender, "  #{self.command_help(cmd)}")
12         end
13       end
14     else
15       self.send_usage(socket, sender, args)
16     end
17   end
18   
19   def self.cmd_help_help
20     [nil, "Displays this help"]
21   end
22   
23   def self.cmd_about(socket, sender, isprivate, args)
24     about = <<EOF
25 I am a Direct Connect bot written in Ruby.
26 I was written by Kevin Ballard <kevin@sb.org>.
27 My code is available at http://repo.or.cz/w/dcbot.git
28 EOF
29     about.split("\n").each do |line|
30       socket.sendPrivateMessage(sender, line)
31     end
32   end
33   
34   def self.cmd_about_help
35     [nil, "Displays information about this bot"]
36   end
37   
38   def self.command_help(cmd)
39     message = "#{CMD_PREFIX}#{cmd}"
40     if PluginBase.has_command_help?(cmd) then
41       arghelp, cmdhelp = PluginBase.command_help(cmd).call()
42       message << " #{arghelp}" unless arghelp.nil? or arghelp.empty?
43       message << " - #{cmdhelp}"
44     end
45     message
46   end
47   
48   def self.send_usage(socket, user, cmd)
49     socket.sendPrivateMessage(user, "Usage: #{self.command_help(cmd)}")
50   end
51 end