mirror of
https://github.com/reactos/reactos.git
synced 2025-06-12 20:08:29 +00:00
- Moved commands outside TechBot.Library to TechBot.Commands.Common and TechBot.Commands.MSDN except for Command base classes
- Made TechBot more configurable through .config files - Code refactoring - Removed automatic parameter parsing support to make everyone happy svn path=/trunk/; revision=33586
This commit is contained in:
parent
6d51a10a1b
commit
ac77d9d3a6
47 changed files with 1783 additions and 489 deletions
66
irc/TechBot/TechBot.Commands.Common/HResultCommand.cs
Normal file
66
irc/TechBot/TechBot.Commands.Common/HResultCommand.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using System.Xml;
|
||||
|
||||
using TechBot.Library;
|
||||
|
||||
namespace TechBot.Commands.Common
|
||||
{
|
||||
[Command("hresult", Help = "!hresult <value>")]
|
||||
public class HResultCommand : XmlLookupCommand
|
||||
{
|
||||
public HResultCommand()
|
||||
{
|
||||
}
|
||||
|
||||
public override string XmlFile
|
||||
{
|
||||
get { return Settings.Default.HResultXml; }
|
||||
}
|
||||
|
||||
public override void ExecuteCommand()
|
||||
{
|
||||
if (Text == null)
|
||||
{
|
||||
Say("Please provide a valid HRESULT value.");
|
||||
}
|
||||
else
|
||||
{
|
||||
NumberParser np = new NumberParser();
|
||||
long hresult = np.Parse(Text);
|
||||
if (np.Error)
|
||||
{
|
||||
Say("{0} is not a valid HRESULT value.", Text);
|
||||
return;
|
||||
}
|
||||
|
||||
string description = GetHresultDescription(hresult);
|
||||
if (description != null)
|
||||
{
|
||||
Say("{0} is {1}.",
|
||||
Text,
|
||||
description);
|
||||
}
|
||||
else
|
||||
{
|
||||
Say("I don't know about HRESULT {0}.", Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetHresultDescription(long hresult)
|
||||
{
|
||||
XmlElement root = base.m_XmlDocument.DocumentElement;
|
||||
XmlNode node = root.SelectSingleNode(String.Format("Hresult[@value='{0}']",
|
||||
hresult.ToString("X8")));
|
||||
if (node != null)
|
||||
{
|
||||
XmlAttribute text = node.Attributes["text"];
|
||||
if (text == null)
|
||||
throw new Exception("Node has no text attribute.");
|
||||
return text.Value;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue