Esempio n. 1
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.  This includes loading any configuration files,
        /// starting services, etc.  Allowed to throw Exceptions.
        ///
        /// This function should be used to validates that the environment is good for the plugin.
        /// For example, it has all dependencies installed, config files are in the correct spot, etc.
        /// It should also load GetHandlers() with the handlers.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string configPath = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "UserListBot",
                "UserListBotConfig.xml"
                );

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

            this.userListConfig = XmlLoader.LoadConfig(configPath);

            // User query command:
            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = this.userListConfig.Command,
                    LineAction = this.HandleGetUsersCommand,
                    CoolDown   = this.userListConfig.Cooldown
                };

                MessageHandler userQueryHandler = new MessageHandler(
                    msgConfig
                    );

                this.handlers.Add(userQueryHandler);
            }
            {
                AllHandlerConfig allHandlerConfig = new AllHandlerConfig
                {
                    AllAction = this.HandleNamesResponse
                };
                AllHandler nameResponseHandler = new AllHandler(allHandlerConfig);
                this.handlers.Add(nameResponseHandler);
            }

            {
                AllHandlerConfig allHandlerConfig = new AllHandlerConfig
                {
                    AllAction = this.HandleEndOfNamesResponse
                };
                AllHandler endOfNamesHandler = new AllHandler(allHandlerConfig);
                this.handlers.Add(endOfNamesHandler);
            }
        }
Esempio n. 2
0
        // -------- Functions --------

        /// <summary>
        /// Parses a user list bot config from the given XML file.
        /// </summary>
        /// <param name="xmlFilePath">The path of the XML file.</param>
        /// <returns>The parsed user list bot config.</returns>
        public static UserListBotConfig LoadConfig(string xmlFilePath)
        {
            if (File.Exists(xmlFilePath) == false)
            {
                throw new FileNotFoundException("Could not find user list bot config file " + xmlFilePath);
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(xmlFilePath);

            XmlElement rootNode = doc.DocumentElement;

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

            UserListBotConfig config = new UserListBotConfig();

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

                case "cooldown":
                    config.Cooldown = int.Parse(childNode.InnerText);
                    break;
                }
            }

            config.Validate();

            return(config);
        }
Esempio n. 3
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.  This includes loading any configuration files,
        /// starting services, etc.  Allowed to throw Exceptions.
        ///
        /// This function should be used to validates that the environment is good for the plugin.
        /// For example, it has all dependencies installed, config files are in the correct spot, etc.
        /// It should also load GetHandlers() with the handlers.
        /// </summary>
        /// <param name="pluginPath">
        /// The absolute path to the plugin, including the file name.  To just get
        /// the path to the plugin, call Path.GetDirectoryName on this argument.
        /// </param>
        /// <param name="ircConfig">The IRC config we are using.</param>
        public void Init(string pluginPath, IIrcConfig ircConfig)
        {
            string configPath = Path.Combine(
                Path.GetDirectoryName(pluginPath),
                "UserListBotConfig.xml"
                );

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

            this.ircConfig      = ircConfig;
            this.userListConfig = XmlLoader.LoadConfig(configPath);

            // User query command:
            {
                MessageHandler userQueryHandler = new MessageHandler(
                    this.userListConfig.Command.Replace("{%nick%}", this.ircConfig.Nick),
                    this.HandleGetUsersCommand,
                    this.userListConfig.Cooldown
                    );

                this.handlers.Add(userQueryHandler);
            }
            {
                AllHandler nameResponseHandler = new AllHandler(HandleNamesResponse);
                this.handlers.Add(nameResponseHandler);
            }

            {
                AllHandler endOfNamesHandler = new AllHandler(HandleEndOfNamesResponse);
                this.handlers.Add(endOfNamesHandler);
            }
        }