[CLI] Cleanup

pull/278/head
Alexey Golub 5 years ago
parent 1d39fe9c53
commit a01835efb6

@ -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)

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

@ -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();

@ -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();

@ -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();

@ -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();

@ -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();

@ -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);
}
}
Loading…
Cancel
Save