- Moved commands outside TechBot.Library to TechBot.Commands.Common and TechBot.Commands.MSDN except for Command base classes

- Made TechBot more configurable through .config files
- Code refactoring
- Removed automatic parameter parsing support to make everyone happy

svn path=/trunk/; revision=33586
This commit is contained in:
Marc Piulachs 2008-05-18 15:54:43 +00:00
parent 6d51a10a1b
commit ac77d9d3a6
47 changed files with 1783 additions and 489 deletions

View file

@ -1,4 +1,5 @@
using System;
using System.Text.RegularExpressions;
namespace TechBot.Library
{
@ -6,6 +7,7 @@ namespace TechBot.Library
{
protected TechBotService m_TechBotService = null;
protected MessageContext m_Context = null;
protected string m_Params = null;
public TechBotService TechBot
{
@ -30,10 +32,15 @@ namespace TechBot.Library
}
}
public void ParseParameters(string paramaters)
public string Parameters
{
ParametersParser parser = new ParametersParser(paramaters, this);
parser.Parse();
get { return m_Params; }
set { m_Params = value; }
}
protected virtual void Say()
{
TechBot.ServiceOutput.WriteLine(Context, string.Empty);
}
protected virtual void Say(string message)
@ -47,5 +54,13 @@ namespace TechBot.Library
}
public abstract void ExecuteCommand();
public virtual void Initialize()
{
}
public virtual void DeInitialize()
{
}
}
}

View file

@ -6,13 +6,12 @@ namespace TechBot.Library
{
public abstract class XmlLookupCommand : XmlCommand
{
private string m_Text = null;
protected string m_Text = null;
[CommandParameter("text", "The value to check")]
public string Text
public virtual string Text
{
get { return m_Text; }
set { m_Text = value; }
get { return Parameters; }
set { Parameters = value; }
}
}
}

View file

@ -1,9 +1,10 @@
using System;
using System.Reflection;
using System.Collections;
namespace TechBot.Library
{
[Command("help", Help = "!help")]
[Command("help", Help = "!help or !help -name:[CommandName]", Description = "Shows this help , type 'help -name:[CommandName]'")]
public class HelpCommand : Command
{
private string m_CommandName = null;
@ -15,8 +16,8 @@ namespace TechBot.Library
[CommandParameter("Name", "The command name to show help")]
public string CommandName
{
get { return m_CommandName; }
set { m_CommandName = value; }
get { return Parameters; }
set { Parameters = value; }
}
public override void ExecuteCommand()
@ -27,7 +28,8 @@ namespace TechBot.Library
foreach (CommandBuilder command in TechBot.Commands)
{
Say("!{0} - {1}",
Say("{0}{1} - {2}",
Settings.Default.CommandPrefix,
command.Name,
command.Description);
}
@ -43,7 +45,29 @@ namespace TechBot.Library
else
{
Say("Command '{0}' help:", CommandName);
Say("");
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();
}
}
}