- Moved commands outside TechBot.Library to TechBot.Commands.Common and TechBot.Comma...
[reactos.git] / irc / TechBot / TechBot.Commands.Common / NtStatusCommand.cs
1 using System;
2 using System.Xml;
3
4 using TechBot.Library;
5
6 namespace TechBot.Commands.Common
7 {
8 [Command("ntstatus", Help = "!ntstatus <value>")]
9 public class NtStatusCommand : XmlLookupCommand
10 {
11 public NtStatusCommand()
12 {
13 }
14
15 public override string XmlFile
16 {
17 get { return Settings.Default.NtStatusXml; }
18 }
19
20 public override void ExecuteCommand()
21 {
22 if (Text == null)
23 {
24 Say("Please provide a valid NTSTATUS value.");
25 }
26 else
27 {
28 NumberParser np = new NumberParser();
29 long ntstatus = np.Parse(Text);
30 if (np.Error)
31 {
32 Say("{0} is not a valid NTSTATUS value.", Text);
33 return;
34 }
35
36 string description = GetNtstatusDescription(ntstatus);
37 if (description != null)
38 {
39 Say("{0} is {1}.",
40 Text,
41 description);
42 }
43 else
44 {
45 Say("I don't know about NTSTATUS {0}.", Text);
46 }
47 }
48 }
49
50 public string GetNtstatusDescription(long ntstatus)
51 {
52 XmlElement root = base.m_XmlDocument.DocumentElement;
53 XmlNode node = root.SelectSingleNode(String.Format("Ntstatus[@value='{0}']",
54 ntstatus.ToString("X8")));
55 if (node != null)
56 {
57 XmlAttribute text = node.Attributes["text"];
58 if (text == null)
59 throw new Exception("Node has no text attribute.");
60 return text.Value;
61 }
62 else
63 return null;
64 }
65 }
66 }