private async void ProcessCommand(object obj) { var prefix = obj as string; try { while (!Cancellation.Token.IsCancellationRequested) { if (TryDequeue(prefix, out var command)) { Console.WriteLine($"[{DateTime.Now}] Id={command.Context.Message.Id}, User={command.Context.User.Id}, Input={command.Input}"); var result = await command.Service.ExecuteAsync(command.Context, command.Input, ServiceProvider); var log = new AWSLambda.Entities.CommandLog() { MessageId = command.Context.Message.Id, UserId = command.Context.User.Id, GuildId = 0, ChannelId = command.Context.Channel.Id, ChannelType = -1, Prefix = command.Prefix, Module = command.Module, Command = command.Command, Input = command.Input, ErrorReason = result.ErrorReason, }; switch (command.Context.Channel) { case IGuildChannel _: log.ChannelType = 0; log.GuildId = command.Context.Guild.Id; break; case IDMChannel _: log.ChannelType = 1; break; case IGroupChannel _: log.ChannelType = 3; break; } if (result.Error == CommandError.Exception) { await command.Context.Message.AddReactionAsync(BotReaction.Error); } else if (!result.IsSuccess) { await command.Context.Message.AddReactionAsync(BotReaction.Unknown); } PushLog(log); } } } catch (OperationCanceledException) { } }
private async Task PushLog(AWSLambda.Entities.CommandLog log) { try { await Task.Run(() => ServiceProvider.GetService <PreferenceService>().Update(log)); } catch (Exception) { /* nothing */ } }