Add warning about IsBotToken deprecation

This commit is contained in:
Tyrrrz 2023-08-21 01:03:29 +03:00
parent 817d54039b
commit 60389ab002
6 changed files with 28 additions and 10 deletions

View file

@ -29,5 +29,23 @@ public abstract class DiscordCommandBase : ICommand
private DiscordClient? _discordClient; private DiscordClient? _discordClient;
protected DiscordClient Discord => _discordClient ??= new DiscordClient(Token); 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;
}
} }

View file

@ -136,7 +136,7 @@ public abstract class ExportCommandBase : DiscordCommandBase
private ChannelExporter? _channelExporter; private ChannelExporter? _channelExporter;
protected ChannelExporter Exporter => _channelExporter ??= new ChannelExporter(Discord); protected ChannelExporter Exporter => _channelExporter ??= new ChannelExporter(Discord);
protected async ValueTask ExecuteAsync(IConsole console, IReadOnlyList<Channel> channels) protected async ValueTask ExportAsync(IConsole console, IReadOnlyList<Channel> channels)
{ {
// Asset reuse can only be enabled if the download assets option is set // Asset reuse can only be enabled if the download assets option is set
// https://github.com/Tyrrrz/DiscordChatExporter/issues/425 // https://github.com/Tyrrrz/DiscordChatExporter/issues/425
@ -268,7 +268,7 @@ public abstract class ExportCommandBase : DiscordCommandBase
throw new CommandException("Export failed."); throw new CommandException("Export failed.");
} }
protected async ValueTask ExecuteAsync(IConsole console, IReadOnlyList<Snowflake> channelIds) protected async ValueTask ExportAsync(IConsole console, IReadOnlyList<Snowflake> channelIds)
{ {
var cancellationToken = console.RegisterCancellationHandler(); 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 // Support Ukraine callout
if (!IsUkraineSupportMessageDisabled) if (!IsUkraineSupportMessageDisabled)
@ -323,6 +323,6 @@ public abstract class ExportCommandBase : DiscordCommandBase
console.Output.WriteLine(""); console.Output.WriteLine("");
} }
return default; await base.ExecuteAsync(console);
} }
} }

View file

@ -106,6 +106,6 @@ public class ExportAllCommand : ExportCommandBase
if (!IncludeVoiceChannels) if (!IncludeVoiceChannels)
channels.RemoveAll(c => c.Kind.IsVoice()); channels.RemoveAll(c => c.Kind.IsVoice());
await base.ExecuteAsync(console, channels); await ExportAsync(console, channels);
} }
} }

View file

@ -23,6 +23,6 @@ public class ExportChannelsCommand : ExportCommandBase
public override async ValueTask ExecuteAsync(IConsole console) public override async ValueTask ExecuteAsync(IConsole console)
{ {
await base.ExecuteAsync(console); await base.ExecuteAsync(console);
await base.ExecuteAsync(console, ChannelIds); await ExportAsync(console, ChannelIds);
} }
} }

View file

@ -19,6 +19,6 @@ public class ExportDirectMessagesCommand : ExportCommandBase
await console.Output.WriteLineAsync("Fetching channels..."); await console.Output.WriteLineAsync("Fetching channels...");
var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken); var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken);
await base.ExecuteAsync(console, channels); await ExportAsync(console, channels);
} }
} }

View file

@ -38,6 +38,6 @@ public class ExportGuildCommand : ExportCommandBase
.Where(c => IncludeVoiceChannels || !c.Kind.IsVoice()) .Where(c => IncludeVoiceChannels || !c.Kind.IsVoice())
.ToArray(); .ToArray();
await base.ExecuteAsync(console, channels); await ExportAsync(console, channels);
} }
} }