Exemplo n.º 1
0
        public void TestExceptionOnShortMessages()
        {
            var huifyied = Huify.HuifyMe("д");

            huifyied = Huify.HuifyMe("да");
            huifyied = Huify.HuifyMe("даг");
            huifyied = Huify.HuifyMe("даги");
        }
        private Activity ProcessHuifyMessage(Activity activity)
        {
            if (activity.From.Id == ConfigurationManager.AppSettings["MasterId"])
            {
                return(null);
            }

            var messageText    = activity.Text;
            var conversationId = activity.Conversation.Id;

            var state         = WebApiApplication.ChatSettings.State;
            var delay         = WebApiApplication.ChatSettings.Delay;
            var delaySettings = WebApiApplication.ChatSettings.DelaySettings;

            if (!state.ContainsKey(conversationId) || !state[conversationId])
            {
                return(null);
            }

            if (delay.ContainsKey(conversationId))
            {
                delay[conversationId] -= 1;
            }
            else
            {
                Tuple <int, int> delaySetting;
                if (delaySettings.TryGetValue(conversationId, out delaySetting))
                {
                    delay[conversationId] = Rnd.Next(delaySetting.Item1, delaySetting.Item2 + 1);
                }
                else
                {
                    delay[conversationId] = Rnd.Next(4);
                }
            }

            if (delay[conversationId] != 0)
            {
                return(null);
            }

            delay.Remove(conversationId);
            var huifiedMessage = Huify.HuifyMe(messageText);

            if (string.IsNullOrEmpty(huifiedMessage))
            {
                return(null);
            }

            var reply = new Reply();

            reply.Text = huifiedMessage;

            return(reply.CreateReplyActivity(activity));
        }