-revert janderwalds change until because it breaks the gcc 4.x build
[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, WineBugUrl, SambaBugUrl;
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 string WineBugUrl,
33 string SambaBugUrl)
34 {
35 this.serviceOutput = serviceOutput;
36 this.chmPath = chmPath;
37 this.mainChm = mainChm;
38 this.ntstatusXml = ntstatusXml;
39 this.winerrorXml = winerrorXml;
40 this.hresultXml = hresultXml;
41 this.wmXml = wmXml;
42 this.svnCommand = svnCommand;
43 this.bugUrl = bugUrl;
44 this.WineBugUrl = WineBugUrl;
45 this.SambaBugUrl = SambaBugUrl;
46 }
47
48 public void Run()
49 {
50 commands.Add(new HelpCommand(serviceOutput,
51 commands));
52 /*commands.Add(new ApiCommand(serviceOutput,
53 chmPath,
54 mainChm));*/
55 commands.Add(new NtStatusCommand(serviceOutput,
56 ntstatusXml));
57 commands.Add(new WinerrorCommand(serviceOutput,
58 winerrorXml));
59 commands.Add(new HresultCommand(serviceOutput,
60 hresultXml));
61 commands.Add(new ErrorCommand(serviceOutput,
62 ntstatusXml,
63 winerrorXml,
64 hresultXml));
65 commands.Add(new WmCommand(serviceOutput,
66 wmXml));
67 commands.Add(new SvnCommand(serviceOutput,
68 svnCommand));
69 commands.Add(new BugCommand(serviceOutput,
70 bugUrl,
71 WineBugUrl,
72 SambaBugUrl));
73 }
74
75 public void InjectMessage(MessageContext context,
76 string message)
77 {
78 if (message.StartsWith("!"))
79 ParseCommandMessage(context,
80 message);
81 }
82
83 private bool IsCommandMessage(string message)
84 {
85 return message.StartsWith("!");
86 }
87
88 public void ParseCommandMessage(MessageContext context,
89 string message)
90 {
91 if (!IsCommandMessage(message))
92 return;
93
94 message = message.Substring(1).Trim();
95 int index = message.IndexOf(' ');
96 string commandName;
97 string parameters = "";
98 if (index != -1)
99 {
100 commandName = message.Substring(0, index).Trim();
101 parameters = message.Substring(index).Trim();
102 }
103 else
104 commandName = message.Trim();
105
106 foreach (ICommand command in commands)
107 {
108 if (command.CanHandle(commandName))
109 {
110 command.Handle(context,
111 commandName, parameters);
112 return;
113 }
114 }
115 }
116 }
117 }