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()); } }
public async Task <bool> ProcessAsync(SocketGuildUser guildUserBefore, SocketGuildUser guildUserAfter) { if (IsBoostAdded(guildUserBefore, guildUserAfter)) { await BoostAdded(guildUserAfter).ConfigureAwait(false); return(true); } else if (IsBoostRemoved(guildUserBefore, guildUserAfter)) { await BoostRemoved(guildUserAfter).ConfigureAwait(false); return(true); } if (!IsChangeDetected(guildUserBefore, guildUserAfter)) { return(false); } var logEmbedBuilder = new LogEmbedBuilder("Uživatel na serveru byl aktualizován.", LogEmbedType.GuildMemberUpdated); logEmbedBuilder .SetAuthor(guildUserBefore) .SetFooter($"UserID: {guildUserBefore.Id}") .AddField("Změny", "---------------------------------------------"); if (guildUserBefore.Nickname != guildUserAfter.Nickname) { if (string.IsNullOrEmpty(guildUserBefore.Nickname) && !string.IsNullOrEmpty(guildUserAfter.Nickname)) { logEmbedBuilder.AddField("Server alias", $"(None) -> {guildUserAfter.Nickname}"); } else if (!string.IsNullOrEmpty(guildUserBefore.Nickname) && string.IsNullOrEmpty(guildUserAfter.Nickname)) { logEmbedBuilder.AddField("Server alias", $"{guildUserBefore.Nickname} -> (None)"); } else { logEmbedBuilder.AddField("Server alias", $"{guildUserBefore.Nickname} -> {guildUserAfter.Nickname}"); } } await SendEmbedAsync(logEmbedBuilder).ConfigureAwait(false); return(true); }
public async Task ProcessAsync(SocketGuildUser user) { var logEmbedBuilder = new LogEmbedBuilder("Uživatel opustil server.", LogEmbedType.UserLeft); var ban = await user.Guild.FindBanAsync(user); logEmbedBuilder = logEmbedBuilder .SetAuthor(user) .AddField("Počet členů na serveru", user.Guild.MemberCount, true) .AddField("Udělen ban", (ban != null).TranslateToCz(), true) .SetFooter($"MemberID: {user.Id}"); if (!string.IsNullOrEmpty(ban?.Reason)) { logEmbedBuilder.AddField("Důvod banu", ban.Reason); } await SendEmbedAsync(logEmbedBuilder).ConfigureAwait(false); }