DATABASE WOOOOOOOOOOOOOOOOOOO!
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ bin/
|
|||||||
obj/
|
obj/
|
||||||
Reactor.sln
|
Reactor.sln
|
||||||
.env
|
.env
|
||||||
|
reactor.db
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DotNetEnv" Version="3.1.1" />
|
<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="System.Data.SQLite" Version="2.0.2" />
|
||||||
<PackageReference Include="Valour.Sdk" Version="0.5.19" />
|
<PackageReference Include="Valour.Sdk" Version="0.5.19" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -12,30 +12,36 @@ namespace Reactor.Services
|
|||||||
HashSet<long> initializedPlanets,
|
HashSet<long> initializedPlanets,
|
||||||
string prefix)
|
string prefix)
|
||||||
{
|
{
|
||||||
|
//Check token is valid
|
||||||
if (string.IsNullOrWhiteSpace(token))
|
if (string.IsNullOrWhiteSpace(token))
|
||||||
{
|
{
|
||||||
Console.WriteLine("TOKEN not set.");
|
Console.WriteLine("TOKEN not set.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Login to the bot
|
||||||
var loginResult = await client.InitializeUser(token);
|
var loginResult = await client.InitializeUser(token);
|
||||||
if (!loginResult.Success)
|
if (!loginResult.Success)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Login failed: {loginResult.Message}");
|
Console.WriteLine($"Login failed: {loginResult.Message}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"Logged in as {client.Me.Name} (ID: {client.Me.Id})");
|
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 () =>
|
client.PlanetService.JoinedPlanetsUpdated += async () =>
|
||||||
{
|
{
|
||||||
await PlanetService.InitializePlanetsAsync(client, channelCache, initializedPlanets);
|
await PlanetService.InitializePlanetsAsync(client, channelCache, initializedPlanets);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Initialize the Messages
|
||||||
client.MessageService.MessageReceived += async (msg) => await MessageService.HandleMessageAsync(client, channelCache, msg, prefix);
|
client.MessageService.MessageReceived += async (msg) => await MessageService.HandleMessageAsync(client, channelCache, msg, prefix);
|
||||||
|
|
||||||
|
//Bot is active and ready
|
||||||
Console.WriteLine("Bot ready and listening...");
|
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