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