-using System;\r
-using System.Collections;\r
-using System.Collections.Generic;\r
-using System.IO;\r
-using System.Data;\r
-using System.Threading;\r
-\r
-using TechBot.IRCLibrary;\r
-\r
-namespace TechBot.Library\r
-{\r
- public abstract class TechBotService\r
- {\r
- protected IServiceOutput serviceOutput;\r
- private string chmPath;\r
- private string mainChm;\r
- \r
- public TechBotService(IServiceOutput serviceOutput,\r
- string chmPath,\r
- string mainChm)\r
- {\r
- this.serviceOutput = serviceOutput;\r
- this.chmPath = chmPath;\r
- this.mainChm = mainChm;\r
- }\r
-\r
- public virtual void Run()\r
- {\r
- CommandFactory.LoadPlugins();\r
- }\r
-\r
- public IServiceOutput ServiceOutput\r
- {\r
- get { return serviceOutput; }\r
- }\r
-\r
- public CommandBuilderCollection Commands\r
- {\r
- get { return CommandFactory.Commands; }\r
- }\r
-\r
- public void InjectMessage(MessageContext context, string message)\r
- {\r
- ParseCommandMessage(context,\r
- message);\r
- }\r
- \r
- private bool IsCommandMessage(string message)\r
- {\r
- return message.StartsWith("!");\r
- }\r
-\r
- public void ParseCommandMessage(MessageContext context,\r
- string message)\r
- {\r
- if (!IsCommandMessage(message))\r
- return;\r
-\r
- message = message.Substring(1).Trim();\r
- int index = message.IndexOf(' ');\r
- string commandName;\r
- string commandParams = "";\r
- if (index != -1)\r
- {\r
- commandName = message.Substring(0, index).Trim();\r
- commandParams = message.Substring(index).Trim();\r
- }\r
- else\r
- commandName = message.Trim();\r
-\r
- foreach (CommandBuilder command in Commands)\r
- {\r
- if (command.Name == commandName)\r
- {\r
- //Create a new instance of the required command type\r
- Command cmd = command.CreateCommand();\r
-\r
- cmd.TechBot = this;\r
- cmd.Context = context;\r
- cmd.ParseParameters(message);\r
- cmd.ExecuteCommand();\r
-\r
- return;\r
- }\r
- }\r
- }\r
- }\r
-}\r
+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.Run();
+ 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;
+ }
+ }
+ }
+ }
+}