mirror of
https://github.com/reactos/reactos.git
synced 2025-07-28 11:31:54 +00:00
- 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:
parent
6d51a10a1b
commit
ac77d9d3a6
47 changed files with 1783 additions and 489 deletions
|
@ -13,6 +13,7 @@ namespace TechBot.Library
|
|||
private string m_name = "";
|
||||
private string m_description = "";
|
||||
private bool m_Required = true;
|
||||
private bool m_Default = false;
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
@ -26,6 +27,12 @@ namespace TechBot.Library
|
|||
|
||||
public bool Required { get { return m_Required; } }
|
||||
|
||||
public bool DefaultParameter
|
||||
{
|
||||
get { return m_Default; }
|
||||
set { m_Default = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ namespace TechBot.Library
|
|||
{
|
||||
Assembly assPlugin = Assembly.LoadFile(sFile);
|
||||
|
||||
Console.WriteLine("Loading plugins from : {0}", assPlugin.Location);
|
||||
|
||||
if (assPlugin != null)
|
||||
{
|
||||
foreach (Type pluginType in assPlugin.GetTypes())
|
||||
|
@ -36,6 +38,12 @@ namespace TechBot.Library
|
|||
{
|
||||
if (pluginType.IsAbstract == false)
|
||||
{
|
||||
CommandBuilder cmdBuilder = new CommandBuilder(pluginType);
|
||||
|
||||
Console.WriteLine("{0}:{1}",
|
||||
cmdBuilder.Name,
|
||||
cmdBuilder.Description);
|
||||
|
||||
//Add it to the list.
|
||||
Commands.Add(new CommandBuilder(pluginType));
|
||||
}
|
||||
|
|
11
irc/TechBot/TechBot.Library/Settings.Designer.cs
generated
11
irc/TechBot/TechBot.Library/Settings.Designer.cs
generated
|
@ -1,7 +1,7 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:2.0.50727.832
|
||||
// Runtime Version:2.0.50727.1433
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
|
@ -67,5 +67,14 @@ namespace TechBot.Library {
|
|||
return ((string)(this["SVNRoot"]));
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("@")]
|
||||
public string CommandPrefix {
|
||||
get {
|
||||
return ((string)(this["CommandPrefix"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,5 +17,8 @@
|
|||
<Setting Name="SVNRoot" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">svn://svn.reactos.org/trunk/reactos</Value>
|
||||
</Setting>
|
||||
<Setting Name="CommandPrefix" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">@</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
|
@ -48,19 +48,9 @@
|
|||
<Compile Include="Factory\CommandFactory.cs" />
|
||||
<Compile Include="Commands\Base\Command.cs" />
|
||||
<Compile Include="Commands\Base\XmlCommand.cs" />
|
||||
<Compile Include="Commands\BugCommand.cs" />
|
||||
<Compile Include="Commands\HelpCommand.cs" />
|
||||
<Compile Include="Commands\HResultCommand.cs" />
|
||||
<Compile Include="Commands\NtStatusCommand.cs" />
|
||||
<Compile Include="Commands\ReactOSBugUrl.cs" />
|
||||
<Compile Include="Commands\SambaBugUrl.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="NumberParser.cs" />
|
||||
<Compile Include="ParametersParser.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ServiceOutput.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
|
@ -78,10 +68,6 @@
|
|||
<Reference Include="System.XML" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CHMLibrary\CHMLibrary.csproj">
|
||||
<Project>{72E5CCA1-6318-4D62-964D-CB23A5C743B5}</Project>
|
||||
<Name>CHMLibrary</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\TechBot.IRCLibrary\TechBot.IRCLibrary.csproj">
|
||||
<Project>{D2A57931-DF04-4BC3-BD11-75DF4F3B0A88}</Project>
|
||||
<Name>TechBot.IRCLibrary</Name>
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace TechBot.Library
|
|||
{
|
||||
if (context is ChannelMessageContext)
|
||||
{
|
||||
Thread.Sleep (500);
|
||||
ChannelMessageContext channelContext = context as ChannelMessageContext;
|
||||
channelContext.Channel.Talk(message);
|
||||
}
|
||||
|
@ -37,8 +38,6 @@ namespace TechBot.Library
|
|||
private string channelnames;
|
||||
private string botname;
|
||||
private string password;
|
||||
private string chmPath;
|
||||
private string mainChm;
|
||||
private IrcClient m_IrcClient;
|
||||
private ArrayList channels = new ArrayList();
|
||||
private bool isStopped = false;
|
||||
|
@ -47,10 +46,8 @@ namespace TechBot.Library
|
|||
int port,
|
||||
string channelnames,
|
||||
string botname,
|
||||
string password,
|
||||
string chmPath,
|
||||
string mainChm)
|
||||
: base (new IrcServiceOutput() , chmPath , mainChm)
|
||||
string password)
|
||||
: base (new IrcServiceOutput())
|
||||
{
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
|
@ -60,8 +57,6 @@ namespace TechBot.Library
|
|||
this.password = null;
|
||||
else
|
||||
this.password = password;
|
||||
this.chmPath = chmPath;
|
||||
this.mainChm = mainChm;
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
|
|
|
@ -1,88 +1,101 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Data;
|
||||
using System.Threading;
|
||||
|
||||
using TechBot.IRCLibrary;
|
||||
|
||||
namespace TechBot.Library
|
||||
{
|
||||
public abstract class TechBotService
|
||||
{
|
||||
protected IServiceOutput serviceOutput;
|
||||
private string chmPath;
|
||||
private string mainChm;
|
||||
|
||||
public TechBotService(IServiceOutput serviceOutput,
|
||||
string chmPath,
|
||||
string mainChm)
|
||||
{
|
||||
this.serviceOutput = serviceOutput;
|
||||
this.chmPath = chmPath;
|
||||
this.mainChm = mainChm;
|
||||
}
|
||||
|
||||
public virtual void Run()
|
||||
{
|
||||
CommandFactory.LoadPlugins();
|
||||
}
|
||||
|
||||
public IServiceOutput ServiceOutput
|
||||
{
|
||||
get { return serviceOutput; }
|
||||
}
|
||||
|
||||
public CommandBuilderCollection Commands
|
||||
{
|
||||
get { return CommandFactory.Commands; }
|
||||
}
|
||||
|
||||
public void InjectMessage(MessageContext context, string message)
|
||||
{
|
||||
ParseCommandMessage(context,
|
||||
message);
|
||||
}
|
||||
|
||||
private bool IsCommandMessage(string message)
|
||||
{
|
||||
return message.StartsWith("!");
|
||||
}
|
||||
|
||||
public void ParseCommandMessage(MessageContext context,
|
||||
string message)
|
||||
{
|
||||
if (!IsCommandMessage(message))
|
||||
return;
|
||||
|
||||
message = message.Substring(1).Trim();
|
||||
int index = message.IndexOf(' ');
|
||||
string commandName;
|
||||
string commandParams = "";
|
||||
if (index != -1)
|
||||
{
|
||||
commandName = message.Substring(0, index).Trim();
|
||||
commandParams = message.Substring(index).Trim();
|
||||
}
|
||||
else
|
||||
commandName = message.Trim();
|
||||
|
||||
foreach (CommandBuilder command in Commands)
|
||||
{
|
||||
if (command.Name == commandName)
|
||||
{
|
||||
//Create a new instance of the required command type
|
||||
Command cmd = command.CreateCommand();
|
||||
|
||||
cmd.TechBot = this;
|
||||
cmd.Context = context;
|
||||
cmd.ParseParameters(message);
|
||||
cmd.ExecuteCommand();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Data;
|
||||
using System.Threading;
|
||||
|
||||
using TechBot.IRCLibrary;
|
||||
|
||||
namespace TechBot.Library
|
||||
{
|
||||
public abstract class TechBotService
|
||||
{
|
||||
protected IServiceOutput m_ServiceOutput;
|
||||
|
||||
public TechBotService(IServiceOutput serviceOutput)
|
||||
{
|
||||
m_ServiceOutput = serviceOutput;
|
||||
}
|
||||
|
||||
public virtual void Run()
|
||||
{
|
||||
CommandFactory.LoadPlugins();
|
||||
}
|
||||
|
||||
public IServiceOutput ServiceOutput
|
||||
{
|
||||
get { return m_ServiceOutput; }
|
||||
}
|
||||
|
||||
public CommandBuilderCollection Commands
|
||||
{
|
||||
get { return CommandFactory.Commands; }
|
||||
}
|
||||
|
||||
public void InjectMessage(MessageContext context, string message)
|
||||
{
|
||||
ParseCommandMessage(context,
|
||||
message);
|
||||
}
|
||||
|
||||
private bool IsCommandMessage(string message)
|
||||
{
|
||||
return message.StartsWith(Settings.Default.CommandPrefix);
|
||||
}
|
||||
|
||||
public void InjectMessage(string message)
|
||||
{
|
||||
ParseCommandMessage(null, message);
|
||||
}
|
||||
|
||||
public void ParseCommandMessage(MessageContext context,
|
||||
string message)
|
||||
{
|
||||
if (!IsCommandMessage(message))
|
||||
return;
|
||||
|
||||
message = message.Substring(1).Trim();
|
||||
int index = message.IndexOf(' ');
|
||||
string commandName;
|
||||
string commandParams = "";
|
||||
if (index != -1)
|
||||
{
|
||||
commandName = message.Substring(0, index).Trim();
|
||||
commandParams = message.Substring(index).Trim();
|
||||
}
|
||||
else
|
||||
commandName = message.Trim();
|
||||
|
||||
foreach (CommandBuilder command in Commands)
|
||||
{
|
||||
if (command.Name == commandName)
|
||||
{
|
||||
//Create a new instance of the required command type
|
||||
Command cmd = command.CreateCommand();
|
||||
|
||||
cmd.TechBot = this;
|
||||
cmd.Context = context;
|
||||
cmd.Parameters = commandParams;
|
||||
|
||||
try
|
||||
{
|
||||
cmd.Initialize();
|
||||
cmd.ExecuteCommand();
|
||||
cmd.DeInitialize();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ServiceOutput.WriteLine(context, string.Format("Uops! Just crashed with exception '{0}' at {1}",
|
||||
e.Message,
|
||||
e.Source));
|
||||
|
||||
ServiceOutput.WriteLine(context, e.StackTrace);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
<setting name="SVNRoot" serializeAs="String">
|
||||
<value>svn://svn.reactos.org/trunk/reactos</value>
|
||||
</setting>
|
||||
<setting name="CommandPrefix" serializeAs="String">
|
||||
<value>@</value>
|
||||
</setting>
|
||||
</TechBot.Library.Settings>
|
||||
</applicationSettings>
|
||||
</configuration>
|
Loading…
Add table
Add a link
Reference in a new issue