mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-24 19:54:22 -04:00
Migrate DiscordChatExporter.Cli to CliFx
This commit is contained in:
parent
117d1b7e4a
commit
58ba99e0c6
29 changed files with 419 additions and 546 deletions
|
@ -1,80 +1,35 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using CommandLine;
|
||||
using DiscordChatExporter.Cli.Verbs;
|
||||
using DiscordChatExporter.Cli.Verbs.Options;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using DiscordChatExporter.Core.Services;
|
||||
using StyletIoC;
|
||||
|
||||
namespace DiscordChatExporter.Cli
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
private static void PrintTokenHelp()
|
||||
private static IContainer BuildContainer()
|
||||
{
|
||||
Console.WriteLine("# To get user token:");
|
||||
Console.WriteLine(" 1. Open Discord");
|
||||
Console.WriteLine(" 2. Press Ctrl+Shift+I to show developer tools");
|
||||
Console.WriteLine(" 3. Navigate to the Application tab");
|
||||
Console.WriteLine(" 4. Select \"Local Storage\" > \"https://discordapp.com\" on the left");
|
||||
Console.WriteLine(" 5. Press Ctrl+R to reload");
|
||||
Console.WriteLine(" 6. Find \"token\" at the bottom and copy the value");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("# To get bot token:");
|
||||
Console.WriteLine(" 1. Go to Discord developer portal");
|
||||
Console.WriteLine(" 2. Open your application's settings");
|
||||
Console.WriteLine(" 3. Navigate to the Bot section on the left");
|
||||
Console.WriteLine(" 4. Under Token click Copy");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("# To get guild ID or guild channel ID:");
|
||||
Console.WriteLine(" 1. Open Discord");
|
||||
Console.WriteLine(" 2. Open Settings");
|
||||
Console.WriteLine(" 3. Go to Appearance section");
|
||||
Console.WriteLine(" 4. Enable Developer Mode");
|
||||
Console.WriteLine(" 5. Right click on the desired guild or channel and click Copy ID");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("# To get direct message channel ID:");
|
||||
Console.WriteLine(" 1. Open Discord");
|
||||
Console.WriteLine(" 2. Open the desired direct message channel");
|
||||
Console.WriteLine(" 3. Press Ctrl+Shift+I to show developer tools");
|
||||
Console.WriteLine(" 4. Navigate to the Console tab");
|
||||
Console.WriteLine(" 5. Type \"window.location.href\" and press Enter");
|
||||
Console.WriteLine(" 6. Copy the first long sequence of numbers inside the URL");
|
||||
var builder = new StyletIoCBuilder();
|
||||
|
||||
// Autobind the .Services assembly
|
||||
builder.Autobind(typeof(DataService).Assembly);
|
||||
|
||||
// Bind settings as singleton
|
||||
builder.Bind<SettingsService>().ToSelf().InSingletonScope();
|
||||
|
||||
// Set instance
|
||||
return builder.BuildContainer();
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
public static Task<int> Main(string[] args)
|
||||
{
|
||||
// Get all verb types
|
||||
var verbTypes = new[]
|
||||
{
|
||||
typeof(ExportChannelOptions),
|
||||
typeof(ExportDirectMessagesOptions),
|
||||
typeof(ExportGuildOptions),
|
||||
typeof(GetChannelsOptions),
|
||||
typeof(GetDirectMessageChannelsOptions),
|
||||
typeof(GetGuildsOptions)
|
||||
};
|
||||
var container = BuildContainer();
|
||||
|
||||
// Parse command line arguments
|
||||
var parsedArgs = Parser.Default.ParseArguments(args, verbTypes);
|
||||
|
||||
// Execute commands
|
||||
parsedArgs.WithParsed<ExportChannelOptions>(o => new ExportChannelVerb(o).Execute());
|
||||
parsedArgs.WithParsed<ExportDirectMessagesOptions>(o => new ExportDirectMessagesVerb(o).Execute());
|
||||
parsedArgs.WithParsed<ExportGuildOptions>(o => new ExportGuildVerb(o).Execute());
|
||||
parsedArgs.WithParsed<GetChannelsOptions>(o => new GetChannelsVerb(o).Execute());
|
||||
parsedArgs.WithParsed<GetDirectMessageChannelsOptions>(o => new GetDirectMessageChannelsVerb(o).Execute());
|
||||
parsedArgs.WithParsed<GetGuildsOptions>(o => new GetGuildsVerb(o).Execute());
|
||||
|
||||
// Show token help if help requested or no verb specified
|
||||
parsedArgs.WithNotParsed(errs =>
|
||||
{
|
||||
var err = errs.First();
|
||||
|
||||
if (err.Tag == ErrorType.NoVerbSelectedError)
|
||||
PrintTokenHelp();
|
||||
|
||||
if (err.Tag == ErrorType.HelpVerbRequestedError && args.Length == 1)
|
||||
PrintTokenHelp();
|
||||
});
|
||||
return new CliApplicationBuilder()
|
||||
.AddCommandsFromThisAssembly()
|
||||
.UseCommandFactory(schema => (ICommand) container.Get(schema.Type))
|
||||
.Build()
|
||||
.RunAsync(args);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue