public async Task <Dictionary <string, int> > GetDeleter(IGuild guild, DbMsg message, DateTime deletedAt, Func <IUser, string> formatter) { var weightDictionary = new Dictionary <string, int>(); if (MessagesDeletedByBot.TryGetValue(message.Id, out var botDelReason)) { weightDictionary[$"mlapi: {botDelReason}"] = 666; return(weightDictionary); } _auditLogLock.WaitOne(); try { var log = await guild.GetAuditLogsAsync(limit : 15, actionType : ActionType.MessageDeleted); var correctChannel = log.Where(x => { var data = x.Data as MessageDeleteAuditLogData; return(data.ChannelId == message.ChannelId && data.Target.Id == message.Author.Id); }); var ordered = correctChannel .OrderBy(x => Math.Abs((x.CreatedAt - deletedAt).TotalMilliseconds)); foreach (var thing in ordered) { var usr = guild.GetUserAsync(thing.User.Id).Result; var diff = DateTime.UtcNow - thing.CreatedAt.UtcDateTime; var weight = 100 - (int)diff.TotalMinutes; if (weight >= 0) { weightDictionary[formatter(usr)] = weight; } } weightDictionary[formatter(message.Author)] = 2; weightDictionary["any bot"] = 1; weightDictionary["failed to fetch"] = disconnected.GetValueOrDefault(false) ? 25 : 0; } finally { _auditLogLock.Release(); } return(weightDictionary); }
private async Task Client_MessagesBulkDeleted(IReadOnlyCollection <Cacheable <IMessage, ulong> > arg1, Cacheable <IMessageChannel, ulong> cached) { var arg2 = await cached.GetOrDownloadAsync(); if (arg2 is ITextChannel channel) { var desc = $"{arg1.Count} messages bulk deleted; ids:"; string reason = null; var pages = new List <string>(); foreach (var x in arg1) { if (reason == null) { reason = MessagesDeletedByBot.GetValueOrDefault(x.Id, null); } var row = "\r\n" + x.Id.ToString(); if (desc.Length + row.Length > 2000) { desc = "[Part 1] " + desc; pages.Add(desc); desc = ""; } desc += row; } foreach (var page in pages) { var embed = new EmbedBuilder() .WithTitle("Messages Bulk Deleted") .WithDescription(page); if (reason != null) { embed.AddField("Reason", reason); } await SendLog(channel.Guild, "bulkdelete", embed); } } }