mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 16:35:49 +00:00
- Add support for "!wm <value>" and "!wm <name>" commands.
- Update the #develop project file. - Add list of window message values. Thanks to Royce3. svn path=/trunk/; revision=20164
This commit is contained in:
parent
fe84901940
commit
bd0b0b3d09
9 changed files with 467 additions and 12 deletions
|
@ -16,6 +16,7 @@ namespace TechBot.Library
|
|||
private string ntstatusXml;
|
||||
private string winerrorXml;
|
||||
private string hresultXml;
|
||||
private string wmXml;
|
||||
private string svnCommand;
|
||||
private IrcClient client;
|
||||
private ArrayList channels = new ArrayList(); /* IrcChannel */
|
||||
|
@ -31,18 +32,20 @@ namespace TechBot.Library
|
|||
string ntstatusXml,
|
||||
string winerrorXml,
|
||||
string hresultXml,
|
||||
string wmXml,
|
||||
string svnCommand)
|
||||
{
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.channelnames = channelnames;
|
||||
this.botname = botname;
|
||||
this.chmPath = chmPath;
|
||||
this.mainChm = mainChm;
|
||||
this.ntstatusXml = ntstatusXml;
|
||||
this.winerrorXml = winerrorXml;
|
||||
this.hresultXml = hresultXml;
|
||||
this.svnCommand = svnCommand;
|
||||
this.botname = botname;
|
||||
this.chmPath = chmPath;
|
||||
this.mainChm = mainChm;
|
||||
this.ntstatusXml = ntstatusXml;
|
||||
this.winerrorXml = winerrorXml;
|
||||
this.hresultXml = hresultXml;
|
||||
this.wmXml = wmXml;
|
||||
this.svnCommand = svnCommand;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
|
@ -53,6 +56,7 @@ namespace TechBot.Library
|
|||
ntstatusXml,
|
||||
winerrorXml,
|
||||
hresultXml,
|
||||
wmXml,
|
||||
svnCommand);
|
||||
service.Run();
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
<File name=".\HresultCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
||||
<File name=".\WinerrorCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
||||
<File name=".\SvnCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
||||
<File name=".\WmCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
||||
<File name=".\MessageContext.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
||||
</Contents>
|
||||
<References>
|
||||
<Reference type="Project" refto="CHMLibrary" localcopy="True" />
|
||||
|
|
|
@ -15,16 +15,18 @@ namespace TechBot.Library
|
|||
private string ntstatusXml;
|
||||
private string winerrorXml;
|
||||
private string hresultXml;
|
||||
private string wmXml;
|
||||
private string svnCommand;
|
||||
private ArrayList commands = new ArrayList();
|
||||
|
||||
public TechBotService(IServiceOutput serviceOutput,
|
||||
string chmPath,
|
||||
string mainChm,
|
||||
string ntstatusXml,
|
||||
string winerrorXml,
|
||||
string hresultXml,
|
||||
string svnCommand)
|
||||
string mainChm,
|
||||
string ntstatusXml,
|
||||
string winerrorXml,
|
||||
string hresultXml,
|
||||
string wmXml,
|
||||
string svnCommand)
|
||||
{
|
||||
this.serviceOutput = serviceOutput;
|
||||
this.chmPath = chmPath;
|
||||
|
@ -32,6 +34,7 @@ namespace TechBot.Library
|
|||
this.ntstatusXml = ntstatusXml;
|
||||
this.winerrorXml = winerrorXml;
|
||||
this.hresultXml = hresultXml;
|
||||
this.wmXml = wmXml;
|
||||
this.svnCommand = svnCommand;
|
||||
}
|
||||
|
||||
|
@ -48,6 +51,8 @@ namespace TechBot.Library
|
|||
winerrorXml));
|
||||
commands.Add(new HresultCommand(serviceOutput,
|
||||
hresultXml));
|
||||
commands.Add(new WmCommand(serviceOutput,
|
||||
wmXml));
|
||||
commands.Add(new SvnCommand(serviceOutput,
|
||||
svnCommand));
|
||||
}
|
||||
|
|
104
irc/TechBot/TechBot.Library/WmCommand.cs
Normal file
104
irc/TechBot/TechBot.Library/WmCommand.cs
Normal file
|
@ -0,0 +1,104 @@
|
|||
using System;
|
||||
using System.Xml;
|
||||
|
||||
namespace TechBot.Library
|
||||
{
|
||||
public class WmCommand : BaseCommand, ICommand
|
||||
{
|
||||
private IServiceOutput serviceOutput;
|
||||
private string wmXml;
|
||||
private XmlDocument wmXmlDocument;
|
||||
|
||||
public WmCommand(IServiceOutput serviceOutput,
|
||||
string wmXml)
|
||||
{
|
||||
this.serviceOutput = serviceOutput;
|
||||
this.wmXml = wmXml;
|
||||
wmXmlDocument = new XmlDocument();
|
||||
wmXmlDocument.Load(wmXml);
|
||||
}
|
||||
|
||||
public bool CanHandle(string commandName)
|
||||
{
|
||||
return CanHandle(commandName,
|
||||
new string[] { "wm" });
|
||||
}
|
||||
|
||||
public void Handle(MessageContext context,
|
||||
string commandName,
|
||||
string parameters)
|
||||
{
|
||||
string wmText = parameters;
|
||||
if (wmText.Equals(String.Empty))
|
||||
{
|
||||
serviceOutput.WriteLine(context,
|
||||
"Please provide a valid window message value or name.");
|
||||
return;
|
||||
}
|
||||
|
||||
NumberParser np = new NumberParser();
|
||||
long wm = np.Parse(wmText);
|
||||
string output;
|
||||
if (np.Error)
|
||||
{
|
||||
// Assume "!wm <name>" form.
|
||||
output = GetWmNumber(wmText);
|
||||
}
|
||||
else
|
||||
{
|
||||
output = GetWmDescription(wm);
|
||||
}
|
||||
|
||||
if (output != null)
|
||||
{
|
||||
serviceOutput.WriteLine(context,
|
||||
String.Format("{0} is {1}.",
|
||||
wmText,
|
||||
output));
|
||||
}
|
||||
else
|
||||
{
|
||||
serviceOutput.WriteLine(context,
|
||||
String.Format("I don't know about window message {0}.",
|
||||
wmText));
|
||||
}
|
||||
}
|
||||
|
||||
public string Help()
|
||||
{
|
||||
return "!wm <value> or !wm <name>";
|
||||
}
|
||||
|
||||
private string GetWmDescription(long wm)
|
||||
{
|
||||
XmlElement root = wmXmlDocument.DocumentElement;
|
||||
XmlNode node = root.SelectSingleNode(String.Format("WindowMessage[@value='{0}']",
|
||||
wm));
|
||||
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;
|
||||
}
|
||||
|
||||
private string GetWmNumber(string wmName)
|
||||
{
|
||||
XmlElement root = wmXmlDocument.DocumentElement;
|
||||
XmlNode node = root.SelectSingleNode(String.Format("WindowMessage[@text='{0}']",
|
||||
wmName));
|
||||
if (node != null)
|
||||
{
|
||||
XmlAttribute value = node.Attributes["value"];
|
||||
if (value == null)
|
||||
throw new Exception("Node has no value attribute.");
|
||||
return value.Value;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue