Set the ConfigFlags value in registry if not present
[reactos.git] / irc / TechBot / TechBot.Library / TechBotService.cs
1 using System;
2 using System.Collections;
3 using System.IO;
4 using System.Data;
5 using System.Threading;
6 using TechBot.IRCLibrary;
7
8 namespace TechBot.Library
9 {
10 public class TechBotService
11 {
12 private IServiceOutput serviceOutput;
13 private string chmPath;
14 private string mainChm;
15 private string ntstatusXml;
16 private string winerrorXml;
17 private string hresultXml;
18 private string wmXml;
19 private string svnCommand;
20 private string bugUrl;
21 private ArrayList commands = new ArrayList();
22
23 public TechBotService(IServiceOutput serviceOutput,
24 string chmPath,
25 string mainChm,
26 string ntstatusXml,
27 string winerrorXml,
28 string hresultXml,
29 string wmXml,
30 string svnCommand,
31 string bugUrl)
32 {
33 this.serviceOutput = serviceOutput;
34 this.chmPath = chmPath;
35 this.mainChm = mainChm;
36 this.ntstatusXml = ntstatusXml;
37 this.winerrorXml = winerrorXml;
38 this.hresultXml = hresultXml;
39 this.wmXml = wmXml;
40 this.svnCommand = svnCommand;
41 this.bugUrl = bugUrl;
42 }
43
44 public void Run()
45 {
46 commands.Add(new HelpCommand(serviceOutput,
47 commands));
48 commands.Add(new ApiCommand(serviceOutput,
49 chmPath,
50 mainChm));
51 commands.Add(new NtStatusCommand(serviceOutput,
52 ntstatusXml));
53 commands.Add(new WinerrorCommand(serviceOutput,
54 winerrorXml));
55 commands.Add(new HresultCommand(serviceOutput,
56 hresultXml));
57 commands.Add(new WmCommand(serviceOutput,
58 wmXml));
59 commands.Add(new SvnCommand(serviceOutput,
60 svnCommand));
61 commands.Add(new BugCommand(serviceOutput,
62 bugUrl));
63 }
64
65 public void InjectMessage(MessageContext context,
66 string message)
67 {
68 if (message.StartsWith("!"))
69 ParseCommandMessage(context,
70 message);
71 }
72
73 private bool IsCommandMessage(string message)
74 {
75 return message.StartsWith("!");
76 }
77
78 public void ParseCommandMessage(MessageContext context,
79 string message)
80 {
81 if (!IsCommandMessage(message))
82 return;
83
84 message = message.Substring(1).Trim();
85 int index = message.IndexOf(' ');
86 string commandName;
87 string parameters = "";
88 if (index != -1)
89 {
90 commandName = message.Substring(0, index).Trim();
91 parameters = message.Substring(index).Trim();
92 }
93 else
94 commandName = message.Trim();
95
96 foreach (ICommand command in commands)
97 {
98 if (command.CanHandle(commandName))
99 {
100 command.Handle(context,
101 commandName, parameters);
102 return;
103 }
104 }
105 }
106 }
107 }