Correct bugs
This commit is contained in:
parent
cfeabd7a9e
commit
810c9fb3e7
3 changed files with 117 additions and 41 deletions
|
|
@ -12,6 +12,8 @@ namespace BetterSecondBot
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
AppDomain currentDomain = AppDomain.CurrentDomain;
|
||||||
|
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(PanicMode);
|
||||||
if (helpers.notempty(Environment.GetEnvironmentVariable("Basic_BotUserName")) == true)
|
if (helpers.notempty(Environment.GetEnvironmentVariable("Basic_BotUserName")) == true)
|
||||||
{
|
{
|
||||||
new CliDocker();
|
new CliDocker();
|
||||||
|
|
@ -24,6 +26,13 @@ namespace BetterSecondBot
|
||||||
Thread.Sleep(5000);
|
Thread.Sleep(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void PanicMode(object sender, UnhandledExceptionEventArgs args)
|
||||||
|
{
|
||||||
|
Exception e = (Exception)args.ExceptionObject;
|
||||||
|
Console.WriteLine("PanicMode caught : " + e.Message);
|
||||||
|
Console.WriteLine("Runtime terminating: {0}", args.IsTerminating);
|
||||||
|
}
|
||||||
|
|
||||||
public static class AssemblyInfo
|
public static class AssemblyInfo
|
||||||
{
|
{
|
||||||
/// <summary> Gets the git hash value from the assembly
|
/// <summary> Gets the git hash value from the assembly
|
||||||
|
|
|
||||||
|
|
@ -407,7 +407,9 @@ namespace BetterSecondBot.HttpService
|
||||||
|
|
||||||
public IPAddress handleGetClientIP()
|
public IPAddress handleGetClientIP()
|
||||||
{
|
{
|
||||||
if(disableIPchecks == true)
|
try
|
||||||
|
{
|
||||||
|
if (disableIPchecks == true)
|
||||||
{
|
{
|
||||||
return IPAddress.Parse("127.0.0.1");
|
return IPAddress.Parse("127.0.0.1");
|
||||||
}
|
}
|
||||||
|
|
@ -416,6 +418,12 @@ namespace BetterSecondBot.HttpService
|
||||||
return HttpContext.Request.RemoteEndPoint.Address;
|
return HttpContext.Request.RemoteEndPoint.Address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error getting client ip");
|
||||||
|
return IPAddress.Parse("0.0.0.0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -486,7 +494,7 @@ namespace BetterSecondBot.HttpService
|
||||||
|
|
||||||
protected Object BasicReply(string input, string command)
|
protected Object BasicReply(string input, string command)
|
||||||
{
|
{
|
||||||
return BasicReply(input, command);
|
return BasicReply(input, command, new string[] { });
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object BasicReply(string input,string command, string[] args)
|
protected Object BasicReply(string input,string command, string[] args)
|
||||||
|
|
@ -503,7 +511,7 @@ namespace BetterSecondBot.HttpService
|
||||||
|
|
||||||
protected Object Failure(string input, string command)
|
protected Object Failure(string input, string command)
|
||||||
{
|
{
|
||||||
return Failure(input, command);
|
return Failure(input, command, new string[] { });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -279,8 +279,16 @@ namespace BetterSecondBot.bottypes
|
||||||
}
|
}
|
||||||
string outputto = "none";
|
string outputto = "none";
|
||||||
List<string> bigbits = message.Split(new[] { "#|#" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
List<string> bigbits = message.Split(new[] { "#|#" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||||
|
if(bigbits.Count == 0)
|
||||||
|
{
|
||||||
|
bigbits.Add("");
|
||||||
|
}
|
||||||
List<string> bits = bigbits[0].Split(new[] { "|||" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
List<string> bits = bigbits[0].Split(new[] { "|||" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||||
if (bits.Count == 1)
|
if(bits.Count < 1)
|
||||||
|
{
|
||||||
|
bits.Add("");
|
||||||
|
}
|
||||||
|
if (bits.Count < 2)
|
||||||
{
|
{
|
||||||
bits.Add("");
|
bits.Add("");
|
||||||
}
|
}
|
||||||
|
|
@ -293,7 +301,17 @@ namespace BetterSecondBot.bottypes
|
||||||
{
|
{
|
||||||
frommaster = true;
|
frommaster = true;
|
||||||
}
|
}
|
||||||
CoreCommandLib(sender_uuid, frommaster, bits[0], bits[1].Split("~#~", StringSplitOptions.RemoveEmptyEntries), signing_code, outputto);
|
try
|
||||||
|
{
|
||||||
|
string command = bits[0];
|
||||||
|
string[] args = bits[1].Split("~#~", StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
CoreCommandLib(sender_uuid, frommaster, command, args, signing_code, outputto);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LogFormater.Crit("[CoreCommandLib] exploded: " + e.Message + "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,14 +323,30 @@ namespace BetterSecondBot.bottypes
|
||||||
string ott = Tokens.OneTimeToken();
|
string ott = Tokens.OneTimeToken();
|
||||||
WebApiControllerWithTokens Endpoint = commandEndpoints[endpointcommandmap[command]];
|
WebApiControllerWithTokens Endpoint = commandEndpoints[endpointcommandmap[command]];
|
||||||
MethodInfo theMethod = Endpoint.GetType().GetMethod(command);
|
MethodInfo theMethod = Endpoint.GetType().GetMethod(command);
|
||||||
|
if (theMethod != null)
|
||||||
|
{
|
||||||
List<string> argsList = args.ToList();
|
List<string> argsList = args.ToList();
|
||||||
argsList.Add(ott);
|
argsList.Add(ott);
|
||||||
string reply = "Inconnect number of args expected: "+ theMethod.GetParameters().Count().ToString()+" but got: "+ argsList.Count.ToString();
|
string reply = "Inconnect number of args expected: " + theMethod.GetParameters().Count().ToString() + " but got: " + argsList.Count.ToString();
|
||||||
bool status = false;
|
bool status = false;
|
||||||
if (argsList.Count == theMethod.GetParameters().Count())
|
if (argsList.Count == theMethod.GetParameters().Count())
|
||||||
{
|
{
|
||||||
status = true;
|
status = true;
|
||||||
object processed = theMethod.Invoke(Endpoint, argsList.ToArray<object>());
|
try
|
||||||
|
{
|
||||||
|
if (Endpoint == null)
|
||||||
|
{
|
||||||
|
return new KeyValuePair<bool, string>(false, "Endpoint is null");
|
||||||
|
}
|
||||||
|
if (argsList.Count == 0)
|
||||||
|
{
|
||||||
|
return new KeyValuePair<bool, string>(false, "Zero args at final check require at min 1");
|
||||||
|
}
|
||||||
|
object[] argsWorker = argsList.ToArray<object>();
|
||||||
|
object processed = theMethod.Invoke(Endpoint, argsWorker);
|
||||||
|
reply = "Error";
|
||||||
|
if(processed != null)
|
||||||
|
{
|
||||||
reply = JsonConvert.SerializeObject(processed);
|
reply = JsonConvert.SerializeObject(processed);
|
||||||
}
|
}
|
||||||
return new KeyValuePair<bool, string>(status, reply);
|
return new KeyValuePair<bool, string>(status, reply);
|
||||||
|
|
@ -322,6 +356,18 @@ namespace BetterSecondBot.bottypes
|
||||||
return new KeyValuePair<bool, string>(false, e.Message);
|
return new KeyValuePair<bool, string>(false, e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return new KeyValuePair<bool, string>(status, reply);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new KeyValuePair<bool, string>(false, "theMethod is null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new KeyValuePair<bool, string>(false, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void CoreCommandLib(UUID sender, bool Master, string command, string[] args, string signingcode, string targetreply)
|
protected void CoreCommandLib(UUID sender, bool Master, string command, string[] args, string signingcode, string targetreply)
|
||||||
{
|
{
|
||||||
|
|
@ -349,16 +395,10 @@ namespace BetterSecondBot.bottypes
|
||||||
{
|
{
|
||||||
return CallAPI(command, args, replyvia, false);
|
return CallAPI(command, args, replyvia, false);
|
||||||
}
|
}
|
||||||
public string CallAPI(string command, string[] args, string replyvia, bool customcommand)
|
|
||||||
|
protected string customCommand(string command, string[] args, string replyvia, bool customcommand)
|
||||||
{
|
{
|
||||||
if(commandnameLowerToReal.ContainsKey(command.ToLowerInvariant()) == false)
|
if (customcommand == true)
|
||||||
{
|
|
||||||
if (custom_commands.ContainsKey(command) == false)
|
|
||||||
{
|
|
||||||
SmartCommandReply(false, replyvia, "Unknown command", command);
|
|
||||||
return "{ status: \"false\", message: \"Unknown\" }";
|
|
||||||
}
|
|
||||||
if(customcommand == true)
|
|
||||||
{
|
{
|
||||||
SmartCommandReply(false, replyvia, "Custom command lockout", command);
|
SmartCommandReply(false, replyvia, "Custom command lockout", command);
|
||||||
return "{ status: \"false\", message: \"Custom command lockout\" }";
|
return "{ status: \"false\", message: \"Custom command lockout\" }";
|
||||||
|
|
@ -377,10 +417,29 @@ namespace BetterSecondBot.bottypes
|
||||||
loop++;
|
loop++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CallAPI(command_args_split[0], args_passed.Split("~#~"),"None",true);
|
CallAPI(command_args_split[0], args_passed.Split("~#~"), "None", true);
|
||||||
}
|
}
|
||||||
return "{ status: \"true\", message: \"mixed reply custom command\" }";
|
return "{ status: \"true\", message: \"mixed reply custom command\" }";
|
||||||
}
|
}
|
||||||
|
public string CallAPI(string command, string[] args, string replyvia, bool customcommand)
|
||||||
|
{
|
||||||
|
if(command == null)
|
||||||
|
{
|
||||||
|
return "No command";
|
||||||
|
}
|
||||||
|
if (replyvia == null)
|
||||||
|
{
|
||||||
|
replyvia = "none";
|
||||||
|
}
|
||||||
|
if (commandnameLowerToReal.ContainsKey(command.ToLowerInvariant()) == false)
|
||||||
|
{
|
||||||
|
if (custom_commands.ContainsKey(command) == false)
|
||||||
|
{
|
||||||
|
SmartCommandReply(false, replyvia, "Unknown command", command);
|
||||||
|
return "{ status: \"false\", message: \"Unknown\" }";
|
||||||
|
}
|
||||||
|
customCommand(command, args, replyvia, customcommand);
|
||||||
|
}
|
||||||
KeyValuePair<bool, string> statusreply = callAPIcommand(command, args);
|
KeyValuePair<bool, string> statusreply = callAPIcommand(command, args);
|
||||||
SmartCommandReply(statusreply.Key, replyvia, statusreply.Value, command);
|
SmartCommandReply(statusreply.Key, replyvia, statusreply.Value, command);
|
||||||
return "{ status: \"" + statusreply.Key.ToString() + "\", message: \""+ statusreply.Value+"\" command: \""+command+"\", args: \""+string.Join("~#~",args)+"\" }";
|
return "{ status: \"" + statusreply.Key.ToString() + "\", message: \""+ statusreply.Value+"\" command: \""+command+"\", args: \""+string.Join("~#~",args)+"\" }";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue