diff --git a/bot/bot/Bot.cs b/bot/bot/Bot.cs index 48b84a5..12317bd 100644 --- a/bot/bot/Bot.cs +++ b/bot/bot/Bot.cs @@ -19,7 +19,7 @@ namespace bot { public static void loadNavigationList() { navigationList = new List(); - var r = Query.Reader("SELECT * FROM `navigate`", _G.conn); + var r = Query.Reader("SELECT * FROM `navigate`", _G.spawnNewConnection()); while(r.Read()) { navigationList.Add(new NavigationNode( r.GetInt32("findtype"), @@ -32,7 +32,7 @@ namespace bot { public static void loadResponseList() { responseList = new List(); - var r = Query.Reader("SELECT * FROM `responses`", _G.conn); + var r = Query.Reader("SELECT * FROM `responses`", _G.spawnNewConnection()); while(r.Read()) { responseList.Add(new Response( r.GetString("conditions"), diff --git a/bot/bot/Condition.cs b/bot/bot/Condition.cs index cc3ebd6..a50e3a4 100644 --- a/bot/bot/Condition.cs +++ b/bot/bot/Condition.cs @@ -3,10 +3,33 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using OpenQA.Selenium.Firefox; +using OpenQA.Selenium; +using OpenQA.Selenium.Internal; +using OpenQA.Selenium.Support.UI; +using MySql.Data.MySqlClient; +using System.Threading; using System.Reflection; namespace bot { class Condition { - + public bool not; + public Type conditionType; + public string parameter; + + public Condition() { } + + public Condition(bool n, Type c, string p) { + not = n; + conditionType = c; + parameter = p; + } + + public Condition(bool n, int c, string p) { + not = n; + string typeName = (string)(new MySqlCommand("SELECT `name` FROM `conditions` WHERE `id`=" + c, _G.conn)).ExecuteScalar(); + conditionType = Assembly.GetExecutingAssembly().GetTypes().Where(t => String.Equals(t.Namespace, "bot.conditions", StringComparison.Ordinal) && String.Equals(t.Name, typeName, StringComparison.Ordinal)).ToArray()[0]; + parameter = p; + } } } diff --git a/bot/bot/ConditionHolder.cs b/bot/bot/ConditionHolder.cs index 6411272..2d27e43 100644 --- a/bot/bot/ConditionHolder.cs +++ b/bot/bot/ConditionHolder.cs @@ -6,10 +6,46 @@ using System.Threading.Tasks; namespace bot { class ConditionHolder { - + List conditions = new List(); + List sequence = new List(); - public ConditionHolder(string condstring) { + public ConditionHolder(string condstring, bool baselvl = true) { + List c = condstring.Split(';').ToList(); + c.RemoveAt(c.Count - 1); + int i = 0, searching = -1; + int[] pair = { -1, -1 }; + for(int on = 0; on < c.Count; on++) { + string cond = c[on]; + List tk = cond.Split(',').ToList(); + if(tk.Count > 2) { + if(Int32.Parse(tk[0]) > 0 && searching == -1) { + searching = 0; + pair[0] = i; + } + if(searching != -1) + searching += Int32.Parse(tk[0]) - Int32.Parse(tk[4]); + if(searching == 0) { + searching = -1; + pair[1] = i; + string str = "", tmp = ""; + if(pair[0] != 0) { + //tmp = condstring.Substring(0, + } else { + + } + str = condstring.Substring((pair[0] == 0) ? 0 : _G.indexOfNth(condstring, ';', pair[0] + 1) + 1, _G.indexOfNth(condstring, ';', pair[1] + 2) + 1); + str = Int32.Parse(str.Substring(0, str.IndexOf(','))) - 1 + str.Substring(str.IndexOf(',')); + + sequence.Add(new ConditionHolder(str, false)); + } + i++; + } + } + } + + public bool calculateValue(Message msg) { + return true; } } } diff --git a/bot/bot/_G.cs b/bot/bot/_G.cs index 9deb6fe..a382195 100644 --- a/bot/bot/_G.cs +++ b/bot/bot/_G.cs @@ -92,6 +92,15 @@ namespace bot { Query.Quiet("INSERT INTO `error` (`time`,`msg`) VALUES ('"+ getLocalTimeFromUTC() +" UTC"+ timezone +"','"+err+"')", errconn); } + public static int indexOfNth(string str, char c, int index) { + int fcount = 0; + for(int i = 0; i < str.Length; i++) { + if(str[i] == c) fcount++; + if(fcount == index) return i; + } + return -1; + } + public delegate void threadFunc(); public static void startThread(threadFunc t) { runningThreads.Add((new Thread(new ThreadStart(t)))); diff --git a/www/img/edit.png b/www/img/edit.png new file mode 100644 index 0000000..0bfecd5 Binary files /dev/null and b/www/img/edit.png differ diff --git a/www/resp.php b/www/resp.php index 9dc6a88..c2501c0 100644 --- a/www/resp.php +++ b/www/resp.php @@ -1,17 +1,57 @@ id] = $cond->friendlyname; + } -$q = mysql_query("SELECT * FROM `conditions`"); -while($cond = mysql_fetch_object($q)) { - $condtypes[$cond->id] = $cond->friendlyname; + $ret = "IF "; + $conds = explode(";",$str); + $conds = array_slice($conds, 0, count($conds)-1); + foreach($conds as $cond) { + $tk = explode(",",$cond); + if(count($tk) > 3) { + for($i = 0; $i < intval($tk[0]); $i++) + $ret .= "("; + if($tk[1] == "1") + $ret .= "not "; + $ret .= "". $condtypes[intval($tk[2])] ." ". $tk[3]; + for($i = 0; $i < intval($tk[4]); $i++) + $ret .= ")"; + $ret .= " "; + } else { + if($tk[0] == 0) $ret .= "AND "; + else if($tk[0] == 1) $ret .= "OR "; + } + } + $ret .= "THEN ". strtolower($resptype) .""; + return $ret; } -if($_POST["resptype"]) { +if($_GET['del']) { + mysql_query("DELETE FROM `responses` WHERE `id`=".$_GET['del']); + header("Location: resp.php"); +} + +if($_POST["editId"]) { $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["if". $i ."param"])) break; + $c .= $_POST['if'.$i.'lpar'].",".$_POST['if'.$i.'not'].",".$_POST['if'.$i.'cond'].",".$_POST['if'.$i.'param'].",".$_POST['if'.$i.'rpar'].";"; + if(isset($_POST["op".$i])) $c .= $_POST["op".$i] .";"; + } + + mysql_query("UPDATE `responses` SET `conditions`='". mysql_real_escape_string($c) ."', `respid`=". $_POST['resptype'] .", `parameters`='". mysql_real_escape_string($_POST['parameters']) ."', `cooldown`=". (($_POST['cdd']==0)?-1:$_POST['cooldown']) ." WHERE `id`=". $_POST['editId']) or die(mysql_error()); + header("Location: resp.php"); +} + +if($_POST["resptype"] && !$_POST["editId"]) { + $c = ""; + for($i=1;;$i++) { + if(!isset($_POST["if". $i ."param"])) break; + $c .= $_POST['if'.$i.'lpar'].",".$_POST['if'.$i.'not'].",".$_POST['if'.$i.'cond'].",".$_POST['if'.$i.'param'].",".$_POST['if'.$i.'rpar'].";"; if(isset($_POST["op".$i])) $c .= $_POST["op".$i] .";"; } @@ -24,6 +64,11 @@ include("header.php");