From 60389ab0023d83c8570170ac4bbe4eac388577be Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Mon, 21 Aug 2023 01:03:29 +0300 Subject: [PATCH] Add warning about `IsBotToken` deprecation --- .../Commands/Base/DiscordCommandBase.cs | 20 ++++++++++++++++++- .../Commands/Base/ExportCommandBase.cs | 10 +++++----- .../Commands/ExportAllCommand.cs | 2 +- .../Commands/ExportChannelsCommand.cs | 2 +- .../Commands/ExportDirectMessagesCommand.cs | 2 +- .../Commands/ExportGuildCommand.cs | 2 +- 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/DiscordChatExporter.Cli/Commands/Base/DiscordCommandBase.cs b/DiscordChatExporter.Cli/Commands/Base/DiscordCommandBase.cs index f24b4e0..a4f1edd 100644 --- a/DiscordChatExporter.Cli/Commands/Base/DiscordCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/Base/DiscordCommandBase.cs @@ -29,5 +29,23 @@ public abstract class DiscordCommandBase : ICommand private DiscordClient? _discordClient; protected DiscordClient Discord => _discordClient ??= new DiscordClient(Token); - public abstract ValueTask ExecuteAsync(IConsole console); + public virtual ValueTask ExecuteAsync(IConsole console) + { +#pragma warning disable CS0618 + // Warn if the bot option is used + if (IsBotToken) + { + using (console.WithForegroundColor(ConsoleColor.DarkYellow)) + { + console.Error.WriteLine( + "Warning: Option --bot is deprecated and should not be used. " + + "The type of the provided token is now inferred automatically. " + + "Please update your workflows as this option may be completely removed in a future version." + ); + } + } +#pragma warning restore CS0618 + + return default; + } } \ No newline at end of file diff --git a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs index a523c9b..8cb3c4e 100644 --- a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs @@ -136,7 +136,7 @@ public abstract class ExportCommandBase : DiscordCommandBase private ChannelExporter? _channelExporter; protected ChannelExporter Exporter => _channelExporter ??= new ChannelExporter(Discord); - protected async ValueTask ExecuteAsync(IConsole console, IReadOnlyList channels) + protected async ValueTask ExportAsync(IConsole console, IReadOnlyList channels) { // Asset reuse can only be enabled if the download assets option is set // https://github.com/Tyrrrz/DiscordChatExporter/issues/425 @@ -268,7 +268,7 @@ public abstract class ExportCommandBase : DiscordCommandBase throw new CommandException("Export failed."); } - protected async ValueTask ExecuteAsync(IConsole console, IReadOnlyList channelIds) + protected async ValueTask ExportAsync(IConsole console, IReadOnlyList channelIds) { var cancellationToken = console.RegisterCancellationHandler(); @@ -303,10 +303,10 @@ public abstract class ExportCommandBase : DiscordCommandBase } } - await ExecuteAsync(console, channels); + await ExportAsync(console, channels); } - public override ValueTask ExecuteAsync(IConsole console) + public override async ValueTask ExecuteAsync(IConsole console) { // Support Ukraine callout if (!IsUkraineSupportMessageDisabled) @@ -323,6 +323,6 @@ public abstract class ExportCommandBase : DiscordCommandBase console.Output.WriteLine(""); } - return default; + await base.ExecuteAsync(console); } } \ No newline at end of file diff --git a/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs b/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs index a6525c9..e32353e 100644 --- a/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs @@ -106,6 +106,6 @@ public class ExportAllCommand : ExportCommandBase if (!IncludeVoiceChannels) channels.RemoveAll(c => c.Kind.IsVoice()); - await base.ExecuteAsync(console, channels); + await ExportAsync(console, channels); } } \ No newline at end of file diff --git a/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs index 79352d2..0fc648f 100644 --- a/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs @@ -23,6 +23,6 @@ public class ExportChannelsCommand : ExportCommandBase public override async ValueTask ExecuteAsync(IConsole console) { await base.ExecuteAsync(console); - await base.ExecuteAsync(console, ChannelIds); + await ExportAsync(console, ChannelIds); } } \ No newline at end of file diff --git a/DiscordChatExporter.Cli/Commands/ExportDirectMessagesCommand.cs b/DiscordChatExporter.Cli/Commands/ExportDirectMessagesCommand.cs index b6f7862..fbbe4c9 100644 --- a/DiscordChatExporter.Cli/Commands/ExportDirectMessagesCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportDirectMessagesCommand.cs @@ -19,6 +19,6 @@ public class ExportDirectMessagesCommand : ExportCommandBase await console.Output.WriteLineAsync("Fetching channels..."); var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken); - await base.ExecuteAsync(console, channels); + await ExportAsync(console, channels); } } \ No newline at end of file diff --git a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs index ee021ba..955f4d1 100644 --- a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs @@ -38,6 +38,6 @@ public class ExportGuildCommand : ExportCommandBase .Where(c => IncludeVoiceChannels || !c.Kind.IsVoice()) .ToArray(); - await base.ExecuteAsync(console, channels); + await ExportAsync(console, channels); } } \ No newline at end of file