bot: trace startup sequence to stdout

This commit is contained in:
Ske 2019-04-20 22:25:03 +02:00
parent e7fa5625b6
commit 0d6b6bf08e
2 changed files with 36 additions and 10 deletions

32
.vscode/launch.json vendored
View File

@ -1,16 +1,28 @@
{ {
// Use IntelliSense to learn about possible attributes. // Use IntelliSense to find out which attributes exist for C# debugging
// Hover to view descriptions of existing attributes. // Use hover for the description of the existing attributes
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "PluralKit", "name": ".NET Core Launch (console)",
"type": "python", "type": "coreclr",
"request": "launch", "request": "launch",
"program": "${workspaceRoot}/src/bot_main.py", "preLaunchTask": "build",
"args": ["${workspaceRoot}/pluralkit.conf"], // If you have changed target frameworks, make sure to update the program path.
"console": "integratedTerminal", "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}"
} }
] ]
} }

View File

@ -23,6 +23,8 @@ namespace PluralKit
private async Task MainAsync() private async Task MainAsync()
{ {
Console.WriteLine("Starting PluralKit...");
// Dapper by default tries to pass ulongs to Npgsql, which rejects them since PostgreSQL technically // Dapper by default tries to pass ulongs to Npgsql, which rejects them since PostgreSQL technically
// doesn't support unsigned types on its own. // 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. // 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()) using (var services = BuildServiceProvider())
{ {
Console.WriteLine("- Connecting to database...");
var connection = services.GetRequiredService<IDbConnection>() as NpgsqlConnection; var connection = services.GetRequiredService<IDbConnection>() as NpgsqlConnection;
connection.ConnectionString = Environment.GetEnvironmentVariable("PK_DATABASE_URI"); connection.ConnectionString = Environment.GetEnvironmentVariable("PK_DATABASE_URI");
await connection.OpenAsync(); await connection.OpenAsync();
Console.WriteLine("- Connecting to Discord...");
var client = services.GetRequiredService<IDiscordClient>() as DiscordSocketClient; var client = services.GetRequiredService<IDiscordClient>() as DiscordSocketClient;
await client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("PK_TOKEN")); await client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("PK_TOKEN"));
await client.StartAsync(); await client.StartAsync();
Console.WriteLine("- Initializing bot...");
await services.GetRequiredService<Bot>().Init(); await services.GetRequiredService<Bot>().Init();
await Task.Delay(-1); await Task.Delay(-1);
} }
} }
@ -85,11 +91,19 @@ namespace PluralKit
_commands.CommandExecuted += CommandExecuted; _commands.CommandExecuted += CommandExecuted;
await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services); await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services);
_client.Ready += Ready;
_client.MessageReceived += MessageReceived; _client.MessageReceived += MessageReceived;
_client.ReactionAdded += _proxy.HandleReactionAddedAsync; _client.ReactionAdded += _proxy.HandleReactionAddedAsync;
_client.MessageDeleted += _proxy.HandleMessageDeletedAsync; _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<CommandInfo> cmd, ICommandContext ctx, IResult _result) private async Task CommandExecuted(Optional<CommandInfo> cmd, ICommandContext ctx, IResult _result)
{ {
if (!_result.IsSuccess) { if (!_result.IsSuccess) {