Exemplo n.º 1
0
        public void TestAsAliasWhenTrue()
        {
            var config = new Config();

            config.SetValue("Aliases", "test", "alias one");

            Mock <IConfigService>()
            .Setup(call => call.GetConfig())
            .Returns(config);

            Assert.IsTrue(service.IsAlias("test"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="room"></param>
        public void Handle(Message message, Room room)
        {
            // Check bot can handle this message
            if (!CanHandle(message, room))
            {
                return;
            }

            // Check for aliases
            if (AliasService.IsAlias(message.Body))
            {
                message.Body = AliasService.GetAlias(message.Body);
            }

            // Remove Alias bypass
            if (message.Body.StartsWith("!"))
            {
                message.Body = message.Body.Substring(1);
            }

            var handled = false;

            // Check each handler
            foreach (var handler in Handlers)
            {
                if (!handler.CanHandle(message))
                {
                    continue;
                }

                handler.Receive(message, room);

                handled = true;

                break;
            }

            if (!handled)
            {
                HipChatService.Say(room, "I didn't understand: {0}", message.Body);
            }
        }