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:
@@ -288,15 +288,51 @@ 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);
|
||||
data.Variables.Set(variable);
|
||||
data.Log(new LogEntry("Parsed variable" + " | Name: " + variable.Name + " | Value: " + variable.ToString() + Environment.NewLine, isCapture ? Colors.OrangeRed : Colors.Gold));
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user