Beispiel #1
0
        private async Task ExportChannelMetadata()
        {
            Console.Write("Exporting channel metadata... ");

            using (InlineProgress progress = new InlineProgress())
            {
                // Get channels

                // Filter and order channels
                channels = channels
                           .OrderBy(c => Enum.GetName(typeof(ChannelType), c.Type))
                           .OrderBy(c => c.ParentId)
                           .ToArray();

                // Generate default file name
                string fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, guild, "Channel");

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

                // Export
                await exportService.ExportGuildChannelsAsync(channels, filePath, Options.ExportFormat, Options.BucketName);

                progress.ReportCompletion();
            }
        }
        protected async Task ExportChannelAsync(IConsole console, Channel channel)
        {
            // Configure settings
            if (!DateFormat.IsNullOrWhiteSpace())
            {
                SettingsService.DateFormat = DateFormat;
            }

            console.Output.Write($"Exporting channel [{channel.Name}]... ");
            using (var progress = new InlineProgress(console))
            {
                // Get chat log
                var chatLog = await DataService.GetChatLogAsync(GetToken(), channel, After, Before, progress);

                // Generate file path if not set or is a directory
                var filePath = OutputPath;
                if (filePath.IsNullOrWhiteSpace() || ExportHelper.IsDirectoryPath(filePath))
                {
                    // Generate default file name
                    var fileName = ExportHelper.GetDefaultExportFileName(ExportFormat, chatLog.Guild,
                                                                         chatLog.Channel, After, Before);

                    // Combine paths
                    filePath = Path.Combine(filePath ?? "", fileName);
                }

                // Export
                await ExportService.ExportChatLogAsync(chatLog, filePath, ExportFormat, PartitionLimit);

                // Report successful completion
                progress.ReportCompletion();
            }
        }
        public override async Task ExecuteAsync()
        {
            // Get services
            var settingsService = Container.Instance.Get <SettingsService>();
            var dataService     = Container.Instance.Get <DataService>();
            var exportService   = Container.Instance.Get <ExportService>();

            // Configure settings
            if (!Options.DateFormat.IsNullOrWhiteSpace())
            {
                settingsService.DateFormat = Options.DateFormat;
            }

            // Get channels
            var channels = await dataService.GetGuildChannelsAsync(Options.GetToken(), Options.GuildId);

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

            // Loop through channels
            foreach (var channel in channels)
            {
                try
                {
                    // Track progress
                    Console.Write($"Exporting channel [{channel.Name}]... ");
                    using (var progress = new InlineProgress())
                    {
                        // Get chat log
                        var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), channel,
                                                                        Options.After, Options.Before, progress);

                        // Generate default file name
                        var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild,
                                                                             chatLog.Channel, Options.After, Options.Before);

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

                        // Export
                        await exportService.ExportChatLogAsync(chatLog, filePath, Options.ExportFormat,
                                                               Options.PartitionLimit);

                        // 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");
                }
            }
        }
Beispiel #4
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();
                }
            }
        }
Beispiel #5
0
        private async Task ExportGuildChatLogs()
        {
            // Filter and order channels
            channels = channels.Where(c => c.Type == ChannelType.GuildTextChat || c.Type == ChannelType.News).OrderBy(c => c.Name).ToArray();

            ChatLog[] chatLogs = new ChatLog[channels.Count];

            // 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
                        chatLogs[i] = await dataService.GetChatLogAsync(Options.GetToken(), guild, channels[i],
                                                                        Options.After, Options.Before, progress);

                        // Generate default file name
                        string fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, guild,
                                                                                chatLogs[i].Channel, Options.After, Options.Before);

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

                        // Export
                        await exportService.ExportChatLogAsync(chatLogs[i], filePath, Options.ExportFormat,
                                                               Options.PartitionLimit, Options.BucketName);

                        // 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");
                }
            }
        }
Beispiel #6
0
        private async Task ExportGuildMetadata()
        {
            Console.Write("Exporting guild metadata... ");

            using (InlineProgress progress = new InlineProgress())
            {
                // Generate default file name
                string fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, guild, "Guild");

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

                // Export
                await exportService.ExportGuildAsync(guild, filePath, Options.ExportFormat, Options.BucketName);

                progress.ReportCompletion();
            }
        }
        public override async Task ExecuteAsync()
        {
            // Get services
            var settingsService = Container.Instance.Get <SettingsService>();
            var dataService     = Container.Instance.Get <DataService>();
            var exportService   = Container.Instance.Get <ExportService>();

            // Configure settings
            if (!Options.DateFormat.IsNullOrWhiteSpace())
            {
                settingsService.DateFormat = Options.DateFormat;
            }

            // Track progress
            Console.Write($"Exporting channel [{Options.ChannelId}]... ");
            using (var progress = new InlineProgress())
            {
                // Get chat log
                var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), Options.ChannelId,
                                                                Options.After, Options.Before, progress);

                // Generate file path if not set or is a directory
                var filePath = Options.OutputPath;
                if (filePath.IsNullOrWhiteSpace() || ExportHelper.IsDirectoryPath(filePath))
                {
                    // Generate default file name
                    var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild,
                                                                         chatLog.Channel, Options.After, Options.Before);

                    // Combine paths
                    filePath = Path.Combine(filePath ?? "", fileName);
                }

                // Export
                await exportService.ExportChatLogAsync(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit);

                // Report successful completion
                progress.ReportCompletion();
            }
        }
Beispiel #8
0
        public override async Task ExecuteAsync()
        {
            // Get services
            SettingsService settingsService = Container.Instance.Get <SettingsService>();
            DataService     dataService     = Container.Instance.Get <DataService>();
            ExportService   exportService   = Container.Instance.Get <ExportService>();

            // Configure settings
            if (!Options.DateFormat.IsNullOrWhiteSpace())
            {
                settingsService.DateFormat = Options.DateFormat;
            }


            try
            {
                Guild guild = await dataService.GetGuildAsync(Options.GetToken(), Options.GuildId);

                Console.Write($"Exporting members of guild [{Options.GuildId}]... ");
                using (var progress = new InlineProgress())
                {
                    // Get guild members
                    IReadOnlyList <GuildMember> guildMembers = await dataService.GetGuildMembersAsync(Options.GetToken(), guild.Id);

                    // Order guild members by date of join in descending order
                    guildMembers = guildMembers.OrderByDescending(c => c.JoinedAt).ToArray();

                    // Generate default file name
                    var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, guild, "GuildMember");

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

                    // Export
                    await exportService.ExportGuildMembersAsync(guildMembers, filePath, Options.ExportFormat, Options.BucketName);

                    progress.ReportCompletion();
                }

                Console.Write($"Exporting roles of guild [{Options.GuildId}]... ");
                using (var progress = new InlineProgress())
                {
                    // Get guild roles
                    IReadOnlyList <Role> roles = await dataService.GetGuildRolesAsync(Options.GetToken(), guild.Id);

                    // Order guild roles by position in descending order (Highest position goes first)
                    roles = roles.OrderByDescending(c => c.Position).ToArray();

                    var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, guild, "Role");
                    var filePath = Path.Combine(Options.OutputPath ?? "", fileName);
                    await exportService.ExportGuildRolesAsync(roles, filePath, Options.ExportFormat, Options.BucketName);

                    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");
            }
        }