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;
|
||||
|
||||
namespace bot {
|
||||
class Bot {
|
||||
class Bot : StringSanitizer {
|
||||
public static MySqlConnection conn;
|
||||
static string tmp;
|
||||
|
||||
static void Main(string[] args) {
|
||||
conn = new MySqlConnection("SERVER="+ _G.serveraddr +";DATABASE="+ _G.dbname +";UID="+ _G.dbuser +";PASSWORD="+ _G.dbpass +";");
|
||||
conn.Open();
|
||||
|
||||
tmp = "DELETE FROM resptypes WHERE ";
|
||||
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) { }
|
||||
tmp += "name<>'"+ typeInfo[0] +"' AND ";
|
||||
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 {
|
||||
static class Query {
|
||||
static object Scalar(string query, MySqlConnection conn) {
|
||||
return (new MySqlCommand(query, conn)).ExecuteScalar();
|
||||
static public object Scalar(string query, MySqlConnection conn) {
|
||||
try {
|
||||
return (new MySqlCommand(query, conn)).ExecuteScalar();
|
||||
} catch(Exception e) {
|
||||
Console.WriteLine(e.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static void Quiet(string query, MySqlConnection conn) {
|
||||
(new MySqlCommand(query, conn)).ExecuteNonQuery();
|
||||
static public bool Quiet(string query, MySqlConnection conn) {
|
||||
try {
|
||||
(new MySqlCommand(query, conn)).ExecuteNonQuery();
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
Console.WriteLine(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static MySqlDataReader Reader(string query, MySqlConnection conn) {
|
||||
// TODO write this
|
||||
static public MySqlDataReader Reader(string query, MySqlConnection conn) {
|
||||
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();
|
||||
}
|
||||
|
||||
public static void callResponse(String responseName) {
|
||||
public static void callResponse(String responseName, string parameters, Message msg) {
|
||||
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() {
|
||||
|
|
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="responses\jumble.cs" />
|
||||
<Compile Include="responses\replace.cs" />
|
||||
<Compile Include="StringSanitizer.cs" />
|
||||
<Compile Include="_G.cs" />
|
||||
<Compile Include="Message.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
|
|
@ -3,8 +3,17 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Reflection;
|
||||
|
||||
namespace bot.responses {
|
||||
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.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Reflection;
|
||||
|
||||
namespace bot.responses {
|
||||
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