Give access to AutoRespond matches inside scripts

Available as %match_u%, %match_1% and so on
See #770 for initial suggestion
See #772 for in-progress implementation
This commit is contained in:
ORelio 2020-03-27 21:14:05 +01:00
parent e4e1f0b9fa
commit 00112e4c6a
25 changed files with 129 additions and 69 deletions

View file

@ -25,17 +25,18 @@ namespace MinecraftClient.ChatBots
private bool csharp;
private Thread thread;
private ManualResetEvent tpause;
private Dictionary<string, object> localVars;
public Script(string filename)
{
ParseArguments(filename);
}
public Script(string filename, string ownername)
public Script(string filename, string ownername, Dictionary<string, object> localVars)
: this(filename)
{
if (ownername != "")
owner = ownername;
this.owner = ownername;
this.localVars = localVars;
}
private void ParseArguments(string argstr)
@ -135,14 +136,14 @@ namespace MinecraftClient.ChatBots
csharp = file.EndsWith(".cs");
thread = null;
if (owner != null)
if (!String.IsNullOrEmpty(owner))
SendPrivateMessage(owner, "Script '" + file + "' loaded.");
}
else
{
LogToConsole("File not found: '" + System.IO.Path.GetFullPath(file) + "'");
if (owner != null)
if (!String.IsNullOrEmpty(owner))
SendPrivateMessage(owner, "File not found: '" + file + "'");
UnloadBot(); //No need to keep the bot active
@ -161,7 +162,7 @@ namespace MinecraftClient.ChatBots
{
try
{
CSharpRunner.Run(this, tpause, lines, args);
CSharpRunner.Run(this, tpause, lines, args, localVars);
}
catch (CSharpException e)
{
@ -198,7 +199,7 @@ namespace MinecraftClient.ChatBots
{
if (instruction_line[0] != '#' && instruction_line[0] != '/' && instruction_line[1] != '/')
{
instruction_line = Settings.ExpandVars(instruction_line);
instruction_line = Settings.ExpandVars(instruction_line, localVars);
string instruction_name = instruction_line.Split(' ')[0];
switch (instruction_name.ToLower())
{