2005-01-15 19:27:25 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
2007-12-10 19:08:13 +00:00
|
|
|
using System.Collections.Generic;
|
2005-01-15 19:27:25 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Data;
|
|
|
|
using System.Threading;
|
2008-05-07 14:59:28 +00:00
|
|
|
|
2005-01-15 19:27:25 +00:00
|
|
|
using TechBot.IRCLibrary;
|
|
|
|
|
|
|
|
namespace TechBot.Library
|
|
|
|
{
|
2008-05-07 14:59:28 +00:00
|
|
|
public abstract class TechBotService
|
2005-01-15 19:27:25 +00:00
|
|
|
{
|
2008-05-07 14:59:28 +00:00
|
|
|
protected IServiceOutput serviceOutput;
|
2005-01-15 19:27:25 +00:00
|
|
|
private string chmPath;
|
|
|
|
private string mainChm;
|
|
|
|
|
|
|
|
public TechBotService(IServiceOutput serviceOutput,
|
|
|
|
string chmPath,
|
2007-12-10 19:08:13 +00:00
|
|
|
string mainChm)
|
2005-01-15 19:27:25 +00:00
|
|
|
{
|
|
|
|
this.serviceOutput = serviceOutput;
|
|
|
|
this.chmPath = chmPath;
|
|
|
|
this.mainChm = mainChm;
|
|
|
|
}
|
2007-12-10 19:08:13 +00:00
|
|
|
|
2008-05-07 14:59:28 +00:00
|
|
|
public virtual void Run()
|
2007-12-10 19:08:13 +00:00
|
|
|
{
|
2008-05-07 14:59:28 +00:00
|
|
|
CommandFactory.LoadPlugins();
|
2007-12-10 19:08:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public IServiceOutput ServiceOutput
|
|
|
|
{
|
|
|
|
get { return serviceOutput; }
|
|
|
|
}
|
|
|
|
|
2008-05-07 14:59:28 +00:00
|
|
|
public CommandBuilderCollection Commands
|
2007-12-10 19:08:13 +00:00
|
|
|
{
|
2008-05-07 14:59:28 +00:00
|
|
|
get { return CommandFactory.Commands; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public void InjectMessage(MessageContext context, string message)
|
|
|
|
{
|
|
|
|
ParseCommandMessage(context,
|
|
|
|
message);
|
2007-12-10 19:08:13 +00:00
|
|
|
}
|
2005-01-15 19:27:25 +00:00
|
|
|
|
|
|
|
private bool IsCommandMessage(string message)
|
|
|
|
{
|
|
|
|
return message.StartsWith("!");
|
|
|
|
}
|
|
|
|
|
2005-02-16 21:07:55 +00:00
|
|
|
public void ParseCommandMessage(MessageContext context,
|
|
|
|
string message)
|
2005-01-15 19:27:25 +00:00
|
|
|
{
|
|
|
|
if (!IsCommandMessage(message))
|
|
|
|
return;
|
|
|
|
|
|
|
|
message = message.Substring(1).Trim();
|
|
|
|
int index = message.IndexOf(' ');
|
|
|
|
string commandName;
|
2007-12-10 19:08:13 +00:00
|
|
|
string commandParams = "";
|
2005-01-15 19:27:25 +00:00
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
commandName = message.Substring(0, index).Trim();
|
2007-12-10 19:08:13 +00:00
|
|
|
commandParams = message.Substring(index).Trim();
|
2005-01-15 19:27:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
commandName = message.Trim();
|
|
|
|
|
2008-05-07 14:59:28 +00:00
|
|
|
foreach (CommandBuilder command in Commands)
|
|
|
|
{
|
|
|
|
if (command.Name == commandName)
|
2007-12-10 19:08:13 +00:00
|
|
|
{
|
2008-05-07 14:59:28 +00:00
|
|
|
//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;
|
2007-12-10 19:08:13 +00:00
|
|
|
}
|
2008-05-07 14:59:28 +00:00
|
|
|
}
|
2005-01-15 19:27:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|