2 using System.Collections;
3 using System.Collections.Generic;
6 using System.Threading;
8 using TechBot.IRCLibrary;
10 namespace TechBot.Library
12 public abstract class TechBotService
14 protected IServiceOutput m_ServiceOutput;
16 public TechBotService(IServiceOutput serviceOutput)
18 m_ServiceOutput = serviceOutput;
21 public virtual void Run()
23 CommandFactory.LoadPlugins();
26 public IServiceOutput ServiceOutput
28 get { return m_ServiceOutput; }
31 public CommandBuilderCollection Commands
33 get { return CommandFactory.Commands; }
36 public void InjectMessage(MessageContext context, string message)
38 ParseCommandMessage(context,
42 private bool IsCommandMessage(string message)
44 return message.StartsWith(Settings.Default.CommandPrefix);
47 public void InjectMessage(string message)
49 ParseCommandMessage(null, message);
52 public void ParseCommandMessage(MessageContext context,
55 if (!IsCommandMessage(message))
58 message = message.Substring(1).Trim();
59 int index = message.IndexOf(' ');
61 string commandParams = "";
64 commandName = message.Substring(0, index).Trim();
65 commandParams = message.Substring(index).Trim();
68 commandName = message.Trim();
70 foreach (CommandBuilder command in Commands)
72 if (command.Name == commandName)
74 //Create a new instance of the required command type
75 Command cmd = command.CreateCommand();
78 cmd.Context = context;
79 cmd.Parameters = commandParams;
89 ServiceOutput.WriteLine(context, string.Format("Uops! Just crashed with exception '{0}' at {1}",
93 ServiceOutput.WriteLine(context, e.StackTrace);