- Moved commands outside TechBot.Library to TechBot.Commands.Common and TechBot.Comma...
[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 private string m_CommandName = null;
11
12 public HelpCommand()
13 {
14 }
15
16 [CommandParameter("Name", "The command name to show help")]
17 public string CommandName
18 {
19 get { return Parameters; }
20 set { Parameters = value; }
21 }
22
23 public override void ExecuteCommand()
24 {
25 if (CommandName == null)
26 {
27 Say("I support the following commands:");
28
29 foreach (CommandBuilder command in TechBot.Commands)
30 {
31 Say("{0}{1} - {2}",
32 Settings.Default.CommandPrefix,
33 command.Name,
34 command.Description);
35 }
36 }
37 else
38 {
39 CommandBuilder cmdBuilder = TechBot.Commands.Find(CommandName);
40
41 if (cmdBuilder == null)
42 {
43 Say("Command '{0}' is not recognized. Type '!help' to show all available commands", CommandName);
44 }
45 else
46 {
47 Say("Command '{0}' help:", CommandName);
48 Say();
49 Say(cmdBuilder.Description);
50 Say();
51 Say(cmdBuilder.Help);
52 Say();
53 Say("Parameters :");
54 Say();
55
56 PropertyInfo[] propertyInfoArray = cmdBuilder.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
57 foreach (PropertyInfo propertyInfo in propertyInfoArray)
58 {
59 CommandParameterAttribute[] commandAttributes = (CommandParameterAttribute[])
60 Attribute.GetCustomAttributes(propertyInfo, typeof(CommandParameterAttribute));
61
62 foreach (CommandParameterAttribute parameter in commandAttributes)
63 {
64 Say("\t-{0}: [{1}]",
65 parameter.Name,
66 parameter.Description);
67 }
68 }
69
70 Say();
71 }
72 }
73 }
74 }
75 }