mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Added access to App Vars inside the Chat Bot API via 3 new methods. Added access to Random class inside the execif command
This commit is contained in:
parent
beabe14c92
commit
0a57c927d7
2 changed files with 33 additions and 22 deletions
|
|
@ -45,35 +45,15 @@ namespace MinecraftClient.Commands
|
|||
{
|
||||
var interpreter = new Interpreter();
|
||||
interpreter.SetVariable("MCC", handler);
|
||||
interpreter.SetVariable("random", new Random());
|
||||
|
||||
foreach (KeyValuePair<string, object> entry in Settings.Config.AppVar.GetVariables())
|
||||
interpreter.SetVariable(entry.Key, entry.Value);
|
||||
|
||||
var result = interpreter.Eval<bool>(expressionText);
|
||||
|
||||
bool shouldExec = result;
|
||||
|
||||
/*if (result is bool)
|
||||
shouldExec = (bool)result;
|
||||
else if (result is string)
|
||||
shouldExec = !string.IsNullOrEmpty((string)result) && ((string)result).Trim().Contains("true", StringComparison.OrdinalIgnoreCase);
|
||||
else if (result is int)
|
||||
shouldExec = (int)result > 0;
|
||||
else if (result is double)
|
||||
shouldExec = (double)result > 0;
|
||||
else if (result is float)
|
||||
shouldExec = (float)result > 0;
|
||||
else if (result is Int16)
|
||||
shouldExec = (Int16)result > 0;
|
||||
else if (result is Int32)
|
||||
shouldExec = (Int32)result > 0;
|
||||
else if (result is Int64)
|
||||
shouldExec = (Int64)result > 0;
|
||||
*/
|
||||
|
||||
handler.Log.Debug("[Execif] Result Type: " + result.GetType().Name);
|
||||
|
||||
if (shouldExec)
|
||||
if (result)
|
||||
{
|
||||
CmdResult output = new();
|
||||
handler.PerformInternalCommand(resultCommand, ref output);
|
||||
|
|
|
|||
|
|
@ -978,6 +978,37 @@ namespace MinecraftClient.Scripting
|
|||
Handler.BotLoad(chatBot);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set an App Variable
|
||||
/// </summary>
|
||||
/// <param name="name">App variable name</param>
|
||||
/// <param name="value">App variable value</param>
|
||||
/// <returns>void</returns>
|
||||
protected void SetAppVar(string name, object value)
|
||||
{
|
||||
Config.AppVar.SetVar(name, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a value from an App Variable
|
||||
/// </summary>
|
||||
/// <param name="name">App variable name</param>
|
||||
/// <returns>App Variable value</returns>
|
||||
protected object? GetAppVar(string name)
|
||||
{
|
||||
return Config.AppVar.GetVar(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces variables in text with their values from the App Var registry
|
||||
/// </summary>
|
||||
/// <param name="text">Your text with variables</param>
|
||||
/// <returns>text with variables replaced with their values</returns>
|
||||
protected string ExpandAppVars(string text)
|
||||
{
|
||||
return Config.AppVar.ExpandVars(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether Terrain and Movements is enabled.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue