altered several year numbers from "2005" to "2006"
[reactos.git] / irc / TechBot / TechBot.Library / BugCommand.cs
1 using System;
2
3 namespace TechBot.Library
4 {
5 public class BugCommand : BaseCommand, ICommand
6 {
7 private IServiceOutput serviceOutput;
8 private string RosBugUrl;
9 private string WineBugUrl;
10 private string SambaBugUrl;
11
12 public BugCommand(IServiceOutput serviceOutput,
13 string RosBugUrl,
14 string WineBugUrl,
15 string SambaBugUrl)
16 {
17 this.serviceOutput = serviceOutput;
18 this.RosBugUrl = RosBugUrl;
19 this.WineBugUrl = WineBugUrl;
20 this.SambaBugUrl = SambaBugUrl;
21 }
22
23 public bool CanHandle(string commandName)
24 {
25 return CanHandle(commandName,
26 new string[] { "bug" });
27 }
28
29 public void Handle(MessageContext context,
30 string commandName,
31 string parameters)
32 {
33 string bugText = parameters;
34 if (bugText.Equals(String.Empty))
35 {
36 serviceOutput.WriteLine(context,
37 "Please provide a valid bug number.");
38 return;
39 }
40
41 NumberParser np = new NumberParser();
42 long bug = np.Parse(bugText);
43 if (np.Error)
44 {
45 serviceOutput.WriteLine(context,
46 String.Format("{0} is not a valid bug number.",
47 bugText));
48 return;
49 }
50
51 string bugUrl = this.RosBugUrl;
52
53 if (context is ChannelMessageContext)
54 {
55 ChannelMessageContext channelContext = context as ChannelMessageContext;
56 if (channelContext.Channel.Name == "winehackers")
57 bugUrl = this.WineBugUrl;
58 else if (channelContext.Channel.Name == "samba-technical")
59 bugUrl = this.SambaBugUrl;
60 }
61
62 serviceOutput.WriteLine(context,
63 String.Format(bugUrl, bug));
64 }
65
66 public string Help()
67 {
68 return "!bug <number>";
69 }
70 }
71 }