mirror of
https://github.com/openbullet/openbullet.git
synced 2023-10-21 07:33:42 -05:00
Added the ability to not create an empty variable when the Parse Block fails.
This commit is contained in:
@@ -321,10 +321,10 @@ CAPTCHA "http://example.com/image.png" -> VAR "CAP"
|
||||
This will spawn and execute a Parse Block.
|
||||
|
||||
Syntax:
|
||||
PARSE "TARGET" LR "LEFT" "RIGHT" [Recursive?] [UseRegexLR?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" CSS "SELECTOR" "ATTRIBUTE" [INDEX / Recursive?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" JSON "FIELD" [Recursive?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" REGEX "REGEX" "OUTPUT" [Recursive?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" LR "LEFT" "RIGHT" [Recursive?] [EncodeOutput?] [CreateEmpty?] [UseRegexLR?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" CSS "SELECTOR" "ATTRIBUTE" [INDEX / Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" JSON "FIELD" [Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" REGEX "REGEX" "OUTPUT" [Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
|
||||
Examples:
|
||||
PARSE "<SOURCE>" LR "<span>" "</span>" Recursive=True -> CAP "BALANCE" "$" ""
|
||||
|
||||
@@ -76,7 +76,8 @@
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
<CheckBox Content="Recursive" IsChecked="{Binding Recursive}" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Encode Output" IsChecked="{Binding EncodeOutput}" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Enc. Output" IsChecked="{Binding EncodeOutput}" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Create Empty" IsChecked="{Binding CreateEmpty}" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Use Regex" IsChecked="{Binding UseRegexLR}" VerticalContentAlignment="Center" >
|
||||
<CheckBox.ToolTip>
|
||||
<TextBlock>Whether the program matches the LEFT and RIGHT strings through a regex pattern<LineBreak /> or with simple string in string searches</TextBlock>
|
||||
@@ -114,6 +115,7 @@
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<CheckBox Content="Recursive" IsChecked="{Binding Recursive}" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Encode Output" IsChecked="{Binding EncodeOutput}" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Create Empty" IsChecked="{Binding CreateEmpty}" VerticalContentAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
@@ -126,6 +128,7 @@
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<CheckBox Content="Recursive" IsChecked="{Binding Recursive}" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Encode Output" IsChecked="{Binding EncodeOutput}" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Create Empty" IsChecked="{Binding CreateEmpty}" VerticalContentAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
@@ -142,6 +145,7 @@
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<CheckBox Content="Recursive" IsChecked="{Binding Recursive}" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Encode Output" IsChecked="{Binding EncodeOutput}" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Create Empty" IsChecked="{Binding CreateEmpty}" VerticalContentAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
|
||||
@@ -28,10 +28,10 @@ RECAPTCHA "URL" "SITEKEY" -> VAR "NAME"
|
||||
CAPTCHA "URL" [Base64?] [SendScreenshot?] -> VAR "NAME"
|
||||
</item>
|
||||
<item name="PARSE">
|
||||
PARSE "TARGET" LR "LEFT" "RIGHT" [Recursive?] [EncodeOutput?] [UseRegexLR?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" CSS "SELECTOR" "ATTRIBUTE" [INDEX / Recursive?] [EncodeOutput?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" JSON "FIELD" [Recursive?] [EncodeOutput?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" REGEX "REGEX" "OUTPUT" [Recursive?] [EncodeOutput?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" LR "LEFT" "RIGHT" [Recursive?] [EncodeOutput?] [CreateEmpty?] [UseRegexLR?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" CSS "SELECTOR" "ATTRIBUTE" [INDEX / Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" JSON "FIELD" [Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" REGEX "REGEX" "OUTPUT" [Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
</item>
|
||||
<item name="UTILITY">
|
||||
UTILITY LIST "List Name" ACTION [PARAMETERS] [-> VAR/CAP "NAME"]
|
||||
|
||||
@@ -288,16 +288,52 @@ namespace RuriLib
|
||||
/// <param name="prefix">The string to add at the start of the value</param>
|
||||
/// <param name="suffix">The string to add at the end of the value</param>
|
||||
/// <param name="urlEncode">Whether to URLencode the values before creating the variables</param>
|
||||
public static void InsertVariables(BotData data, bool isCapture, bool recursive, List<string> values, string variableName, string prefix, string suffix, bool urlEncode)
|
||||
/// <param name="createEmpty">Whether to create an empty (single) variable if the list of values is empty</param>
|
||||
public static void InsertVariables(BotData data, bool isCapture, bool recursive, List<string> values, string variableName, string prefix, string suffix, bool urlEncode, bool createEmpty)
|
||||
{
|
||||
var list = values.Select(v => ReplaceValues(prefix, data) + v.Trim() + ReplaceValues(suffix, data)).ToList();
|
||||
if (urlEncode) list = list.Select(v => System.Uri.EscapeDataString(v)).ToList();
|
||||
CVar variable;
|
||||
if (recursive) variable = new CVar(variableName, list, isCapture);
|
||||
else variable = new CVar(variableName, list.Count == 0 ? "" : list.First(), isCapture);
|
||||
|
||||
CVar variable = null;
|
||||
if (recursive)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
{
|
||||
if (createEmpty)
|
||||
{
|
||||
variable = new CVar(variableName, list, isCapture);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
variable = new CVar(variableName, list, isCapture);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (list.Count == 0)
|
||||
{
|
||||
if (createEmpty)
|
||||
{
|
||||
variable = new CVar(variableName, "", isCapture);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
variable = new CVar(variableName, list.First(), isCapture);
|
||||
}
|
||||
}
|
||||
|
||||
if (variable != null)
|
||||
{
|
||||
data.Variables.Set(variable);
|
||||
data.Log(new LogEntry("Parsed variable" + " | Name: " + variable.Name + " | Value: " + variable.ToString() + Environment.NewLine, isCapture ? Colors.OrangeRed : Colors.Gold));
|
||||
}
|
||||
else
|
||||
{
|
||||
data.Log(new LogEntry("Could not parse any data. The variable was not created.", Colors.White));
|
||||
}
|
||||
}
|
||||
|
||||
#region File Utilities
|
||||
/// <summary>
|
||||
|
||||
@@ -690,7 +690,7 @@ namespace RuriLib
|
||||
}
|
||||
|
||||
var isList = outputs.Count > 1 || InputString.Contains("[*]") || InputString.Contains("(*)") || InputString.Contains("{*}");
|
||||
InsertVariables(data, isCapture, isList, outputs, variableName, "", "", false);
|
||||
InsertVariables(data, isCapture, isList, outputs, variableName, "", "", false, true);
|
||||
}
|
||||
|
||||
#region Base64
|
||||
|
||||
@@ -63,6 +63,10 @@ namespace RuriLib
|
||||
/// <summary>Whether to URL encode the parsed text.</summary>
|
||||
public bool EncodeOutput { get { return encodeOutput; } set { encodeOutput = value; OnPropertyChanged(); } }
|
||||
|
||||
private bool createEmpty = true;
|
||||
/// <summary>Whether to create the variable with an empty value if the parsing was not successful.</summary>
|
||||
public bool CreateEmpty { get { return createEmpty; } set { createEmpty = value; OnPropertyChanged(); } }
|
||||
|
||||
private ParseType type = ParseType.LR;
|
||||
/// <summary>The parsing algorithm being used.</summary>
|
||||
public ParseType Type { get { return type; } set { type = value; OnPropertyChanged(); } }
|
||||
@@ -151,7 +155,7 @@ namespace RuriLib
|
||||
LineParser.SetBool(ref input, this);
|
||||
else if (LineParser.Lookahead(ref input) == TokenType.Integer)
|
||||
CssElementIndex = LineParser.ParseInt(ref input, "INDEX");
|
||||
if (LineParser.Lookahead(ref input) == TokenType.Boolean)
|
||||
while (LineParser.Lookahead(ref input) == TokenType.Boolean)
|
||||
LineParser.SetBool(ref input, this);
|
||||
break;
|
||||
|
||||
@@ -216,6 +220,7 @@ namespace RuriLib
|
||||
.Literal(RightString)
|
||||
.Boolean(Recursive, "Recursive")
|
||||
.Boolean(EncodeOutput, "EncodeOutput")
|
||||
.Boolean(CreateEmpty, "CreateEmpty")
|
||||
.Boolean(UseRegexLR, "UseRegexLR");
|
||||
break;
|
||||
|
||||
@@ -225,14 +230,18 @@ namespace RuriLib
|
||||
.Literal(AttributeName);
|
||||
if (Recursive) writer.Boolean(Recursive, "Recursive");
|
||||
else writer.Integer(CssElementIndex, "CssElementIndex");
|
||||
writer.Boolean(EncodeOutput, "EncodeOutput");
|
||||
|
||||
writer
|
||||
.Boolean(EncodeOutput, "EncodeOutput")
|
||||
.Boolean(CreateEmpty, "CreateEmpty");
|
||||
break;
|
||||
|
||||
case ParseType.JSON:
|
||||
writer
|
||||
.Literal(JsonField)
|
||||
.Boolean(Recursive, "Recursive")
|
||||
.Boolean(EncodeOutput, "EncodeOutput");
|
||||
.Boolean(EncodeOutput, "EncodeOutput")
|
||||
.Boolean(CreateEmpty, "CreateEmpty");
|
||||
break;
|
||||
|
||||
case ParseType.REGEX:
|
||||
@@ -240,7 +249,8 @@ namespace RuriLib
|
||||
.Literal(RegexString)
|
||||
.Literal(RegexOutput)
|
||||
.Boolean(Recursive, "Recursive")
|
||||
.Boolean(EncodeOutput, "EncodeOutput");
|
||||
.Boolean(EncodeOutput, "EncodeOutput")
|
||||
.Boolean(CreateEmpty, "CreateEmpty");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -260,7 +270,7 @@ namespace RuriLib
|
||||
{
|
||||
base.Process(data);
|
||||
|
||||
InsertVariables(data, isCapture, recursive, Parse(data), variableName, prefix, suffix, encodeOutput);
|
||||
InsertVariables(data, isCapture, recursive, Parse(data), variableName, prefix, suffix, encodeOutput, createEmpty);
|
||||
}
|
||||
|
||||
private List<string> Parse(BotData data)
|
||||
|
||||
@@ -341,7 +341,7 @@ namespace RuriLib
|
||||
|
||||
if (outputs.Count != 0)
|
||||
{
|
||||
InsertVariables(data, isCapture, recursive, outputs, outputVariable, "", "", false);
|
||||
InsertVariables(data, isCapture, recursive, outputs, outputVariable, "", "", false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user