* refactor the code to make it more OOP and extensible
[reactos.git] / irc / TechBot / TechBot.Library / ApiCommand.cs
index b6aab95..c0f3cc1 100644 (file)
@@ -7,22 +7,17 @@ using HtmlHelp.ChmDecoding;
 \r
 namespace TechBot.Library\r
 {\r
-       public class ApiCommand : BaseCommand, ICommand\r
+       public class ApiCommand : Command\r
        {\r
                private const bool IsVerbose = false;\r
 \r
                private HtmlHelpSystem chm;\r
-               private IServiceOutput serviceOutput;\r
                private string chmPath;\r
                private string mainChm;\r
-               \r
-               public ApiCommand(IServiceOutput serviceOutput,\r
-                                 string chmPath,\r
-                                 string mainChm)\r
+\r
+        public ApiCommand(TechBotService techBot)\r
+            : base(techBot)\r
                {\r
-                       this.serviceOutput = serviceOutput;\r
-                       this.chmPath = chmPath;\r
-                       this.mainChm = mainChm;\r
                        Run();\r
                }\r
                \r
@@ -30,7 +25,7 @@ namespace TechBot.Library
                                            string message)\r
                {\r
                        if (IsVerbose)\r
-                               serviceOutput.WriteLine(context,\r
+                TechBot.ServiceOutput.WriteLine(context,\r
                                                        message);\r
                }\r
 \r
@@ -65,14 +60,21 @@ namespace TechBot.Library
                        Console.WriteLine(String.Format("Loaded {0} CHMs",\r
                                                        chm.FileList.Length));\r
                }\r
-               \r
+\r
+        public override string[] AvailableCommands\r
+        {\r
+            get { return new string[] { "api" }; }\r
+        }\r
+\r
+        /*\r
                public bool CanHandle(string commandName)\r
                {\r
                        return CanHandle(commandName,\r
                                         new string[] { "api" });\r
                }\r
+*/\r
                \r
-               public void Handle(MessageContext context,\r
+               public override void Handle(MessageContext context,\r
                                   string commandName,\r
                                   string parameters)\r
                {\r
@@ -82,8 +84,8 @@ namespace TechBot.Library
                                Search(context,\r
                                       parameters);\r
                }\r
-               \r
-               public string Help()\r
+\r
+        public override string Help()\r
                {\r
                        return "!api <apiname>";\r
                }\r
@@ -177,7 +179,7 @@ namespace TechBot.Library
                        if (prototype == null || prototype.Trim().Equals(String.Empty))\r
                                return false;\r
                        string formattedPrototype = FormatPrototype(prototype);\r
-                       serviceOutput.WriteLine(context,\r
+            TechBot.ServiceOutput.WriteLine(context,\r
                                                formattedPrototype);\r
                        return true;\r
                }\r
@@ -203,7 +205,7 @@ namespace TechBot.Library
                                        if (prototype == null || prototype.Trim().Equals(String.Empty))\r
                                                continue;\r
                                        string formattedPrototype = FormatPrototype(prototype);\r
-                                       serviceOutput.WriteLine(context,\r
+                    TechBot.ServiceOutput.WriteLine(context,\r
                                                                formattedPrototype);\r
                                        return true;\r
                                }\r
@@ -214,14 +216,14 @@ namespace TechBot.Library
                private void DisplayNoResult(MessageContext context,\r
                                             string keyword)\r
                {\r
-                       serviceOutput.WriteLine(context,\r
+            TechBot.ServiceOutput.WriteLine(context,\r
                                                String.Format("I don't know about keyword {0}",\r
                                                              keyword));\r
                }\r
 \r
                private void DisplayNoKeyword(MessageContext context)\r
                {\r
-                       serviceOutput.WriteLine(context,\r
+            TechBot.ServiceOutput.WriteLine(context,\r
                                                "Please give me a keyword.");\r
                }\r
 \r