base work pt 2
woaher
This commit is contained in:
parent
3f2b5661fa
commit
d1545c00f7
7 changed files with 68 additions and 13 deletions
|
@ -14,20 +14,27 @@ using MySql.Data.MySqlClient;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace bot {
|
namespace bot {
|
||||||
class Bot {
|
class Bot : StringSanitizer {
|
||||||
public static MySqlConnection conn;
|
public static MySqlConnection conn;
|
||||||
|
static string tmp;
|
||||||
|
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
conn = new MySqlConnection("SERVER="+ _G.serveraddr +";DATABASE="+ _G.dbname +";UID="+ _G.dbuser +";PASSWORD="+ _G.dbpass +";");
|
conn = new MySqlConnection("SERVER="+ _G.serveraddr +";DATABASE="+ _G.dbname +";UID="+ _G.dbuser +";PASSWORD="+ _G.dbpass +";");
|
||||||
conn.Open();
|
conn.Open();
|
||||||
|
|
||||||
|
tmp = "DELETE FROM resptypes WHERE ";
|
||||||
foreach(Type t in ResponseCaller.getResponseTypes()) {
|
foreach(Type t in ResponseCaller.getResponseTypes()) {
|
||||||
string[] typeInfo = (string[])t.GetMethod("getInfo").Invoke(null, null);
|
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) { }
|
tmp += "name<>'"+ typeInfo[0] +"' AND ";
|
||||||
try { (new MySqlCommand("INSERT INTO `resptypes` (name,friendlyname,description) VALUES ('" + typeInfo[0] + "','" + typeInfo[1].Replace("'", "\\'") + "','" + typeInfo[2].Replace("'", "\\'") + "')", conn)).ExecuteNonQuery(); } catch(Exception e) { }
|
Query.Quiet("UPDATE `resptypes` SET friendlyname='" + Sanitize(typeInfo[1]) + "',description='" + Sanitize(typeInfo[2]) + "' WHERE name='" + typeInfo[0] + "'", conn);
|
||||||
|
Query.Quiet("INSERT INTO `resptypes` (name,friendlyname,description) VALUES ('" + typeInfo[0] + "','" + Sanitize(typeInfo[1]) + "','" + Sanitize(typeInfo[2]) + "')", conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tmp = tmp.Substring(0, tmp.Length - 5);
|
||||||
|
Query.Quiet(tmp, conn);
|
||||||
|
|
||||||
|
while(true) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,16 +7,32 @@ using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
namespace bot {
|
namespace bot {
|
||||||
static class Query {
|
static class Query {
|
||||||
static object Scalar(string query, MySqlConnection conn) {
|
static public object Scalar(string query, MySqlConnection conn) {
|
||||||
|
try {
|
||||||
return (new MySqlCommand(query, conn)).ExecuteScalar();
|
return (new MySqlCommand(query, conn)).ExecuteScalar();
|
||||||
|
} catch(Exception e) {
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Quiet(string query, MySqlConnection conn) {
|
static public bool Quiet(string query, MySqlConnection conn) {
|
||||||
|
try {
|
||||||
(new MySqlCommand(query, conn)).ExecuteNonQuery();
|
(new MySqlCommand(query, conn)).ExecuteNonQuery();
|
||||||
|
return true;
|
||||||
|
} catch(Exception e) {
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static MySqlDataReader Reader(string query, MySqlConnection conn) {
|
static public MySqlDataReader Reader(string query, MySqlConnection conn) {
|
||||||
// TODO write this
|
try {
|
||||||
|
return (new MySqlCommand(query, conn)).ExecuteReader();
|
||||||
|
} catch(Exception e) {
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@ namespace bot {
|
||||||
responseTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => String.Equals(t.Namespace, "bot.responses", StringComparison.Ordinal)).ToArray();
|
responseTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => String.Equals(t.Namespace, "bot.responses", StringComparison.Ordinal)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void callResponse(String responseName) {
|
public static void callResponse(String responseName, string parameters, Message msg) {
|
||||||
loadResponseTypes();
|
loadResponseTypes();
|
||||||
//responseTypes[0].GetMethod("test").Invoke(null, "");
|
responseTypes.First(t => t.Name == responseName).GetMethod("performOperation").Invoke(null, new Object[]{(object)parameters, (object)msg});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type[] getResponseTypes() {
|
public static Type[] getResponseTypes() {
|
||||||
|
|
13
bot/bot/StringSanitizer.cs
Normal file
13
bot/bot/StringSanitizer.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace bot {
|
||||||
|
class StringSanitizer {
|
||||||
|
public static String Sanitize(String str) {
|
||||||
|
return str.Replace("'", "\\'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -94,6 +94,7 @@
|
||||||
<Compile Include="Query.cs" />
|
<Compile Include="Query.cs" />
|
||||||
<Compile Include="responses\jumble.cs" />
|
<Compile Include="responses\jumble.cs" />
|
||||||
<Compile Include="responses\replace.cs" />
|
<Compile Include="responses\replace.cs" />
|
||||||
|
<Compile Include="StringSanitizer.cs" />
|
||||||
<Compile Include="_G.cs" />
|
<Compile Include="_G.cs" />
|
||||||
<Compile Include="Message.cs" />
|
<Compile Include="Message.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|
|
@ -3,8 +3,17 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace bot.responses {
|
namespace bot.responses {
|
||||||
class jumble {
|
class jumble {
|
||||||
|
static public string[] getInfo() {
|
||||||
|
return new string[] {"junble"/*typeof(jumble).Name*/, "Jumble Message",
|
||||||
|
"Takes all words in the sentence and rearranges them randomly, sending the result to the chat."};
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void performOperation(string parameters, Message msg) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,8 +3,17 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace bot.responses {
|
namespace bot.responses {
|
||||||
class replace {
|
class replace {
|
||||||
|
static public string[] getInfo() {
|
||||||
|
return new string[] {typeof(replace).Name, "Replace Phrase",
|
||||||
|
"Takes a message, replaces all instances of the specified phrase, and sends it to the chat."};
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void performOperation(string parameters, Message msg) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue