From 0d6b6bf08e47d372a42d0cee12912510e4a7afb4 Mon Sep 17 00:00:00 2001 From: Ske Date: Sat, 20 Apr 2019 22:25:03 +0200 Subject: [PATCH] bot: trace startup sequence to stdout --- .vscode/launch.json | 32 ++++++++++++++++++++++---------- PluralKit/Bot.cs | 14 ++++++++++++++ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 841353a4..ed7f245b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,16 +1,28 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ { - "name": "PluralKit", - "type": "python", + "name": ".NET Core Launch (console)", + "type": "coreclr", "request": "launch", - "program": "${workspaceRoot}/src/bot_main.py", - "args": ["${workspaceRoot}/pluralkit.conf"], - "console": "integratedTerminal", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/PluralKit.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "envFile": "${workspaceFolder}/.env" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" } ] } \ No newline at end of file diff --git a/PluralKit/Bot.cs b/PluralKit/Bot.cs index 128cefa8..8d578d14 100644 --- a/PluralKit/Bot.cs +++ b/PluralKit/Bot.cs @@ -23,6 +23,8 @@ namespace PluralKit private async Task MainAsync() { + Console.WriteLine("Starting PluralKit..."); + // Dapper by default tries to pass ulongs to Npgsql, which rejects them since PostgreSQL technically // doesn't support unsigned types on its own. // Instead we add a custom mapper to encode them as signed integers instead, converting them back and forth. @@ -32,15 +34,19 @@ namespace PluralKit using (var services = BuildServiceProvider()) { + Console.WriteLine("- Connecting to database..."); var connection = services.GetRequiredService() as NpgsqlConnection; connection.ConnectionString = Environment.GetEnvironmentVariable("PK_DATABASE_URI"); await connection.OpenAsync(); + Console.WriteLine("- Connecting to Discord..."); var client = services.GetRequiredService() as DiscordSocketClient; await client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("PK_TOKEN")); await client.StartAsync(); + Console.WriteLine("- Initializing bot..."); await services.GetRequiredService().Init(); + await Task.Delay(-1); } } @@ -85,11 +91,19 @@ namespace PluralKit _commands.CommandExecuted += CommandExecuted; await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services); + _client.Ready += Ready; _client.MessageReceived += MessageReceived; _client.ReactionAdded += _proxy.HandleReactionAddedAsync; _client.MessageDeleted += _proxy.HandleMessageDeletedAsync; } + private Task Ready() + { + Console.WriteLine($"Shard #{_client.ShardId} connected to {_client.Guilds.Sum(g => g.Channels.Count)} channels in {_client.Guilds.Count} guilds."); + Console.WriteLine($"PluralKit started as {_client.CurrentUser.Username}#{_client.CurrentUser.Discriminator} ({_client.CurrentUser.Id})."); + return Task.CompletedTask; + } + private async Task CommandExecuted(Optional cmd, ICommandContext ctx, IResult _result) { if (!_result.IsSuccess) {