mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 14:53:40 +00:00
- code refactoring
- made more and more easily extensible: * commands automatically loaded from plugins dlls * declarative and automatic command parameter parsing * common code moved to base classes - other fixes svn path=/trunk/; revision=33344
This commit is contained in:
parent
e3407fdd9c
commit
d7b2077ed8
42 changed files with 2263 additions and 1689 deletions
|
@ -1,14 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<project name="TechBot" default="build">
|
|
||||||
|
|
||||||
<target name="build" description="Build components">
|
|
||||||
<delete dir="bin" failonerror="false" />
|
|
||||||
<nant buildfile="Compression/Default.build" />
|
|
||||||
<nant buildfile="CHMLibrary/Default.build" />
|
|
||||||
<nant buildfile="TechBot.IRCLibrary/Default.build" />
|
|
||||||
<nant buildfile="TechBot.Library/Default.build" />
|
|
||||||
<nant buildfile="TechBot.Console/Default.build" />
|
|
||||||
<nant buildfile="TechBot/Default.build" />
|
|
||||||
</target>
|
|
||||||
|
|
||||||
</project>
|
|
39
irc/TechBot/TechBot.Console/ConsoleTechBotService.cs
Normal file
39
irc/TechBot/TechBot.Console/ConsoleTechBotService.cs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using TechBot.Library;
|
||||||
|
|
||||||
|
namespace TechBot.Console
|
||||||
|
{
|
||||||
|
public class ConsoleServiceOutput : IServiceOutput
|
||||||
|
{
|
||||||
|
public void WriteLine(MessageContext context,
|
||||||
|
string message)
|
||||||
|
{
|
||||||
|
System.Console.WriteLine(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ConsoleTechBotService : TechBotService
|
||||||
|
{
|
||||||
|
public ConsoleTechBotService(
|
||||||
|
string chmPath,
|
||||||
|
string mainChm)
|
||||||
|
: base(new ConsoleServiceOutput(), chmPath, mainChm)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Run()
|
||||||
|
{
|
||||||
|
//Call the base class
|
||||||
|
base.Run();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
string s = System.Console.ReadLine();
|
||||||
|
InjectMessage(null, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,16 +4,6 @@ using TechBot.Library;
|
||||||
|
|
||||||
namespace TechBot.Console
|
namespace TechBot.Console
|
||||||
{
|
{
|
||||||
public class ConsoleServiceOutput : IServiceOutput
|
|
||||||
{
|
|
||||||
public void WriteLine(MessageContext context,
|
|
||||||
string message)
|
|
||||||
{
|
|
||||||
System.Console.WriteLine(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class MainClass
|
class MainClass
|
||||||
{
|
{
|
||||||
private static void VerifyRequiredOption(string optionName,
|
private static void VerifyRequiredOption(string optionName,
|
||||||
|
@ -208,53 +198,43 @@ namespace TechBot.Console
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void RunIrcService()
|
//private static void RunIrcService()
|
||||||
|
//{
|
||||||
|
// IrcTechBotService ircService = new IrcTechBotService(IRCServerHostName,
|
||||||
|
// IRCServerHostPort,
|
||||||
|
// IRCChannelNames,
|
||||||
|
// IRCBotName,
|
||||||
|
// IRCBotPassword,
|
||||||
|
// ChmPath,
|
||||||
|
// MainChm);
|
||||||
|
// ircService.Run();
|
||||||
|
//}
|
||||||
|
|
||||||
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
IrcService ircService = new IrcService(IRCServerHostName,
|
TechBotService m_TechBot = null;
|
||||||
|
|
||||||
|
if (args.Length > 0 && args[0].ToLower().Equals("irc"))
|
||||||
|
{
|
||||||
|
m_TechBot = new IrcTechBotService(IRCServerHostName,
|
||||||
IRCServerHostPort,
|
IRCServerHostPort,
|
||||||
IRCChannelNames,
|
IRCChannelNames,
|
||||||
IRCBotName,
|
IRCBotName,
|
||||||
IRCBotPassword,
|
IRCBotPassword,
|
||||||
ChmPath,
|
ChmPath,
|
||||||
MainChm,
|
MainChm);
|
||||||
//NtstatusXml,
|
|
||||||
//WinerrorXml,
|
|
||||||
//HresultXml,
|
|
||||||
//WmXml,
|
|
||||||
//SvnCommand,
|
|
||||||
BugUrl,
|
|
||||||
WineBugUrl,
|
|
||||||
SambaBugUrl);
|
|
||||||
ircService.Run();
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
{
|
||||||
if (args.Length > 0 && args[0].ToLower().Equals("irc"))
|
|
||||||
{
|
|
||||||
RunIrcService();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.Console.WriteLine("TechBot running console service...");
|
System.Console.WriteLine("TechBot running console service...");
|
||||||
TechBotService service = new TechBotService(new ConsoleServiceOutput(),
|
m_TechBot = new ConsoleTechBotService(
|
||||||
ChmPath,
|
ChmPath,
|
||||||
MainChm);
|
MainChm);
|
||||||
//NtstatusXml,
|
|
||||||
//WinerrorXml,
|
|
||||||
//HresultXml,
|
|
||||||
//WmXml,
|
|
||||||
//SvnCommand,
|
|
||||||
//BugUrl,
|
|
||||||
//WineBugUrl,
|
|
||||||
//SambaBugUrl);
|
|
||||||
service.Run();
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
string s = System.Console.ReadLine();
|
|
||||||
service.InjectMessage(null,
|
|
||||||
s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_TechBot.Run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -38,6 +38,7 @@
|
||||||
-->
|
-->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AssemblyInfo.cs" />
|
<Compile Include="AssemblyInfo.cs" />
|
||||||
|
<Compile Include="ConsoleTechBotService.cs" />
|
||||||
<Compile Include="Main.cs" />
|
<Compile Include="Main.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
35
irc/TechBot/TechBot.Library/Attributes/CommandAttribute.cs
Normal file
35
irc/TechBot/TechBot.Library/Attributes/CommandAttribute.cs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
public class CommandAttribute : Attribute
|
||||||
|
{
|
||||||
|
private string m_Name = null;
|
||||||
|
private string m_Help = "No help for this command is available";
|
||||||
|
private string m_Desc = "No description for this command is available";
|
||||||
|
|
||||||
|
public CommandAttribute(string name)
|
||||||
|
{
|
||||||
|
m_Name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return m_Name; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Help
|
||||||
|
{
|
||||||
|
get { return m_Help; }
|
||||||
|
set { m_Help = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Description
|
||||||
|
{
|
||||||
|
get { return m_Desc; }
|
||||||
|
set { m_Desc = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This class implements an alias attribute to work in conjunction
|
||||||
|
/// with the <see cref="CommandLineSwitchAttribute">CommandLineSwitchAttribute</see>
|
||||||
|
/// attribute. If the CommandLineSwitchAttribute exists, then this attribute
|
||||||
|
/// defines an alias for it.
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage( AttributeTargets.Property )]
|
||||||
|
public class CommandParameterAliasAttribute : Attribute
|
||||||
|
{
|
||||||
|
#region Private Variables
|
||||||
|
protected string m_Alias = "";
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
public string Alias
|
||||||
|
{
|
||||||
|
get { return m_Alias; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
public CommandParameterAliasAttribute(string alias)
|
||||||
|
{
|
||||||
|
m_Alias = alias;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
/// <summary>Implements a basic command-line switch by taking the
|
||||||
|
/// switching name and the associated description.</summary>
|
||||||
|
/// <remark>Only currently is implemented for properties, so all
|
||||||
|
/// auto-switching variables should have a get/set method supplied.</remark>
|
||||||
|
[AttributeUsage( AttributeTargets.Property )]
|
||||||
|
public class CommandParameterAttribute : Attribute
|
||||||
|
{
|
||||||
|
#region Private Variables
|
||||||
|
private string m_name = "";
|
||||||
|
private string m_description = "";
|
||||||
|
private bool m_Required = true;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
/// <summary>Accessor for retrieving the switch-name for an associated
|
||||||
|
/// property.</summary>
|
||||||
|
public string Name { get { return m_name; } }
|
||||||
|
|
||||||
|
/// <summary>Accessor for retrieving the description for a switch of
|
||||||
|
/// an associated property.</summary>
|
||||||
|
public string Description { get { return m_description; } }
|
||||||
|
|
||||||
|
public bool Required { get { return m_Required; } }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attribute constructor.
|
||||||
|
/// </summary>
|
||||||
|
public CommandParameterAttribute(string name, string description)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
m_description = description;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,50 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace TechBot.Library
|
|
||||||
{
|
|
||||||
public abstract class BugCommand : Command//, ICommand
|
|
||||||
{
|
|
||||||
public BugCommand(TechBotService techBot) : base (techBot)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Handle(MessageContext context,
|
|
||||||
string commandName,
|
|
||||||
string parameters)
|
|
||||||
{
|
|
||||||
string bugText = parameters;
|
|
||||||
if (bugText.Equals(String.Empty))
|
|
||||||
{
|
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
|
||||||
"Please provide a valid bug number.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NumberParser np = new NumberParser();
|
|
||||||
long bug = np.Parse(bugText);
|
|
||||||
if (np.Error)
|
|
||||||
{
|
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
|
||||||
String.Format("{0} is not a valid bug number.",
|
|
||||||
bugText));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
string bugUrl = this.RosBugUrl;
|
|
||||||
|
|
||||||
if (context is ChannelMessageContext)
|
|
||||||
{
|
|
||||||
ChannelMessageContext channelContext = context as ChannelMessageContext;
|
|
||||||
if (channelContext.Channel.Name == "winehackers")
|
|
||||||
bugUrl = this.WineBugUrl;
|
|
||||||
else if (channelContext.Channel.Name == "samba-technical")
|
|
||||||
bugUrl = this.SambaBugUrl;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
TechBot.ServiceOutput.WriteLine(context, String.Format(BugUrl, bug));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract string BugUrl { get; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
public class CommandBuilderCollection : List<CommandBuilder>
|
||||||
|
{
|
||||||
|
public CommandBuilder Find(string name)
|
||||||
|
{
|
||||||
|
foreach (CommandBuilder command in this)
|
||||||
|
{
|
||||||
|
if (command.Name == name)
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,53 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace TechBot.Library
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
public interface ICommand
|
|
||||||
{
|
|
||||||
bool CanHandle(string commandName);
|
|
||||||
void Handle(MessageContext context,
|
|
||||||
string commandName,
|
|
||||||
string parameters);
|
|
||||||
//string Help();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public abstract class Command
|
|
||||||
{
|
|
||||||
protected TechBotService m_TechBotService = null;
|
|
||||||
|
|
||||||
public Command(TechBotService techbot)
|
|
||||||
{
|
|
||||||
m_TechBotService = techbot;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TechBotService TechBot
|
|
||||||
{
|
|
||||||
get { return m_TechBotService; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract string[] AvailableCommands { get; }
|
|
||||||
|
|
||||||
public abstract void Handle(MessageContext context,
|
|
||||||
string commandName,
|
|
||||||
string parameters);
|
|
||||||
|
|
||||||
/*
|
|
||||||
protected bool CanHandle(string commandName,
|
|
||||||
string[] availableCommands)
|
|
||||||
{
|
|
||||||
foreach (string availableCommand in availableCommands)
|
|
||||||
{
|
|
||||||
if (String.Compare(availableCommand, commandName, true) == 0)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public virtual string Help()
|
|
||||||
{
|
|
||||||
return "No help is available for this command";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,6 +7,7 @@ using HtmlHelp.ChmDecoding;
|
||||||
|
|
||||||
namespace TechBot.Library
|
namespace TechBot.Library
|
||||||
{
|
{
|
||||||
|
[Command("api", Help = "!api <apiname>")]
|
||||||
public class ApiCommand : Command
|
public class ApiCommand : Command
|
||||||
{
|
{
|
||||||
private const bool IsVerbose = false;
|
private const bool IsVerbose = false;
|
||||||
|
@ -15,8 +16,7 @@ namespace TechBot.Library
|
||||||
private string chmPath;
|
private string chmPath;
|
||||||
private string mainChm;
|
private string mainChm;
|
||||||
|
|
||||||
public ApiCommand(TechBotService techBot)
|
public ApiCommand()
|
||||||
: base(techBot)
|
|
||||||
{
|
{
|
||||||
Run();
|
Run();
|
||||||
}
|
}
|
||||||
|
@ -61,22 +61,7 @@ namespace TechBot.Library
|
||||||
chm.FileList.Length));
|
chm.FileList.Length));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string[] AvailableCommands
|
public override void Handle(MessageContext context)
|
||||||
{
|
|
||||||
get { return new string[] { "api" }; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
public bool CanHandle(string commandName)
|
|
||||||
{
|
|
||||||
return CanHandle(commandName,
|
|
||||||
new string[] { "api" });
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public override void Handle(MessageContext context,
|
|
||||||
string commandName,
|
|
||||||
string parameters)
|
|
||||||
{
|
{
|
||||||
if (parameters.Trim().Equals(String.Empty))
|
if (parameters.Trim().Equals(String.Empty))
|
||||||
DisplayNoKeyword(context);
|
DisplayNoKeyword(context);
|
||||||
|
@ -85,11 +70,6 @@ namespace TechBot.Library
|
||||||
parameters);
|
parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Help()
|
|
||||||
{
|
|
||||||
return "!api <apiname>";
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool SearchIndex(MessageContext context,
|
private bool SearchIndex(MessageContext context,
|
||||||
string keyword)
|
string keyword)
|
||||||
{
|
{
|
51
irc/TechBot/TechBot.Library/Commands/Base/Command.cs
Normal file
51
irc/TechBot/TechBot.Library/Commands/Base/Command.cs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
public abstract class Command
|
||||||
|
{
|
||||||
|
protected TechBotService m_TechBotService = null;
|
||||||
|
protected MessageContext m_Context = null;
|
||||||
|
|
||||||
|
public TechBotService TechBot
|
||||||
|
{
|
||||||
|
get { return m_TechBotService; }
|
||||||
|
set { m_TechBotService = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageContext Context
|
||||||
|
{
|
||||||
|
get { return m_Context; }
|
||||||
|
set { m_Context = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
CommandAttribute commandAttribute = (CommandAttribute)
|
||||||
|
Attribute.GetCustomAttribute(GetType(), typeof(CommandAttribute));
|
||||||
|
|
||||||
|
return commandAttribute.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ParseParameters(string paramaters)
|
||||||
|
{
|
||||||
|
ParametersParser parser = new ParametersParser(paramaters, this);
|
||||||
|
parser.Parse();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Say(string message)
|
||||||
|
{
|
||||||
|
TechBot.ServiceOutput.WriteLine(Context, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Say(string format , params object[] args)
|
||||||
|
{
|
||||||
|
TechBot.ServiceOutput.WriteLine(Context, String.Format(format, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void ExecuteCommand();
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,8 +9,7 @@ namespace TechBot.Library
|
||||||
{
|
{
|
||||||
protected XmlDocument m_XmlDocument;
|
protected XmlDocument m_XmlDocument;
|
||||||
|
|
||||||
public XmlCommand(TechBotService techBot)
|
public XmlCommand()
|
||||||
: base(techBot)
|
|
||||||
{
|
{
|
||||||
m_XmlDocument = new XmlDocument();
|
m_XmlDocument = new XmlDocument();
|
||||||
m_XmlDocument.Load(XmlFile);
|
m_XmlDocument.Load(XmlFile);
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
public abstract class XmlLookupCommand : XmlCommand
|
||||||
|
{
|
||||||
|
private string m_Text = null;
|
||||||
|
|
||||||
|
[CommandParameter("text", "The value to check")]
|
||||||
|
public string Text
|
||||||
|
{
|
||||||
|
get { return m_Text; }
|
||||||
|
set { m_Text = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
irc/TechBot/TechBot.Library/Commands/BugCommand.cs
Normal file
41
irc/TechBot/TechBot.Library/Commands/BugCommand.cs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
public abstract class BugCommand : Command
|
||||||
|
{
|
||||||
|
private string m_BugID = null;
|
||||||
|
|
||||||
|
public BugCommand()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[CommandParameter("id", "The bug ID")]
|
||||||
|
public string BugID
|
||||||
|
{
|
||||||
|
get { return m_BugID; }
|
||||||
|
set { m_BugID = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ExecuteCommand()
|
||||||
|
{
|
||||||
|
if (BugID == null)
|
||||||
|
{
|
||||||
|
Say("Please provide a valid bug number.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Say(BugUrl, Int32.Parse(BugID));
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
Say("{0} is not a valid bug number.", BugID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract string BugUrl { get; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,31 +4,18 @@ using System.Collections;
|
||||||
|
|
||||||
namespace TechBot.Library
|
namespace TechBot.Library
|
||||||
{
|
{
|
||||||
|
[Command("error", Help = "!error <value>")]
|
||||||
public class ErrorCommand : Command
|
public class ErrorCommand : Command
|
||||||
{
|
{
|
||||||
private NtStatusCommand ntStatus;
|
private NtStatusCommand ntStatus;
|
||||||
private WinerrorCommand winerror;
|
private WinErrorCommand winerror;
|
||||||
private HResultCommand hresult;
|
private HResultCommand hresult;
|
||||||
|
|
||||||
public ErrorCommand(TechBotService techBot)
|
public ErrorCommand()
|
||||||
: base(techBot)
|
|
||||||
{
|
{
|
||||||
this.ntStatus = new NtStatusCommand(techBot);
|
this.ntStatus = new NtStatusCommand();
|
||||||
this.winerror = new WinerrorCommand(techBot);
|
this.winerror = new WinErrorCommand();
|
||||||
this.hresult = new HResultCommand(techBot);
|
this.hresult = new HResultCommand();
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
public bool CanHandle(string commandName)
|
|
||||||
{
|
|
||||||
return CanHandle(commandName,
|
|
||||||
new string[] { "error" });
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public override string[] AvailableCommands
|
|
||||||
{
|
|
||||||
get { return new string[] { "error" }; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int GetSeverity(long error)
|
private static int GetSeverity(long error)
|
||||||
|
@ -81,12 +68,9 @@ namespace TechBot.Library
|
||||||
return code.ToString();
|
return code.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(MessageContext context,
|
public override void Handle(MessageContext context)
|
||||||
string commandName,
|
|
||||||
string parameters)
|
|
||||||
{
|
{
|
||||||
string originalErrorText = parameters.Trim();
|
if (Text.Equals(String.Empty))
|
||||||
if (originalErrorText.Equals(String.Empty))
|
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(context,
|
||||||
"Please provide an Error Code.");
|
"Please provide an Error Code.");
|
||||||
|
@ -197,10 +181,5 @@ namespace TechBot.Library
|
||||||
TechBot.ServiceOutput.WriteLine(context, String.Format("\t{0}", description));
|
TechBot.ServiceOutput.WriteLine(context, String.Format("\t{0}", description));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Help()
|
|
||||||
{
|
|
||||||
return "!error <value>";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
51
irc/TechBot/TechBot.Library/Commands/HelpCommand.cs
Normal file
51
irc/TechBot/TechBot.Library/Commands/HelpCommand.cs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
[Command("help", Help = "!help")]
|
||||||
|
public class HelpCommand : Command
|
||||||
|
{
|
||||||
|
private string m_CommandName = null;
|
||||||
|
|
||||||
|
public HelpCommand()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[CommandParameter("Name", "The command name to show help")]
|
||||||
|
public string CommandName
|
||||||
|
{
|
||||||
|
get { return m_CommandName; }
|
||||||
|
set { m_CommandName = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ExecuteCommand()
|
||||||
|
{
|
||||||
|
if (CommandName == null)
|
||||||
|
{
|
||||||
|
Say("I support the following commands:");
|
||||||
|
|
||||||
|
foreach (CommandBuilder command in TechBot.Commands)
|
||||||
|
{
|
||||||
|
Say("!{0} - {1}",
|
||||||
|
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);
|
||||||
|
Say("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,10 +3,10 @@ using System.Xml;
|
||||||
|
|
||||||
namespace TechBot.Library
|
namespace TechBot.Library
|
||||||
{
|
{
|
||||||
public class HResultCommand : XmlCommand
|
[Command("hresult", Help = "!hresult <value>")]
|
||||||
|
public class HResultCommand : XmlLookupCommand
|
||||||
{
|
{
|
||||||
public HResultCommand(TechBotService techBot)
|
public HResultCommand()
|
||||||
: base(techBot)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,62 +15,41 @@ namespace TechBot.Library
|
||||||
get { return Settings.Default.HResultXml; }
|
get { return Settings.Default.HResultXml; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string[] AvailableCommands
|
public override void ExecuteCommand()
|
||||||
{
|
{
|
||||||
get { return new string[] { "hresult" }; }
|
if (Text.Equals(String.Empty))
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
public bool CanHandle(string commandName)
|
|
||||||
{
|
{
|
||||||
return CanHandle(commandName,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
new string[] { "hresult" });
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public override void Handle(MessageContext context,
|
|
||||||
string commandName,
|
|
||||||
string parameters)
|
|
||||||
{
|
|
||||||
string hresultText = parameters;
|
|
||||||
if (hresultText.Equals(String.Empty))
|
|
||||||
{
|
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
|
||||||
"Please provide a valid HRESULT value.");
|
"Please provide a valid HRESULT value.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NumberParser np = new NumberParser();
|
NumberParser np = new NumberParser();
|
||||||
long hresult = np.Parse(hresultText);
|
long hresult = np.Parse(Text);
|
||||||
if (np.Error)
|
if (np.Error)
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
String.Format("{0} is not a valid HRESULT value.",
|
String.Format("{0} is not a valid HRESULT value.",
|
||||||
hresultText));
|
Text));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string description = GetHresultDescription(hresult);
|
string description = GetHresultDescription(hresult);
|
||||||
if (description != null)
|
if (description != null)
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
String.Format("{0} is {1}.",
|
String.Format("{0} is {1}.",
|
||||||
hresultText,
|
Text,
|
||||||
description));
|
description));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
String.Format("I don't know about HRESULT {0}.",
|
String.Format("I don't know about HRESULT {0}.",
|
||||||
hresultText));
|
Text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Help()
|
|
||||||
{
|
|
||||||
return "!hresult <value>";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetHresultDescription(long hresult)
|
public string GetHresultDescription(long hresult)
|
||||||
{
|
{
|
||||||
XmlElement root = base.m_XmlDocument.DocumentElement;
|
XmlElement root = base.m_XmlDocument.DocumentElement;
|
|
@ -3,10 +3,10 @@ using System.Xml;
|
||||||
|
|
||||||
namespace TechBot.Library
|
namespace TechBot.Library
|
||||||
{
|
{
|
||||||
public class NtStatusCommand : XmlCommand
|
[Command("ntstatus", Help = "!ntstatus <value>")]
|
||||||
|
public class NtStatusCommand : XmlLookupCommand
|
||||||
{
|
{
|
||||||
public NtStatusCommand(TechBotService techBot)
|
public NtStatusCommand()
|
||||||
: base(techBot)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,60 +15,41 @@ namespace TechBot.Library
|
||||||
get { return Settings.Default.NtStatusXml; }
|
get { return Settings.Default.NtStatusXml; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string[] AvailableCommands
|
public override void ExecuteCommand()
|
||||||
{
|
{
|
||||||
get { return new string[] { "ntstatus" }; }
|
if (Text.Equals(String.Empty))
|
||||||
}
|
|
||||||
/*
|
|
||||||
public bool CanHandle(string commandName)
|
|
||||||
{
|
{
|
||||||
return CanHandle(commandName,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
new string[] { "ntstatus" });
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
public override void Handle(MessageContext context,
|
|
||||||
string commandName,
|
|
||||||
string parameters)
|
|
||||||
{
|
|
||||||
string ntstatusText = parameters;
|
|
||||||
if (ntstatusText.Equals(String.Empty))
|
|
||||||
{
|
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
|
||||||
"Please provide a valid NTSTATUS value.");
|
"Please provide a valid NTSTATUS value.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NumberParser np = new NumberParser();
|
NumberParser np = new NumberParser();
|
||||||
long ntstatus = np.Parse(ntstatusText);
|
long ntstatus = np.Parse(Text);
|
||||||
if (np.Error)
|
if (np.Error)
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
String.Format("{0} is not a valid NTSTATUS value.",
|
String.Format("{0} is not a valid NTSTATUS value.",
|
||||||
ntstatusText));
|
Text));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string description = GetNtstatusDescription(ntstatus);
|
string description = GetNtstatusDescription(ntstatus);
|
||||||
if (description != null)
|
if (description != null)
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
String.Format("{0} is {1}.",
|
String.Format("{0} is {1}.",
|
||||||
ntstatusText,
|
Text,
|
||||||
description));
|
description));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
String.Format("I don't know about NTSTATUS {0}.",
|
String.Format("I don't know about NTSTATUS {0}.",
|
||||||
ntstatusText));
|
Text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Help()
|
|
||||||
{
|
|
||||||
return "!ntstatus <value>";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetNtstatusDescription(long ntstatus)
|
public string GetNtstatusDescription(long ntstatus)
|
||||||
{
|
{
|
||||||
XmlElement root = base.m_XmlDocument.DocumentElement;
|
XmlElement root = base.m_XmlDocument.DocumentElement;
|
|
@ -4,26 +4,16 @@ using System.Text;
|
||||||
|
|
||||||
namespace TechBot.Library
|
namespace TechBot.Library
|
||||||
{
|
{
|
||||||
|
[Command("rosbug", Help = "!rosbug <number>")]
|
||||||
class ReactOSBugUrl : BugCommand
|
class ReactOSBugUrl : BugCommand
|
||||||
{
|
{
|
||||||
public ReactOSBugUrl(TechBotService techBot)
|
public ReactOSBugUrl()
|
||||||
: base(techBot)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string[] AvailableCommands
|
|
||||||
{
|
|
||||||
get { return new string[] { "rosbug" }; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string BugUrl
|
protected override string BugUrl
|
||||||
{
|
{
|
||||||
get { return "http://www.reactos.org/bugzilla/show_bug.cgi?id={0}"; }
|
get { return "http://www.reactos.org/bugzilla/show_bug.cgi?id={0}"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Help()
|
|
||||||
{
|
|
||||||
return "!rosbug <number>";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
19
irc/TechBot/TechBot.Library/Commands/SambaBugUrl.cs
Normal file
19
irc/TechBot/TechBot.Library/Commands/SambaBugUrl.cs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
[Command("sambabug", Help = "!sambabug <number>")]
|
||||||
|
class SambaBugUrl : BugCommand
|
||||||
|
{
|
||||||
|
public SambaBugUrl()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string BugUrl
|
||||||
|
{
|
||||||
|
get { return "https://bugzilla.samba.org/show_bug.cgi?id={0}"; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
irc/TechBot/TechBot.Library/Commands/SvnCommand.cs
Normal file
20
irc/TechBot/TechBot.Library/Commands/SvnCommand.cs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
[Command("svn", Help = "!svn")]
|
||||||
|
public class SvnCommand : Command
|
||||||
|
{
|
||||||
|
private string m_SvnRoot;
|
||||||
|
|
||||||
|
public SvnCommand()
|
||||||
|
{
|
||||||
|
m_SvnRoot = Settings.Default.SVNRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ExecuteCommand()
|
||||||
|
{
|
||||||
|
Say("svn co {0}", m_SvnRoot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
irc/TechBot/TechBot.Library/Commands/WineBugUrl.cs
Normal file
19
irc/TechBot/TechBot.Library/Commands/WineBugUrl.cs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
[Command("winebug", Help = "!winebug <number>")]
|
||||||
|
class WineBugUrl : BugCommand
|
||||||
|
{
|
||||||
|
public WineBugUrl()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string BugUrl
|
||||||
|
{
|
||||||
|
get { return "http://bugs.winehq.org/show_bug.cgi?id={0}"; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,10 +3,10 @@ using System.Xml;
|
||||||
|
|
||||||
namespace TechBot.Library
|
namespace TechBot.Library
|
||||||
{
|
{
|
||||||
public class WinerrorCommand : XmlCommand
|
[Command("winerror", Help = "!winerror <value>")]
|
||||||
|
public class WinErrorCommand : XmlLookupCommand
|
||||||
{
|
{
|
||||||
public WinerrorCommand(TechBotService techBot)
|
public WinErrorCommand()
|
||||||
: base(techBot)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,59 +15,46 @@ namespace TechBot.Library
|
||||||
get { return Settings.Default.WinErrorXml; }
|
get { return Settings.Default.WinErrorXml; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string[] AvailableCommands
|
public override void ExecuteCommand()
|
||||||
{
|
{
|
||||||
get { return new string[] { "winerror" }; }
|
if (Text.Equals(String.Empty))
|
||||||
}
|
|
||||||
|
|
||||||
public override void Handle(MessageContext context,
|
|
||||||
string commandName,
|
|
||||||
string parameters)
|
|
||||||
{
|
{
|
||||||
string winerrorText = parameters;
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
if (winerrorText.Equals(String.Empty))
|
|
||||||
{
|
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
|
||||||
"Please provide a valid System Error Code value.");
|
"Please provide a valid System Error Code value.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NumberParser np = new NumberParser();
|
NumberParser np = new NumberParser();
|
||||||
long winerror = np.Parse(winerrorText);
|
long winerror = np.Parse(Text);
|
||||||
if (np.Error)
|
if (np.Error)
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
String.Format("{0} is not a valid System Error Code value.",
|
String.Format("{0} is not a valid System Error Code value.",
|
||||||
winerrorText));
|
Text));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string description = GetWinerrorDescription(winerror);
|
string description = GetWinerrorDescription(winerror);
|
||||||
if (description != null)
|
if (description != null)
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
String.Format("{0} is {1}.",
|
String.Format("{0} is {1}.",
|
||||||
winerrorText,
|
Text,
|
||||||
description));
|
description));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
String.Format("I don't know about System Error Code {0}.",
|
String.Format("I don't know about System Error Code {0}.",
|
||||||
winerrorText));
|
Text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Help()
|
|
||||||
{
|
|
||||||
return "!winerror <value>";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetWinerrorDescription(long winerror)
|
public string GetWinerrorDescription(long winerror)
|
||||||
{
|
{
|
||||||
XmlElement root = base.m_XmlDocument.DocumentElement;
|
XmlElement root = base.m_XmlDocument.DocumentElement;
|
||||||
XmlNode node = root.SelectSingleNode(String.Format("Winerror[@value='{0}']",
|
XmlNode node = root.SelectSingleNode(String.Format("Winerror[@value='{0}']",
|
||||||
winerror));
|
Text));
|
||||||
if (node != null)
|
if (node != null)
|
||||||
{
|
{
|
||||||
XmlAttribute text = node.Attributes["text"];
|
XmlAttribute text = node.Attributes["text"];
|
|
@ -3,10 +3,12 @@ using System.Xml;
|
||||||
|
|
||||||
namespace TechBot.Library
|
namespace TechBot.Library
|
||||||
{
|
{
|
||||||
|
[Command("wm" , Help = "!wm <value> or !wm <name>")]
|
||||||
public class WMCommand : XmlCommand
|
public class WMCommand : XmlCommand
|
||||||
{
|
{
|
||||||
public WMCommand(TechBotService techBot)
|
private string m_WMText = null;
|
||||||
: base(techBot)
|
|
||||||
|
public WMCommand()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,30 +17,29 @@ namespace TechBot.Library
|
||||||
get { return Settings.Default.WMXml; }
|
get { return Settings.Default.WMXml; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string[] AvailableCommands
|
[CommandParameter("wm", "The windows message to check")]
|
||||||
|
public string WMText
|
||||||
{
|
{
|
||||||
get { return new string[] { "wm" }; }
|
get { return m_WMText; }
|
||||||
|
set { m_WMText = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(MessageContext context,
|
public override void ExecuteCommand()
|
||||||
string commandName,
|
|
||||||
string parameters)
|
|
||||||
{
|
{
|
||||||
string wmText = parameters;
|
if (WMText.Equals(String.Empty))
|
||||||
if (wmText.Equals(String.Empty))
|
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
"Please provide a valid window message value or name.");
|
"Please provide a valid window message value or name.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NumberParser np = new NumberParser();
|
NumberParser np = new NumberParser();
|
||||||
long wm = np.Parse(wmText);
|
long wm = np.Parse(WMText);
|
||||||
string output;
|
string output;
|
||||||
if (np.Error)
|
if (np.Error)
|
||||||
{
|
{
|
||||||
// Assume "!wm <name>" form.
|
// Assume "!wm <name>" form.
|
||||||
output = GetWmNumber(wmText);
|
output = GetWmNumber(WMText);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -47,24 +48,19 @@ namespace TechBot.Library
|
||||||
|
|
||||||
if (output != null)
|
if (output != null)
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
String.Format("{0} is {1}.",
|
String.Format("{0} is {1}.",
|
||||||
wmText,
|
WMText,
|
||||||
output));
|
output));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
TechBot.ServiceOutput.WriteLine(Context,
|
||||||
String.Format("I don't know about window message {0}.",
|
String.Format("I don't know about window message {0}.",
|
||||||
wmText));
|
WMText));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Help()
|
|
||||||
{
|
|
||||||
return "!wm <value> or !wm <name>";
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetWmDescription(long wm)
|
private string GetWmDescription(long wm)
|
||||||
{
|
{
|
||||||
XmlElement root = base.m_XmlDocument.DocumentElement;
|
XmlElement root = base.m_XmlDocument.DocumentElement;
|
52
irc/TechBot/TechBot.Library/Factory/CommandBuilder.cs
Normal file
52
irc/TechBot/TechBot.Library/Factory/CommandBuilder.cs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
public class CommandBuilder
|
||||||
|
{
|
||||||
|
private Type m_CommandType;
|
||||||
|
private string m_CommandName;
|
||||||
|
private string m_CommandHelp;
|
||||||
|
private string m_CommandDesc;
|
||||||
|
|
||||||
|
public CommandBuilder(Type commandType)
|
||||||
|
{
|
||||||
|
m_CommandType = commandType;
|
||||||
|
|
||||||
|
CommandAttribute commandAttribute = (CommandAttribute)
|
||||||
|
Attribute.GetCustomAttribute(commandType, typeof(CommandAttribute));
|
||||||
|
|
||||||
|
m_CommandName = commandAttribute.Name;
|
||||||
|
m_CommandHelp = commandAttribute.Help;
|
||||||
|
m_CommandDesc = commandAttribute.Description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return m_CommandName; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Help
|
||||||
|
{
|
||||||
|
get { return m_CommandHelp; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Description
|
||||||
|
{
|
||||||
|
get { return m_CommandDesc; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type Type
|
||||||
|
{
|
||||||
|
get { return m_CommandType; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command CreateCommand()
|
||||||
|
{
|
||||||
|
return (Command)Type.Assembly.CreateInstance(Type.FullName, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
irc/TechBot/TechBot.Library/Factory/CommandFactory.cs
Normal file
54
irc/TechBot/TechBot.Library/Factory/CommandFactory.cs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
public class CommandFactory
|
||||||
|
{
|
||||||
|
private static CommandBuilderCollection m_Commands = new CommandBuilderCollection();
|
||||||
|
|
||||||
|
private CommandFactory()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LoadPlugins()
|
||||||
|
{
|
||||||
|
//get the file names of the dll files in the current directory.
|
||||||
|
FileInfo objExeInfo = new FileInfo(@"C:\Ros\current\irc\TechBot\TechBot.Console\bin\Debug\");
|
||||||
|
|
||||||
|
foreach (FileInfo objInfo in objExeInfo.Directory.GetFiles("*.dll"))
|
||||||
|
{
|
||||||
|
LoadPluginsFromDLLFile(objInfo.FullName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void LoadPluginsFromDLLFile(string sFile)
|
||||||
|
{
|
||||||
|
Assembly assPlugin = Assembly.LoadFile(sFile);
|
||||||
|
|
||||||
|
if (assPlugin != null)
|
||||||
|
{
|
||||||
|
foreach (Type pluginType in assPlugin.GetTypes())
|
||||||
|
{
|
||||||
|
if (pluginType.IsSubclassOf(typeof(Command)))
|
||||||
|
{
|
||||||
|
if (pluginType.IsAbstract == false)
|
||||||
|
{
|
||||||
|
//Add it to the list.
|
||||||
|
Commands.Add(new CommandBuilder(pluginType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandBuilderCollection Commands
|
||||||
|
{
|
||||||
|
get { return m_Commands; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,37 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
|
|
||||||
namespace TechBot.Library
|
|
||||||
{
|
|
||||||
public class HelpCommand : Command
|
|
||||||
{
|
|
||||||
public HelpCommand(TechBotService techBot)
|
|
||||||
: base(techBot)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string[] AvailableCommands
|
|
||||||
{
|
|
||||||
get { return new string[] { "help" }; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Handle(
|
|
||||||
MessageContext context,
|
|
||||||
string commandName,
|
|
||||||
string parameters)
|
|
||||||
{
|
|
||||||
TechBot.ServiceOutput.WriteLine(context, "I support the following commands:");
|
|
||||||
|
|
||||||
foreach (Command command in TechBot.Commands)
|
|
||||||
{
|
|
||||||
TechBot.ServiceOutput.WriteLine(context,
|
|
||||||
command.Help());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Help()
|
|
||||||
{
|
|
||||||
return "!help";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,43 +7,33 @@ namespace TechBot.Library
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class ChannelMessageContext : MessageContext
|
public class ChannelMessageContext : MessageContext
|
||||||
{
|
{
|
||||||
private IrcChannel channel;
|
private IrcChannel m_IrcChannel;
|
||||||
|
|
||||||
public IrcChannel Channel
|
public IrcChannel Channel
|
||||||
{
|
{
|
||||||
get
|
get { return m_IrcChannel; }
|
||||||
{
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChannelMessageContext(IrcChannel channel)
|
public ChannelMessageContext(IrcChannel channel)
|
||||||
{
|
{
|
||||||
this.channel = channel;
|
m_IrcChannel = channel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class UserMessageContext : MessageContext
|
public class UserMessageContext : MessageContext
|
||||||
{
|
{
|
||||||
private IrcUser user;
|
private IrcUser m_IrcUser;
|
||||||
|
|
||||||
public IrcUser User
|
public IrcUser User
|
||||||
{
|
{
|
||||||
get
|
get { return m_IrcUser; }
|
||||||
{
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserMessageContext(IrcUser user)
|
public UserMessageContext(IrcUser user)
|
||||||
{
|
{
|
||||||
this.user = user;
|
m_IrcUser = user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
537
irc/TechBot/TechBot.Library/ParametersParser.cs
Normal file
537
irc/TechBot/TechBot.Library/ParametersParser.cs
Normal file
|
@ -0,0 +1,537 @@
|
||||||
|
using System;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
//Code taken from : http://www.codeproject.com/KB/recipes/commandlineparser.aspx
|
||||||
|
|
||||||
|
namespace TechBot.Library
|
||||||
|
{
|
||||||
|
/// <summary>Implementation of a command-line parsing class. Is capable of
|
||||||
|
/// having switches registered with it directly or can examine a registered
|
||||||
|
/// class for any properties with the appropriate attributes appended to
|
||||||
|
/// them.</summary>
|
||||||
|
public class ParametersParser
|
||||||
|
{
|
||||||
|
/// <summary>A simple internal class for passing back to the caller
|
||||||
|
/// some information about the switch. The internals/implementation
|
||||||
|
/// of this class has privillaged access to the contents of the
|
||||||
|
/// SwitchRecord class.</summary>
|
||||||
|
public class SwitchInfo
|
||||||
|
{
|
||||||
|
#region Private Variables
|
||||||
|
private object m_Switch = null;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
public string Name { get { return (m_Switch as SwitchRecord).Name; } }
|
||||||
|
public string Description { get { return (m_Switch as SwitchRecord).Description; } }
|
||||||
|
public string[] Aliases { get { return (m_Switch as SwitchRecord).Aliases; } }
|
||||||
|
public System.Type Type { get { return (m_Switch as SwitchRecord).Type; } }
|
||||||
|
public object Value { get { return (m_Switch as SwitchRecord).Value; } }
|
||||||
|
public object InternalValue { get { return (m_Switch as SwitchRecord).InternalValue; } }
|
||||||
|
public bool IsEnum { get { return (m_Switch as SwitchRecord).Type.IsEnum; } }
|
||||||
|
public string[] Enumerations { get { return (m_Switch as SwitchRecord).Enumerations; } }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for the SwitchInfo class. Note, in order to hide to the outside world
|
||||||
|
/// information not necessary to know, the constructor takes a System.Object (aka
|
||||||
|
/// object) as it's registering type. If the type isn't of the correct type, an exception
|
||||||
|
/// is thrown.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rec">The SwitchRecord for which this class store information.</param>
|
||||||
|
/// <exception cref="ArgumentException">Thrown if the rec parameter is not of
|
||||||
|
/// the type SwitchRecord.</exception>
|
||||||
|
public SwitchInfo( object rec )
|
||||||
|
{
|
||||||
|
if ( rec is SwitchRecord )
|
||||||
|
m_Switch = rec;
|
||||||
|
else
|
||||||
|
throw new ArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The SwitchRecord is stored within the parser's collection of registered
|
||||||
|
/// switches. This class is private to the outside world.
|
||||||
|
/// </summary>
|
||||||
|
private class SwitchRecord
|
||||||
|
{
|
||||||
|
#region Private Variables
|
||||||
|
private string m_name = "";
|
||||||
|
private string m_description = "";
|
||||||
|
private object m_value = null;
|
||||||
|
private System.Type m_switchType = typeof(bool);
|
||||||
|
private System.Collections.ArrayList m_Aliases = null;
|
||||||
|
private string m_Pattern = "";
|
||||||
|
|
||||||
|
// The following advanced functions allow for callbacks to be
|
||||||
|
// made to manipulate the associated data type.
|
||||||
|
private System.Reflection.MethodInfo m_SetMethod = null;
|
||||||
|
private System.Reflection.MethodInfo m_GetMethod = null;
|
||||||
|
private object m_PropertyOwner = null;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private Utility Functions
|
||||||
|
private void Initialize( string name, string description )
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
m_description = description;
|
||||||
|
|
||||||
|
BuildPattern();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BuildPattern()
|
||||||
|
{
|
||||||
|
string matchString = Name;
|
||||||
|
|
||||||
|
if ( Aliases != null && Aliases.Length > 0 )
|
||||||
|
foreach( string s in Aliases )
|
||||||
|
matchString += "|" + s;
|
||||||
|
|
||||||
|
string strPatternStart = @"(\s|^)(?<match>(-{1,2}|/)(";
|
||||||
|
string strPatternEnd; // To be defined below.
|
||||||
|
|
||||||
|
// The common suffix ensures that the switches are followed by
|
||||||
|
// a white-space OR the end of the string. This will stop
|
||||||
|
// switches such as /help matching /helpme
|
||||||
|
//
|
||||||
|
string strCommonSuffix = @"(?=(\s|$))";
|
||||||
|
|
||||||
|
if ( Type == typeof(bool) )
|
||||||
|
strPatternEnd = @")(?<value>(\+|-){0,1}))";
|
||||||
|
else if ( Type == typeof(string) )
|
||||||
|
strPatternEnd = @")(?::|\s+))((?:"")(?<value>.+)(?:"")|(?<value>\S+))";
|
||||||
|
else if ( Type == typeof(int) )
|
||||||
|
strPatternEnd = @")(?::|\s+))((?<value>(-|\+)[0-9]+)|(?<value>[0-9]+))";
|
||||||
|
else if ( Type.IsEnum )
|
||||||
|
{
|
||||||
|
string[] enumNames = Enumerations;
|
||||||
|
string e_str = enumNames[0];
|
||||||
|
for ( int e=1; e<enumNames.Length; e++ )
|
||||||
|
e_str += "|" + enumNames[e];
|
||||||
|
strPatternEnd = @")(?::|\s+))(?<value>" + e_str + @")";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new System.ArgumentException();
|
||||||
|
|
||||||
|
// Set the internal regular expression pattern.
|
||||||
|
m_Pattern = strPatternStart + matchString + strPatternEnd + strCommonSuffix;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
public object Value
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if ( ReadValue != null )
|
||||||
|
return ReadValue;
|
||||||
|
else
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public object InternalValue
|
||||||
|
{
|
||||||
|
get { return m_value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return m_name; }
|
||||||
|
set { m_name = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Description
|
||||||
|
{
|
||||||
|
get { return m_description; }
|
||||||
|
set { m_description = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public System.Type Type
|
||||||
|
{
|
||||||
|
get { return m_switchType; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string[] Aliases
|
||||||
|
{
|
||||||
|
get { return (m_Aliases != null) ? (string[])m_Aliases.ToArray(typeof(string)): null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Pattern
|
||||||
|
{
|
||||||
|
get { return m_Pattern; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public System.Reflection.MethodInfo SetMethod
|
||||||
|
{
|
||||||
|
set { m_SetMethod = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public System.Reflection.MethodInfo GetMethod
|
||||||
|
{
|
||||||
|
set { m_GetMethod = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public object PropertyOwner
|
||||||
|
{
|
||||||
|
set { m_PropertyOwner = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ReadValue
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
object o = null;
|
||||||
|
if ( m_PropertyOwner != null && m_GetMethod != null )
|
||||||
|
o = m_GetMethod.Invoke( m_PropertyOwner, null );
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string[] Enumerations
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if ( m_switchType.IsEnum )
|
||||||
|
return System.Enum.GetNames( m_switchType );
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
public SwitchRecord( string name, string description )
|
||||||
|
{
|
||||||
|
Initialize( name, description );
|
||||||
|
}
|
||||||
|
|
||||||
|
public SwitchRecord( string name, string description, System.Type type )
|
||||||
|
{
|
||||||
|
if ( type == typeof(bool) ||
|
||||||
|
type == typeof(string) ||
|
||||||
|
type == typeof(int) ||
|
||||||
|
type.IsEnum )
|
||||||
|
{
|
||||||
|
m_switchType = type;
|
||||||
|
Initialize( name, description );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new ArgumentException("Currently only Ints, Bool and Strings are supported");
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
public void AddAlias( string alias )
|
||||||
|
{
|
||||||
|
if ( m_Aliases == null )
|
||||||
|
m_Aliases = new System.Collections.ArrayList();
|
||||||
|
m_Aliases.Add( alias );
|
||||||
|
|
||||||
|
BuildPattern();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Notify( object value )
|
||||||
|
{
|
||||||
|
if ( m_PropertyOwner != null && m_SetMethod != null )
|
||||||
|
{
|
||||||
|
object[] parameters = new object[1];
|
||||||
|
parameters[0] = value;
|
||||||
|
m_SetMethod.Invoke( m_PropertyOwner, parameters );
|
||||||
|
}
|
||||||
|
m_value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region Private Variables
|
||||||
|
private string m_commandLine = "";
|
||||||
|
private string m_workingString = "";
|
||||||
|
private string m_applicationName = "";
|
||||||
|
private string[] m_splitParameters = null;
|
||||||
|
private System.Collections.ArrayList m_switches = null;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private Utility Functions
|
||||||
|
private void ExtractApplicationName()
|
||||||
|
{
|
||||||
|
Regex r = new Regex(@"^(?<commandLine>("".+""|(\S)+))(?<remainder>.+)",
|
||||||
|
RegexOptions.ExplicitCapture);
|
||||||
|
Match m = r.Match(m_commandLine);
|
||||||
|
if ( m != null && m.Groups["commandLine"] != null )
|
||||||
|
{
|
||||||
|
m_applicationName = m.Groups["commandLine"].Value;
|
||||||
|
m_workingString = m.Groups["remainder"].Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SplitParameters()
|
||||||
|
{
|
||||||
|
// Populate the split parameters array with the remaining parameters.
|
||||||
|
// Note that if quotes are used, the quotes are removed.
|
||||||
|
// e.g. one two three "four five six"
|
||||||
|
// 0 - one
|
||||||
|
// 1 - two
|
||||||
|
// 2 - three
|
||||||
|
// 3 - four five six
|
||||||
|
// (e.g. 3 is not in quotes).
|
||||||
|
Regex r = new Regex(@"((\s*(""(?<param>.+?)""|(?<param>\S+))))",
|
||||||
|
RegexOptions.ExplicitCapture);
|
||||||
|
MatchCollection m = r.Matches( m_workingString );
|
||||||
|
|
||||||
|
if ( m != null )
|
||||||
|
{
|
||||||
|
m_splitParameters = new string[ m.Count ];
|
||||||
|
for ( int i=0; i < m.Count; i++ )
|
||||||
|
m_splitParameters[i] = m[i].Groups["param"].Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleSwitches()
|
||||||
|
{
|
||||||
|
if ( m_switches != null )
|
||||||
|
{
|
||||||
|
foreach ( SwitchRecord s in m_switches )
|
||||||
|
{
|
||||||
|
Regex r = new Regex( s.Pattern,
|
||||||
|
RegexOptions.ExplicitCapture
|
||||||
|
| RegexOptions.IgnoreCase );
|
||||||
|
MatchCollection m = r.Matches( m_workingString );
|
||||||
|
if ( m != null )
|
||||||
|
{
|
||||||
|
for ( int i=0; i < m.Count; i++ )
|
||||||
|
{
|
||||||
|
string value = null;
|
||||||
|
if ( m[i].Groups != null && m[i].Groups["value"] != null )
|
||||||
|
value = m[i].Groups["value"].Value;
|
||||||
|
|
||||||
|
if ( s.Type == typeof(bool))
|
||||||
|
{
|
||||||
|
bool state = true;
|
||||||
|
// The value string may indicate what value we want.
|
||||||
|
if ( m[i].Groups != null && m[i].Groups["value"] != null )
|
||||||
|
{
|
||||||
|
switch ( value )
|
||||||
|
{
|
||||||
|
case "+": state = true;
|
||||||
|
break;
|
||||||
|
case "-": state = false;
|
||||||
|
break;
|
||||||
|
case "": if ( s.ReadValue != null )
|
||||||
|
state = !(bool)s.ReadValue;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.Notify( state );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if ( s.Type == typeof(string) )
|
||||||
|
s.Notify( value );
|
||||||
|
else if ( s.Type == typeof(int) )
|
||||||
|
s.Notify( int.Parse( value ) );
|
||||||
|
else if ( s.Type.IsEnum )
|
||||||
|
s.Notify( System.Enum.Parse(s.Type,value,true) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_workingString = r.Replace(m_workingString, " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
public string ApplicationName
|
||||||
|
{
|
||||||
|
get { return m_applicationName; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string[] Parameters
|
||||||
|
{
|
||||||
|
get { return m_splitParameters; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public SwitchInfo[] Switches
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if ( m_switches == null )
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SwitchInfo[] si = new SwitchInfo[ m_switches.Count ];
|
||||||
|
for ( int i=0; i<m_switches.Count; i++ )
|
||||||
|
si[i] = new SwitchInfo( m_switches[i] );
|
||||||
|
return si;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public object this[string name]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if ( m_switches != null )
|
||||||
|
for ( int i=0; i<m_switches.Count; i++ )
|
||||||
|
if ( string.Compare( (m_switches[i] as SwitchRecord).Name, name, true )==0 )
|
||||||
|
return (m_switches[i] as SwitchRecord).Value;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>This function returns a list of the unhandled switches
|
||||||
|
/// that the parser has seen, but not processed.</summary>
|
||||||
|
/// <remark>The unhandled switches are not removed from the remainder
|
||||||
|
/// of the command-line.</remark>
|
||||||
|
public string[] UnhandledSwitches
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string switchPattern = @"(\s|^)(?<match>(-{1,2}|/)(.+?))(?=(\s|$))";
|
||||||
|
Regex r = new Regex( switchPattern,
|
||||||
|
RegexOptions.ExplicitCapture
|
||||||
|
| RegexOptions.IgnoreCase );
|
||||||
|
MatchCollection m = r.Matches( m_workingString );
|
||||||
|
|
||||||
|
if ( m != null )
|
||||||
|
{
|
||||||
|
string[] unhandled = new string[ m.Count ];
|
||||||
|
for ( int i=0; i < m.Count; i++ )
|
||||||
|
unhandled[i] = m[i].Groups["match"].Value;
|
||||||
|
return unhandled;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
public void AddSwitch( string name, string description )
|
||||||
|
{
|
||||||
|
if ( m_switches == null )
|
||||||
|
m_switches = new System.Collections.ArrayList();
|
||||||
|
|
||||||
|
SwitchRecord rec = new SwitchRecord( name, description );
|
||||||
|
m_switches.Add( rec );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddSwitch( string[] names, string description )
|
||||||
|
{
|
||||||
|
if ( m_switches == null )
|
||||||
|
m_switches = new System.Collections.ArrayList();
|
||||||
|
SwitchRecord rec = new SwitchRecord( names[0], description );
|
||||||
|
for ( int s=1; s<names.Length; s++ )
|
||||||
|
rec.AddAlias( names[s] );
|
||||||
|
m_switches.Add( rec );
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Parse()
|
||||||
|
{
|
||||||
|
ExtractApplicationName();
|
||||||
|
|
||||||
|
// Remove switches and associated info.
|
||||||
|
HandleSwitches();
|
||||||
|
|
||||||
|
// Split parameters.
|
||||||
|
SplitParameters();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object InternalValue(string name)
|
||||||
|
{
|
||||||
|
if ( m_switches != null )
|
||||||
|
for ( int i=0; i<m_switches.Count; i++ )
|
||||||
|
if ( string.Compare( (m_switches[i] as SwitchRecord).Name, name, true )==0 )
|
||||||
|
return (m_switches[i] as SwitchRecord).InternalValue;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
public ParametersParser( string commandLine )
|
||||||
|
{
|
||||||
|
m_commandLine = commandLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParametersParser( string commandLine,
|
||||||
|
object classForAutoAttributes )
|
||||||
|
{
|
||||||
|
m_commandLine = commandLine;
|
||||||
|
|
||||||
|
Type type = classForAutoAttributes.GetType();
|
||||||
|
System.Reflection.MemberInfo[] members = type.GetMembers();
|
||||||
|
|
||||||
|
for(int i=0; i<members.Length; i++)
|
||||||
|
{
|
||||||
|
object[] attributes = members[i].GetCustomAttributes(false);
|
||||||
|
if(attributes.Length > 0)
|
||||||
|
{
|
||||||
|
SwitchRecord rec = null;
|
||||||
|
|
||||||
|
foreach ( Attribute attribute in attributes )
|
||||||
|
{
|
||||||
|
if ( attribute is CommandParameterAttribute )
|
||||||
|
{
|
||||||
|
CommandParameterAttribute switchAttrib =
|
||||||
|
(CommandParameterAttribute) attribute;
|
||||||
|
|
||||||
|
// Get the property information. We're only handling
|
||||||
|
// properties at the moment!
|
||||||
|
if ( members[i] is System.Reflection.PropertyInfo )
|
||||||
|
{
|
||||||
|
System.Reflection.PropertyInfo pi = (System.Reflection.PropertyInfo) members[i];
|
||||||
|
|
||||||
|
rec = new SwitchRecord( switchAttrib.Name,
|
||||||
|
switchAttrib.Description,
|
||||||
|
pi.PropertyType );
|
||||||
|
|
||||||
|
// Map in the Get/Set methods.
|
||||||
|
rec.SetMethod = pi.GetSetMethod();
|
||||||
|
rec.GetMethod = pi.GetGetMethod();
|
||||||
|
rec.PropertyOwner = classForAutoAttributes;
|
||||||
|
|
||||||
|
// Can only handle a single switch for each property
|
||||||
|
// (otherwise the parsing of aliases gets silly...)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// See if any aliases are required. We can only do this after
|
||||||
|
// a switch has been registered and the framework doesn't make
|
||||||
|
// any guarantees about the order of attributes, so we have to
|
||||||
|
// walk the collection a second time.
|
||||||
|
if ( rec != null )
|
||||||
|
{
|
||||||
|
foreach ( Attribute attribute in attributes )
|
||||||
|
{
|
||||||
|
if (attribute is CommandParameterAliasAttribute)
|
||||||
|
{
|
||||||
|
CommandParameterAliasAttribute aliasAttrib =
|
||||||
|
(CommandParameterAliasAttribute)attribute;
|
||||||
|
rec.AddAlias( aliasAttrib.Alias );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assuming we have a switch record (that may or may not have
|
||||||
|
// aliases), add it to the collection of switches.
|
||||||
|
if ( rec != null )
|
||||||
|
{
|
||||||
|
if ( m_switches == null )
|
||||||
|
m_switches = new System.Collections.ArrayList();
|
||||||
|
m_switches.Add( rec );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,29 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace TechBot.Library
|
|
||||||
{
|
|
||||||
class SambaBugUrl : BugCommand
|
|
||||||
{
|
|
||||||
public SambaBugUrl(TechBotService techBot)
|
|
||||||
: base(techBot)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string[] AvailableCommands
|
|
||||||
{
|
|
||||||
get { return new string[] { "sambabug" }; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string BugUrl
|
|
||||||
{
|
|
||||||
get { return "https://bugzilla.samba.org/show_bug.cgi?id={0}"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Help()
|
|
||||||
{
|
|
||||||
return "!sambabug <number>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,7 +4,6 @@ namespace TechBot.Library
|
||||||
{
|
{
|
||||||
public interface IServiceOutput
|
public interface IServiceOutput
|
||||||
{
|
{
|
||||||
void WriteLine(MessageContext context,
|
void WriteLine(MessageContext context, string message);
|
||||||
string message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace TechBot.Library
|
|
||||||
{
|
|
||||||
public class SvnCommand : Command
|
|
||||||
{
|
|
||||||
private string m_SvnRoot;
|
|
||||||
|
|
||||||
public SvnCommand(TechBotService techBot)
|
|
||||||
: base(techBot)
|
|
||||||
{
|
|
||||||
m_SvnRoot = Settings.Default.SVNRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string[] AvailableCommands
|
|
||||||
{
|
|
||||||
get { return new string[] { "svn" }; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Handle(MessageContext context,
|
|
||||||
string commandName,
|
|
||||||
string parameters)
|
|
||||||
{
|
|
||||||
TechBot.ServiceOutput.WriteLine(context, string.Format("svn co {0}" , m_SvnRoot));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Help()
|
|
||||||
{
|
|
||||||
return "!svn";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -39,21 +39,29 @@
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ApiCommand.cs" />
|
<Compile Include="Attributes\CommandAttribute.cs" />
|
||||||
<Compile Include="BugCommand.cs" />
|
<Compile Include="Attributes\CommandParameterAliasAttribute.cs" />
|
||||||
|
<Compile Include="Attributes\CommandParameterAttribute.cs" />
|
||||||
|
<Compile Include="Collections\CommandBuilderCollection.cs" />
|
||||||
|
<Compile Include="Commands\Base\XmlLookupCommand.cs" />
|
||||||
|
<Compile Include="Factory\CommandBuilder.cs" />
|
||||||
|
<Compile Include="Factory\CommandFactory.cs" />
|
||||||
|
<Compile Include="Commands\Base\Command.cs" />
|
||||||
<Compile Include="Commands\Base\XmlCommand.cs" />
|
<Compile Include="Commands\Base\XmlCommand.cs" />
|
||||||
<Compile Include="SambaBugUrl.cs" />
|
<Compile Include="Commands\BugCommand.cs" />
|
||||||
<Compile Include="WineBugUrl.cs" />
|
<Compile Include="Commands\HelpCommand.cs" />
|
||||||
<Compile Include="ErrorCommand.cs" />
|
<Compile Include="Commands\HResultCommand.cs" />
|
||||||
<Compile Include="HelpCommand.cs" />
|
<Compile Include="Commands\NtStatusCommand.cs" />
|
||||||
<Compile Include="HresultCommand.cs" />
|
<Compile Include="Commands\ReactOSBugUrl.cs" />
|
||||||
<Compile Include="Command.cs" />
|
<Compile Include="Commands\SambaBugUrl.cs" />
|
||||||
<Compile Include="IrcService.cs" />
|
<Compile Include="Commands\SvnCommand.cs" />
|
||||||
|
<Compile Include="Commands\WineBugUrl.cs" />
|
||||||
|
<Compile Include="Commands\WinerrorCommand.cs" />
|
||||||
|
<Compile Include="Commands\WMCommand.cs" />
|
||||||
<Compile Include="MessageContext.cs" />
|
<Compile Include="MessageContext.cs" />
|
||||||
<Compile Include="NtStatusCommand.cs" />
|
|
||||||
<Compile Include="NumberParser.cs" />
|
<Compile Include="NumberParser.cs" />
|
||||||
|
<Compile Include="ParametersParser.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ReactOSBugUrl.cs" />
|
|
||||||
<Compile Include="ServiceOutput.cs" />
|
<Compile Include="ServiceOutput.cs" />
|
||||||
<Compile Include="Settings.cs" />
|
<Compile Include="Settings.cs" />
|
||||||
<Compile Include="Settings.Designer.cs">
|
<Compile Include="Settings.Designer.cs">
|
||||||
|
@ -61,10 +69,8 @@
|
||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
<DependentUpon>Settings.settings</DependentUpon>
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="SvnCommand.cs" />
|
<Compile Include="TechBotIrcService.cs" />
|
||||||
<Compile Include="TechBotService.cs" />
|
<Compile Include="TechBotService.cs" />
|
||||||
<Compile Include="WinerrorCommand.cs" />
|
|
||||||
<Compile Include="WmCommand.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
|
|
@ -7,41 +7,50 @@ using TechBot.IRCLibrary;
|
||||||
|
|
||||||
namespace TechBot.Library
|
namespace TechBot.Library
|
||||||
{
|
{
|
||||||
public class IrcService : IServiceOutput
|
public class IrcServiceOutput : IServiceOutput
|
||||||
|
{
|
||||||
|
public void WriteLine(MessageContext context,
|
||||||
|
string message)
|
||||||
|
{
|
||||||
|
if (context is ChannelMessageContext)
|
||||||
|
{
|
||||||
|
ChannelMessageContext channelContext = context as ChannelMessageContext;
|
||||||
|
channelContext.Channel.Talk(message);
|
||||||
|
}
|
||||||
|
else if (context is UserMessageContext)
|
||||||
|
{
|
||||||
|
UserMessageContext userContext = context as UserMessageContext;
|
||||||
|
userContext.User.Talk(message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException(String.Format("Unhandled message context '{0}'",
|
||||||
|
context.GetType()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class IrcTechBotService : TechBotService
|
||||||
{
|
{
|
||||||
private string hostname;
|
|
||||||
private int port;
|
private int port;
|
||||||
|
private string hostname;
|
||||||
private string channelnames;
|
private string channelnames;
|
||||||
private string botname;
|
private string botname;
|
||||||
private string password;
|
private string password;
|
||||||
private string chmPath;
|
private string chmPath;
|
||||||
private string mainChm;
|
private string mainChm;
|
||||||
private string ntstatusXml;
|
|
||||||
private string winerrorXml;
|
|
||||||
private string hresultXml;
|
|
||||||
private string wmXml;
|
|
||||||
private string svnCommand;
|
|
||||||
private string bugUrl, WineBugUrl, SambaBugUrl;
|
|
||||||
private IrcClient m_IrcClient;
|
private IrcClient m_IrcClient;
|
||||||
private ArrayList channels = new ArrayList(); /* IrcChannel */
|
private ArrayList channels = new ArrayList();
|
||||||
private TechBotService service;
|
|
||||||
private bool isStopped = false;
|
private bool isStopped = false;
|
||||||
|
|
||||||
public IrcService(string hostname,
|
public IrcTechBotService(string hostname,
|
||||||
int port,
|
int port,
|
||||||
string channelnames,
|
string channelnames,
|
||||||
string botname,
|
string botname,
|
||||||
string password,
|
string password,
|
||||||
string chmPath,
|
string chmPath,
|
||||||
string mainChm,
|
string mainChm)
|
||||||
//string ntstatusXml,
|
: base (new IrcServiceOutput() , chmPath , mainChm)
|
||||||
//string winerrorXml,
|
|
||||||
//string hresultXml,
|
|
||||||
//string wmXml,
|
|
||||||
//string svnCommand,
|
|
||||||
string BugUrl,
|
|
||||||
string WineBugUrl,
|
|
||||||
string SambaBugUrl)
|
|
||||||
{
|
{
|
||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
|
@ -53,30 +62,12 @@ namespace TechBot.Library
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.chmPath = chmPath;
|
this.chmPath = chmPath;
|
||||||
this.mainChm = mainChm;
|
this.mainChm = mainChm;
|
||||||
this.ntstatusXml = ntstatusXml;
|
|
||||||
this.winerrorXml = winerrorXml;
|
|
||||||
this.hresultXml = hresultXml;
|
|
||||||
this.wmXml = wmXml;
|
|
||||||
this.svnCommand = svnCommand;
|
|
||||||
this.bugUrl = BugUrl;
|
|
||||||
this.WineBugUrl = WineBugUrl;
|
|
||||||
this.SambaBugUrl = SambaBugUrl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run()
|
public override void Run()
|
||||||
{
|
{
|
||||||
service = new TechBotService(this,
|
//Call the base class
|
||||||
chmPath,
|
base.Run();
|
||||||
mainChm);
|
|
||||||
//ntstatusXml,
|
|
||||||
//winerrorXml,
|
|
||||||
//hresultXml,
|
|
||||||
//wmXml,
|
|
||||||
//svnCommand,
|
|
||||||
//bugUrl,
|
|
||||||
//WineBugUrl,
|
|
||||||
//SambaBugUrl);
|
|
||||||
service.Run();
|
|
||||||
|
|
||||||
m_IrcClient = new IrcClient();
|
m_IrcClient = new IrcClient();
|
||||||
m_IrcClient.Encoding = Encoding.GetEncoding("iso-8859-1");
|
m_IrcClient.Encoding = Encoding.GetEncoding("iso-8859-1");
|
||||||
|
@ -147,26 +138,6 @@ namespace TechBot.Library
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteLine(MessageContext context,
|
|
||||||
string message)
|
|
||||||
{
|
|
||||||
if (context is ChannelMessageContext)
|
|
||||||
{
|
|
||||||
ChannelMessageContext channelContext = context as ChannelMessageContext;
|
|
||||||
channelContext.Channel.Talk(message);
|
|
||||||
}
|
|
||||||
else if (context is UserMessageContext)
|
|
||||||
{
|
|
||||||
UserMessageContext userContext = context as UserMessageContext;
|
|
||||||
userContext.User.Talk(message);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException(String.Format("Unhandled message context '{0}'",
|
|
||||||
context.GetType()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ExtractMessage(string parameters,
|
private void ExtractMessage(string parameters,
|
||||||
out string message)
|
out string message)
|
||||||
{
|
{
|
||||||
|
@ -270,7 +241,7 @@ namespace TechBot.Library
|
||||||
Console.WriteLine(String.Format("Injecting: {0} from {1}",
|
Console.WriteLine(String.Format("Injecting: {0} from {1}",
|
||||||
injectMessage,
|
injectMessage,
|
||||||
GetMessageSource(context)));
|
GetMessageSource(context)));
|
||||||
service.InjectMessage(context,
|
InjectMessage(context,
|
||||||
injectMessage);
|
injectMessage);
|
||||||
}
|
}
|
||||||
else
|
else
|
|
@ -4,63 +4,29 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
using TechBot.IRCLibrary;
|
using TechBot.IRCLibrary;
|
||||||
|
|
||||||
namespace TechBot.Library
|
namespace TechBot.Library
|
||||||
{
|
{
|
||||||
public class TechBotService
|
public abstract class TechBotService
|
||||||
{
|
{
|
||||||
private IServiceOutput serviceOutput;
|
protected IServiceOutput serviceOutput;
|
||||||
private string chmPath;
|
private string chmPath;
|
||||||
private string mainChm;
|
private string mainChm;
|
||||||
private string ntstatusXml;
|
|
||||||
private string winerrorXml;
|
|
||||||
private string hresultXml;
|
|
||||||
private string wmXml;
|
|
||||||
private string svnCommand;
|
|
||||||
private string bugUrl, WineBugUrl, SambaBugUrl;
|
|
||||||
private List<Command> commands = new List<Command>();
|
|
||||||
|
|
||||||
public TechBotService(IServiceOutput serviceOutput,
|
public TechBotService(IServiceOutput serviceOutput,
|
||||||
string chmPath,
|
string chmPath,
|
||||||
string mainChm)
|
string mainChm)
|
||||||
//string ntstatusXml,
|
|
||||||
//string winerrorXml,
|
|
||||||
//string hresultXml,
|
|
||||||
//string wmXml,
|
|
||||||
//string svnCommand,
|
|
||||||
//string bugUrl,
|
|
||||||
//string WineBugUrl,
|
|
||||||
//string SambaBugUrl)
|
|
||||||
{
|
{
|
||||||
this.serviceOutput = serviceOutput;
|
this.serviceOutput = serviceOutput;
|
||||||
this.chmPath = chmPath;
|
this.chmPath = chmPath;
|
||||||
this.mainChm = mainChm;
|
this.mainChm = mainChm;
|
||||||
this.ntstatusXml = ntstatusXml;
|
|
||||||
this.winerrorXml = winerrorXml;
|
|
||||||
this.hresultXml = hresultXml;
|
|
||||||
this.wmXml = wmXml;
|
|
||||||
this.svnCommand = svnCommand;
|
|
||||||
this.bugUrl = bugUrl;
|
|
||||||
this.WineBugUrl = WineBugUrl;
|
|
||||||
this.SambaBugUrl = SambaBugUrl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run()
|
public virtual void Run()
|
||||||
{
|
{
|
||||||
commands.Add(new HelpCommand(this));
|
CommandFactory.LoadPlugins();
|
||||||
/*commands.Add(new ApiCommand(serviceOutput,
|
|
||||||
chmPath,
|
|
||||||
mainChm));*/
|
|
||||||
commands.Add(new NtStatusCommand(this));
|
|
||||||
commands.Add(new WinerrorCommand(this));
|
|
||||||
commands.Add(new HResultCommand(this));
|
|
||||||
commands.Add(new ErrorCommand(this));
|
|
||||||
commands.Add(new WMCommand(this));
|
|
||||||
commands.Add(new SvnCommand(this));
|
|
||||||
commands.Add(new ReactOSBugUrl(this));
|
|
||||||
commands.Add(new SambaBugUrl(this));
|
|
||||||
commands.Add(new WineBugUrl(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IServiceOutput ServiceOutput
|
public IServiceOutput ServiceOutput
|
||||||
|
@ -68,15 +34,13 @@ namespace TechBot.Library
|
||||||
get { return serviceOutput; }
|
get { return serviceOutput; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public IList<Command> Commands
|
public CommandBuilderCollection Commands
|
||||||
{
|
{
|
||||||
get { return commands; }
|
get { return CommandFactory.Commands; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InjectMessage(MessageContext context,
|
public void InjectMessage(MessageContext context, string message)
|
||||||
string message)
|
|
||||||
{
|
{
|
||||||
if (message.StartsWith("!"))
|
|
||||||
ParseCommandMessage(context,
|
ParseCommandMessage(context,
|
||||||
message);
|
message);
|
||||||
}
|
}
|
||||||
|
@ -104,19 +68,21 @@ namespace TechBot.Library
|
||||||
else
|
else
|
||||||
commandName = message.Trim();
|
commandName = message.Trim();
|
||||||
|
|
||||||
foreach (Command command in commands)
|
foreach (CommandBuilder command in Commands)
|
||||||
{
|
{
|
||||||
foreach (string cmd in command.AvailableCommands)
|
if (command.Name == commandName)
|
||||||
{
|
{
|
||||||
if (cmd == commandName)
|
//Create a new instance of the required command type
|
||||||
{
|
Command cmd = command.CreateCommand();
|
||||||
command.Handle(context,
|
|
||||||
commandName,
|
cmd.TechBot = this;
|
||||||
commandParams);
|
cmd.Context = context;
|
||||||
|
cmd.ParseParameters(message);
|
||||||
|
cmd.ExecuteCommand();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace TechBot.Library
|
|
||||||
{
|
|
||||||
class WineBugUrl : BugCommand
|
|
||||||
{
|
|
||||||
public WineBugUrl(TechBotService techBot)
|
|
||||||
: base(techBot)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string[] AvailableCommands
|
|
||||||
{
|
|
||||||
get { return new string[] { "winebug" }; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string BugUrl
|
|
||||||
{
|
|
||||||
get { return "http://bugs.winehq.org/show_bug.cgi?id={0}"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Help()
|
|
||||||
{
|
|
||||||
return "!winebug <number>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
<Combine fileversion="1.0" name="TechBot" description="">
|
|
||||||
<StartMode startupentry="TechBot" single="True">
|
|
||||||
<Execute entry="TechBot" type="None" />
|
|
||||||
<Execute entry="TechBot.Library" type="None" />
|
|
||||||
<Execute entry="CHMLibrary" type="None" />
|
|
||||||
<Execute entry="Compression" type="None" />
|
|
||||||
<Execute entry="TechBot.Console" type="None" />
|
|
||||||
<Execute entry="TechBot.IRCLibrary" type="None" />
|
|
||||||
</StartMode>
|
|
||||||
<Entries>
|
|
||||||
<Entry filename=".\TechBot\TechBot.prjx" />
|
|
||||||
<Entry filename=".\TechBot.Library\TechBot.Library.prjx" />
|
|
||||||
<Entry filename=".\CHMLibrary\CHMLibrary.prjx" />
|
|
||||||
<Entry filename=".\Compression\Compression.prjx" />
|
|
||||||
<Entry filename=".\TechBot.Console\TechBot.Console.prjx" />
|
|
||||||
<Entry filename=".\TechBot.IRCLibrary\TechBot.IRCLibrary.prjx" />
|
|
||||||
</Entries>
|
|
||||||
<Configurations active="Debug">
|
|
||||||
<Configuration name="Release">
|
|
||||||
<Entry name="TechBot" configurationname="Debug" build="False" />
|
|
||||||
<Entry name="TechBot.Library" configurationname="Debug" build="False" />
|
|
||||||
<Entry name="CHMLibrary" configurationname="Debug" build="False" />
|
|
||||||
<Entry name="Compression" configurationname="Debug" build="False" />
|
|
||||||
<Entry name="TechBot.Console" configurationname="Debug" build="False" />
|
|
||||||
<Entry name="TechBot.IRCLibrary" configurationname="Debug" build="False" />
|
|
||||||
</Configuration>
|
|
||||||
<Configuration name="Debug">
|
|
||||||
<Entry name="TechBot" configurationname="Debug" build="False" />
|
|
||||||
<Entry name="TechBot.Library" configurationname="Debug" build="False" />
|
|
||||||
<Entry name="CHMLibrary" configurationname="Debug" build="False" />
|
|
||||||
<Entry name="Compression" configurationname="Debug" build="False" />
|
|
||||||
<Entry name="TechBot.Console" configurationname="Debug" build="False" />
|
|
||||||
<Entry name="TechBot.IRCLibrary" configurationname="Debug" build="False" />
|
|
||||||
</Configuration>
|
|
||||||
</Configurations>
|
|
||||||
</Combine>
|
|
28
irc/TechBot/TechBot/ProjectInstaller.cs
Normal file
28
irc/TechBot/TechBot/ProjectInstaller.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.ServiceProcess;
|
||||||
|
using System.Configuration.Install;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TechBot
|
||||||
|
{
|
||||||
|
[RunInstaller(true)]
|
||||||
|
public class ProjectInstaller : Installer
|
||||||
|
{
|
||||||
|
public ProjectInstaller()
|
||||||
|
{
|
||||||
|
ServiceProcessInstaller spi = null;
|
||||||
|
ServiceInstaller si = null;
|
||||||
|
|
||||||
|
spi = new ServiceProcessInstaller();
|
||||||
|
spi.Account = ServiceAccount.LocalSystem;
|
||||||
|
|
||||||
|
si = new ServiceInstaller();
|
||||||
|
si.ServiceName = "TechBot";
|
||||||
|
si.StartType = ServiceStartMode.Automatic;
|
||||||
|
|
||||||
|
Installers.AddRange(new Installer[] { spi, si });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,21 +51,21 @@ namespace TechBot
|
||||||
SetupConfiguration();
|
SetupConfiguration();
|
||||||
System.Console.WriteLine("TechBot irc service...");
|
System.Console.WriteLine("TechBot irc service...");
|
||||||
|
|
||||||
IrcService ircService = new IrcService(IRCServerHostName,
|
IrcTechBotService ircService = new IrcTechBotService(IRCServerHostName,
|
||||||
IRCServerHostPort,
|
IRCServerHostPort,
|
||||||
IRCChannelNames,
|
IRCChannelNames,
|
||||||
IRCBotName,
|
IRCBotName,
|
||||||
IRCBotPassword,
|
IRCBotPassword,
|
||||||
ChmPath,
|
ChmPath,
|
||||||
MainChm,
|
MainChm);
|
||||||
//NtstatusXml,
|
//NtstatusXml,
|
||||||
//WinerrorXml,
|
//WinerrorXml,
|
||||||
//HresultXml,
|
//HresultXml,
|
||||||
//WmXml,
|
//WmXml,
|
||||||
//SvnCommand,
|
//SvnCommand,
|
||||||
BugUrl,
|
//BugUrl,
|
||||||
WineBugUrl,
|
//WineBugUrl,
|
||||||
SambaBugUrl);
|
//SambaBugUrl);
|
||||||
ircService.Run();
|
ircService.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,9 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AssemblyInfo.cs" />
|
<Compile Include="AssemblyInfo.cs" />
|
||||||
|
<Compile Include="ProjectInstaller.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="ServiceThread.cs" />
|
<Compile Include="ServiceThread.cs" />
|
||||||
<Compile Include="TechBotService.cs">
|
<Compile Include="TechBotService.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
|
@ -52,6 +55,7 @@
|
||||||
<Reference Include="System.Configuration.Install" />
|
<Reference Include="System.Configuration.Install" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.ServiceProcess" />
|
<Reference Include="System.ServiceProcess" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\TechBot.IRCLibrary\TechBot.IRCLibrary.csproj">
|
<ProjectReference Include="..\TechBot.IRCLibrary\TechBot.IRCLibrary.csproj">
|
||||||
|
|
|
@ -80,18 +80,3 @@ namespace TechBot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[RunInstaller(true)]
|
|
||||||
public class ProjectInstaller : Installer
|
|
||||||
{
|
|
||||||
public ProjectInstaller()
|
|
||||||
{
|
|
||||||
ServiceProcessInstaller spi = new ServiceProcessInstaller();
|
|
||||||
spi.Account = ServiceAccount.LocalSystem;
|
|
||||||
|
|
||||||
ServiceInstaller si = new ServiceInstaller();
|
|
||||||
si.ServiceName = "TechBot";
|
|
||||||
si.StartType = ServiceStartMode.Automatic;
|
|
||||||
Installers.AddRange(new Installer[] {spi, si});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue