Exemple #1
0
        /// <summary>
        /// Loads the karma bot config from the given xml file.
        /// </summary>
        /// <param name="xmlFilePath">The file name to load.</param>
        /// <returns>A karma bot config object from the given xml file.</returns>
        public static KarmaBotConfig LoadKarmaBotConfig(string xmlFilePath)
        {
            if (File.Exists(xmlFilePath) == false)
            {
                throw new FileNotFoundException("Could not find karma bot plugin config file " + xmlFilePath);
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(xmlFilePath);

            XmlElement rootNode = doc.DocumentElement;

            if (rootNode.Name != karmaBotConfigRootNode)
            {
                throw new XmlException(
                          "Root XML node should be named \"" + karmaBotConfigRootNode + "\".  Got: " + rootNode.Name
                          );
            }

            KarmaBotConfig config = new KarmaBotConfig();

            foreach (XmlNode childNode in rootNode.ChildNodes)
            {
                switch (childNode.Name)
                {
                case "increasecmd":
                    config.IncreaseCommandRegex = childNode.InnerText;
                    break;

                case "decreasecmd":
                    config.DecreaseCommandRegex = childNode.InnerText;
                    break;

                case "querycmd":
                    config.QueryCommand = childNode.InnerText;
                    break;
                }
            }
            config.Validate();
            return(config);
        }
Exemple #2
0
        // -------- Functions --------

        /// <summary>
        /// Inits this plugin.
        /// </summary>
        /// <param name="pluginPath">Path to the plugin DLL</param>
        /// <param name="ircConfig">The IRC config being used.</param>
        public void Init(string pluginPath, IIrcConfig ircConfig)
        {
            string dbPath = Path.Combine(
                Path.GetDirectoryName(pluginPath),
                "karmabot.db"
                );

            string configPath = Path.Combine(
                Path.GetDirectoryName(pluginPath),
                "KarmaBotConfig.xml"
                );

            if (File.Exists(configPath) == false)
            {
                throw new FileNotFoundException(
                          "Can not open " + configPath
                          );
            }

            this.config   = XmlLoader.LoadKarmaBotConfig(configPath);
            this.dataBase = new KarmaBotDatabase(dbPath);

            MessageHandler increaseHandler = new MessageHandler(
                this.config.IncreaseCommandRegex,
                HandleIncreaseCommand
                );

            MessageHandler decreaseCommand = new MessageHandler(
                this.config.DecreaseCommandRegex,
                HandleDecreaseCommand
                );

            MessageHandler queryCommand = new MessageHandler(
                this.config.QueryCommand,
                HandleQueryCommand
                );

            this.handlers.Add(increaseHandler);
            this.handlers.Add(decreaseCommand);
            this.handlers.Add(queryCommand);
        }
Exemple #3
0
        // -------- Functions --------

        /// <summary>
        /// Inits this plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string karmaBotRoot = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "KarmaBot"
                );

            string dbPath = Path.Combine(
                karmaBotRoot,
                "karmabot.ldb"
                );

            string configPath = Path.Combine(
                karmaBotRoot,
                "KarmaBotConfig.xml"
                );

            if (File.Exists(configPath) == false)
            {
                throw new FileNotFoundException(
                          "Can not open " + configPath
                          );
            }

            this.config       = XmlLoader.LoadKarmaBotConfig(configPath);
            this.dataBase     = new KarmaBotDatabase(dbPath);
            this.eventSender  = initor.ChaskisEventSender;
            this.eventCreator = initor.ChaskisEventCreator;

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = this.config.IncreaseCommandRegex,
                    LineAction = HandleIncreaseCommand
                };

                MessageHandler increaseHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlers.Add(increaseHandler);
            }

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = this.config.DecreaseCommandRegex,
                    LineAction = HandleDecreaseCommand
                };

                MessageHandler decreaseCommand = new MessageHandler(
                    msgConfig
                    );
                this.handlers.Add(decreaseCommand);
            }

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = this.config.QueryCommand,
                    LineAction = HandleQueryCommand
                };

                MessageHandler queryCommand = new MessageHandler(
                    msgConfig
                    );
                this.handlers.Add(queryCommand);
            }

            {
                ChaskisEventHandler chaskisQuery = initor.ChaskisEventCreator.CreatePluginEventHandler(
                    this.HandleChaskisQueryCommand
                    );
                this.handlers.Add(chaskisQuery);
            }
        }