diff --git a/bot/bot/Bot.cs b/bot/bot/Bot.cs
index a5240ee..16e8fd4 100644
--- a/bot/bot/Bot.cs
+++ b/bot/bot/Bot.cs
@@ -19,11 +19,11 @@ namespace bot {
static List indResponseList = new List();
public static void loadNavigationList() {
- navigationList = new List();
+ List tmpList = new List();
var tmp = _G.spawnNewConnection();
var r = Query.Reader("SELECT * FROM `navigate`", tmp);
while(r.Read()) {
- navigationList.Add(new NavigationNode(
+ tmpList.Add(new NavigationNode(
r.GetInt32("findtype"),
r.GetString("locator"),
r.GetInt32("action"),
@@ -31,21 +31,23 @@ namespace bot {
}
r.Close();
tmp.Close();
+ navigationList = tmpList;
}
public static void loadResponseList() {
- responseList = new List();
+ List tmpListDep = new List();
+ List tmpListInd = new List();
var tmp = _G.spawnNewConnection();
var r = Query.Reader("SELECT * FROM `responses`", tmp);
while(r.Read()) {
if(!r.GetBoolean("independent"))
- responseList.Add(new Response(
+ tmpListDep.Add(new Response(
r.GetString("conditions"),
r.GetInt32("respid"),
r.GetString("parameters"),
r.GetInt32("cooldown")));
else
- indResponseList.Add(new Response(
+ tmpListInd.Add(new Response(
r.GetString("conditions"),
r.GetInt32("respid"),
r.GetString("parameters"),
@@ -53,6 +55,8 @@ namespace bot {
}
r.Close();
tmp.Close();
+ responseList = tmpListDep;
+ indResponseList = tmpListInd;
}
static void Main(string[] args) {
@@ -112,10 +116,10 @@ namespace bot {
while(Chat.isChatting(_G.driver)) {
Message msg = Chat.waitForNewMessage(_G.driver);
if(msg == null) break;
- if(msg.msg == "!dump") {
+ /*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");
diff --git a/bot/bot/Chat.cs b/bot/bot/Chat.cs
index 1b7e2ed..5092698 100644
--- a/bot/bot/Chat.cs
+++ b/bot/bot/Chat.cs
@@ -96,7 +96,12 @@ namespace bot {
} catch(Exception err) { }
}
Console.WriteLine(msg);
- return new Message(msg.Substring(0, msg.IndexOf(':')), msg.Substring(msg.IndexOf(':') + 2));
+
+ try {
+ return new Message(msg.Substring(0, msg.IndexOf(':')), msg.Substring(msg.IndexOf(':') + 2));
+ } catch(Exception err) {
+ return new Message("","");
+ }
} else return null;
}
}
diff --git a/bot/bot/Pulse.cs b/bot/bot/Pulse.cs
index 527ea60..86e0f96 100644
--- a/bot/bot/Pulse.cs
+++ b/bot/bot/Pulse.cs
@@ -6,6 +6,8 @@ using System.Threading.Tasks;
namespace bot {
class Pulse {
+ public const int pulseTime = 60;
+
public static void updateHeartbeat() {
string beat = _G.getLocalTimeFromUTC().ToString();
Query.Quiet("UPDATE `updater` SET `heartbeat`='" + beat + "' WHERE `id`=1", _G.conn);
@@ -34,7 +36,7 @@ namespace bot {
DateTime t = new DateTime(0);
while(true) {
- if((DateTime.Now - t).TotalSeconds > 30) {
+ if((DateTime.Now - t).TotalSeconds > pulseTime) {
updateHeartbeat();
checkUpdates();
t = DateTime.Now;
diff --git a/bot/bot/responses/sendmsg.cs b/bot/bot/responses/sendmsg.cs
index 8aaa3e9..718250e 100644
--- a/bot/bot/responses/sendmsg.cs
+++ b/bot/bot/responses/sendmsg.cs
@@ -4,6 +4,10 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
+using OpenQA.Selenium.Firefox;
+using OpenQA.Selenium;
+using OpenQA.Selenium.Internal;
+using OpenQA.Selenium.Support.UI;
namespace bot.responses {
class sendmsg {
@@ -11,15 +15,20 @@ namespace bot.responses {
static public string[] getInfo() {
return new string[] {typeof(sendmsg).Name, "Send Message",
- "Sends a message or messages. New lines seperate strings, causing the bot to pick one randomly. To break up a string into multiple messages, seperate clauses with the accent grave (`). {0} is replaced by the message sender's name."};
+ "Sends a message or messages. New lines seperate strings, causing the bot to pick one randomly. To break up a string into multiple messages, seperate clauses with the accent grave (`). {0} is replaced by the message sender's name. {1} is replaced by a random user that's logged into the chat."};
}
static public void performOperation(string parameters, Message msg) {
string[] parts = parameters.Split('\n');
string selected = (parts.Length>1)?parts[rng.Next(parts.Length)]:parts[0];
parts = selected.Split('`');
+
+ List onlineUsers = new List();
+ foreach(IWebElement elem in _G.driver.FindElement(By.Id("onlineList")).FindElements(By.XPath("*")))
+ onlineUsers.Add(elem.Text);
+
foreach(string part in parts)
- Chat.sendMessage(String.Format(part,msg.name));
+ Chat.sendMessage(String.Format(part,msg.name,onlineUsers[rng.Next(0,onlineUsers.Count)]));
}
}
}
\ No newline at end of file
diff --git a/sql/structure.sql b/sql/structure.sql
index c490f3b..eab0343 100644
--- a/sql/structure.sql
+++ b/sql/structure.sql
@@ -1 +1,97 @@
-TODO: EXPORT SQL
\ No newline at end of file
+SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8 */;
+
+
+CREATE TABLE IF NOT EXISTS `admin` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `username` varchar(20) NOT NULL DEFAULT 'admin',
+ `password` varchar(256) NOT NULL DEFAULT '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918',
+ `accountaccess` tinyint(1) NOT NULL DEFAULT '1',
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+CREATE TABLE IF NOT EXISTS `autonomous` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `startday` int(11) NOT NULL DEFAULT '-1',
+ `starttime` bigint(20) NOT NULL DEFAULT '-1',
+ `periodicity` bigint(20) NOT NULL DEFAULT '1440',
+ `randomness` bigint(20) NOT NULL DEFAULT '0',
+ `respid` int(11) NOT NULL,
+ `parameters` longtext NOT NULL,
+ `autolink` int(11) NOT NULL DEFAULT '-1',
+ `linkrespond` tinyint(1) NOT NULL DEFAULT '1',
+ `timeout` bigint(20) NOT NULL,
+ `torandomness` bigint(20) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+CREATE TABLE IF NOT EXISTS `conditions` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(255) NOT NULL,
+ `friendlyname` varchar(255) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+CREATE TABLE IF NOT EXISTS `config` (
+ `id` int(11) NOT NULL DEFAULT '1',
+ `cooldown` bigint(20) NOT NULL DEFAULT '300',
+ `parsechatbot` tinyint(1) NOT NULL DEFAULT '0',
+ `username` varchar(256) NOT NULL DEFAULT 'BOTMAN360',
+ `name` varchar(256) NOT NULL DEFAULT 'AJAX Bot',
+ `timezone` varchar(6) NOT NULL DEFAULT '+00:00',
+ `dst` tinyint(1) NOT NULL DEFAULT '0',
+ `buffersize` int(11) NOT NULL DEFAULT '50',
+ UNIQUE KEY `id` (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+CREATE TABLE IF NOT EXISTS `error` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `time` varchar(128) NOT NULL,
+ `msg` longtext NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+CREATE TABLE IF NOT EXISTS `navigate` (
+ `id` int(20) NOT NULL AUTO_INCREMENT,
+ `findtype` int(11) NOT NULL,
+ `locator` varchar(256) NOT NULL,
+ `action` int(11) NOT NULL,
+ `parameter` longtext NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+CREATE TABLE IF NOT EXISTS `responses` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `conditions` longtext NOT NULL,
+ `respid` int(11) NOT NULL,
+ `parameters` longtext,
+ `cooldown` bigint(20) NOT NULL DEFAULT '-1',
+ `independent` tinyint(1) NOT NULL DEFAULT '0',
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+CREATE TABLE IF NOT EXISTS `resptypes` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(255) NOT NULL,
+ `friendlyname` varchar(255) NOT NULL,
+ `description` longtext NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `name` (`name`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+CREATE TABLE IF NOT EXISTS `updater` (
+ `id` int(11) NOT NULL DEFAULT '1',
+ `heartbeat` varchar(128) NOT NULL DEFAULT '0',
+ `responses` tinyint(1) NOT NULL DEFAULT '0',
+ `autonomous` tinyint(1) NOT NULL DEFAULT '0',
+ `config` tinyint(1) NOT NULL DEFAULT '0',
+ UNIQUE KEY `id` (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+INSERT INTO `admin` () VALUES ()
+INSERT INTO `config` () VALUES ()
+INSERT INTO `updater` () VALUES ()
\ No newline at end of file
diff --git a/www/auto.php b/www/auto.php
index cb4628c..3c01a13 100644
--- a/www/auto.php
+++ b/www/auto.php
@@ -106,11 +106,13 @@ include("header.php");
?>
- then
+ On trigger,