mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-18 00:22:48 +00:00
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user