示例#1
0
            public override string Evaluate(RequestProcess process)
            {
                string value = this.TupleKey?.Evaluate(process);

                if (!string.IsNullOrWhiteSpace(value))
                {
                    // Get a value from a tuple.
                    int index; Tuple tuple;
                    if (int.TryParse(value, out index) && index >= 0 && index < Tuple.Tuples.Count)
                    {
                        tuple = Tuple.Tuples[index];
                        if (tuple.TryGetValue(this.Key.Evaluate(process), out value))
                        {
                            return(value);
                        }
                    }
                    return(process.Bot.Config.DefaultPredicate);
                }

                // Get a user variable or local variable.
                if (this.LocalVar)
                {
                    return(process.GetVariable(this.Key.Evaluate(process)));
                }
                return(process.User.GetPredicate(this.Key.Evaluate(process)));
            }
示例#2
0
            public li?Pick(RequestProcess process)
            {
                string value;

                foreach (var item in this.items)
                {
                    string?key        = item.Key?.Evaluate(process);
                    string?checkValue = item.Value?.Evaluate(process);

                    Dictionary <string, string> dictionary;
                    if (item.LocalVar)
                    {
                        dictionary = process.Variables;
                    }
                    else
                    {
                        dictionary = process.User.Predicates;
                    }

                    if (key != null && checkValue != null)
                    {
                        if (checkValue == "*")
                        {
                            // '*' is a match if the predicate is bound at all.
                            if (item.LocalVar)
                            {
                                if (process.Variables.TryGetValue(key, out value))
                                {
                                    process.Log(LogLevel.Diagnostic, $"In element <condition>: Local variable {key} matches *.");
                                    return(item);
                                }
                            }
                            else
                            {
                                if (process.User.Predicates.TryGetValue(key, out value))
                                {
                                    process.Log(LogLevel.Diagnostic, $"In element <condition>: Local variable {key} matches *.");
                                    return(item);
                                }
                            }
                        }
                        else
                        {
                            if (item.LocalVar)
                            {
                                if (process.Bot.Config.StringComparer.Equals(process.GetVariable(key), checkValue))
                                {
                                    process.Log(LogLevel.Diagnostic, $"In element <condition>: Local variable {key} matches {checkValue}.");
                                    return(item);
                                }
                            }
                            else
                            {
                                if (process.Bot.Config.StringComparer.Equals(checkValue, process.User.GetPredicate(key)))
                                {
                                    process.Log(LogLevel.Diagnostic, $"In element <condition>: {(item.LocalVar ? "Local variable" : "Predicate")} {key} matches {checkValue}.");
                                    return(item);
                                }
                            }
                        }
                        // No match; keep looking.
                        process.Log(LogLevel.Diagnostic, $"In element <condition>: {(item.LocalVar ? "Local variable" : "Predicate")} {key} does not match {checkValue}.");
                    }
                    else if (key == null && checkValue == null)
                    {
                        // Default case.
                        return(item);
                    }
                    else
                    {
                        process.Log(LogLevel.Warning, "In element <condition>: Missing name, var or value attribute in <li>.");
                    }
                }

                return(null);
            }