mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-06-07 18:04:41 -04:00
Change command line argument style
This commit is contained in:
parent
c7e246540b
commit
83ea7ae317
5 changed files with 51 additions and 41 deletions
|
@ -14,7 +14,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CommandLineParser" Version="1.9.71" />
|
|
||||||
<PackageReference Include="HtmlAgilityPack" Version="1.5.1" />
|
<PackageReference Include="HtmlAgilityPack" Version="1.5.1" />
|
||||||
<PackageReference Include="Newtonsoft.json" Version="10.0.3" />
|
<PackageReference Include="Newtonsoft.json" Version="10.0.3" />
|
||||||
<PackageReference Include="Tyrrrz.Extensions" Version="1.4.0" />
|
<PackageReference Include="Tyrrrz.Extensions" Version="1.4.0" />
|
||||||
|
|
15
DiscordChatExporter/Models/Options.cs
Normal file
15
DiscordChatExporter/Models/Options.cs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
namespace DiscordChatExporter.Models
|
||||||
|
{
|
||||||
|
public class Options
|
||||||
|
{
|
||||||
|
public string Token { get; }
|
||||||
|
|
||||||
|
public string ChannelId { get; }
|
||||||
|
|
||||||
|
public Options(string token, string channelId)
|
||||||
|
{
|
||||||
|
Token = token;
|
||||||
|
ChannelId = channelId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,32 +0,0 @@
|
||||||
using CommandLine;
|
|
||||||
using CommandLine.Text;
|
|
||||||
|
|
||||||
namespace DiscordChatExporter
|
|
||||||
{
|
|
||||||
public class Options
|
|
||||||
{
|
|
||||||
[Option('t', "token", Required = true, HelpText = "Discord access token")]
|
|
||||||
public string Token { get; set; }
|
|
||||||
|
|
||||||
[Option('c', "channel", Required = true, HelpText = "ID of the text channel to export")]
|
|
||||||
public string ChannelId { get; set; }
|
|
||||||
|
|
||||||
[HelpOption]
|
|
||||||
public string GetUsage()
|
|
||||||
{
|
|
||||||
var help = new HelpText
|
|
||||||
{
|
|
||||||
Heading = new HeadingInfo("DiscordChatExporter"),
|
|
||||||
Copyright = new CopyrightInfo("Alexey 'Tyrrrz' Golub", 2017),
|
|
||||||
AdditionalNewLineAfterOption = true,
|
|
||||||
AddDashesToOption = true
|
|
||||||
};
|
|
||||||
help.AddPreOptionsLine("Usage: DiscordChatExporter.exe " +
|
|
||||||
"-t REkOTVqm9RWOTNOLCdiuMpWd.QiglBz.Lub0E0TZ1xX4ZxCtnwtpBhWt3v1 " +
|
|
||||||
"-c 459360869055190534");
|
|
||||||
help.AddOptions(this);
|
|
||||||
|
|
||||||
return help;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +1,59 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DiscordChatExporter.Models;
|
using DiscordChatExporter.Models;
|
||||||
using DiscordChatExporter.Services;
|
using DiscordChatExporter.Services;
|
||||||
|
using Tyrrrz.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter
|
namespace DiscordChatExporter
|
||||||
{
|
{
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
private static readonly Options Options = new Options();
|
|
||||||
|
|
||||||
private static readonly DiscordApiService DiscordApiService = new DiscordApiService();
|
private static readonly DiscordApiService DiscordApiService = new DiscordApiService();
|
||||||
private static readonly ExportService ExportService = new ExportService();
|
private static readonly ExportService ExportService = new ExportService();
|
||||||
|
|
||||||
|
private static Options GetOptions(string[] args)
|
||||||
|
{
|
||||||
|
// Parse the arguments
|
||||||
|
var argsDic = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
foreach (string arg in args)
|
||||||
|
{
|
||||||
|
var match = Regex.Match(arg, "/(.*?):\"?(.*?)\"?$");
|
||||||
|
string key = match.Groups[1].Value;
|
||||||
|
string value = match.Groups[2].Value;
|
||||||
|
|
||||||
|
if (key.IsBlank())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
argsDic[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract required arguments
|
||||||
|
string token = argsDic.GetOrDefault("token");
|
||||||
|
string channelId = argsDic.GetOrDefault("channelId");
|
||||||
|
|
||||||
|
// Verify arguments
|
||||||
|
if (token.IsBlank() || channelId.IsBlank())
|
||||||
|
throw new ArgumentException("Some or all required command line arguments are missing");
|
||||||
|
|
||||||
|
// Create option set
|
||||||
|
return new Options(token, channelId);
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task MainAsync(string[] args)
|
private static async Task MainAsync(string[] args)
|
||||||
{
|
{
|
||||||
// Parse cmd args
|
// Parse cmd args
|
||||||
CommandLine.Parser.Default.ParseArgumentsStrict(args, Options);
|
var options = GetOptions(args);
|
||||||
|
|
||||||
// Get messages
|
// Get messages
|
||||||
Console.WriteLine("Getting messages...");
|
Console.WriteLine("Getting messages...");
|
||||||
var messages = await DiscordApiService.GetMessagesAsync(Options.Token, Options.ChannelId);
|
var messages = await DiscordApiService.GetMessagesAsync(options.Token, options.ChannelId);
|
||||||
var chatLog = new ChatLog(Options.ChannelId, messages);
|
var chatLog = new ChatLog(options.ChannelId, messages);
|
||||||
|
|
||||||
// Export
|
// Export
|
||||||
Console.WriteLine("Exporting messages...");
|
Console.WriteLine("Exporting messages...");
|
||||||
ExportService.Export($"{Options.ChannelId}.html", chatLog);
|
ExportService.Export($"{options.ChannelId}.html", chatLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
|
|
|
@ -25,11 +25,10 @@ You can get your token by opening the Discord app, pressing `Ctrl+Shift+I`, navi
|
||||||
|
|
||||||
You can get the channel ID by enabling `Developer Mode` in `Settings > Appearance` and then right clicking on the channel and clicking on `Copy ID`.
|
You can get the channel ID by enabling `Developer Mode` in `Settings > Appearance` and then right clicking on the channel and clicking on `Copy ID`.
|
||||||
|
|
||||||
- `DiscordChatExporter.exe -t REkOTVqm9RWOTNOLCdiuMpWd.QiglBz.Lub0E0TZ1xX4ZxCtnwtpBhWt3v1 -c 459360869055190534`
|
- `DiscordChatExporter.exe /token:REkOTVqm9RWOTNOLCdiuMpWd.QiglBz.Lub0E0TZ1xX4ZxCtnwtpBhWt3v1 /channelId:459360869055190534`
|
||||||
|
|
||||||
## Libraries used
|
## Libraries used
|
||||||
|
|
||||||
- [CommandLineParser](https://github.com/gsscoder/commandline)
|
|
||||||
- [HtmlAgilityPack](https://github.com/zzzprojects/html-agility-pack)
|
- [HtmlAgilityPack](https://github.com/zzzprojects/html-agility-pack)
|
||||||
- [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)
|
- [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)
|
||||||
- [Tyrrrz.Extensions](https://github.com/Tyrrrz/Extensions)
|
- [Tyrrrz.Extensions](https://github.com/Tyrrrz/Extensions)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue