diff --git a/.gitignore b/.gitignore index e662e97..e6f5bf4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ ## Temporary Exclusions ################# conn.php +_G.cs .idea/ ################# diff --git a/bot/bot/Bot.cs b/bot/bot/Bot.cs new file mode 100644 index 0000000..53dac8d --- /dev/null +++ b/bot/bot/Bot.cs @@ -0,0 +1,33 @@ +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; +using SuperSocket; +using SuperSocket.SocketBase; +using SuperWebSocket; +using MySql.Data.MySqlClient; +using System.Threading; + +namespace bot { + class Bot { + public static MySqlConnection conn; + + static void Main(string[] args) { + conn = new MySqlConnection("SERVER="+ _G.serveraddr +";DATABASE="+ _G.dbname +";UID="+ _G.dbuser +";PASSWORD="+ _G.dbpass +";"); + conn.Open(); + + foreach(Type t in ResponseCaller.getResponseTypes()) { + string[] typeInfo = (string[])t.GetMethod("getInfo").Invoke(null, null); + try { (new MySqlCommand("UPDATE `resptypes` SET friendlyname='" + typeInfo[1].Replace("'", "\\'") + "',description='" + typeInfo[2].Replace("'", "\\'") + "' WHERE name='" + typeInfo[0] + "'", conn)).ExecuteNonQuery(); } catch(Exception e) { } + try { (new MySqlCommand("INSERT INTO `resptypes` (name,friendlyname,description) VALUES ('" + typeInfo[0] + "','" + typeInfo[1].Replace("'", "\\'") + "','" + typeInfo[2].Replace("'", "\\'") + "')", conn)).ExecuteNonQuery(); } catch(Exception e) { } + } + + + } + } +} diff --git a/bot/bot/Main.cs b/bot/bot/Condition.cs similarity index 56% rename from bot/bot/Main.cs rename to bot/bot/Condition.cs index 574a70a..cc3ebd6 100644 --- a/bot/bot/Main.cs +++ b/bot/bot/Condition.cs @@ -3,13 +3,10 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Reflection; -namespace bot -{ - class Main - { - static void Main(string[] args) - { - } +namespace bot { + class Condition { + } } diff --git a/bot/bot/Message.cs b/bot/bot/Message.cs new file mode 100644 index 0000000..6b245bf --- /dev/null +++ b/bot/bot/Message.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bot { + class Message { + public string name; + public string msg; + + public Message(String name, String msg) { + this.name = name; + this.msg = msg; + } + } +} diff --git a/bot/bot/Query.cs b/bot/bot/Query.cs new file mode 100644 index 0000000..4795fe6 --- /dev/null +++ b/bot/bot/Query.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MySql.Data.MySqlClient; + +namespace bot { + static class Query { + static object Scalar(string query, MySqlConnection conn) { + return (new MySqlCommand(query, conn)).ExecuteScalar(); + } + + static void Quiet(string query, MySqlConnection conn) { + (new MySqlCommand(query, conn)).ExecuteNonQuery(); + } + + static MySqlDataReader Reader(string query, MySqlConnection conn) { + // TODO write this + } + } +} diff --git a/bot/bot/Response.cs b/bot/bot/Response.cs new file mode 100644 index 0000000..f09111c --- /dev/null +++ b/bot/bot/Response.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Reflection; +using MySql.Data.MySqlClient; + +namespace bot { + class Response { + public string conditions; + public Type responseType; + public string parameters; + public int cooldown; + public int lastCall; + + public Response(string conditions, string responseType, string parameters, int cooldown) { + this.conditions = 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]; + this.parameters = parameters; + this.cooldown = cooldown; + this.lastCall = 0; + } + + public Response(string conditions, int responseId, string parameters, int cooldown) { + this.conditions = conditions; + string typeName = (string)(new MySqlCommand("SELECT `name` FROM `resptypes` WHERE `id`=" + responseId, Bot.conn)).ExecuteScalar(); + this.responseType = Assembly.GetExecutingAssembly().GetTypes().Where(t => String.Equals(t.Namespace, "bot.responses", StringComparison.Ordinal) && String.Equals(t.Name, typeName, StringComparison.Ordinal)).ToArray()[0]; + this.parameters = parameters; + this.cooldown = cooldown; + this.lastCall = 0; + } + } +} diff --git a/bot/bot/ResponseCaller.cs b/bot/bot/ResponseCaller.cs new file mode 100644 index 0000000..a09bebf --- /dev/null +++ b/bot/bot/ResponseCaller.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Reflection; + +namespace bot { + static class ResponseCaller { + static Type[] responseTypes = null; + + static void loadResponseTypes() { + if(responseTypes == null) + responseTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => String.Equals(t.Namespace, "bot.responses", StringComparison.Ordinal)).ToArray(); + } + + public static void callResponse(String responseName) { + loadResponseTypes(); + //responseTypes[0].GetMethod("test").Invoke(null, ""); + } + + public static Type[] getResponseTypes() { + loadResponseTypes(); + return responseTypes; + } + } +} diff --git a/bot/bot/_GG.cs b/bot/bot/_GG.cs new file mode 100644 index 0000000..70b7100 --- /dev/null +++ b/bot/bot/_GG.cs @@ -0,0 +1,18 @@ +/* + * MODIFY THIS FILE TO FIT YOUR SERVER'S CONFIGURATION! + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bot { + static class _GG { + const string serveraddr = "ADDR"; + const string dbuser = "NAME"; + const string dbpass = "PWD"; + const string dbname = "DATABASE_NAME"; + } +} diff --git a/bot/bot/bot.csproj b/bot/bot/bot.csproj index 2b027db..74d6944 100644 --- a/bot/bot/bot.csproj +++ b/bot/bot/bot.csproj @@ -32,6 +32,45 @@ 4 + + dll\log4net.dll + + + dll\Microsoft.Scripting.dll + + + dll\MySql.Data.dll + + + dll\MySql.Data.Entity.EF5.dll + + + dll\MySql.Data.Entity.EF6.dll + + + dll\MySql.Web.dll + + + dll\Selenium.WebDriverBackedSelenium.dll + + + dll\SuperSocket.Common.dll + + + dll\SuperSocket.Dlr.dll + + + dll\SuperSocket.Facility.dll + + + dll\SuperSocket.SocketBase.dll + + + dll\SuperSocket.SocketEngine.dll + + + dll\SuperWebSocket.dll + @@ -39,14 +78,36 @@ + + dll\ThoughtWorks.Selenium.Core.dll + + + dll\WebDriver.dll + + + dll\WebDriver.Support.dll + - + + + + + + + + + + + + + +