private async Task ProcessWithCacheRecordAsync(IMessage message, ISocketMessageChannel channel) { var auditLogRecord = await GetAuditLogRecord(channel, message.Author.Id).ConfigureAwait(false); var streams = new List <Tuple <string, Stream> >(); try { var logEmbedBuilder = new LogEmbedBuilder("Zpráva byla odebrána", LogEmbedType.MessageDeleted); logEmbedBuilder .SetAuthor(message.Author, true) .SetFooter($"MessageID: {message.Id} | AuthorID: {message.Author?.Id}") .AddField("Odesláno v", message.CreatedAt.LocalDateTime.ToLocaleDatetime()) .AddField("Kanál", $"<#{message.Channel.Id}> ({message.Channel.Id})"); if (auditLogRecord != null) { logEmbedBuilder.AddField("Smazal", auditLogRecord.User.GetShortName()); } else { logEmbedBuilder.AddField("Smazal", message.Author.GetShortName()); } if (string.IsNullOrEmpty(message.Content)) { logEmbedBuilder.AddField("Obsah", "-"); } else { logEmbedBuilder.AddCodeBlockField("Obsah", message.Content); } if (message.Attachments.Count > 0) { foreach (var messageAttachment in message.Attachments) { var attachmentStream = await GetAttachmentStreamAsync(messageAttachment).ConfigureAwait(false); if (!string.IsNullOrEmpty(attachmentStream.Item1) && attachmentStream.Item2 != null) { streams.Add(attachmentStream); } } } var loggerChannel = GetLoggerRoom(); await loggerChannel.SendMessageAsync(embed : logEmbedBuilder.Build()).ConfigureAwait(false); foreach (var stream in streams) { await loggerChannel.SendFileAsync(stream.Item2, stream.Item1).ConfigureAwait(false); } } finally { streams.ForEach(o => o.Item2.Dispose()); } }
protected async Task <RestUserMessage> SendEmbedAsync(LogEmbedBuilder embedBuilder) { var loggerRoom = GetLoggerRoom(); if (loggerRoom == null) { return(null); } return(await loggerRoom.SendMessageAsync(embed : embedBuilder.Build()).ConfigureAwait(false)); }
protected async Task <RestUserMessage> SendEmbedToAdminChannel(LogEmbedBuilder embedBuilder) { var channel = GetLoggerRoom(true); return(await channel.SendMessageAsync(embed : embedBuilder.Build()).ConfigureAwait(false)); }