e
This commit is contained in:
MallocNull 2014-07-21 16:04:58 -05:00
parent 32d4fc69fc
commit 76b334be3e
4 changed files with 49 additions and 14 deletions

10
bot/bot/Autonomous.cs Normal file
View file

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bot {
class Autonomous {
}
}

View file

@ -16,6 +16,7 @@ namespace bot {
static List<NavigationNode> navigationList = new List<NavigationNode>();
static List<Response> responseList = new List<Response>();
static List<Response> indResponseList = new List<Response>();
public static void loadNavigationList() {
navigationList = new List<NavigationNode>();
@ -35,15 +36,20 @@ namespace bot {
public static void loadResponseList() {
responseList = new List<Response>();
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;
}
}
}
}

View file

@ -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();

View file

@ -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");
<option value="1">Custom</option>
</select>
<input type="textbox" name="cooldown" id="cooldown" size="6" value="<?php echo $config->cooldown; ?>" disabled="disabled" /> seconds
<select name="indie" id="indie" disabled="disabled">
<option value="0">dependent on the default cooldown</option>
<option value="1">independent of the default cooldown</option>
</select>
</p>
<p>
<input type="button" name="addResponse" value="Add Response" onclick="evaluateCondition();" />
@ -504,6 +512,10 @@ include("header.php");
<option value="1"<?php if($response->cooldown != -1) { ?> selected="selected"<?php } ?>>Custom</option>
</select>
<input type="textbox" name="cooldown" id="cooldown" size="6" value="<?php if($response->cooldown == -1) echo $config->cooldown; else echo $response->cooldown; ?>"<?php if($response->cooldown == -1) { ?> disabled="disabled"<?php } ?> /> seconds
<select name="indie" id="indie"<?php if($response->cooldown == -1) { ?> disabled="disabled"<?php } ?>>
<option value="0">dependent on the default cooldown</option>
<option value="1"<?php if($response->independent) { ?> selected="selected"<?php } ?>>independent of the default cooldown</option>
</select>
</p>
<p>
<input type="button" name="editResponse" value="Edit Response" onclick="evaluateCondition();" />