diff --git a/bot/bot/Bot.cs b/bot/bot/Bot.cs index 7dab118..48b84a5 100644 --- a/bot/bot/Bot.cs +++ b/bot/bot/Bot.cs @@ -7,9 +7,6 @@ using OpenQA.Selenium.Firefox; using OpenQA.Selenium; using OpenQA.Selenium.Internal; using OpenQA.Selenium.Support.UI; -using SuperSocket; -using SuperSocket.SocketBase; -using SuperWebSocket; using MySql.Data.MySqlClient; using System.Threading; @@ -81,6 +78,11 @@ namespace bot { _G.driver = new FirefoxDriver(); 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); + } _G.startThread(Pulse.pulseThread); diff --git a/bot/bot/ConditionHolder.cs b/bot/bot/ConditionHolder.cs new file mode 100644 index 0000000..9d868e2 --- /dev/null +++ b/bot/bot/ConditionHolder.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bot { + class ConditionHolder { + public ConditionHolder(string conditions) { + + } + } +} diff --git a/bot/bot/NavigationNode.cs b/bot/bot/NavigationNode.cs index a75b978..08b5add 100644 --- a/bot/bot/NavigationNode.cs +++ b/bot/bot/NavigationNode.cs @@ -7,9 +7,6 @@ using OpenQA.Selenium.Firefox; using OpenQA.Selenium; using OpenQA.Selenium.Internal; using OpenQA.Selenium.Support.UI; -using SuperSocket; -using SuperSocket.SocketBase; -using SuperWebSocket; using MySql.Data.MySqlClient; using System.Threading; diff --git a/bot/bot/Response.cs b/bot/bot/Response.cs index 28d5cfe..da6e93c 100644 --- a/bot/bot/Response.cs +++ b/bot/bot/Response.cs @@ -8,14 +8,14 @@ using MySql.Data.MySqlClient; namespace bot { class Response { - public string conditions; + public ConditionHolder conditions; public Type responseType; public string parameters; public int cooldown; public int lastCall; public Response(string conditions, string responseType, string parameters, int cooldown) { - this.conditions = conditions; + this.conditions = new ConditionHolder(conditions); this.responseType = Assembly.GetExecutingAssembly().GetTypes().Where(t => String.Equals(t.Namespace, "bot.responses", StringComparison.Ordinal) && String.Equals(t.Name, responseType, StringComparison.Ordinal)).ToArray()[0]; this.parameters = parameters; this.cooldown = cooldown; @@ -23,7 +23,7 @@ namespace bot { } public Response(string conditions, int responseId, string parameters, int cooldown) { - this.conditions = conditions; + this.conditions = new ConditionHolder(conditions); string typeName = (string)(new MySqlCommand("SELECT `name` FROM `resptypes` WHERE `id`=" + responseId, _G.conn)).ExecuteScalar(); this.responseType = Assembly.GetExecutingAssembly().GetTypes().Where(t => String.Equals(t.Namespace, "bot.responses", StringComparison.Ordinal) && String.Equals(t.Name, typeName, StringComparison.Ordinal)).ToArray()[0]; this.parameters = parameters; diff --git a/bot/bot/_G.cs b/bot/bot/_G.cs index 7dc511c..9deb6fe 100644 --- a/bot/bot/_G.cs +++ b/bot/bot/_G.cs @@ -7,9 +7,6 @@ using OpenQA.Selenium.Firefox; using OpenQA.Selenium; using OpenQA.Selenium.Internal; using OpenQA.Selenium.Support.UI; -using SuperSocket; -using SuperSocket.SocketBase; -using SuperWebSocket; using MySql.Data.MySqlClient; using System.Threading; @@ -40,12 +37,21 @@ namespace bot { for(int i = 0; i < 4; i++) dbinfo[i] = r.ReadLine(); } catch(Exception e) { - Environment.FailFast("Error attempting to read from dbinfo.txt: "+e.Message+"\n\nProper format:\nSERVER ADDRESS\nUSERNAME\nPASSWORD\nDATABASE_NAME"); + criticalError("Error attempting to read from dbinfo.txt: " + e.Message + "\n\nProper format:\nSERVER ADDRESS\nUSERNAME\nPASSWORD\nDATABASE_NAME"); return false; } return true; } + public static void criticalError(string err, bool log = false) { + if(log) + logError(err); + Console.WriteLine(err); + Console.WriteLine("Press any key to quit."); + Console.ReadKey(); + Environment.FailFast(err); + } + public static bool isDaylightSavings() { return (observeDST) ? TimeZoneInfo.GetSystemTimeZones().First(o => o.DisplayName.ToLower().Contains("central time")).IsDaylightSavingTime(DateTime.UtcNow) : false; } @@ -76,14 +82,14 @@ namespace bot { tmp = new MySqlConnection("SERVER=" + dbinfo[0] + ";DATABASE=" + dbinfo[3] + ";UID=" + dbinfo[1] + ";PASSWORD=" + dbinfo[2] + ";"); tmp.Open(); } catch(Exception e) { - Environment.FailFast("Could not open database connection!"); + criticalError("Could not open database connection!"); return null; } return tmp; } public static void logError(string err) { - (new MySqlCommand("INSERT INTO `error` (`time`,`msg`) VALUES ('"+ getLocalTimeFromUTC() +" UTC"+ timezone +"','"+err+"')", errconn)).ExecuteNonQuery(); + Query.Quiet("INSERT INTO `error` (`time`,`msg`) VALUES ('"+ getLocalTimeFromUTC() +" UTC"+ timezone +"','"+err+"')", errconn); } public delegate void threadFunc(); diff --git a/bot/bot/bot.csproj b/bot/bot/bot.csproj index 1ffd3e8..a8ee87f 100644 --- a/bot/bot/bot.csproj +++ b/bot/bot/bot.csproj @@ -53,24 +53,6 @@ dll\Selenium.WebDriverBackedSelenium.dll - - dll\SuperSocket.Common.dll - - - dll\SuperSocket.Dlr.dll - - - dll\SuperSocket.Facility.dll - - - dll\SuperSocket.SocketBase.dll - - - dll\SuperSocket.SocketEngine.dll - - - dll\SuperWebSocket.dll - diff --git a/www/config.php b/www/config.php index b07ee0a..70e2e6e 100644 --- a/www/config.php +++ b/www/config.php @@ -248,8 +248,8 @@ include("header.php"); ?>
DST? dst) { ?> checked="checked" /> - Chat Username: - Bot Name: + Chat Username: + Bot Name: @@ -274,14 +274,14 @@ include("header.php"); ?> - + - findtype == 0 || $row->action == 0) { ?>style='display: none;' value="parameter; ?>" /> + findtype == 0 || $row->action == 0) { ?>style='display: none;' value="parameter); ?>" /> diff --git a/www/conn_generic.php b/www/conn_generic.php index 8a17047..8b83884 100644 --- a/www/conn_generic.php +++ b/www/conn_generic.php @@ -5,6 +5,14 @@ session_start(); $config = mysql_fetch_object(mysql_query("SELECT * FROM `config` WHERE `id`=1")); +function escapeDoubleQuotes($str) { + return str_replace('"','\\"',$str); +} + +function escapeSingleQuotes($str) { + return str_replace("'","\\'",$str); +} + function checkIfLoggedIn() { if(mysql_num_rows(mysql_query("SELECT * FROM `admin` WHERE `username`='". mysql_real_escape_string($_SESSION['user']) ."' AND `password`='". $_SESSION['pwd'] ."'")) > 0) return true; diff --git a/www/index.php b/www/index.php index b297431..e34caa0 100644 --- a/www/index.php +++ b/www/index.php @@ -1,6 +1,8 @@ + +$condtypes = array(); +$resptypes = array(); + +$q = mysql_query("SELECT * FROM `conditions`"); +while($cond = mysql_fetch_object($q)) { + $condtypes[$cond->id] = array(); +} + +if($_POST["resptype"]) { + $c = ""; + for($i=1;;$i++) { + if(!isset($_POST["if". $i ."group"])) break; + $c .= $_POST['if'.$i.'group'] .",".$_POST['if'.$i.'not'].",".$_POST['if'.$i.'cond'].",".$_POST['if'.$i.'param'].";"; + if(isset($_POST["op".$i])) $c .= $_POST["op".$i] .";"; + } + + mysql_query("INSERT INTO `responses` (`conditions`,`respid`,`parameters`,`cooldown`) VALUES ('". mysql_real_escape_string($c) ."',". $_POST['resptype'] .",'". mysql_real_escape_string($_POST['parameters']) ."',". (($_POST['ccd']==0)?-1:$_POST['cooldown']) .")") or die(mysql_error()); + header("Location: resp.php"); +} + +include("header.php"); +?>
@@ -57,70 +199,84 @@ include("header.php"); ?> Create New Response -

- If - - - - - - - - +

+

+ If + + + + + + + + + + - - - Add Condition - -

-

- then - - ". $desc ."

"; - $i++; - } - ?> -

-

- - - - Parameters: -

- -
-

-

- -      - -

+ + Add Condition + +

+

+ then + + ". $desc ."

"; + $i++; + } + ?> +

+

+ + + + Parameters: +

+ +
+

+

+ Cooldown: + + seconds +

+

+ +      + +

+
Edit Response