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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue