bot: add generic runtime error handler
This commit is contained in:
parent
0d6b6bf08e
commit
41d9c84d76
@ -113,27 +113,38 @@ namespace PluralKit
|
|||||||
|
|
||||||
private async Task MessageReceived(SocketMessage _arg)
|
private async Task MessageReceived(SocketMessage _arg)
|
||||||
{
|
{
|
||||||
// Ignore system messages (member joined, message pinned, etc)
|
try {
|
||||||
var arg = _arg as SocketUserMessage;
|
// Ignore system messages (member joined, message pinned, etc)
|
||||||
if (arg == null) return;
|
var arg = _arg as SocketUserMessage;
|
||||||
|
if (arg == null) return;
|
||||||
|
|
||||||
// Ignore bot messages
|
// Ignore bot messages
|
||||||
if (arg.Author.IsBot || arg.Author.IsWebhook) return;
|
if (arg.Author.IsBot || arg.Author.IsWebhook) return;
|
||||||
|
|
||||||
int argPos = 0;
|
int argPos = 0;
|
||||||
// Check if message starts with the command prefix
|
// Check if message starts with the command prefix
|
||||||
if (arg.HasStringPrefix("pk;", ref argPos) || arg.HasStringPrefix("pk!", ref argPos) || arg.HasMentionPrefix(_client.CurrentUser, ref argPos))
|
if (arg.HasStringPrefix("pk;", ref argPos) || arg.HasStringPrefix("pk!", ref argPos) || arg.HasMentionPrefix(_client.CurrentUser, ref argPos))
|
||||||
{
|
{
|
||||||
// If it does, fetch the sender's system (because most commands need that) into the context,
|
// If it does, fetch the sender's system (because most commands need that) into the context,
|
||||||
// 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
|
{
|
||||||
await _proxy.HandleMessageAsync(arg);
|
// If not, try proxying anyway
|
||||||
|
await _proxy.HandleMessageAsync(arg);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Generic exception handler
|
||||||
|
HandleRuntimeError(_arg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleRuntimeError(SocketMessage arg, Exception e)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user