From 76b334be3e564807e6cb81b480c14bc2a276fbd2 Mon Sep 17 00:00:00 2001 From: MallocNull Date: Mon, 21 Jul 2014 16:04:58 -0500 Subject: [PATCH] thing e --- bot/bot/Autonomous.cs | 10 ++++++++++ bot/bot/Bot.cs | 31 ++++++++++++++++++++++--------- bot/bot/Response.cs | 4 ++-- www/resp.php | 18 +++++++++++++++--- 4 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 bot/bot/Autonomous.cs diff --git a/bot/bot/Autonomous.cs b/bot/bot/Autonomous.cs new file mode 100644 index 0000000..e1391ce --- /dev/null +++ b/bot/bot/Autonomous.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bot { + class Autonomous { + } +} diff --git a/bot/bot/Bot.cs b/bot/bot/Bot.cs index fb718b2..93898ca 100644 --- a/bot/bot/Bot.cs +++ b/bot/bot/Bot.cs @@ -16,6 +16,7 @@ namespace bot { static List navigationList = new List(); static List responseList = new List(); + static List indResponseList = new List(); public static void loadNavigationList() { navigationList = new List(); @@ -35,15 +36,20 @@ namespace bot { public static void loadResponseList() { responseList = new List(); var tmp = _G.spawnNewConnection(); - var r = Query.Reader("SELECT * FROM `responses`", tmp); + var r = Query.Reader("SELECT * FROM `responses` WHERE", tmp); while(r.Read()) { - responseList.Add(new Response( - r.GetString("conditions"), - r.GetInt32("respid"), - r.GetString("parameters"), - r.GetInt32("cooldown"))); - bool value = responseList.Last().conditions.calculateValue(new Message("guy", "the time is nigh to say nicenight")); - value = !value; + if(!r.GetBoolean("independent")) + responseList.Add(new Response( + r.GetString("conditions"), + r.GetInt32("respid"), + r.GetString("parameters"), + r.GetInt32("cooldown"))); + else + indResponseList.Add(new Response( + r.GetString("conditions"), + r.GetInt32("respid"), + r.GetString("parameters"), + r.GetInt32("cooldown"))); } r.Close(); tmp.Close(); @@ -115,9 +121,16 @@ namespace bot { Chat.sendMessage("response 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; + if(response.triggerResponse(msg)) { + lastAction = DateTime.Now; + break; + } } } } diff --git a/bot/bot/Response.cs b/bot/bot/Response.cs index 6cd63b8..c29af2f 100644 --- a/bot/bot/Response.cs +++ b/bot/bot/Response.cs @@ -15,7 +15,7 @@ namespace bot { public int cooldown; public DateTime lastCall; - public Response(string conditions, string responseType, string parameters, int cooldown) { + public Response(string conditions, string responseType, string parameters, int cooldown, bool independent = false) { this.conditions = new ConditionHolder(conditions); this.condstr = 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]; @@ -24,7 +24,7 @@ namespace bot { this.lastCall = new DateTime(0); } - public Response(string conditions, int responseId, string parameters, int cooldown) { + public Response(string conditions, int responseId, string parameters, int cooldown, bool independent = false) { this.conditions = new ConditionHolder(conditions); this.condstr = conditions; string typeName = (string)(new MySqlCommand("SELECT `name` FROM `resptypes` WHERE `id`=" + responseId, _G.conn)).ExecuteScalar(); diff --git a/www/resp.php b/www/resp.php index 2ffd789..290b782 100644 --- a/www/resp.php +++ b/www/resp.php @@ -43,7 +43,7 @@ if($_POST["editId"]) { 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()); + 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']) .", `independent`=". $_POST['indie'] ." WHERE `id`=". $_POST['editId']) or die(mysql_error()); mysql_query("UPDATE `updater` SET `responses`=1 WHERE `id`=1"); header("Location: resp.php"); } @@ -56,7 +56,7 @@ if($_POST["resptype"] && !$_POST["editId"]) { 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()); + mysql_query("INSERT INTO `responses` (`conditions`,`respid`,`parameters`,`cooldown`,`independent`) VALUES ('". mysql_real_escape_string($c) ."',". $_POST['resptype'] .",'". mysql_real_escape_string($_POST['parameters']) ."',". (($_POST['ccd']==0)?-1:$_POST['cooldown']) .",". $_POST['indie'] .")") or die(mysql_error()); mysql_query("UPDATE `updater` SET `responses`=1 WHERE `id`=1"); header("Location: resp.php"); } @@ -78,9 +78,13 @@ include("header.php"); function coolChange() { if(document.getElementById("cdd").selectedIndex == 0) { document.getElementById("cooldown").disabled = true; + document.getElementById("indie").disabled = true; document.getElementById("cooldown").value = defaultCool; - } else + document.getElementById("indie").selectedIndex = 0; + } else { document.getElementById("cooldown").disabled = false; + document.getElementById("indie").disabled = false; + } } function redrawList() { @@ -367,6 +371,10 @@ include("header.php"); seconds +

@@ -504,6 +512,10 @@ include("header.php"); cooldown == -1) { ?> disabled="disabled" /> seconds +