Streaming exporter

Fixes #125
Closes #177
This commit is contained in:
Alexey Golub
2019-12-07 18:43:24 +02:00
parent fc38afe6a0
commit 2a223599f9
44 changed files with 1132 additions and 1098 deletions

View File

@@ -16,13 +16,6 @@ namespace DiscordChatExporter.Cli.Commands
{
}
public override async Task ExecuteAsync(IConsole console)
{
// Get channel
var channel = await DataService.GetChannelAsync(GetToken(), ChannelId);
// Export
await ExportChannelAsync(console, channel);
}
public override async Task ExecuteAsync(IConsole console) => await ExportAsync(console, ChannelId);
}
}

View File

@@ -6,7 +6,6 @@ using CliFx.Services;
using CliFx.Utilities;
using DiscordChatExporter.Core.Models;
using DiscordChatExporter.Core.Services;
using DiscordChatExporter.Core.Services.Helpers;
namespace DiscordChatExporter.Cli.Commands
{
@@ -16,17 +15,16 @@ namespace DiscordChatExporter.Cli.Commands
protected ExportService ExportService { get; }
[CommandOption("format", 'f', Description = "Output file format.")]
public ExportFormat ExportFormat { get; set; } = ExportFormat.HtmlDark;
[CommandOption("output", 'o', Description = "Output file or directory path.")]
public string? OutputPath { get; set; }
[CommandOption("after",Description = "Limit to messages sent after this date.")]
[CommandOption("after", Description = "Limit to messages sent after this date.")]
public DateTimeOffset? After { get; set; }
[CommandOption("before",Description = "Limit to messages sent before this date.")]
[CommandOption("before", Description = "Limit to messages sent before this date.")]
public DateTimeOffset? Before { get; set; }
[CommandOption("partition", 'p', Description = "Split output into partitions limited to this number of messages.")]
@@ -42,34 +40,32 @@ namespace DiscordChatExporter.Cli.Commands
ExportService = exportService;
}
protected async Task ExportChannelAsync(IConsole console, Channel channel)
protected async Task ExportAsync(IConsole console, Guild guild, Channel channel)
{
// Configure settings
if (!string.IsNullOrWhiteSpace(DateFormat))
SettingsService.DateFormat = DateFormat!;
SettingsService.DateFormat = DateFormat;
console.Output.Write($"Exporting channel [{channel.Name}]... ");
var progress = console.CreateProgressTicker();
// 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 (string.IsNullOrWhiteSpace(filePath) || 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);
var outputPath = OutputPath ?? Directory.GetCurrentDirectory();
await ExportService.ExportChatLogAsync(GetToken(), guild, channel,
outputPath, ExportFormat, PartitionLimit,
After, Before, progress);
console.Output.WriteLine();
}
protected async Task ExportAsync(IConsole console, Channel channel)
{
var guild = await DataService.GetGuildAsync(GetToken(), channel.GuildId);
await ExportAsync(console, guild, channel);
}
protected async Task ExportAsync(IConsole console, string channelId)
{
var channel = await DataService.GetChannelAsync(GetToken(), channelId);
await ExportAsync(console, channel);
}
}
}

View File

@@ -29,7 +29,7 @@ namespace DiscordChatExporter.Cli.Commands
{
try
{
await ExportChannelAsync(console, channel);
await ExportAsync(console, channel);
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
{

View File

@@ -33,7 +33,7 @@ namespace DiscordChatExporter.Cli.Commands
{
try
{
await ExportChannelAsync(console, channel);
await ExportAsync(console, channel);
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
{