mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-10-01 08:37:26 +00:00
Authored-by: Vanessa <vanessalouwagie@gmail.com> Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com>
50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using System.Text.Json;
|
|
using Content.DiscordBot;
|
|
using Content.Server.Database;
|
|
using Discord;
|
|
using Discord.Commands;
|
|
using Discord.Interactions;
|
|
using Discord.WebSocket;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
var client = new DiscordSocketClient();
|
|
|
|
client.Log += msg => Console.Out.WriteLineAsync($"[{msg.Severity}] {msg.Message}");
|
|
|
|
string? token = null;
|
|
string? connectionString = null;
|
|
if (File.Exists("config.json"))
|
|
{
|
|
var config = await JsonSerializer.DeserializeAsync<Config>(File.OpenRead("config.json")) ?? new Config();
|
|
token = config.Token;
|
|
}
|
|
|
|
#if DEBUG
|
|
if (Environment.GetEnvironmentVariable("DISCORD_TOKEN") is { } envToken)
|
|
token = envToken;
|
|
|
|
if (Environment.GetEnvironmentVariable("DATABASE_STRING") is { } dbString)
|
|
connectionString = dbString;
|
|
#endif
|
|
|
|
if (string.IsNullOrWhiteSpace(token))
|
|
throw new ArgumentException("No token found.");
|
|
|
|
if (string.IsNullOrWhiteSpace(connectionString))
|
|
throw new ArgumentException("No database connection string found.");
|
|
|
|
await client.LoginAsync(TokenType.Bot, token);
|
|
await client.StartAsync();
|
|
|
|
var builder = new DbContextOptionsBuilder<PostgresServerDbContext>();
|
|
builder.UseNpgsql(connectionString);
|
|
var db = new PostgresServerDbContext(builder.Options);
|
|
// await db.Database.MigrateAsync();
|
|
|
|
var interaction = new InteractionService(client);
|
|
var handler = new CommandHandler(client, new CommandService(), interaction, db);
|
|
await handler.InstallCommandsAsync();
|
|
|
|
// Block this task until the program is closed.
|
|
await Task.Delay(-1);
|