Beispiel #1
0
        // ---------------- Functions ----------------

        public static RssBotConfig ParseConfig(string fileName)
        {
            if (File.Exists(fileName) == false)
            {
                throw new FileNotFoundException("Can not find Rss Bot Config " + fileName);
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(fileName);

            XmlNode rootNode = doc.DocumentElement;

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

            RssBotConfig config = new RssBotConfig();

            foreach (XmlNode childNode in rootNode.ChildNodes)
            {
                if (childNode.Name == "feed")
                {
                    Feed feed = new Feed();

                    foreach (XmlNode feedNode in childNode.ChildNodes)
                    {
                        switch (feedNode.Name)
                        {
                        case "url":
                            feed.Url = feedNode.InnerText;
                            break;

                        case "refreshinterval":
                            long minutes = long.Parse(feedNode.InnerText);
                            feed.RefreshInterval = TimeSpan.FromMinutes(minutes);
                            break;

                        case "channel":
                            feed.AddChannel(feedNode.InnerText);
                            break;
                        }
                    }

                    config.AddFeed(feed);
                }
            }

            config.Validate();

            return(config);
        }
Beispiel #2
0
        // ---------------- Functions ----------------

        /// <summary>
        /// Initializes the plugin.
        /// </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,
                "RssBot",
                "RssBotConfig.xml"
                );

            this.admins = initor.IrcConfig.Admins;

            this.pluginLogger = initor.Log;

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

            this.scheduler = initor.EventScheduler;

            this.rssConfig = XmlLoader.ParseConfig(configPath);
            foreach (Feed feed in this.rssConfig.Feeds)
            {
                FeedReader reader = new FeedReader(feed, initor.HttpClient);

                reader.Init();

                int eventId = this.scheduler.ScheduleRecurringEvent(
                    feed.RefreshInterval,
                    delegate(IIrcWriter writer)
                {
                    CheckForUpdates(reader, writer, feed.Channels);
                }
                    );

                this.feedReaders.Add(eventId, reader);
            }

            MessageHandlerConfig msgConfig = new MessageHandlerConfig
            {
                LineRegex  = @"!debug\s+rssbot\s+updatefeed\s+(?<url>\S+)",
                LineAction = this.HandleDebug
            };

            MessageHandler debugHandler = new MessageHandler(
                msgConfig
                );

            this.handlers.Add(debugHandler);
        }