Skip to content

Instantly share code, notes, and snippets.

@allquixotic
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allquixotic/1bcc4d9e501e9784cf9b to your computer and use it in GitHub Desktop.
Save allquixotic/1bcc4d9e501e9784cf9b to your computer and use it in GitHub Desktop.
Support ModBot on Mono/Linux (CentOS 5 with Mono 3.0.7) by switching out System.Data.SQLite for Mono.Data.Sqlite, changing Data Source, etc. Also fixed a weird NPE in Irc.cs. To get everything working, we had to download the MySQL/Net Connector binary, the JSON.Net binary, recompile sqlite to a newer version (it was only 3.3.x and needed 3.5.x),…
diff --git a/ModBot/Commands.cs b/ModBot/Commands.cs
index 8180c45..b6c1840 100644
--- a/ModBot/Commands.cs
+++ b/ModBot/Commands.cs
@@ -1,15 +1,15 @@
using System;
using System.Linq;
using System.Text;
-using System.Data.SQLite;
+using Mono.Data.Sqlite;
using System.IO;
namespace ModBot
{
class Commands
{
- private SQLiteConnection myDB;
- private SQLiteCommand cmd;
+ private SqliteConnection myDB;
+ private SqliteCommand cmd;
public Commands()
{
@@ -20,12 +20,12 @@ namespace ModBot
{
if (File.Exists("ModBot.sqlite"))
{
- myDB = new SQLiteConnection("Data Source=ModBot.sqlite;Version=3;");
+ myDB = new SqliteConnection("Data Source=ModBot.sqlite;Version=3;");
myDB.Open();
String sql = "CREATE TABLE IF NOT EXISTS commands (id INTEGER PRIMARY KEY, command TEXT, level INTEGER DEFAULT 0, output TEXT DEFAULT null);";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -33,13 +33,13 @@ namespace ModBot
}
else
{
- SQLiteConnection.CreateFile("ModBot.sqlite");
- myDB = new SQLiteConnection("Data Source=ModBot.sqlite;Version=3;");
+ SqliteConnection.CreateFile("ModBot.sqlite");
+ myDB = new SqliteConnection("Data Source=ModBot.sqlite;Version=3;");
myDB.Open();
String sql = "CREATE TABLE IF NOT EXISTS commands (id INTEGER PRIMARY KEY, command TEXT, level INTEGER DEFAULT 0, output TEXT DEFAULT null);";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -49,9 +49,9 @@ namespace ModBot
public bool cmdExists(String command)
{
String sql = "SELECT * FROM commands";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
- using (SQLiteDataReader r = cmd.ExecuteReader())
+ using (SqliteDataReader r = cmd.ExecuteReader())
{
while (r.Read())
{
@@ -70,7 +70,7 @@ namespace ModBot
String sql = String.Format("INSERT INTO commands (command, level, output) VALUES (\"{0}\", {1}, \"{2}\");", command, level, output);
//String sql = "INSERT INTO commands (command, level, output) VALUES (\"" + command + "\", " + level + ", \"" + output + "\");";
Console.WriteLine(sql);
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -79,7 +79,7 @@ namespace ModBot
public void removeCommand(String command)
{
String sql = "DELETE FROM commands WHERE command = \"" + command + "\";";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -88,9 +88,9 @@ namespace ModBot
public int LevelRequired(String command)
{
String sql = String.Format("SELECT * FROM commands WHERE command = \"{0}\";", command);
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
- using (SQLiteDataReader r = cmd.ExecuteReader())
+ using (SqliteDataReader r = cmd.ExecuteReader())
{
while (r.Read())
{
@@ -105,9 +105,9 @@ namespace ModBot
{
StringBuilder list = new StringBuilder();
String sql = "SELECT * FROM commands;";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
- using (SQLiteDataReader r = cmd.ExecuteReader())
+ using (SqliteDataReader r = cmd.ExecuteReader())
{
while (r.Read())
{
@@ -121,9 +121,9 @@ namespace ModBot
public string getOutput(String command)
{
String sql = "SELECT * FROM commands WHERE command = \"" + command + "\";";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
- using (SQLiteDataReader r = cmd.ExecuteReader())
+ using (SqliteDataReader r = cmd.ExecuteReader())
{
while (r.Read())
{
diff --git a/ModBot/Database.cs b/ModBot/Database.cs
index 641d2a7..97c049d 100644
--- a/ModBot/Database.cs
+++ b/ModBot/Database.cs
@@ -1,15 +1,15 @@
using System;
using System.Linq;
using System.Text;
-using System.Data.SQLite;
+using Mono.Data.Sqlite;
using System.IO;
namespace ModBot
{
class Database
{
- private SQLiteConnection myDB;
- private SQLiteCommand cmd;
+ private SqliteConnection myDB;
+ private SqliteCommand cmd;
private string channel;
public Database()
@@ -22,13 +22,13 @@ namespace ModBot
{
if (File.Exists("ModBot.sqlite"))
{
- myDB = new SQLiteConnection("Data Source=ModBot.sqlite;Version=3;");
+ myDB = new SqliteConnection("Data Source=file:ModBot.sqlite;Version=3;");
myDB.Open();
String sql;
sql = "CREATE TABLE IF NOT EXISTS '" + channel + "' (id INTEGER PRIMARY KEY, user TEXT, currency INTEGER DEFAULT 0, subscriber INTEGER DEFAULT 0, btag TEXT DEFAULT null, userlevel INTEGER DEFAULT 0);";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -37,14 +37,14 @@ namespace ModBot
{
sql = "INSERT INTO '" + channel + "' SELECT * FROM transfers;";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
/*sql = "DROP TABLE transfers;";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}*/
@@ -53,13 +53,13 @@ namespace ModBot
}
else
{
- SQLiteConnection.CreateFile("ModBot.sqlite");
- myDB = new SQLiteConnection("Data Source=ModBot.sqlite;Version=3;");
+ SqliteConnection.CreateFile("ModBot.sqlite");
+ myDB = new SqliteConnection("Data Source=file:ModBot.sqlite;Version=3;");
myDB.Open();
String sql = "CREATE TABLE IF NOT EXISTS '"+channel+"' (id INTEGER PRIMARY KEY, user TEXT, currency INTEGER DEFAULT 0, subscriber INTEGER DEFAULT 0, btag TEXT DEFAULT null, userlevel INTEGER DEFAULT 0);";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -71,7 +71,7 @@ namespace ModBot
if (!userExists(user))
{
String sql = "INSERT INTO '"+channel+"' (user) VALUES ('" + user + "');";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -82,9 +82,9 @@ namespace ModBot
{
if (userExists(user)) {
String sql = "SELECT * FROM '" + channel + "' WHERE user = \"" + user + "\";";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
- using (SQLiteDataReader r = cmd.ExecuteReader())
+ using (SqliteDataReader r = cmd.ExecuteReader())
{
if (r.Read())
{
@@ -108,7 +108,7 @@ namespace ModBot
newUser(user);
}
String sql = "UPDATE '" + channel + "' SET currency = currency + " + amount + " WHERE user = \"" + user + "\";";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -121,7 +121,7 @@ namespace ModBot
newUser(user);
}
String sql = "UPDATE '" + channel + "' SET currency = currency - " + amount + " WHERE user = \"" + user + "\";";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -130,9 +130,9 @@ namespace ModBot
public bool userExists(String user)
{
String sql = "SELECT * FROM '" + channel + "';";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
- using (SQLiteDataReader r = cmd.ExecuteReader())
+ using (SqliteDataReader r = cmd.ExecuteReader())
{
while (r.Read())
{
@@ -151,9 +151,9 @@ namespace ModBot
if (userExists(user))
{
String sql = "SELECT * FROM '" + channel + "' WHERE user = \"" + user + "\";";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
- using (SQLiteDataReader r = cmd.ExecuteReader())
+ using (SqliteDataReader r = cmd.ExecuteReader())
{
if (r.Read())
{
@@ -182,7 +182,7 @@ namespace ModBot
newUser(user);
}
String sql = "UPDATE '" + channel + "' SET btag = \"" + btag + "\" WHERE user = \"" + user + "\";";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -198,9 +198,9 @@ namespace ModBot
else
{
String sql = "SELECT * FROM '" + channel + "' WHERE user = \"" + user + "\";";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
- using (SQLiteDataReader r = cmd.ExecuteReader())
+ using (SqliteDataReader r = cmd.ExecuteReader())
{
if (r.Read())
{
@@ -221,7 +221,7 @@ namespace ModBot
if (userExists(user))
{
String sql = String.Format("UPDATE '" + channel + "' SET subscriber = 1 WHERE user = \"{0}\";", user);
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -235,7 +235,7 @@ namespace ModBot
if (userExists(user))
{
String sql = String.Format("UPDATE '" + channel + "' SET subscriber = 0 WHERE user = \"{0}\";", user);
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -254,9 +254,9 @@ namespace ModBot
else
{
String sql = "SELECT * FROM '" + channel + "' WHERE user = \"" + user + "\";";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
- using (SQLiteDataReader r = cmd.ExecuteReader())
+ using (SqliteDataReader r = cmd.ExecuteReader())
{
if (r.Read())
{
@@ -277,7 +277,7 @@ namespace ModBot
{
String sql = "UPDATE '" + channel + "' SET userlevel = \"" + level + "\" WHERE user = \"" + user + "\";";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
cmd.ExecuteNonQuery();
}
@@ -288,9 +288,9 @@ namespace ModBot
String sql = "SELECT COUNT(*) FROM sqlite_master WHERE name = '" + table + "';";
try
{
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
- using (SQLiteDataReader r = cmd.ExecuteReader())
+ using (SqliteDataReader r = cmd.ExecuteReader())
{
while (r.Read())
{
@@ -303,7 +303,7 @@ namespace ModBot
}
}
}
- catch (SQLiteException e)
+ catch (SqliteException e)
{
Console.WriteLine(e);
return false;
@@ -314,9 +314,9 @@ namespace ModBot
{
String sql = "SELECT * FROM '" + table + "';";
- using (cmd = new SQLiteCommand(sql, myDB))
+ using (cmd = new SqliteCommand(sql, myDB))
{
- using (SQLiteDataReader r = cmd.ExecuteReader())
+ using (SqliteDataReader r = cmd.ExecuteReader())
{
if (r.HasRows)
{
@@ -330,4 +330,4 @@ namespace ModBot
}
}
}
-}
\ No newline at end of file
+}
diff --git a/ModBot/Irc.cs b/ModBot/Irc.cs
index 7cc662e..8d8c567 100644
--- a/ModBot/Irc.cs
+++ b/ModBot/Irc.cs
@@ -187,7 +187,8 @@ namespace ModBot
private void parseMessage(String message)
{
- //print(message);
+if(message == null) { return; }
+print("parseMessage: " + message);
String[] msg = message.Split(' ');
diff --git a/ModBot/ModBot.csproj b/ModBot/ModBot.csproj
index 1ec241a..c933e7c 100644
--- a/ModBot/ModBot.csproj
+++ b/ModBot/ModBot.csproj
@@ -65,9 +65,9 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
- <Reference Include="System.Data.SQLite, Version=1.0.86.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
+ <Reference Include="Mono.Data.Sqlite, Version=1.0.86.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>Externals\SQLite\System.Data.SQLite.dll</HintPath>
+ <HintPath>Externals\SQLite\Mono.Data.Sqlite.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@@ -169,4 +169,4 @@
<Target Name="AfterBuild">
</Target>
-->
-</Project>
\ No newline at end of file
+</Project>
diff --git a/ModBot/obj/x86/Debug/ModBot.exe b/ModBot/obj/x86/Debug/ModBot.exe
old mode 100644
new mode 100755
index a844157..b2eafc4
Binary files a/ModBot/obj/x86/Debug/ModBot.exe and b/ModBot/obj/x86/Debug/ModBot.exe differ
diff --git a/OneTimeConverter/Form1.cs b/OneTimeConverter/Form1.cs
index 30e0a1d..f7bda74 100644
--- a/OneTimeConverter/Form1.cs
+++ b/OneTimeConverter/Form1.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
-using System.Data.SQLite;
+using Mono.Data.Sqlite;
using System.Drawing;
using System.Linq;
using System.Text;
@@ -14,8 +14,8 @@ namespace OneTimeConverter
{
public partial class Form1 : Form
{
- private SQLiteConnection sqliteDB;
- private SQLiteCommand sqliteCMD;
+ private SqliteConnection sqliteDB;
+ private SqliteCommand sqliteCMD;
private MySqlConnection mysqlDB;
private MySqlCommand mysqlCMD;
@@ -51,15 +51,15 @@ namespace OneTimeConverter
}
Console.WriteLine("Data grabbed from MySQL successfully.");
- SQLiteConnection.CreateFile("ModBot.sqlite");
- sqliteDB = new SQLiteConnection("Data Source=ModBot.sqlite;Version=3;");
+ SqliteConnection.CreateFile("ModBot.sqlite");
+ sqliteDB = new SqliteConnection("Data Source=ModBot.sqlite;Version=3;");
sqliteDB.Open();
Console.WriteLine("ModBot.sqlite created. Adding new users now.");
sql = "CREATE TABLE IF NOT EXISTS transfers (id INTEGER PRIMARY KEY, user TEXT, currency INTEGER DEFAULT 0, subscriber INTEGER DEFAULT 0, btag TEXT DEFAULT null, userlevel INTEGER DEFAULT 0);";
- using (sqliteCMD = new SQLiteCommand(sql, sqliteDB))
+ using (sqliteCMD = new SqliteCommand(sql, sqliteDB))
{
sqliteCMD.ExecuteNonQuery();
}
@@ -68,7 +68,7 @@ namespace OneTimeConverter
{
sql = String.Format("INSERT INTO transfers (user, currency) VALUES (\"{0}\", {1})", user, transfers[user]);
//Console.WriteLine(sql);
- using (sqliteCMD = new SQLiteCommand(sql, sqliteDB))
+ using (sqliteCMD = new SqliteCommand(sql, sqliteDB))
{
sqliteCMD.ExecuteNonQuery();
}
diff --git a/OneTimeConverter/OneTimeConverter.csproj b/OneTimeConverter/OneTimeConverter.csproj
index 47391e6..d3c1212 100644
--- a/OneTimeConverter/OneTimeConverter.csproj
+++ b/OneTimeConverter/OneTimeConverter.csproj
@@ -59,8 +59,8 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
- <Reference Include="System.Data.SQLite">
- <HintPath>..\..\ModBot\ModBot\Externals\SQLite\System.Data.SQLite.dll</HintPath>
+ <Reference Include="Mono.Data.Sqlite">
+ <HintPath>..\..\ModBot\ModBot\Externals\SQLite\Mono.Data.Sqlite.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@@ -132,4 +132,4 @@
<Target Name="AfterBuild">
</Target>
-->
-</Project>
\ No newline at end of file
+</Project>
diff --git a/OneTimeConverter/obj/x86/Debug/OneTimeConverter.exe b/OneTimeConverter/obj/x86/Debug/OneTimeConverter.exe
old mode 100644
new mode 100755
index e895b40..27245f8
Binary files a/OneTimeConverter/obj/x86/Debug/OneTimeConverter.exe and b/OneTimeConverter/obj/x86/Debug/OneTimeConverter.exe differ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment