Exemplo n.º 1
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.  This includes loading any configuration files,
        /// starting services, etc.
        /// </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,
                "WelcomeBot",
                "WelcomeBotConfig.xml"
                );

            WelcomeBotConfig config = XmlLoader.LoadConfig(configPath);

            this.Init(initor, config);
        }
Exemplo n.º 2
0
        // ---------------- Functions ----------------

        public static WelcomeBotConfig LoadConfig(string xmlFilePath)
        {
            if (File.Exists(xmlFilePath) == false)
            {
                throw new FileNotFoundException("Could not find welcomebot config file " + xmlFilePath);
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(xmlFilePath);

            XmlElement rootNode = doc.DocumentElement;

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

            WelcomeBotConfig config = new WelcomeBotConfig();

            foreach (XmlNode childNode in rootNode.ChildNodes)
            {
                switch (childNode.Name)
                {
                case "joinmessages":
                    config.EnableJoinMessages = bool.Parse(childNode.InnerText);
                    break;

                case "partmessages":
                    config.EnablePartMessages = bool.Parse(childNode.InnerText);
                    break;

                case "kickmessages":
                    config.EnableKickMessages = bool.Parse(childNode.InnerText);
                    break;

                case "karmabotintegration":
                    config.KarmaBotIntegration = bool.Parse(childNode.InnerText);
                    break;

                default:
                    // Ignore everything else, we don't care about anything else.
                    break;
                }
            }

            config.Validate();

            return(config);
        }
Exemplo n.º 3
0
        /// <summary>
        /// An initor that is used if we already know the config object.
        /// </summary>
        public void Init(PluginInitor initor, WelcomeBotConfig config)
        {
            if (this.isLoaded == false)
            {
                this.eventCreator = initor.ChaskisEventCreator;
                this.eventSender  = initor.ChaskisEventSender;

                if (config.EnableJoinMessages)
                {
                    JoinHandlerConfig joinHandlerConfig = new JoinHandlerConfig
                    {
                        JoinAction = this.JoinMessage
                    };
                    this.handlers.Add(new JoinHandler(joinHandlerConfig));
                }

                if (config.EnablePartMessages)
                {
                    PartHandlerConfig partHandlerConfig = new PartHandlerConfig
                    {
                        PartAction = PartMessage
                    };
                    this.handlers.Add(new PartHandler(partHandlerConfig));
                }

                if (config.EnableKickMessages)
                {
                    KickHandlerConfig kickHandlerConfig = new KickHandlerConfig
                    {
                        KickAction = KickMessage
                    };

                    this.handlers.Add(new KickHandler(kickHandlerConfig));
                }

                if (config.EnableJoinMessages && config.KarmaBotIntegration)
                {
                    ChaskisEventHandler karmaHandler = this.eventCreator.CreatePluginEventHandler(
                        "karmabot",
                        HandleKarmaQuery
                        );
                    this.handlers.Add(karmaHandler);
                }

                this.isLoaded = true;
            }
        }