/// <summary> /// Checks the comparison between left and right member. /// </summary> /// <param name="data">The BotData used for variable replacement.</param> /// <returns>Whether the comparison is valid</returns> public bool CheckKey(BotData data) { try { return(ConditionChecker.Verify(LeftTerm, Condition, RightTerm, data)); } catch { return(false); } // Return false if e.g. we can't parse the number for a LessThan/GreaterThan comparison. }
/// <summary> /// Gets the Action that needs to be executed. /// </summary> /// <param name="line">The data line to parse</param> /// <param name="data">The BotData needed for variable replacement</param> /// <returns>The Action to execute</returns> public static Action Parse(string line, BotData data) { var input = line.Trim(); var field = LineParser.ParseToken(ref input, TokenType.Parameter, true).ToUpper(); return(new Action(() => { var name = ""; Condition cond = Condition.EqualTo; switch (field) { case "COOKIE": if (LineParser.Lookahead(ref input) == TokenType.Parameter) { cond = (Condition)LineParser.ParseEnum(ref input, "TYPE", typeof(Condition)); } name = LineParser.ParseLiteral(ref input, "NAME"); for (int i = 0; i < data.Cookies.Count; i++) { var curr = data.Cookies.ToList()[i].Key; if (ConditionChecker.Verify(curr, cond, name, data)) { data.Cookies.Remove(curr); } } break; case "VAR": if (LineParser.Lookahead(ref input) == TokenType.Parameter) { cond = (Condition)LineParser.ParseEnum(ref input, "TYPE", typeof(Condition)); } name = LineParser.ParseLiteral(ref input, "NAME"); data.Variables.Remove(cond, name, data); break; case "GVAR": if (LineParser.Lookahead(ref input) == TokenType.Parameter) { cond = (Condition)LineParser.ParseEnum(ref input, "TYPE", typeof(Condition)); } name = LineParser.ParseLiteral(ref input, "NAME"); try { data.GlobalVariables.Remove(cond, name, data); } catch { } break; default: throw new ArgumentException($"Invalid identifier {field}"); } data.Log(new LogEntry($"DELETE command executed on field {field}", Colors.White)); })); }
/// <summary> /// Parses a condition made of left-hand term, condition type and right-hand term and verifies if it's true. /// </summary> /// <param name="cfLine">The reference to the line to parse</param> /// <param name="data">The BotData needed for variable replacement</param> /// <returns></returns> public static bool ParseCheckCondition(ref string cfLine, BotData data) { var first = LineParser.ParseLiteral(ref cfLine, "STRING"); var condition = (Condition)LineParser.ParseEnum(ref cfLine, "CONDITION", typeof(Condition)); var second = ""; if (condition != Condition.Exists) { second = LineParser.ParseLiteral(ref cfLine, "STRING"); } return(ConditionChecker.Verify(first, condition, second, data)); }
/// <summary> /// Checks the comparison between left and right member. /// </summary> /// <param name="data">The BotData used for variable replacement.</param> /// <returns>Whether the comparison is valid</returns> public bool CheckKey(BotData data) { return(ConditionChecker.Verify(LeftTerm, Condition, RightTerm, data)); }
/// <summary> /// <para>Removes all non-hidden variables if their name matches a condition.</para> /// <para>The name of the variables in the list are the left-hand term of the comparison.</para> /// </summary> /// <param name="cond">The condition type</param> /// <param name="name">The right-hand term of the comparison</param> /// <param name="data">The BotData object used for variable replacement</param> public void Remove(Condition cond, string name, BotData data) { All.RemoveAll(v => ConditionChecker.Verify(v.Name, cond, name, data) && !v.Hidden); }