DATABASE WOOOOOOOOOOOOOOOOOOO!
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
bin/
|
||||
obj/
|
||||
Reactor.sln
|
||||
.env
|
||||
.env
|
||||
reactor.db
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNetEnv" Version="3.1.1" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.3" />
|
||||
<PackageReference Include="System.Data.SQLite" Version="2.0.2" />
|
||||
<PackageReference Include="Valour.Sdk" Version="0.5.19" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -12,30 +12,36 @@ namespace Reactor.Services
|
||||
HashSet<long> 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...");
|
||||
}
|
||||
}
|
||||
|
||||
40
Services/DatabaseService.cs
Normal file
40
Services/DatabaseService.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user