democracy

norway sucks a cock
This commit is contained in:
MallocNull 2014-10-19 15:57:05 -05:00
parent e8b72fbdf8
commit ce4e171db2
8 changed files with 87 additions and 19 deletions

View file

@ -80,12 +80,16 @@ namespace bot {
Console.Write("Updating response types on database ... ");
tmp = "DELETE FROM resptypes WHERE ";
foreach(Type t in ResponseCaller.getResponseTypes()) {
string[] typeInfo = (string[])t.GetMethod("getInfo").Invoke(null, null);
tmp += "name<>'" + typeInfo[0] + "' AND ";
if((Int64)Query.Scalar("SELECT COUNT(*) FROM `resptypes` WHERE `name`='" + typeInfo[0] + "'", _G.conn) > 0)
Query.Quiet("UPDATE `resptypes` SET friendlyname='" + Sanitizer.Sanitize(typeInfo[1]) + "',description='" + Sanitizer.Sanitize(typeInfo[2]) + "' WHERE name='" + typeInfo[0] + "'", _G.conn);
else
Query.Quiet("INSERT INTO `resptypes` (name,friendlyname,description) VALUES ('" + typeInfo[0] + "','" + Sanitizer.Sanitize(typeInfo[1]) + "','" + Sanitizer.Sanitize(typeInfo[2]) + "')", _G.conn);
try {
string[] typeInfo = (string[])t.GetMethod("getInfo").Invoke(null, null);
tmp += "name<>'" + typeInfo[0] + "' AND ";
if((Int64)Query.Scalar("SELECT COUNT(*) FROM `resptypes` WHERE `name`='" + typeInfo[0] + "'", _G.conn) > 0)
Query.Quiet("UPDATE `resptypes` SET friendlyname='" + Sanitizer.Sanitize(typeInfo[1]) + "',description='" + Sanitizer.Sanitize(typeInfo[2]) + "' WHERE name='" + typeInfo[0] + "'", _G.conn);
else
Query.Quiet("INSERT INTO `resptypes` (name,friendlyname,description) VALUES ('" + typeInfo[0] + "','" + Sanitizer.Sanitize(typeInfo[1]) + "','" + Sanitizer.Sanitize(typeInfo[2]) + "')", _G.conn);
} catch(Exception e) {
_G.criticalError("Response type found in database does not match compiled response types! Update program.");
}
}
tmp = tmp.Substring(0, tmp.Length - 5);
Query.Quiet(tmp, _G.conn);
@ -94,12 +98,16 @@ namespace bot {
Console.Write("Updating conditions on database ... ");
tmp = "DELETE FROM conditions WHERE ";
foreach(Type t in ConditionChecker.getConditions()) {
string[] typeInfo = (string[])t.GetMethod("getInfo").Invoke(null, null);
tmp += "name<>'" + typeInfo[0] + "' AND ";
if((Int64)Query.Scalar("SELECT COUNT(*) FROM `conditions` WHERE `name`='" + typeInfo[0] + "'", _G.conn) > 0)
Query.Quiet("UPDATE `conditions` SET friendlyname='" + Sanitizer.Sanitize(typeInfo[1]) + "' WHERE name='" + typeInfo[0] + "'", _G.conn);
else
Query.Quiet("INSERT INTO `conditions` (name,friendlyname) VALUES ('" + typeInfo[0] + "','" + Sanitizer.Sanitize(typeInfo[1]) + "')", _G.conn);
try {
string[] typeInfo = (string[])t.GetMethod("getInfo").Invoke(null, null);
tmp += "name<>'" + typeInfo[0] + "' AND ";
if((Int64)Query.Scalar("SELECT COUNT(*) FROM `conditions` WHERE `name`='" + typeInfo[0] + "'", _G.conn) > 0)
Query.Quiet("UPDATE `conditions` SET friendlyname='" + Sanitizer.Sanitize(typeInfo[1]) + "' WHERE name='" + typeInfo[0] + "'", _G.conn);
else
Query.Quiet("INSERT INTO `conditions` (name,friendlyname) VALUES ('" + typeInfo[0] + "','" + Sanitizer.Sanitize(typeInfo[1]) + "')", _G.conn);
} catch(Exception e) {
_G.criticalError("Condition found in database does not match compiled conditions! Update program.");
}
}
tmp = tmp.Substring(0, tmp.Length - 5);
Query.Quiet(tmp, _G.conn);
@ -134,10 +142,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");

View file

@ -20,8 +20,8 @@ namespace bot {
List<IWebElement> chatdata = d.FindElement(By.Id("chatList")).FindElements(By.TagName("div")).ToList();
messageDivSize = chatdata.Count;
foreach(IWebElement we in chatdata) {
if(Int32.Parse(we.GetAttribute("id").Substring(11)) > currentMessage)
currentMessage = Int32.Parse(we.GetAttribute("id").Substring(11));
if(Int32.Parse(we.GetAttribute("id").Substring(we.GetAttribute("id").LastIndexOf('_') + 1)) > currentMessage)
currentMessage = Int32.Parse(we.GetAttribute("id").Substring(we.GetAttribute("id").LastIndexOf('_') + 1));
}
if(d.FindElement(By.Id("audioButton")).GetAttribute("class").ToLower() == "button")
d.FindElement(By.Id("audioButton")).Click();
@ -74,7 +74,7 @@ namespace bot {
List<IWebElement> chatdata = d.FindElement(By.Id("chatList")).FindElements(By.TagName("div")).ToList();
bool found = false;
foreach(IWebElement we in chatdata) {
int nodeID = Int32.Parse(we.GetAttribute("id").Substring(11));
int nodeID = Int32.Parse(we.GetAttribute("id").Substring(we.GetAttribute("id").LastIndexOf('_') + 1));
if(nodeID > currentMessage) {
currentMessage = nodeID;
found = true;

View file

@ -89,6 +89,7 @@
<Compile Include="responses\jumble.cs" />
<Compile Include="responses\poker.cs" />
<Compile Include="responses\replace.cs" />
<Compile Include="responses\vote.cs" />
<Compile Include="Sanitizer.cs" />
<Compile Include="_G.cs" />
<Compile Include="Message.cs" />
@ -101,8 +102,12 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="dbinfo.txt" />
<Content Include="dbinfo_generic.txt" />
<Content Include="dbinfo.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="dbinfo_generic.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

Binary file not shown.

Binary file not shown.

55
bot/bot/responses/vote.cs Normal file
View file

@ -0,0 +1,55 @@
using System;
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;
namespace bot.responses {
class vote {
static private Random rng = new Random();
static public string[] getInfo() {
return new string[] {typeof(vote).Name, "Call Vote",
"Calls a vote in the chat."};
}
static private bool voteCalled = false;
static private DateTime voteStarted = DateTime.Now;
static private List<string> voters = new List<string>();
static private string param = "";
static public void performOperation(string parameters, Message msg) {
string[] pars = parameters.Split('\n');
if(msg.msg.ToLower() != "!vote") {
if(!voteCalled || (DateTime.Now - voteStarted).TotalSeconds > 120) {
voters.Clear();
voteCalled = true;
param = msg.msg.Split(' ')[1];
voteStarted = DateTime.Now;
Chat.sendMessage(pars[0]);
}
} else {
Console.WriteLine((DateTime.Now - voteStarted).TotalSeconds);
if(voteCalled && (DateTime.Now - voteStarted).TotalSeconds < 120 && !voters.Contains(msg.name)) {
voters.Add(msg.name);
int people = _G.driver.FindElement(By.Id("onlineList")).FindElements(By.XPath("*")).Count;
if(voters.Count >= people / 3) {
Chat.sendMessage(String.Format(pars[1], param));
Chat.sendMessage(String.Format(pars[2], param));
} else
Chat.sendMessage(voters.Count + "/" + people / 3 + " votes recorded.");
} else {
if(voteCalled && (DateTime.Now - voteStarted).TotalSeconds > 120) {
Chat.sendMessage("Vote has expired!");
voteCalled = false;
}
}
}
}
}
}