From 27f6a74ba6cc3c17dd9781a43453ea4d2cf6d6c2 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Wed, 14 Dec 2005 18:13:05 +0000 Subject: [PATCH] Implement "!bug " command. svn path=/trunk/; revision=20165 --- irc/TechBot/TechBot.Console/App.config | 1 + irc/TechBot/TechBot.Console/Main.cs | 18 ++++++- irc/TechBot/TechBot.Library/BugCommand.cs | 54 +++++++++++++++++++ irc/TechBot/TechBot.Library/IrcService.cs | 8 ++- .../TechBot.Library/TechBot.Library.prjx | 1 + irc/TechBot/TechBot.Library/TechBotService.cs | 7 ++- irc/TechBot/TechBot/App.config | 1 + irc/TechBot/TechBot/ServiceThread.cs | 5 +- 8 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 irc/TechBot/TechBot.Library/BugCommand.cs diff --git a/irc/TechBot/TechBot.Console/App.config b/irc/TechBot/TechBot.Console/App.config index 03b57ba4892..28d804b75d6 100644 --- a/irc/TechBot/TechBot.Console/App.config +++ b/irc/TechBot/TechBot.Console/App.config @@ -12,5 +12,6 @@ + diff --git a/irc/TechBot/TechBot.Console/Main.cs b/irc/TechBot/TechBot.Console/Main.cs index d6e60452401..7c41f5d073d 100644 --- a/irc/TechBot/TechBot.Console/Main.cs +++ b/irc/TechBot/TechBot.Console/Main.cs @@ -158,6 +158,18 @@ namespace TechBot.Console } } + private static string BugUrl + { + get + { + string optionName = "BugUrl"; + string s = ConfigurationSettings.AppSettings[optionName]; + VerifyRequiredOption(optionName, + s); + return s; + } + } + private static void RunIrcService() { IrcService ircService = new IrcService(IRCServerHostName, @@ -170,7 +182,8 @@ namespace TechBot.Console WinerrorXml, HresultXml, WmXml, - SvnCommand); + SvnCommand, + BugUrl); ircService.Run(); } @@ -190,7 +203,8 @@ namespace TechBot.Console WinerrorXml, HresultXml, WmXml, - SvnCommand); + SvnCommand, + BugUrl); service.Run(); while (true) { diff --git a/irc/TechBot/TechBot.Library/BugCommand.cs b/irc/TechBot/TechBot.Library/BugCommand.cs new file mode 100644 index 00000000000..955abe78e39 --- /dev/null +++ b/irc/TechBot/TechBot.Library/BugCommand.cs @@ -0,0 +1,54 @@ +using System; + +namespace TechBot.Library +{ + public class BugCommand : BaseCommand, ICommand + { + private IServiceOutput serviceOutput; + private string bugUrl; + + public BugCommand(IServiceOutput serviceOutput, + string bugUrl) + { + this.serviceOutput = serviceOutput; + this.bugUrl = bugUrl; + } + + public bool CanHandle(string commandName) + { + return CanHandle(commandName, + new string[] { "bug" }); + } + + public void Handle(MessageContext context, + string commandName, + string parameters) + { + string bugText = parameters; + if (bugText.Equals(String.Empty)) + { + serviceOutput.WriteLine(context, + "Please provide a valid bug number."); + return; + } + + NumberParser np = new NumberParser(); + long bug = np.Parse(bugText); + if (np.Error) + { + serviceOutput.WriteLine(context, + String.Format("{0} is not a valid bug number.", + bugText)); + return; + } + + serviceOutput.WriteLine(context, + String.Format(bugUrl, bug)); + } + + public string Help() + { + return "!bug "; + } + } +} diff --git a/irc/TechBot/TechBot.Library/IrcService.cs b/irc/TechBot/TechBot.Library/IrcService.cs index 587bd9ba959..a771f418de6 100644 --- a/irc/TechBot/TechBot.Library/IrcService.cs +++ b/irc/TechBot/TechBot.Library/IrcService.cs @@ -18,6 +18,7 @@ namespace TechBot.Library private string hresultXml; private string wmXml; private string svnCommand; + private string bugUrl; private IrcClient client; private ArrayList channels = new ArrayList(); /* IrcChannel */ private TechBotService service; @@ -33,7 +34,8 @@ namespace TechBot.Library string winerrorXml, string hresultXml, string wmXml, - string svnCommand) + string svnCommand, + string bugUrl) { this.hostname = hostname; this.port = port; @@ -46,6 +48,7 @@ namespace TechBot.Library this.hresultXml = hresultXml; this.wmXml = wmXml; this.svnCommand = svnCommand; + this.bugUrl = bugUrl; } public void Run() @@ -57,7 +60,8 @@ namespace TechBot.Library winerrorXml, hresultXml, wmXml, - svnCommand); + svnCommand, + bugUrl); service.Run(); client = new IrcClient(); diff --git a/irc/TechBot/TechBot.Library/TechBot.Library.prjx b/irc/TechBot/TechBot.Library/TechBot.Library.prjx index cce5c674a77..b2d45aca957 100644 --- a/irc/TechBot/TechBot.Library/TechBot.Library.prjx +++ b/irc/TechBot/TechBot.Library/TechBot.Library.prjx @@ -13,6 +13,7 @@ + diff --git a/irc/TechBot/TechBot.Library/TechBotService.cs b/irc/TechBot/TechBot.Library/TechBotService.cs index 1236998d343..e169fc82482 100644 --- a/irc/TechBot/TechBot.Library/TechBotService.cs +++ b/irc/TechBot/TechBot.Library/TechBotService.cs @@ -17,6 +17,7 @@ namespace TechBot.Library private string hresultXml; private string wmXml; private string svnCommand; + private string bugUrl; private ArrayList commands = new ArrayList(); public TechBotService(IServiceOutput serviceOutput, @@ -26,7 +27,8 @@ namespace TechBot.Library string winerrorXml, string hresultXml, string wmXml, - string svnCommand) + string svnCommand, + string bugUrl) { this.serviceOutput = serviceOutput; this.chmPath = chmPath; @@ -36,6 +38,7 @@ namespace TechBot.Library this.hresultXml = hresultXml; this.wmXml = wmXml; this.svnCommand = svnCommand; + this.bugUrl = bugUrl; } public void Run() @@ -55,6 +58,8 @@ namespace TechBot.Library wmXml)); commands.Add(new SvnCommand(serviceOutput, svnCommand)); + commands.Add(new BugCommand(serviceOutput, + bugUrl)); } public void InjectMessage(MessageContext context, diff --git a/irc/TechBot/TechBot/App.config b/irc/TechBot/TechBot/App.config index 03b57ba4892..28d804b75d6 100644 --- a/irc/TechBot/TechBot/App.config +++ b/irc/TechBot/TechBot/App.config @@ -12,5 +12,6 @@ + diff --git a/irc/TechBot/TechBot/ServiceThread.cs b/irc/TechBot/TechBot/ServiceThread.cs index 5a612194dc9..0c9547878ba 100644 --- a/irc/TechBot/TechBot/ServiceThread.cs +++ b/irc/TechBot/TechBot/ServiceThread.cs @@ -18,6 +18,7 @@ namespace TechBot private string WmXml; private string WinerrorXml; private string SvnCommand; + private string BugUrl; private EventLog eventLog; public ServiceThread(EventLog eventLog) @@ -38,6 +39,7 @@ namespace TechBot WmXml = ConfigurationSettings.AppSettings["WmXml"]; WinerrorXml = ConfigurationSettings.AppSettings["WinerrorXml"]; SvnCommand = ConfigurationSettings.AppSettings["SvnCommand"]; + BugUrl = ConfigurationSettings.AppSettings["BugUrl"]; } public void Run() @@ -55,7 +57,8 @@ namespace TechBot WinerrorXml, HresultXml, WmXml, - SvnCommand); + SvnCommand, + BugUrl); ircService.Run(); } -- 2.17.1