示例#1
0
 private bool GetAuditLogEntry(IGuild guild, out IAuditLogEntry auditLog, Discord.ActionType type)
 {
     auditLog = guild.GetAuditLogsAsync(5).GetAwaiter().GetResult().FirstOrDefault(x => x.Action == type);
     if (auditLog == null)
     {
         return(false);
     }
     //var timeStamp = SnowflakeUtils.FromSnowflake(auditLog.Id);
     //if (timeStamp > DateTimeOffset.Now - TimeSpan.FromSeconds(5)) return false;
     return(auditLog.User.Id != _client.CurrentUser.Id);
 }
        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);
        }