Exemplo n.º 1
0
        private bool RunExecutor(IExecutor executor, Msg message)
        {
            ComparatorResult results = Comparator.Process(message.Command, executor.Commands);

            if (results.Matched)
            {
                Console.WriteLine(message.Command + " deduced to: " + results.ValidCommand);

                message.Command = results.ValidCommand;
                executor.Execute(message);
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        public ComparatorResult Process(string command, List <string> executorKeys)
        {
            ComparatorResult results = new ComparatorResult(command);

            // Is command a part of the executor's keys.
            if (executorKeys.Contains(command))
            {
                results.Match(command);
                return(results);
            }

            // Invoke each advanced check that matches a command in the current executor's command dictionary.
            foreach (string key in executorKeys)
            {
                if (AdvancedChecks.ContainsKey(key))
                {
                    // If the command is matched by the advanced matcher, return results with the current key from the executor's dictionary.
                    if (AdvancedChecks[key].Invoke(command))
                    {
                        results.Match(key);
                        return(results);
                    }
                }
            }

            // Start running syllable comparator
            SylComparator.CommandToSyllables(command);

            // Run comparator with each key in the comparables.
            foreach (string key in Cmd.Comparables)
            {
                if (executorKeys.Contains(key))
                {
                    //If matched, set the current key as the result's valid command.
                    if (SylComparator.Match(key))
                    {
                        results.Match(key);
                        return(results);
                    }
                }
            }

            return(results);
        }