diff --git a/DiscordChatExporter.Cli/Commands/ExportChannelCommand.cs b/DiscordChatExporter.Cli/Commands/ExportChannelCommand.cs index dda10f5..0890c14 100644 --- a/DiscordChatExporter.Cli/Commands/ExportChannelCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportChannelCommand.cs @@ -8,8 +8,8 @@ namespace DiscordChatExporter.Cli.Commands [Command("export", Description = "Export a channel.")] public class ExportChannelCommand : ExportCommandBase { - [CommandOption("channel", 'c', IsRequired = true, Description= "Channel ID.")] - public string ChannelId { get; set; } + [CommandOption("channel", 'c', IsRequired = true, Description = "Channel ID.")] + public string ChannelId { get; set; } = ""; public ExportChannelCommand(SettingsService settingsService, DataService dataService, ExportService exportService) : base(settingsService, dataService, exportService) diff --git a/DiscordChatExporter.Cli/Commands/ExportCommandBase.cs b/DiscordChatExporter.Cli/Commands/ExportCommandBase.cs index 161bc6e..b9b21ef 100644 --- a/DiscordChatExporter.Cli/Commands/ExportCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/ExportCommandBase.cs @@ -19,7 +19,7 @@ namespace DiscordChatExporter.Cli.Commands public ExportFormat ExportFormat { get; set; } = ExportFormat.HtmlDark; [CommandOption("output", 'o', Description = "Output file or directory path.")] - public string? OutputPath { get; set; } + public string OutputPath { get; set; } = Directory.GetCurrentDirectory(); [CommandOption("after", Description = "Limit to messages sent after this date.")] public DateTimeOffset? After { get; set; } @@ -48,9 +48,8 @@ namespace DiscordChatExporter.Cli.Commands console.Output.Write($"Exporting channel [{channel.Name}]... "); var progress = console.CreateProgressTicker(); - var outputPath = OutputPath ?? Directory.GetCurrentDirectory(); - await ExportService.ExportChatLogAsync(GetToken(), guild, channel, - outputPath, ExportFormat, PartitionLimit, + await ExportService.ExportChatLogAsync(Token, guild, channel, + OutputPath, ExportFormat, PartitionLimit, After, Before, progress); console.Output.WriteLine(); @@ -58,13 +57,13 @@ namespace DiscordChatExporter.Cli.Commands protected async ValueTask ExportAsync(IConsole console, Channel channel) { - var guild = await DataService.GetGuildAsync(GetToken(), channel.GuildId); + var guild = await DataService.GetGuildAsync(Token, channel.GuildId); await ExportAsync(console, guild, channel); } protected async ValueTask ExportAsync(IConsole console, string channelId) { - var channel = await DataService.GetChannelAsync(GetToken(), channelId); + var channel = await DataService.GetChannelAsync(Token, channelId); await ExportAsync(console, channel); } } diff --git a/DiscordChatExporter.Cli/Commands/ExportDirectMessagesCommand.cs b/DiscordChatExporter.Cli/Commands/ExportDirectMessagesCommand.cs index 673ac41..92e39b8 100644 --- a/DiscordChatExporter.Cli/Commands/ExportDirectMessagesCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportDirectMessagesCommand.cs @@ -20,7 +20,7 @@ namespace DiscordChatExporter.Cli.Commands public override async ValueTask ExecuteAsync(IConsole console) { // Get channels - var channels = await DataService.GetDirectMessageChannelsAsync(GetToken()); + var channels = await DataService.GetDirectMessageChannelsAsync(Token); // Order channels channels = channels.OrderBy(c => c.Name).ToArray(); diff --git a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs index ead8a3a..c69941e 100644 --- a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs @@ -14,7 +14,7 @@ namespace DiscordChatExporter.Cli.Commands public class ExportGuildCommand : ExportCommandBase { [CommandOption("guild", 'g', IsRequired = true, Description = "Guild ID.")] - public string GuildId { get; set; } + public string GuildId { get; set; } = ""; public ExportGuildCommand(SettingsService settingsService, DataService dataService, ExportService exportService) : base(settingsService, dataService, exportService) @@ -24,7 +24,7 @@ namespace DiscordChatExporter.Cli.Commands public override async ValueTask ExecuteAsync(IConsole console) { // Get channels - var channels = await DataService.GetGuildChannelsAsync(GetToken(), GuildId); + var channels = await DataService.GetGuildChannelsAsync(Token, GuildId); // Filter and order channels channels = channels.Where(c => c.Type.IsExportable()).OrderBy(c => c.Name).ToArray(); diff --git a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs index 1c246ac..4052dab 100644 --- a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs @@ -11,7 +11,7 @@ namespace DiscordChatExporter.Cli.Commands public class GetChannelsCommand : TokenCommandBase { [CommandOption("guild", 'g', IsRequired = true, Description = "Guild ID.")] - public string GuildId { get; set; } + public string GuildId { get; set; } = ""; public GetChannelsCommand(DataService dataService) : base(dataService) @@ -21,7 +21,7 @@ namespace DiscordChatExporter.Cli.Commands public override async ValueTask ExecuteAsync(IConsole console) { // Get channels - var channels = await DataService.GetGuildChannelsAsync(GetToken(), GuildId); + var channels = await DataService.GetGuildChannelsAsync(Token, GuildId); // Filter and order channels channels = channels.Where(c => c.Type.IsExportable()).OrderBy(c => c.Name).ToArray(); diff --git a/DiscordChatExporter.Cli/Commands/GetDirectMessageChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/GetDirectMessageChannelsCommand.cs index 1ae59c4..f4dcc2f 100644 --- a/DiscordChatExporter.Cli/Commands/GetDirectMessageChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetDirectMessageChannelsCommand.cs @@ -17,7 +17,7 @@ namespace DiscordChatExporter.Cli.Commands public override async ValueTask ExecuteAsync(IConsole console) { // Get channels - var channels = await DataService.GetDirectMessageChannelsAsync(GetToken()); + var channels = await DataService.GetDirectMessageChannelsAsync(Token); // Order channels channels = channels.OrderBy(c => c.Name).ToArray(); diff --git a/DiscordChatExporter.Cli/Commands/GetGuildsCommand.cs b/DiscordChatExporter.Cli/Commands/GetGuildsCommand.cs index cc4c552..5dd43e9 100644 --- a/DiscordChatExporter.Cli/Commands/GetGuildsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetGuildsCommand.cs @@ -17,7 +17,7 @@ namespace DiscordChatExporter.Cli.Commands public override async ValueTask ExecuteAsync(IConsole console) { // Get guilds - var guilds = await DataService.GetUserGuildsAsync(GetToken()); + var guilds = await DataService.GetUserGuildsAsync(Token); // Order guilds guilds = guilds.OrderBy(g => g.Name).ToArray(); diff --git a/DiscordChatExporter.Cli/Commands/TokenCommandBase.cs b/DiscordChatExporter.Cli/Commands/TokenCommandBase.cs index 8dacf99..35f23c8 100644 --- a/DiscordChatExporter.Cli/Commands/TokenCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/TokenCommandBase.cs @@ -11,18 +11,18 @@ namespace DiscordChatExporter.Cli.Commands protected DataService DataService { get; } [CommandOption("token", 't', IsRequired = true, Description = "Authorization token.")] - public string TokenValue { get; set; } + public string TokenValue { get; set; } = ""; [CommandOption("bot", 'b', Description = "Whether this authorization token belongs to a bot.")] public bool IsBotToken { get; set; } + protected AuthToken Token => new AuthToken(IsBotToken ? AuthTokenType.Bot : AuthTokenType.User, TokenValue); + protected TokenCommandBase(DataService dataService) { DataService = dataService; } - protected AuthToken GetToken() => new AuthToken(IsBotToken ? AuthTokenType.Bot : AuthTokenType.User, TokenValue); - public abstract ValueTask ExecuteAsync(IConsole console); } } \ No newline at end of file