Exemplo n.º 1
0
        private async Task ProcessMessageDeletedWithCacheAsync(AuditLogItem entity, ISocketMessageChannel channel, IMessage message, SocketGuild guild)
        {
            entity.SetData(MessageDeletedAuditData.Create(channel, message));

            var auditLog = (await guild.GetAuditLogDataAsync(actionType: ActionType.MessageDeleted)).Find(o =>
            {
                var data = (MessageDeleteAuditLogData)o.Data;
                return(data.Target.Id == message.Author.Id && data.ChannelId == channel.Id);
            });

            entity.UserId = await UserSearchService.GetUserIDFromDiscordUserAsync(guild, auditLog?.User ?? message.Author);

            if (message.Attachments.Count > 0)
            {
                foreach (var attachment in message.Attachments.Where(o => o.Size < 10 * 1024 * 1024)) // Max 10MB
                {
                    var fileContent = await attachment.DownloadFileAsync();

                    if (fileContent == null)
                    {
                        continue;
                    }

                    entity.Files.Add(new Database.Entity.File()
                    {
                        Content  = fileContent,
                        Filename = $"{Path.GetFileNameWithoutExtension(attachment.Filename)}_{attachment.Id}{Path.GetExtension(attachment.Filename)}"
                    });
                }
            }
        }
Exemplo n.º 2
0
 private async Task <List <RestAuditLogEntry> > GetAuditLogDataAsync(SocketGuild guild)
 {
     try
     {
         return(await guild.GetAuditLogDataAsync(actionType : ActionType.MessageDeleted).ConfigureAwait(false));
     }
     catch (Exception ex)
     {
         Logger.LogError(ex, "");
         return(new List <RestAuditLogEntry>());
     }
 }
Exemplo n.º 3
0
        private async Task <List <RestAuditLogEntry> > GetAuditLogDataAsync(SocketGuild guild)
        {
            try
            {
                return(await guild.GetAuditLogDataAsync().ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                await LoggingService.WriteAsync(ex.ToString()).ConfigureAwait(false);

                return(new List <RestAuditLogEntry>());
            }
        }