- miscellaneous small fixes
[reactos.git] / irc / TechBot / TechBot.Library / Commands / HelpCommand.cs
1 using System;
2 using System.Reflection;
3 using System.Collections;
4
5 namespace TechBot.Library
6 {
7 [Command("help", Help = "!help or !help -name:[CommandName]", Description = "Shows this help , type 'help -name:[CommandName]'")]
8 public class HelpCommand : Command
9 {
10 public HelpCommand()
11 {
12 }
13
14 [CommandParameter("Name", "The command name to show help")]
15 public string CommandName
16 {
17 get { return Parameters; }
18 set { Parameters = value; }
19 }
20
21 public override void ExecuteCommand()
22 {
23 if (string.IsNullOrEmpty(CommandName))
24 {
25 Say("I support the following commands:");
26
27 foreach (CommandBuilder command in TechBot.Commands)
28 {
29 Say("{0}{1} - {2}",
30 Settings.Default.CommandPrefix,
31 command.Name,
32 command.Description);
33 }
34 }
35 else
36 {
37 CommandBuilder cmdBuilder = TechBot.Commands.Find(CommandName);
38
39 if (cmdBuilder == null)
40 {
41 Say("Command '{0}' is not recognized. Type '!help' to show all available commands", CommandName);
42 }
43 else
44 {
45 Say("Command '{0}' help:", CommandName);
46 Say();
47 Say(cmdBuilder.Description);
48 Say();
49 Say(cmdBuilder.Help);
50 Say();
51 Say("Parameters :");
52 Say();
53
54 PropertyInfo[] propertyInfoArray = cmdBuilder.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
55 foreach (PropertyInfo propertyInfo in propertyInfoArray)
56 {
57 CommandParameterAttribute[] commandAttributes = (CommandParameterAttribute[])
58 Attribute.GetCustomAttributes(propertyInfo, typeof(CommandParameterAttribute));
59
60 foreach (CommandParameterAttribute parameter in commandAttributes)
61 {
62 Say("\t-{0}: [{1}]",
63 parameter.Name,
64 parameter.Description);
65 }
66 }
67
68 Say();
69 }
70 }
71 }
72 }
73 }