diff --git a/.gitignore b/.gitignore
index 932fb31..85bc7cc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
bin/
obj/
Reactor.sln
-.env
\ No newline at end of file
+.env
+reactor.db
\ No newline at end of file
diff --git a/Reactor.csproj b/Reactor.csproj
index f7b91fe..0209f13 100644
--- a/Reactor.csproj
+++ b/Reactor.csproj
@@ -9,6 +9,7 @@
+
diff --git a/Services/BotService.cs b/Services/BotService.cs
index aea440b..8c22ed7 100644
--- a/Services/BotService.cs
+++ b/Services/BotService.cs
@@ -12,30 +12,36 @@ namespace Reactor.Services
HashSet initializedPlanets,
string prefix)
{
+ //Check token is valid
if (string.IsNullOrWhiteSpace(token))
{
Console.WriteLine("TOKEN not set.");
return;
}
+ //Login to the bot
var loginResult = await client.InitializeUser(token);
if (!loginResult.Success)
{
Console.WriteLine($"Login failed: {loginResult.Message}");
return;
}
-
Console.WriteLine($"Logged in as {client.Me.Name} (ID: {client.Me.Id})");
- await PlanetService.InitializePlanetsAsync(client, channelCache, initializedPlanets);
+ //Initialize the Database
+ await DatabaseService.InitializeAsync();
+ //Initialize the Planets
+ await PlanetService.InitializePlanetsAsync(client, channelCache, initializedPlanets);
client.PlanetService.JoinedPlanetsUpdated += async () =>
{
await PlanetService.InitializePlanetsAsync(client, channelCache, initializedPlanets);
};
+ //Initialize the Messages
client.MessageService.MessageReceived += async (msg) => await MessageService.HandleMessageAsync(client, channelCache, msg, prefix);
+ //Bot is active and ready
Console.WriteLine("Bot ready and listening...");
}
}
diff --git a/Services/DatabaseService.cs b/Services/DatabaseService.cs
new file mode 100644
index 0000000..ae69190
--- /dev/null
+++ b/Services/DatabaseService.cs
@@ -0,0 +1,40 @@
+using System.Linq.Expressions;
+using Microsoft.Data.Sqlite;
+
+namespace Reactor.Services
+{
+ public static class DatabaseService
+ {
+ private static string _connectionString = "Data Source=reactor.db";
+
+ public static async Task InitializeAsync()
+ {
+ using var connection = new SqliteConnection(_connectionString);
+ await connection.OpenAsync();
+
+ //ReactionMessages Table
+ var cmd1 = connection.CreateCommand();
+ cmd1.CommandText =
+ "CREATE TABLE IF NOT EXISTS ReactionMessages (" +
+ "Id INTEGER PRIMARY KEY AUTOINCREMENT, " +
+ "PlanetId INTEGER NOT NULL, " +
+ "ChannelId INTEGER NOT NULL, " +
+ "MessageId INTEGER NOT NULL UNIQUE, " +
+ "DeleteDelaySeconds INTEGER NOT NULL DEFAULT 5" +
+ ")";
+ await cmd1.ExecuteNonQueryAsync();
+
+ //ReactionRoles table
+ var cmd2 = connection.CreateCommand();
+ cmd2.CommandText =
+ "CREATE TABLE IF NOT EXISTS ReactionRoles (" +
+ "Id INTEGER PRIMARY KEY AUTOINCREMENT, " +
+ "ReactionMessageId INTEGER NOT NULL, " +
+ "Emoji TEXT NOT NULL, " +
+ "RoleId INTEGER NOT NULL, " +
+ "FOREIGN KEY (ReactionMessageId) REFERENCES ReactionMessages(Id) ON DELETE CASCADE" +
+ ")";
+ await cmd2.ExecuteNonQueryAsync();
+ }
+ }
+}
\ No newline at end of file