示例#1
0
        public void BotJoinsWithRespondToSelfEnabled()
        {
            JoinHandlerConfig joinHandlerConfig = new JoinHandlerConfig
            {
                JoinAction    = this.JoinFunction,
                RespondToSelf = true
            };
            JoinHandler uut = new JoinHandler(joinHandlerConfig);

            string ircString = TestHelpers.ConstructIrcString(
                this.ircConfig.Nick,
                JoinHandler.IrcCommand,
                this.ircConfig.Channels[0],
                string.Empty
                );

            uut.HandleEvent(this.ConstructArgs(ircString));

            Assert.IsNotNull(this.responseReceived);

            // Channels should match.
            Assert.AreEqual(this.ircConfig.Channels[0], this.responseReceived.Channel);

            // Nicks should match.
            Assert.AreEqual(this.ircConfig.Nick, this.responseReceived.User);
        }
        public void CloneTest()
        {
            JoinHandlerConfig config1 = new JoinHandlerConfig();
            JoinHandlerConfig clone   = config1.Clone();

            Assert.AreNotSame(config1, clone);
        }
示例#3
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);
        }
示例#4
0
        public void TestSetup()
        {
            this.ircConfig        = TestHelpers.GetTestIrcConfig();
            this.ircWriter        = new Mock <IIrcWriter>(MockBehavior.Strict);
            this.responseReceived = null;

            JoinHandlerConfig joinHandlerConfig = new JoinHandlerConfig
            {
                JoinAction = this.JoinFunction
            };

            this.uut = new JoinHandler(joinHandlerConfig);
        }
        public void ValidateTest()
        {
            JoinHandlerConfig config = new JoinHandlerConfig();

            config.JoinAction = null;
            Assert.Throws <ValidationException>(() => config.Validate());

            config.JoinAction = delegate(JoinHandlerArgs args)
            {
            };

            Assert.DoesNotThrow(() => config.Validate());
        }
示例#6
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;
            }
        }