Exemple #1
0
        // ---------------- Functions ----------------

        public void Init(PluginInitor initor)
        {
            this.chaskisEventCreator = initor.ChaskisEventCreator;
            this.eventSender         = initor.ChaskisEventSender;
            this.ircConfig           = initor.IrcConfig;
            this.logger = initor.Log;

            this.pluginDir = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "NewVersionNotifier"
                );

            string configPath = Path.Combine(
                this.pluginDir,
                "NewVersionNotifierConfig.xml"
                );

            this.config = XmlLoader.LoadConfig(configPath);

            this.cachedFilePath = Path.Combine(
                this.pluginDir,
                cacheFileName
                );

            if (File.Exists(this.cachedFilePath) == false)
            {
                this.cachedVersion = string.Empty;
            }
            else
            {
                string[] lines = File.ReadAllLines(this.cachedFilePath);
                if (lines.Length == 0)
                {
                    this.cachedVersion = string.Empty;
                }
                else
                {
                    this.cachedVersion = lines[0].Trim();
                }
            }

            ChaskisEventHandler eventHandler = this.chaskisEventCreator.CreatePluginEventHandler(
                "chaskis",
                this.HandleChaskisEvent
                );

            this.ircHandlers.Add(eventHandler);

            JoinHandlerConfig joinHandlerConfig = new JoinHandlerConfig
            {
                JoinAction    = this.OnJoinChannel,
                RespondToSelf = true
            };
            JoinHandler joinHandler = new JoinHandler(joinHandlerConfig);

            this.ircHandlers.Add(joinHandler);
        }
Exemple #2
0
        // ---------------- Functions ----------------

        public static NewVersionNotifierConfig LoadConfig(string configPath)
        {
            if (File.Exists(configPath) == false)
            {
                throw new FileNotFoundException("Could not find " + nameof(NewVersionNotifierConfig) + " file " + configPath);
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(configPath);

            XmlElement rootNode = doc.DocumentElement;

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

            NewVersionNotifierConfig config = new NewVersionNotifierConfig();

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

            config.Validate();

            return(config);
        }