Beispiel #1
0
        private async Task ExportBundledGuildChatLog()
        {
            // Generate default file name
            string fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, guild,
                                                                    null, Options.After, Options.Before);

            // Generate file path
            string filePath = Path.Combine(Options.OutputPath ?? "", fileName);

            var chatLogRenderer = exportService.CreateChatLogRenderer(filePath);

            // Filter and order channels
            channels = channels.Where(c => c.Type == ChannelType.GuildTextChat || c.Type == ChannelType.News).OrderBy(c => c.Name).ToArray();

            // Loop through channels
            for (int i = 0; i < channels.Count; i++)
            {
                try
                {
                    // Track progress
                    Console.Write($"Exporting channel [{channels[i].Name}]... ");
                    using (InlineProgress progress = new InlineProgress())
                    {
                        // Get chat log
                        await dataService.GetAndExportChannelMessagesAsync(Options.GetToken(), guild, channels[i],
                                                                           chatLogRenderer, Options.After, Options.Before, progress);

                        // Report successful completion
                        progress.ReportCompletion();
                    }
                }
                catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.Forbidden)
                {
                    Console.Error.WriteLine("You don't have access to this channel");
                }
                catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
                {
                    Console.Error.WriteLine("This channel doesn't exist");
                }
            }

            if (Options.BucketName != null)
            {
                Console.Write($"Exporting bundled chatlog of guild [{guild.Id}]... ");
                using (InlineProgress progress = new InlineProgress())
                {
                    // upload bundled chatlog to s3
                    await exportService.UploadToS3(Options.BucketName, filePath, progress);

                    // Report successful completion
                    progress.ReportCompletion();
                }
            }
        }