d40ab91e2c7e02ff0ff4b076706b968ef2c2caba
[reactos.git] / irc / TechBot / TechBot.Library / TechBotService.cs
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.IO;
5 using System.Data;
6 using System.Threading;
7 using TechBot.IRCLibrary;
8
9 namespace TechBot.Library
10 {
11 public class TechBotService
12 {
13 private IServiceOutput serviceOutput;
14 private string chmPath;
15 private string mainChm;
16 private string ntstatusXml;
17 private string winerrorXml;
18 private string hresultXml;
19 private string wmXml;
20 private string svnCommand;
21 private string bugUrl, WineBugUrl, SambaBugUrl;
22 private List<Command> commands = new List<Command>();
23
24 public TechBotService(IServiceOutput serviceOutput,
25 string chmPath,
26 string mainChm)
27 //string ntstatusXml,
28 //string winerrorXml,
29 //string hresultXml,
30 //string wmXml,
31 //string svnCommand,
32 //string bugUrl,
33 //string WineBugUrl,
34 //string SambaBugUrl)
35 {
36 this.serviceOutput = serviceOutput;
37 this.chmPath = chmPath;
38 this.mainChm = mainChm;
39 this.ntstatusXml = ntstatusXml;
40 this.winerrorXml = winerrorXml;
41 this.hresultXml = hresultXml;
42 this.wmXml = wmXml;
43 this.svnCommand = svnCommand;
44 this.bugUrl = bugUrl;
45 this.WineBugUrl = WineBugUrl;
46 this.SambaBugUrl = SambaBugUrl;
47 }
48
49 public void Run()
50 {
51 commands.Add(new HelpCommand(this));
52 /*commands.Add(new ApiCommand(serviceOutput,
53 chmPath,
54 mainChm));*/
55 commands.Add(new NtStatusCommand(this));
56 commands.Add(new WinerrorCommand(this));
57 commands.Add(new HResultCommand(this));
58 commands.Add(new ErrorCommand(this));
59 commands.Add(new WMCommand(this));
60 commands.Add(new SvnCommand(this));
61 commands.Add(new ReactOSBugUrl(this));
62 commands.Add(new SambaBugUrl(this));
63 commands.Add(new WineBugUrl(this));
64 }
65
66 public IServiceOutput ServiceOutput
67 {
68 get { return serviceOutput; }
69 }
70
71 public IList<Command> Commands
72 {
73 get { return commands; }
74 }
75
76 public void InjectMessage(MessageContext context,
77 string message)
78 {
79 if (message.StartsWith("!"))
80 ParseCommandMessage(context,
81 message);
82 }
83
84 private bool IsCommandMessage(string message)
85 {
86 return message.StartsWith("!");
87 }
88
89 public void ParseCommandMessage(MessageContext context,
90 string message)
91 {
92 if (!IsCommandMessage(message))
93 return;
94
95 message = message.Substring(1).Trim();
96 int index = message.IndexOf(' ');
97 string commandName;
98 string commandParams = "";
99 if (index != -1)
100 {
101 commandName = message.Substring(0, index).Trim();
102 commandParams = message.Substring(index).Trim();
103 }
104 else
105 commandName = message.Trim();
106
107 foreach (Command command in commands)
108 {
109 foreach (string cmd in command.AvailableCommands)
110 {
111 if (cmd == commandName)
112 {
113 command.Handle(context,
114 commandName,
115 commandParams);
116 return;
117 }
118 }
119 }
120 }
121 }
122 }