diff --git a/bot/bot/Bot.cs b/bot/bot/Bot.cs index 737d86f..3e1c076 100644 --- a/bot/bot/Bot.cs +++ b/bot/bot/Bot.cs @@ -80,12 +80,16 @@ namespace bot { Console.Write("Updating response types on database ... "); tmp = "DELETE FROM resptypes WHERE "; foreach(Type t in ResponseCaller.getResponseTypes()) { - 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); + 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); @@ -94,12 +98,16 @@ namespace bot { Console.Write("Updating conditions on database ... "); tmp = "DELETE FROM conditions WHERE "; foreach(Type t in ConditionChecker.getConditions()) { - 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); + 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); @@ -134,10 +142,10 @@ namespace bot { while(Chat.isChatting(_G.driver)) { Message msg = Chat.waitForNewMessage(_G.driver); if(msg == null) break; - /*if(msg.msg == "!dump") { + 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"); diff --git a/bot/bot/Chat.cs b/bot/bot/Chat.cs index bc2509e..4eef4a3 100644 --- a/bot/bot/Chat.cs +++ b/bot/bot/Chat.cs @@ -17,6 +17,7 @@ namespace bot { static int currentMessage; public static void reloadContext(FirefoxDriver d) { +<<<<<<< HEAD while(true) { try { List chatdata = d.FindElement(By.Id("chatList")).FindElements(By.TagName("div")).ToList(); @@ -28,6 +29,14 @@ namespace bot { break; } catch(Exception shoehorn) {} } +======= + List chatdata = d.FindElement(By.Id("chatList")).FindElements(By.TagName("div")).ToList(); + messageDivSize = chatdata.Count; + foreach(IWebElement we in chatdata) { + if(Int32.Parse(we.GetAttribute("id").Substring(we.GetAttribute("id").LastIndexOf('_') + 1)) > currentMessage) + currentMessage = Int32.Parse(we.GetAttribute("id").Substring(we.GetAttribute("id").LastIndexOf('_') + 1)); + } +>>>>>>> origin/master if(d.FindElement(By.Id("audioButton")).GetAttribute("class").ToLower() == "button") d.FindElement(By.Id("audioButton")).Click(); } @@ -79,7 +88,7 @@ namespace bot { List chatdata = d.FindElement(By.Id("chatList")).FindElements(By.TagName("div")).ToList(); bool found = false; foreach(IWebElement we in chatdata) { - int nodeID = Int32.Parse(we.GetAttribute("id").Substring(11)); + int nodeID = Int32.Parse(we.GetAttribute("id").Substring(we.GetAttribute("id").LastIndexOf('_') + 1)); if(nodeID > currentMessage) { currentMessage = nodeID; found = true; diff --git a/bot/bot/bot.csproj b/bot/bot/bot.csproj index 469a986..7ead100 100644 --- a/bot/bot/bot.csproj +++ b/bot/bot/bot.csproj @@ -89,6 +89,7 @@ + @@ -101,8 +102,12 @@ - - + + Always + + + PreserveNewest +