bot: add generic runtime error handler

This commit is contained in:
Ske 2019-04-20 22:36:54 +02:00
parent 0d6b6bf08e
commit 41d9c84d76

View File

@ -113,6 +113,7 @@ namespace PluralKit
private async Task MessageReceived(SocketMessage _arg) private async Task MessageReceived(SocketMessage _arg)
{ {
try {
// Ignore system messages (member joined, message pinned, etc) // Ignore system messages (member joined, message pinned, etc)
var arg = _arg as SocketUserMessage; var arg = _arg as SocketUserMessage;
if (arg == null) return; if (arg == null) return;
@ -128,12 +129,22 @@ namespace PluralKit
// and start command execution // and start command execution
var system = await _connection.QueryFirstAsync<PKSystem>("select systems.* from systems, accounts where accounts.uid = @Id and systems.id = accounts.system", new { Id = arg.Author.Id }); var system = await _connection.QueryFirstAsync<PKSystem>("select systems.* from systems, accounts where accounts.uid = @Id and systems.id = accounts.system", new { Id = arg.Author.Id });
await _commands.ExecuteAsync(new PKCommandContext(_client, arg as SocketUserMessage, _connection, system), argPos, _services); await _commands.ExecuteAsync(new PKCommandContext(_client, arg as SocketUserMessage, _connection, system), argPos, _services);
} }
else else
{ {
// If not, try proxying anyway // If not, try proxying anyway
await _proxy.HandleMessageAsync(arg); await _proxy.HandleMessageAsync(arg);
} }
} catch (Exception e) {
// Generic exception handler
HandleRuntimeError(_arg, e);
}
}
private void HandleRuntimeError(SocketMessage arg, Exception e)
{
Console.Error.WriteLine(e);
} }
} }
} }