night of autonomous

never program at 4 am
This commit is contained in:
MallocNull 2014-11-08 04:19:55 -06:00
parent 3f26ec1d73
commit d32353a38f
11 changed files with 484 additions and 77 deletions

View file

@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bot", "bot\bot.csproj", "{1E318685-BF0A-4508-AE47-76C7442994D7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "responses", "responses\responses.csproj", "{5CC66C93-279D-4E00-9FE1-FAFF54FC4D6F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -13,6 +15,10 @@ Global
{1E318685-BF0A-4508-AE47-76C7442994D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E318685-BF0A-4508-AE47-76C7442994D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E318685-BF0A-4508-AE47-76C7442994D7}.Release|Any CPU.Build.0 = Release|Any CPU
{5CC66C93-279D-4E00-9FE1-FAFF54FC4D6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5CC66C93-279D-4E00-9FE1-FAFF54FC4D6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5CC66C93-279D-4E00-9FE1-FAFF54FC4D6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5CC66C93-279D-4E00-9FE1-FAFF54FC4D6F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -3,9 +3,126 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using MySql.Data.MySqlClient;
namespace bot {
class Autonomous {
public int id;
public string name;
public int startDay;
public int[] startTime;
public int periodicity;
public int randomness;
public Type responseType;
public string parameters;
public DateTime nextTrigger = new DateTime(0);
public DateTime linkTrigger = new DateTime(0);
public int autolinkid;
public Autonomous autolink;
public bool linkrespond;
public int timeout;
public int torandomness;
public Random rng = new Random();
public Autonomous(int id, string name, int startDay, int[] startTime, int periodicity, int randomness,
string responseType, string parameters,
int autolinkid, bool linkrespond, int timeout, int torandomness) {
this.id = id;
this.name = name;
this.startDay = startDay;
this.startTime = startTime;
this.periodicity = periodicity;
this.randomness = randomness;
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.autolinkid = autolinkid;
this.linkrespond = linkrespond;
this.timeout = timeout;
this.torandomness = torandomness;
CalculateNextTrigger();
}
public Autonomous(int id, string name, int startDay, int[] startTime, int periodicity, int randomness,
int responseId, string parameters,
int autolinkid, bool linkrespond, int timeout, int torandomness) {
this.id = id;
this.name = name;
this.startDay = startDay;
this.startTime = startTime;
this.periodicity = periodicity;
this.randomness = randomness;
string responseType = (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, responseType, StringComparison.Ordinal)).ToArray()[0];
this.parameters = parameters;
this.autolinkid = autolinkid;
this.linkrespond = linkrespond;
this.timeout = timeout;
this.torandomness = torandomness;
CalculateNextTrigger();
}
public void triggerRoutine(bool force = false) {
if(_G.getLocalTimeFromUTC() > nextTrigger || force) {
ResponseCaller.callResponse(responseType, parameters, new Message("null","null"));
CalculateNextTrigger();
if(autolinkid != -1) {
linkTrigger = _G.getLocalTimeFromUTC().AddSeconds(timeout + (rng.Next(2) == 0 ? 1 : -1) * rng.Next(torandomness));
Bot.ignoreResponses = linkrespond;
}
} else if(_G.getLocalTimeFromUTC() > linkTrigger && linkTrigger != new DateTime(0)) {
autolink.triggerRoutine(true);
linkTrigger = new DateTime(0);
Bot.ignoreResponses = false;
}
}
public void CalculateNextTrigger() {
DateTime now = _G.getLocalTimeFromUTC();
if(nextTrigger == new DateTime(0)) {
if(startDay == -2)
nextTrigger = now.AddSeconds(periodicity + (rng.Next(2) == 0 ? 1 : -1) * rng.Next(randomness));
else if(startDay == -1) {
if(startTime[0] == -1)
nextTrigger = now;
else {
if(now.Hour < startTime[0] || (now.Hour == startTime[0] && now.Minute < startTime[1]))
nextTrigger = new DateTime(now.Year, now.Month, now.Day, startTime[0], startTime[1], 0);
else {
DateTime tomorrow = now.AddDays(1);
nextTrigger = new DateTime(tomorrow.Year, tomorrow.Month, tomorrow.Day, startTime[0], startTime[1], 0);
}
}
} else if(startDay == -999)
nextTrigger = now.AddYears(1000);
else {
DateTime tmp;
if((int)now.DayOfWeek == startDay - 1) {
if(now.Hour < startTime[0] || (now.Hour == startTime[0] && now.Minute < startTime[1]))
nextTrigger = new DateTime(now.Year, now.Month, now.Day, startTime[0], startTime[1], 0);
else {
tmp = now.AddDays(7);
nextTrigger = new DateTime(tmp.Year, tmp.Month, tmp.Day, startTime[0], startTime[1], 0);
}
} else {
int adder = (startDay - 1) - (int)now.DayOfWeek;
tmp = now.AddDays(adder);
if(adder < 0) tmp.AddDays(7);
nextTrigger = new DateTime(tmp.Year, tmp.Month, tmp.Day, startTime[0], startTime[1], 0);
}
}
} else if(startDay != -999)
nextTrigger = now.AddSeconds(periodicity + (rng.Next(2) == 0 ? 1 : -1) * rng.Next(randomness));
}
}
}

View file

@ -19,6 +19,20 @@ namespace bot {
static List<Response> indResponseList = new List<Response>();
static List<Autonomous> autoList = new List<Autonomous>();
public static bool ignoreResponses = false;
public static void AutonomousThread() {
while(true) {
try {
foreach(Autonomous auto in autoList) {
auto.triggerRoutine();
}
} catch(Exception e) {
// catch this at some point
}
}
}
public static void loadNavigationList() {
List<NavigationNode> tmpList = new List<NavigationNode>();
var tmp = _G.spawnNewConnection();
@ -61,7 +75,39 @@ namespace bot {
}
public static void loadAutonomousList() {
List<Autonomous> tmpList = new List<Autonomous>();
var tmp = _G.spawnNewConnection();
var r = Query.Reader("SELECT * FROM `autonomous`", tmp);
while(r.Read()) {
tmpList.Add(new Autonomous(
r.GetInt32("id"),
r.GetString("name"),
r.GetInt32("startday"),
new int[] { Int32.Parse(r.GetString("starttime").Split(',')[0]), Int32.Parse(r.GetString("starttime").Split(',')[1]) },
r.GetInt32("periodicity"),
r.GetInt32("randomness"),
r.GetInt32("respid"),
r.GetString("parameters"),
r.GetInt32("autolink"),
!r.GetBoolean("linkrespond"),
r.GetInt32("timeout"),
r.GetInt32("torandomness")));
}
r.Close();
tmp.Close();
autoList = tmpList;
// TODO improve this later
foreach(Autonomous auto in autoList) {
if(auto.autolinkid != -1) {
foreach(Autonomous autoauto in autoList) {
if(auto.autolinkid == autoauto.id) {
auto.autolink = autoauto;
break;
}
}
}
}
}
static void Main(string[] args) {
@ -82,6 +128,10 @@ namespace bot {
loadResponseList();
Console.WriteLine("OK");
Console.Write("Loading autonomous routine list ...");
loadAutonomousList();
Console.WriteLine("OK");
Console.Write("Updating response types on database ... ");
tmp = "DELETE FROM resptypes WHERE ";
foreach(Type t in ResponseCaller.getResponseTypes()) {
@ -136,35 +186,39 @@ namespace bot {
_G.startThread(Pulse.pulseThread);
// TODO add autonomous thread start
Chat.reloadContext(_G.driver);
(new Thread(new ThreadStart(Bot.AutonomousThread))).Start();
Console.WriteLine(_G.propername + " has started successfully.");
DateTime lastAction = new DateTime(0);
while(Chat.isChatting(_G.driver)) {
Message msg = Chat.waitForNewMessage(_G.driver);
if(msg == null) break;
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");
}
if(!ignoreResponses) {
if(msg == null) break;
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");
Bot.loadAutonomousList();
Chat.sendMessage("autonomous list updated");
}
foreach(Response response in indResponseList) {
if(response.triggerResponse(msg)) break;
}
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;
break;
foreach(Response response in responseList) {
if((DateTime.Now - lastAction).TotalSeconds >= _G.defaultCooldown) {
if(response.triggerResponse(msg)) {
lastAction = DateTime.Now;
break;
}
}
}
}

View file

@ -17,6 +17,8 @@ namespace bot {
static int currentMessage;
public static void reloadContext(FirefoxDriver d) {
while(!ProtectionContext.Protect()) ;
Console.WriteLine("reloading context");
while(true) {
try {
@ -35,19 +37,26 @@ namespace bot {
Console.WriteLine("reloading context complete");
if(d.FindElement(By.Id("audioButton")).GetAttribute("class").ToLower() == "button")
d.FindElement(By.Id("audioButton")).Click();
ProtectionContext.Free();
}
public static void sendMessage(string text) {
sendMessage(text, _G.driver);
public static void sendMessage(string text, bool protect = true) {
sendMessage(text, _G.driver, protect);
}
public static void sendMessage(string text, FirefoxDriver d) {
// TODO protection context corrections
public static void sendMessage(string text, FirefoxDriver d, bool protect = true) {
if(protect)
while(!ProtectionContext.Protect()) ;
if(isChatting(d)) {
d.FindElement(By.Id("inputField")).SendKeys(text);
d.FindElement(By.Id("submitButton")).Click();
try { Thread.Sleep(500); } catch(Exception e) { }
}
if(protect)
ProtectionContext.Free();
}
public static bool isChatting(FirefoxDriver d) {

View file

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bot {
class ProtectionContext {
private static bool isWriteable = true;
private static DateTime timeOfWriteProtection = new DateTime(0);
private static int maxProtectionTime = 45;
public static bool Protect() {
if(isWriteable == true || (DateTime.Now-timeOfWriteProtection).TotalSeconds > maxProtectionTime) {
isWriteable = false;
timeOfWriteProtection = DateTime.Now;
return true;
} else return false;
}
public static void Free() {
isWriteable = true;
}
}
}

View file

@ -87,6 +87,7 @@
<Compile Include="conditions\nameis.cs" />
<Compile Include="conditions\random.cs" />
<Compile Include="NavigationNode.cs" />
<Compile Include="ProtectionContext.cs" />
<Compile Include="Pulse.cs" />
<Compile Include="Query.cs" />
<Compile Include="responses\jumble.cs" />

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace bot.conditions {
@ -11,7 +12,8 @@ namespace bot.conditions {
}
static public bool performCheck(Message msg, string parameter) {
return false; // implement
Regex matcher = new Regex("\\b"+ parameter.ToLower() +"\\b");
return matcher.IsMatch(msg.msg.ToLower());
}
}
}

12
bot/responses/Class1.cs Normal file
View file

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace responses
{
public class Class1
{
}
}

View file

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("responses")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Hewlett-Packard")]
[assembly: AssemblyProduct("responses")]
[assembly: AssemblyCopyright("Copyright © Hewlett-Packard 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("dd73d63c-48bf-4a83-a3db-8f13dc5d70ad")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5CC66C93-279D-4E00-9FE1-FAFF54FC4D6F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>responses</RootNamespace>
<AssemblyName>responses</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -6,17 +6,18 @@ if($_GET['del']) {
}
if($_POST["editId"]) {
// TODO update this
mysql_query("UPDATE `autonomous` 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());
$stime = ($_POST['starttimehour'] == -1 || $_POST['starttimemin'] == -1 || $_POST['startday'] == -2) ? "-1,-1" : $_POST['starttimehour'] .",". $_POST['starttimemin'];
mysql_query("UPDATE `autonomous` SET `name`='". mysql_real_escape_string($_POST['arname']) ."', `startday`=". $_POST['startday'] .", `starttime`='". $stime ."', `periodicity`=". $_POST['period'] .", `randomness`=". $_POST['randomness'] .", `respid`=". $_POST['resptype'] .", `parameters`='". mysql_real_escape_string($_POST['parameters']) ."', `autolink`=". $_POST['autolink'] .", `linkrespond`=". (($_POST["respond"]?"1":"0")) .", `timeout`=". $_POST['timeout'] .", `torandomness`=". $_POST['torandom'] ." WHERE `id`=". $_POST['editId']) or die(mysql_error());
mysql_query("UPDATE `updater` SET `autonomous`=1 WHERE `id`=1");
header("Location: auto.php");
}
if($_POST["resptype"] && !$_POST["editId"]) {
$stime = ($_POST['starttimehour'] == -1 || $_POST['starttimemin'] == -1 || $_POST['startday'] == -2) ? "-1,-1" : $_POST['starttimehour'] .",". $_POST['starttimemin'];
if($_POST["autolink"] == -1)
mysql_query("INSERT INTO `autonomous` (`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 `autonomous` (`name`,`startday`,`starttime`,`periodicity`,`randomness`,`respid`,`parameters`) VALUES ('". mysql_real_escape_string($_POST['arname']) ."',". $_POST['startday'] .",'". $stime ."',". $_POST['period'] .",". $_POST['randomness'] .",". $_POST['resptype'] .",'". mysql_real_escape_string($_POST['parameters']) ."')") or die(mysql_error());
else
// do query
mysql_query("INSERT INTO `autonomous` (`name`,`startday`,`starttime`,`periodicity`,`randomness`,`respid`,`parameters`,`autolink`,`linkrespond`,`timeout`,`torandomness`) VALUES ('". mysql_real_escape_string($_POST['arname']) ."',". $_POST['startday'] .",'". $stime ."',". $_POST['period'] .",". $_POST['randomness'] .",". $_POST['resptype'] .",'". mysql_real_escape_string($_POST['parameters']) ."',". $_POST['autolink'] .",". (($_POST["respond"]?"1":"0")) .",". $_POST['timeout'] .",". $_POST['torandom'] .")") or die(mysql_error());
mysql_query("UPDATE `updater` SET `autonomous`=1 WHERE `id`=1");
header("Location: auto.php");
}
@ -27,7 +28,7 @@ include("header.php");
/*var defaultCool = <?php echo $config->cooldown; ?>;*/
function confirmDeletion(id) {
var q = confirm("Are you sure you want to delete this response?");
var q = confirm("Are you sure you want to delete this autonomous routine?");
if(q) window.location.href = "auto.php?del="+id;
}
@ -51,16 +52,18 @@ include("header.php");
function evaluateCondition() {
if(document.getElementById("arname").value.trim() != "") {
if(doTimeTest("Periodicity",document.getElementById("period").value)) {
if(doTimeTest("Randomness",document.getElementById("randomness").value)) {
if(document.getElementById("autolink").selectedIndex != 0) {
if(doTimeTest("Link timeout",document.getElementById("timeout").value)) {
if(doTimeTest("Link randomness",document.getElementById("torandom").value)) {
document.getElementById("auto").submit();
if(document.getElementById("startday").selectedIndex <= 2 || (document.getElementById("startday").selectedIndex > 2 && document.getElementById("sth").selectedIndex != 0 && document.getElementById("stm").selectedIndex != 0)) {
if(doTimeTest("Periodicity",document.getElementById("period").value)) {
if(doTimeTest("Randomness",document.getElementById("randomness").value,true)) {
if(document.getElementById("autolink").selectedIndex != 0) {
if(doTimeTest("Link timeout",document.getElementById("timeout").value)) {
if(doTimeTest("Link randomness",document.getElementById("torandom").value,true)) {
document.getElementById("auto").submit();
}
}
} else {
document.getElementById("auto").submit();
}
} else {
document.getElementById("auto").submit();
}
}
}
@ -79,6 +82,13 @@ include("header.php");
}
}
function handleStartDayChange() {
if(document.getElementById("startday").selectedIndex > 1)
document.getElementById("stdisp").style.display = "inline";
else
document.getElementById("stdisp").style.display = "none";
}
/*function coolChange() {
if(document.getElementById("cdd").selectedIndex == 0) {
document.getElementById("cooldown").disabled = true;
@ -94,22 +104,21 @@ include("header.php");
<p style="margin-top: 0;"><a href="auto.php?do=new">New Autonomous Routine</a></p>
<center>
<?php
$q = mysql_query("SELECT * FROM `auto`");
// TODO update this
/*while($resp = mysql_fetch_object($q)) {
$q = mysql_query("SELECT * FROM `autonomous` ORDER BY `name`");
while($resp = mysql_fetch_object($q)) {
echo "
<table border='0' style='width:790px;border:1px solid black;margin:5px;'>
<tr>
<td style='width:50px;text-align:center;verticle-align:middle;'>
<a href='resp.php?do=edit&id=". $resp->id ."' style='verticle-align: middle;'><img src='img/edit.png' border='0' /></a>
<a href='auto.php?do=edit&id=". $resp->id ."' style='verticle-align: middle;'><img src='img/edit.png' border='0' /></a>
&nbsp;<img src='img/delete.png' border='0' class='fakelink' onclick='confirmDeletion(". $resp->id .");' />
</td>
<td>
". parseConditionString($resp->conditions, mysql_fetch_object(mysql_query("SELECT * FROM `resptypes` WHERE `id`=". $resp->respid))->friendlyname) ."
". $resp->name ."
</td>
</tr>
</table>";
}*/
}
?>
</center>
<?php } else if($_GET["do"]=="new") { ?>
@ -120,8 +129,10 @@ include("header.php");
</p>
<p>
Trigger first routine on
<select name="startday">
<option value="-1">program start</option>
<select name="startday" id="startday" onchange="handleStartDayChange();">
<option value="-2">after first cooldown</option>
<option value="-999">never</option>
<option value="-1">day of program start</option>
<option value="1">Sunday</option>
<option value="2">Monday</option>
<option value="3">Tuesday</option>
@ -130,17 +141,18 @@ include("header.php");
<option value="6">Friday</option>
<option value="7">Saturday</option>
</select>
<span id="stdisp" style="display: none;">
at
<select name="starttimehour">
<select name="starttimehour" id="sth">
<?php
echo "<option value='-1'></option>";
for($i = 1; $i <= 24; $i++) {
for($i = 0; $i <= 23; $i++) {
echo "<option value='$i'>". (($i<10)?"0":"") ."$i</option>";
}
?>
</select>
:
<select name="starttimehour">
<select name="starttimemin" id="stm">
<?php
echo "<option value='-1'></option>";
for($i = 0; $i <= 59; $i++) {
@ -148,6 +160,7 @@ include("header.php");
}
?>
</select>
</span>
</p>
<p>
After first trigger,
@ -198,7 +211,7 @@ include("header.php");
<td><select name="autolink" id="autolink" onchange="handleAutolinkChange();">
<option value="-1">&nbsp;&nbsp;&nbsp;&nbsp;</option>
<?php
$q = mysql_query("SELECT * FROM `autonomous`");
$q = mysql_query("SELECT * FROM `autonomous` ORDER BY `name`");
while($auto = mysql_fetch_object($q)) {
echo "<option value='". $auto->id ."'>". $auto->name ."</option>";
}
@ -241,29 +254,76 @@ include("header.php");
</p>
</form>
<?php } else if($_GET["do"]=="edit") {
$response = mysql_fetch_object(mysql_query("SELECT * FROM `responses` WHERE `id`=".$_GET['id']));
$autono = mysql_fetch_object(mysql_query("SELECT * FROM `autonomous` WHERE `id`=".$_GET['id']));
?>
<legend>Edit Response</legend>
<form method="post" action="" id="resp">
<legend>Edit Autonomous Routine</legend>
<form method="post" action="" id="auto">
<p>
then
Friendly name: <input type="text" name="arname" id="arname" value="<?php echo escapeDoubleQuotes($autono->name); ?>" /> (for future reference)
</p>
<p>
Trigger first routine on
<select name="startday" id="startday" onchange="handleStartDayChange();">
<option value="-2"<?php if($autono->startday == -2) { ?> selected="selected" <?php } ?>>after first cooldown</option>
<option value="-999"<?php if($autono->startday == -999) { ?> selected="selected" <?php } ?>>never</option>
<option value="-1"<?php if($autono->startday == -1) { ?> selected="selected" <?php } ?>>day of program start</option>
<option value="1"<?php if($autono->startday == 1) { ?> selected="selected" <?php } ?>>Sunday</option>
<option value="2"<?php if($autono->startday == 2) { ?> selected="selected" <?php } ?>>Monday</option>
<option value="3"<?php if($autono->startday == 3) { ?> selected="selected" <?php } ?>>Tuesday</option>
<option value="4"<?php if($autono->startday == 4) { ?> selected="selected" <?php } ?>>Wednesday</option>
<option value="5"<?php if($autono->startday == 5) { ?> selected="selected" <?php } ?>>Thursday</option>
<option value="6"<?php if($autono->startday == 6) { ?> selected="selected" <?php } ?>>Friday</option>
<option value="7"<?php if($autono->startday == 7) { ?> selected="selected" <?php } ?>>Saturday</option>
</select>
<span id="stdisp"<?php if($autono->startday == -2) { ?> style="display: none;"<?php } ?>>
at
<select name="starttimehour" id="sth">
<?php
$explodeTime = explode(",", $autono->starttime);
echo "<option value='-1'". ($explodeTime[0] == "-1"?" selected='selected'":"") ."></option>";
for($i = 0; $i <= 23; $i++) {
echo "<option value='$i'". ($explodeTime[0] == "".$i?" selected='selected'":"") .">". (($i<10)?"0":"") ."$i</option>";
}
?>
</select>
:
<select name="starttimemin" id="stm">
<?php
echo "<option value='-1'". ($explodeTime[1] == "-1"?" selected='selected'":"") ."></option>";
for($i = 0; $i <= 59; $i++) {
echo "<option value='$i'". ($explodeTime[1] == "".$i?" selected='selected'":"") .">". (($i<10)?"0":"") ."$i</option>";
}
?>
</select>
</span>
</p>
<p>
After first trigger,
<table border="0">
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>continue triggering every</td><td></td><td><input type="text" name="period" id="period" value="<?php echo $autono->periodicity; ?>" /> seconds</td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>with a randomness of<td>&plusmn;</td></td><td><input type="text" name="randomness" id="randomness" value="<?php echo $autono->randomness; ?>" /> seconds.</td></tr>
</table>
</p>
<p>
On trigger,
<select name="resptype" id="resptype" onchange="handleRespChange();">
<?php
$q = mysql_query("SELECT * FROM `resptypes`");
$descarr = array();
$descdef = "";
for($i = 0;;$i++) {
$type = mysql_fetch_object($q);
if(!$type) break;
echo "<option value='". $type->id ."'";
if($type->id==$response->respid)
echo " selected='selected'";
echo ">". $type->friendlyname ."</option>";
if($autono->respid==$type->id) $descdef = $type->description;
echo "<option value='". $type->id ."'". ($autono->respid==$type->id?" selected='selected'":"") .">". $type->friendlyname ."</option>";
$descarr[$i] = $type->description;
}
?>
</select>
<?php
$i = 0;
foreach($descarr as $desc) {
echo "<p style='display:none;' id='$i'>". $desc ."</p>";
$i++;
@ -272,34 +332,66 @@ include("header.php");
</p>
<p>
<span class="block" id="respDesc">
<?php
echo $d = mysql_fetch_object(mysql_query("SELECT * FROM `resptypes` WHERE `id`=". $response->respid))->description;
?>
</span>
<span class="block">Parameters:
<center>
<textarea name="parameters" rows="8" style="width:95%;"><?php echo $response->parameters; ?></textarea>
</center>
<?php echo $descdef; ?>
</span>
<span class="block">Parameters:
<center>
<textarea name="parameters" rows="8" style="width:95%;"><?php echo $autono->parameters; ?></textarea>
</center></span>
</p>
<p>
Cooldown:
<select name="cdd" id="cdd" onchange="coolChange();">
<option value="0">Default</option>
<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
After triggering,
<table border="0" id="linktable">
<tr>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>Force routine to trigger</td>
<td></td>
<td><select name="autolink" id="autolink" onchange="handleAutolinkChange();">
<option value="-1"<?php if($autono->autolink == -1) { ?> selected="selected" <?php } ?>>&nbsp;&nbsp;&nbsp;&nbsp;</option>
<?php
$q = mysql_query("SELECT * FROM `autonomous` ORDER BY `name`");
while($auto = mysql_fetch_object($q)) {
echo "<option value='". $auto->id ."'". ($autono->autolink == $auto->id?"selected='selected'":"") .">". $auto->name ."</option>";
}
?>
</select></td>
</tr>
<tr<?php if($autono->autolink == -1) { ?> style="display: none;"<?php } ?>>
<td></td>
<td>after</td>
<td></td>
<td>
<input type="text" name="timeout" id="timeout" value="<?php echo $autono->timeout; ?>" /> seconds
</td>
</tr>
<tr<?php if($autono->autolink == -1) { ?> style="display: none;"<?php } ?>>
<td></td>
<td>with a randomness of</td>
<td>&plusmn;</td>
<td>
<input type="text" name="torandom" id="torandom" value="<?php echo $autono->torandomness; ?>" /> seconds.
</td>
</tr>
<tr<?php if($autono->autolink == -1) { ?> style="display: none;"<?php } ?>>
<td></td>
<td>While waiting to trigger, </td>
<td></td>
<td>
<select name="respond" id="respond">
<option value="0"<?php if($autono->linkrespond == 0) { ?> selected="selected" <?php } ?>>do not respond to messages</option>
<option value="1"<?php if($autono->linkrespond == 1) { ?> selected="selected" <?php } ?>>do respond to messages</option>
</select>.
</td>
</tr>
</table>
</p>
<p>
<input type="button" name="editResponse" value="Edit Response" onclick="evaluateCondition();" />
<input type="button" name="editResponse" value="Edit Autonomous Routine" onclick="evaluateCondition();" />
<input type="hidden" name="editId" value="<?php echo $_GET['id']; ?>" />
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" value="Cancel" onclick="window.location.href = 'resp.php';" />
<input type="button" value="Cancel" onclick="window.location.href = 'auto.php';" />
</p>
</form>
<script type="text/javascript">
redrawList();
</script>
<?php } ?>
</fieldset>
</center>