示例#1
0
        public void CcTestChannelDoesNotExist()
        {
            string dummyChannel    = "#dumb";
            string message         = "My Message!";
            string expectedMessage = string.Format(
                "@{0}: I am not in {1}, sorry :(",
                remoteUser,
                dummyChannel
                );

            this.mockWriter.Setup(
                w => w.SendMessage(expectedMessage, this.ircConfig.Channels[0])
                );

            IIrcHandler ccHandler = this.uut.GetHandlers()[1];

            HandlerArgs args = this.GetHandlerArgs(
                "!cc <" + dummyChannel + "> " + message,
                this.ircConfig.Channels[0]
                );

            ccHandler.HandleEvent(args);

            this.mockWriter.VerifyAll();
        }
示例#2
0
        public void BadBCastCommandTest()
        {
            string message = "My Message!";

            IIrcHandler bcastHandler = this.uut.GetHandlers()[0];

            HandlerArgs args = this.GetHandlerArgs(" !broadcast " + message, this.ircConfig.Channels[0]);

            bcastHandler.HandleEvent(args);

            this.mockWriter.VerifyAll();
        }
示例#3
0
        /// <summary>
        /// Converts an XML file to a list of handlers.
        /// </summary>
        /// <param name="rng">
        /// Leave this null to use the default RNG, otherwise pass this in if you want to use your own (e.g. with a different seed)
        /// </param>
        public static IList <IIrcHandler> LoadXmlBotConfig(string file, IIrcConfig ircConfig, Random rng = null)
        {
            ArgumentChecker.IsNotNull(ircConfig, nameof(ircConfig));

            if (File.Exists(file) == false)
            {
                throw new FileNotFoundException("Could not find XmlBotConfig file '" + file + '"');
            }

            List <IIrcHandler> handlers = new List <IIrcHandler>();

            XmlDocument doc = new XmlDocument();

            doc.Load(file);

            XmlNode rootNode = doc.DocumentElement;

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

            foreach (XmlNode messageNode in rootNode.ChildNodes)
            {
                IIrcHandler handler = null;

                if (messageNode.Name.EqualsIgnoreCase("message"))
                {
                    MessageHandlerConfig config = new MessageHandlerConfig();
                    config.Deserialize(messageNode, ircConfig, rng);
                    handler = new MessageHandler(config);
                }
                else if (messageNode.Name.EqualsIgnoreCase("action"))
                {
                    ActionHandlerConfig config = new ActionHandlerConfig();
                    config.Deserialze(messageNode, ircConfig, rng);
                    handler = new ActionHandler(config);
                }

                if (handler != null)
                {
                    handlers.Add(handler);
                }
            }

            return(handlers);
        }
示例#4
0
        public void BadCcCommandTest()
        {
            string message = "My Message!";

            IIrcHandler ccHandler = this.uut.GetHandlers()[1];

            HandlerArgs args = this.GetHandlerArgs(
                " !cc <" + this.ircConfig.Channels[1] + "> " + message, // Note the whitespace.
                this.ircConfig.Channels[0]
                );

            ccHandler.HandleEvent(args);

            this.mockWriter.VerifyAll();
        }
示例#5
0
    public IrcSed(IIrcComm irc, IMeidoComm meido)
    {
        IrcHandlers = new IIrcHandler[] {
            new IrcHandler <IChannelMsg>(HandleMessage)
        };

        Help = new TopicHelp[] {
            new TopicHelp(
                "sed",
                "Interprets messages in the form of s/<SEARCH>/<REPLACE>/<FLAGS>. For more information on " +
                "the specifics of the search and replace expressions, see: " +
                "https://msdn.microsoft.com/en-us/library/az24scfc.aspx")
        };

        this.irc = irc;
    }
示例#6
0
        public bool AddHandler(IIrcHandler handler, MeidoPlugin plugin)
        {
            if (allowedTypes.Contains(handler.IrcEventType))
            {
                log.Verbose("{0}: Adding IrcHandler for type '{1}'",
                            plugin.Name, handler.IrcEventType);

                var handlerList = Get(handler.IrcEventType);
                handlerList.Add(handler);
                return(true);
            }

            log.Error("{0}: Declared an IrcHandler with unsupported type '{1}'. " +
                      "The method for this type will never be called.",
                      plugin.Name, handler.IrcEventType);
            return(false);
        }
示例#7
0
        public void BCastTest()
        {
            string message         = "My Message!";
            string expectedMessage = this.GetExpectedString(message, this.ircConfig.Channels[0]);

            this.mockWriter.Setup(
                w => w.SendBroadcastMessage(expectedMessage)
                );

            IIrcHandler bcastHandler = this.uut.GetHandlers()[0];

            HandlerArgs args = this.GetHandlerArgs("!broadcast " + message, this.ircConfig.Channels[0]);

            bcastHandler.HandleEvent(args);

            this.mockWriter.VerifyAll();
        }
示例#8
0
        public void CcTest()
        {
            string message         = "My Message!";
            string expectedMessage = this.GetExpectedString(message, this.ircConfig.Channels[0]);

            this.mockWriter.Setup(
                w => w.SendMessage(expectedMessage, this.ircConfig.Channels[1])
                );

            IIrcHandler ccHandler = this.uut.GetHandlers()[1];

            HandlerArgs args = this.GetHandlerArgs(
                "!cc <" + this.ircConfig.Channels[1] + "> " + message,
                this.ircConfig.Channels[0]
                );

            ccHandler.HandleEvent(args);

            this.mockWriter.VerifyAll();
        }