public bool evaluateCondition(Message msg) { bool retval = ConditionChecker.checkCondition(conditionType, msg, parameter); ConditionChecker.checkCondition(conditionType, msg, parameter); if (not) { retval = !retval; } return(retval); }
static void Main(string[] args) { Console.Write("Loading database info ... "); _G.loadDatabaseInfo(); Console.WriteLine("OK"); Console.Write("Spawning database connections ... "); _G.conn = _G.spawnNewConnection(); _G.errconn = _G.spawnNewConnection(); Console.WriteLine("OK"); Console.Write("Loading bot configuration ... "); _G.loadConfig(); Console.WriteLine("OK"); Console.Write("Loading response list ... "); loadResponseList(); Console.WriteLine("OK"); Console.Write("Loading autonomous routine list ... "); loadAutonomousList(); Console.WriteLine("OK"); Console.Write("Updating response types on database ... "); tmp = "DELETE FROM resptypes WHERE "; foreach (Type t in ResponseCaller.getResponseTypes()) { try { string[] typeInfo = (string[])t.GetMethod("getInfo").Invoke(null, null); tmp += "name<>'" + typeInfo[0] + "' AND "; if ((Int64)Query.Scalar("SELECT COUNT(*) FROM `resptypes` WHERE `name`='" + typeInfo[0] + "'", _G.conn) > 0) { Query.Quiet("UPDATE `resptypes` SET friendlyname='" + Sanitizer.Sanitize(typeInfo[1]) + "',description='" + Sanitizer.Sanitize(typeInfo[2]) + "' WHERE name='" + typeInfo[0] + "'", _G.conn); } else { Query.Quiet("INSERT INTO `resptypes` (name,friendlyname,description) VALUES ('" + typeInfo[0] + "','" + Sanitizer.Sanitize(typeInfo[1]) + "','" + Sanitizer.Sanitize(typeInfo[2]) + "')", _G.conn); } } catch (Exception e) { _G.criticalError("Response type found in database does not match compiled response types! Update program."); } } tmp = tmp.Substring(0, tmp.Length - 5); Query.Quiet(tmp, _G.conn); Console.WriteLine("OK"); Console.Write("Updating conditions on database ... "); tmp = "DELETE FROM conditions WHERE "; foreach (Type t in ConditionChecker.getConditions()) { try { string[] typeInfo = (string[])t.GetMethod("getInfo").Invoke(null, null); tmp += "name<>'" + typeInfo[0] + "' AND "; if ((Int64)Query.Scalar("SELECT COUNT(*) FROM `conditions` WHERE `name`='" + typeInfo[0] + "'", _G.conn) > 0) { Query.Quiet("UPDATE `conditions` SET friendlyname='" + Sanitizer.Sanitize(typeInfo[1]) + "' WHERE name='" + typeInfo[0] + "'", _G.conn); } else { Query.Quiet("INSERT INTO `conditions` (name,friendlyname) VALUES ('" + typeInfo[0] + "','" + Sanitizer.Sanitize(typeInfo[1]) + "')", _G.conn); } } catch (Exception e) { _G.criticalError("Condition found in database does not match compiled conditions! Update program."); } } tmp = tmp.Substring(0, tmp.Length - 5); Query.Quiet(tmp, _G.conn); Console.WriteLine("OK"); Console.Write("Spawning web driver ... "); _G.driver = new FirefoxDriver(); Console.WriteLine("OK"); while (true) { try { Console.Write("Navigating to chat ... "); foreach (NavigationNode node in navigationList) { node.performNavigation(_G.driver); } try { (new WebDriverWait(_G.driver, new TimeSpan(0, 0, 300))).Until(ExpectedConditions.ElementExists(By.Id("inputField"))); } catch (Exception e) { _G.criticalError("Navigation to chat failed! Fix instructions.", true); } Console.WriteLine("OK"); Console.Write("Starting pulse thread ... "); _G.startThread(Pulse.pulseThread); Console.WriteLine("OK"); Console.Write("Preparing chat context ... "); Chat.reloadContext(_G.driver); Console.WriteLine("OK"); Console.Write("Starting autonomous thread ... "); _G.startThread(Bot.AutonomousThread); Console.WriteLine("OK"); Console.WriteLine(_G.propername + " has started successfully."); DateTime lastAction = new DateTime(0); while (Chat.isChatting(_G.driver)) { Message msg = Chat.waitForNewMessage(_G.driver); if (!ignoreResponses) { if (msg == null) { break; } if (msg.msg == "!dump") { foreach (Response r in responseList) { Chat.sendMessage("IF " + r.condstr + " THEN " + r.responseType.Name); } } if (msg.msg == "!update") { Bot.loadResponseList(); Chat.sendMessage("response list updated"); Bot.loadAutonomousList(); Chat.sendMessage("autonomous list updated"); } foreach (Response response in indResponseList) { if (response.triggerResponse(msg)) { break; } } foreach (Response response in responseList) { if ((DateTime.Now - lastAction).TotalSeconds >= _G.defaultCooldown) { if (response.triggerResponse(msg)) { lastAction = DateTime.Now; break; } } } } } _G.stopAllThreads(); Console.WriteLine("Restarting bot ..."); } catch (Exception err) { _G.criticalError("Main thread experienced unexpected fatal error! Details: " + err.Message + " " + err.StackTrace, true); } } }