示例#1
0
        public string ProcessQuestion(string questionText)
        {
            if (string.IsNullOrEmpty(questionText))
            {
                return(_wrongAnswer);
            }

            try
            {
                string[] splitedQ = questionText.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

                //it can be a command
                if (splitedQ.Length == 2)
                {
                    string possibleCmdName = splitedQ[0];

                    IBotCommand cmd = _commandsAndActions.FirstOrDefault(c => c.Name.Equals(possibleCmdName, StringComparison.InvariantCultureIgnoreCase));

                    //it isn not command
                    if (cmd == null)
                    {
                        return(_strategy.GetAnswer(_answers));
                    }
                    //process command
                    else
                    {
                        return(cmd.ProcessQuery(splitedQ[1]));
                    }
                }
                //regular answer
                else
                {
                    return(_strategy.GetAnswer(_answers));
                }
            }
            catch (Exception ex)
            {
                return($"{_wrongAnswer}\n\t!!! {ex.Message}");
            }
        }