2008-05-07 14:59:28 +00:00
|
|
|
using System;
|
2008-05-18 15:54:43 +00:00
|
|
|
using System.Reflection;
|
2008-05-07 14:59:28 +00:00
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
namespace TechBot.Library
|
|
|
|
{
|
2008-05-18 15:54:43 +00:00
|
|
|
[Command("help", Help = "!help or !help -name:[CommandName]", Description = "Shows this help , type 'help -name:[CommandName]'")]
|
2008-05-07 14:59:28 +00:00
|
|
|
public class HelpCommand : Command
|
|
|
|
{
|
|
|
|
public HelpCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[CommandParameter("Name", "The command name to show help")]
|
|
|
|
public string CommandName
|
|
|
|
{
|
2008-05-18 15:54:43 +00:00
|
|
|
get { return Parameters; }
|
|
|
|
set { Parameters = value; }
|
2008-05-07 14:59:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void ExecuteCommand()
|
|
|
|
{
|
2008-05-18 16:01:34 +00:00
|
|
|
if (string.IsNullOrEmpty(CommandName))
|
2008-05-07 14:59:28 +00:00
|
|
|
{
|
|
|
|
Say("I support the following commands:");
|
|
|
|
|
|
|
|
foreach (CommandBuilder command in TechBot.Commands)
|
|
|
|
{
|
2008-05-18 15:54:43 +00:00
|
|
|
Say("{0}{1} - {2}",
|
|
|
|
Settings.Default.CommandPrefix,
|
2008-05-07 14:59:28 +00:00
|
|
|
command.Name,
|
|
|
|
command.Description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CommandBuilder cmdBuilder = TechBot.Commands.Find(CommandName);
|
|
|
|
|
|
|
|
if (cmdBuilder == null)
|
|
|
|
{
|
|
|
|
Say("Command '{0}' is not recognized. Type '!help' to show all available commands", CommandName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Say("Command '{0}' help:", CommandName);
|
2008-05-18 15:54:43 +00:00
|
|
|
Say();
|
|
|
|
Say(cmdBuilder.Description);
|
|
|
|
Say();
|
|
|
|
Say(cmdBuilder.Help);
|
|
|
|
Say();
|
|
|
|
Say("Parameters :");
|
|
|
|
Say();
|
|
|
|
|
|
|
|
PropertyInfo[] propertyInfoArray = cmdBuilder.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
|
|
|
foreach (PropertyInfo propertyInfo in propertyInfoArray)
|
|
|
|
{
|
|
|
|
CommandParameterAttribute[] commandAttributes = (CommandParameterAttribute[])
|
|
|
|
Attribute.GetCustomAttributes(propertyInfo, typeof(CommandParameterAttribute));
|
|
|
|
|
|
|
|
foreach (CommandParameterAttribute parameter in commandAttributes)
|
|
|
|
{
|
|
|
|
Say("\t-{0}: [{1}]",
|
|
|
|
parameter.Name,
|
|
|
|
parameter.Description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Say();
|
2008-05-07 14:59:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|