mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-07-10 16:01:55 +02:00
Compare commits
80 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f7f6ac9494 | |||
| 481958f4d3 | |||
| 5e3502cbc5 | |||
| 3b03c30865 | |||
| c9e16a7f74 | |||
| f9b6793d47 | |||
| cfbd267d3a | |||
| 2b6f01bf6f | |||
| a44d43eefc | |||
| 0e138bac7d | |||
| 71876febf8 | |||
| 489c786c1e | |||
| eb0c61e173 | |||
| 9341c21963 | |||
| 704c483074 | |||
| 1f0e667085 | |||
| 0b72b73d1d | |||
| 32dd1689d0 | |||
| 2e4d19671a | |||
| 5b4d88ca26 | |||
| 65cc3954b6 | |||
| ffe5544f9c | |||
| bf1ad07a9c | |||
| 338566c1d6 | |||
| 91ea7a443c | |||
| aea96d5eba | |||
| e29f08264c | |||
| ad84ecf6a4 | |||
| ae57a0ff7c | |||
| 1daff4178d | |||
| 3a2b119618 | |||
| 5f27426f44 | |||
| a893ebda68 | |||
| 9221966171 | |||
| 67325b610a | |||
| 3186ce90c8 | |||
| 168d7c8ec9 | |||
| daa1b3f6b3 | |||
| e2780d6666 | |||
| b996215e36 | |||
| 08d9af534b | |||
| bef110a193 | |||
| 12555e576f | |||
| afb4bc67ae | |||
| f80a5fe644 | |||
| b7dca87fb9 | |||
| 8ecc2940b0 | |||
| 407c2bd2ae | |||
| 5b563d4f00 | |||
| ecb615ecf1 | |||
| 7c212ef893 | |||
| 36b4a45f3a | |||
| 51cc132e5d | |||
| cf83cbd89c | |||
| d51d0d4872 | |||
| 2467caac9f | |||
| bd98f4cb6a | |||
| fc7191d74c | |||
| 6c484d1f88 | |||
| c36b8df8e7 | |||
| 0408096746 | |||
| 40d833cd57 | |||
| 0de1f47310 | |||
| e31ff55e33 | |||
| 81525a1076 | |||
| 65ab003ff5 | |||
| 2156c6cd0c | |||
| e97151cd19 | |||
| 271a478a0e | |||
| b40a88c4d3 | |||
| f03f5f8072 | |||
| bfa5d10761 | |||
| 7a9e25c1f0 | |||
| 4599e64f0a | |||
| 4389b4e0bc | |||
| 008bb2f591 | |||
| b8567d384f | |||
| a06b448f4a | |||
| ba4ece9325 | |||
| 880f400e2c |
@@ -1,3 +0,0 @@
|
|||||||
github: Tyrrrz
|
|
||||||
patreon: Tyrrrz
|
|
||||||
custom: ['buymeacoffee.com/Tyrrrz', 'tyrrrz.me/donate']
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<!--
|
|
||||||
|
|
||||||
**Important:**
|
|
||||||
|
|
||||||
Please make sure that there is an existing issue that describes the problem solved by your pull request. If there isn't one, consider creating it first.
|
|
||||||
An open issue offers a good place to iron out requirements, discuss possible solutions, and ask questions.
|
|
||||||
|
|
||||||
Remember to also:
|
|
||||||
|
|
||||||
- Keep your pull request focused and as small as possible. If you want to contribute multiple unrelated changes, please create separate pull requests for them.
|
|
||||||
- Follow the coding style and conventions already established by the project. When in doubt about which style to use, ask in the comments to your pull request.
|
|
||||||
- If you want to start a discussion regarding a specific change you've made, add a review comment to your own code. This can be used to highlight something important or to seek further input from others.
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- Please specify the issue addressed by this pull request -->
|
|
||||||
Closes #ISSUE_NUMBER
|
|
||||||
@@ -20,7 +20,8 @@ jobs:
|
|||||||
- name: Install .NET
|
- name: Install .NET
|
||||||
uses: actions/setup-dotnet@v1.7.2
|
uses: actions/setup-dotnet@v1.7.2
|
||||||
with:
|
with:
|
||||||
dotnet-version: 6.0.x
|
# Fixed version, workaround for https://github.com/dotnet/core/issues/7176
|
||||||
|
dotnet-version: 6.0.100
|
||||||
|
|
||||||
- name: Build & publish (CLI)
|
- name: Build & publish (CLI)
|
||||||
run: dotnet publish DiscordChatExporter.Cli/ -o DiscordChatExporter.Cli/bin/Publish/ --configuration Release
|
run: dotnet publish DiscordChatExporter.Cli/ -o DiscordChatExporter.Cli/bin/Publish/ --configuration Release
|
||||||
|
|||||||
@@ -13,12 +13,13 @@ jobs:
|
|||||||
- name: Install .NET
|
- name: Install .NET
|
||||||
uses: actions/setup-dotnet@v1.7.2
|
uses: actions/setup-dotnet@v1.7.2
|
||||||
with:
|
with:
|
||||||
dotnet-version: 6.0.x
|
# Fixed version, workaround for https://github.com/dotnet/core/issues/7176
|
||||||
|
dotnet-version: 6.0.100
|
||||||
|
|
||||||
- name: Build & test
|
- name: Build & test
|
||||||
# Tests need access to secrets, so we can't run them against PRs because of limited trust
|
# Tests need access to secrets, so we can't run them against PRs because of limited trust
|
||||||
if: ${{ github.event_name != 'pull_request' }}
|
if: ${{ github.event_name != 'pull_request' }}
|
||||||
run: dotnet test --configuration Release --logger GitHubActions
|
run: dotnet test --configuration Release --logger GitHubActions --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
|
||||||
env:
|
env:
|
||||||
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
|
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
|
||||||
DISCORD_TOKEN_BOT: true
|
DISCORD_TOKEN_BOT: true
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 45 KiB |
@@ -1,3 +1,46 @@
|
|||||||
|
### v2.34 (10-Apr-2022)
|
||||||
|
|
||||||
|
- [HTML] Reworked layout to be more consistent with Discord.
|
||||||
|
- [HTML] Changed user profile picture dimensions from `128x128` to `512x512`. (Thanks [@Chris Helder](https://github.com/TheDude53))
|
||||||
|
- [HTML] Improved image scaling for Chromium-based browsers. This should result in higher quality images across the entire export.
|
||||||
|
- [HTML] Hovering over messages will now show short timestamps on the left, indicating the time that the individual messages of the group were sent.
|
||||||
|
- [HTML] Using "download media" option will now also download scripts, styles, fonts, and other similar resources used by the export.
|
||||||
|
- [HTML] Image attachments will now use the provided description as alt text.
|
||||||
|
- [HTML] Fixed a few layout inconsistencies related to embeds.
|
||||||
|
- [GUI] Added a few clickable links to the usage guide to make the process of locating tokens easier.
|
||||||
|
|
||||||
|
### v2.33.2 (07-Mar-2022)
|
||||||
|
|
||||||
|
- Actually fixed it this time.
|
||||||
|
|
||||||
|
### v2.33.1 (07-Mar-2022)
|
||||||
|
|
||||||
|
- Fixed an issue where the application silently failed to run if the system didn't have .NET Runtime 6.0.2 installed. If you continue seeing this issue, please uninstall all existing .NET runtimes from your computer and then try running the application again.
|
||||||
|
|
||||||
|
### v2.33 (06-Mar-2022)
|
||||||
|
|
||||||
|
- Added messages informing about war in Ukraine and available ways to help.
|
||||||
|
- Added support for rendering stickers in HTML and JSON. Lottie-based stickers currently cannot be displayed in HTML exports (see [#803](https://github.com/Tyrrrz/DiscordChatExporter/issues/803)).
|
||||||
|
- Added a new `reaction:` message filter which can be used to check if someone reacted to a message with a specific emoji. You can either pass the emoji name (e.g. `reaction:LUL`) or its ID (e.g. `reaction:41771983429993937`).
|
||||||
|
- [GUI] Added auto-detection for dark mode. If your system is configured to prefer dark mode in applications, DiscordChatExporter will use it by default instead of light mode.
|
||||||
|
- Fixed an issue which caused the export process to crash when downloading media files with extremely long file extensions. (Thanks [@Tomlacko](https://github.com/Tomlacko))
|
||||||
|
- Fixed an issue which caused the export process to crash on invalid mentions.
|
||||||
|
- [GUI] Fixed an issue where the time pickers used to specify export ranges always displayed time in 12-hour format, instead of respecting the system locale.
|
||||||
|
|
||||||
|
### v2.32 (27-Jan-2022)
|
||||||
|
|
||||||
|
- Token kind (user or bot) is now detected automatically. Removed the button to switch token kind in GUI. Option `-b|--bot` in CLI is now deprecated and does nothing.
|
||||||
|
- Updated user token extraction guide to reflect the fact that devtools are no longer accessible in the desktop version of Discord client. The recommended workaround is to open Discord in browser. (Thanks [@Dhananjay-JSR](https://github.com/Dhananjay-JSR))
|
||||||
|
- Fixed an issue which caused an error when parsing invalid date timestamps. Such timestamps are now rendered as "Invalid date", similarly to how the Discord client does it.
|
||||||
|
- Fixed an issue which caused an error when parsing certain embed fields.
|
||||||
|
- Fixed an issue which caused an error when parsing a mention to a user that has no username.
|
||||||
|
- [GUI] Minor visual fixes.
|
||||||
|
|
||||||
|
### v2.31.1 (15-Dec-2021)
|
||||||
|
|
||||||
|
- Fixed an issue which caused an error when parsing certain custom emoji reactions.
|
||||||
|
- [GUI] Improved user interface.
|
||||||
|
|
||||||
### v2.31 (06-Dec-2021)
|
### v2.31 (06-Dec-2021)
|
||||||
|
|
||||||
- Changed target runtime of the application (both GUI and CLI) from .NET 3.1 to .NET 6. Those using the GUI version will not need to take any action as the application should install the necessary prerequisites automatically. Those using the CLI version will need to download and install .NET 6 runtime manually [from here](https://dotnet.microsoft.com/download/dotnet/6.0) (look for ".NET Runtime 6.0.x" section on the right and choose the distribution appropriate for your system).
|
- Changed target runtime of the application (both GUI and CLI) from .NET 3.1 to .NET 6. Those using the GUI version will not need to take any action as the application should install the necessary prerequisites automatically. Those using the CLI version will need to download and install .NET 6 runtime manually [from here](https://dotnet.microsoft.com/download/dotnet/6.0) (look for ".NET Runtime 6.0.x" section on the right and choose the distribution appropriate for your system).
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Version>2.31</Version>
|
<Version>2.34</Version>
|
||||||
<Company>Tyrrrz</Company>
|
<Company>Tyrrrz</Company>
|
||||||
<Copyright>Copyright (c) Alexey Golub</Copyright>
|
<Copyright>Copyright (c) Oleksii Holub</Copyright>
|
||||||
<LangVersion>preview</LangVersion>
|
<LangVersion>preview</LangVersion>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<WarningsAsErrors>nullable</WarningsAsErrors>
|
<WarningsAsErrors>nullable</WarningsAsErrors>
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>true</IsTestProject>
|
<IsTestProject>true</IsTestProject>
|
||||||
<CollectCoverage>true</CollectCoverage>
|
|
||||||
<CoverletOutputFormat>opencover</CoverletOutputFormat>
|
|
||||||
<NoWarn>$(NoWarn);xUnit1013</NoWarn>
|
<NoWarn>$(NoWarn);xUnit1013</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@@ -15,14 +13,14 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AngleSharp" Version="0.16.1" />
|
<PackageReference Include="AngleSharp" Version="0.16.1" />
|
||||||
<PackageReference Include="FluentAssertions" Version="6.2.0" />
|
<PackageReference Include="FluentAssertions" Version="6.6.0" />
|
||||||
<PackageReference Include="GitHubActionsTestLogger" Version="1.2.0" />
|
<PackageReference Include="GitHubActionsTestLogger" Version="1.3.0" PrivateAssets="all" />
|
||||||
<PackageReference Include="JsonExtensions" Version="1.2.0" />
|
<PackageReference Include="JsonExtensions" Version="1.2.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||||
<PackageReference Include="coverlet.msbuild" Version="3.1.0" PrivateAssets="all" />
|
|
||||||
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="all" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="all" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.2" PrivateAssets="all" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using DiscordChatExporter.Core.Exporting;
|
using DiscordChatExporter.Core.Exporting;
|
||||||
using JsonExtensions;
|
using JsonExtensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Fixtures
|
namespace DiscordChatExporter.Cli.Tests.Fixtures;
|
||||||
{
|
|
||||||
public class ExportWrapperFixture : IDisposable
|
public class ExportWrapperFixture : IDisposable
|
||||||
{
|
{
|
||||||
private string DirPath { get; } = Path.Combine(
|
private string DirPath { get; } = Path.Combine(
|
||||||
@@ -36,8 +36,7 @@ namespace DiscordChatExporter.Cli.Tests.Fixtures
|
|||||||
{
|
{
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { channelId },
|
ChannelIds = new[] { channelId },
|
||||||
ExportFormat = format,
|
ExportFormat = format,
|
||||||
OutputPath = filePath
|
OutputPath = filePath
|
||||||
@@ -129,4 +128,3 @@ namespace DiscordChatExporter.Cli.Tests.Fixtures
|
|||||||
|
|
||||||
public void Dispose() => DirectoryEx.DeleteIfExists(DirPath);
|
public void Dispose() => DirectoryEx.DeleteIfExists(DirPath);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using DiscordChatExporter.Cli.Tests.Utils;
|
using DiscordChatExporter.Cli.Tests.Utils;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Fixtures
|
namespace DiscordChatExporter.Cli.Tests.Fixtures;
|
||||||
{
|
|
||||||
public class TempOutputFixture : IDisposable
|
public class TempOutputFixture : IDisposable
|
||||||
{
|
{
|
||||||
public string DirPath { get; } = Path.Combine(
|
public string DirPath { get; } = Path.Combine(
|
||||||
@@ -20,4 +20,3 @@ namespace DiscordChatExporter.Cli.Tests.Fixtures
|
|||||||
|
|
||||||
public void Dispose() => DirectoryEx.DeleteIfExists(DirPath);
|
public void Dispose() => DirectoryEx.DeleteIfExists(DirPath);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Infra
|
namespace DiscordChatExporter.Cli.Tests.Infra;
|
||||||
{
|
|
||||||
internal static class Secrets
|
internal static class Secrets
|
||||||
{
|
{
|
||||||
private static readonly Lazy<string> DiscordTokenLazy = new(() =>
|
private static readonly Lazy<string> DiscordTokenLazy = new(() =>
|
||||||
@@ -22,25 +22,5 @@ namespace DiscordChatExporter.Cli.Tests.Infra
|
|||||||
throw new InvalidOperationException("Discord token not provided for tests.");
|
throw new InvalidOperationException("Discord token not provided for tests.");
|
||||||
});
|
});
|
||||||
|
|
||||||
private static readonly Lazy<bool> IsDiscordTokenBotLazy = new(() =>
|
|
||||||
{
|
|
||||||
var fromEnvironment = Environment.GetEnvironmentVariable("DISCORD_TOKEN_BOT");
|
|
||||||
if (!string.IsNullOrWhiteSpace(fromEnvironment))
|
|
||||||
return string.Equals(fromEnvironment, "true", StringComparison.OrdinalIgnoreCase);
|
|
||||||
|
|
||||||
var secretFilePath = Path.Combine(
|
|
||||||
Path.GetDirectoryName(typeof(Secrets).Assembly.Location) ?? Directory.GetCurrentDirectory(),
|
|
||||||
"DiscordTokenBot.secret"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (File.Exists(secretFilePath))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
public static string DiscordToken => DiscordTokenLazy.Value;
|
public static string DiscordToken => DiscordTokenLazy.Value;
|
||||||
|
|
||||||
public static bool IsDiscordTokenBot => IsDiscordTokenBotLazy.Value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,8 @@ using DiscordChatExporter.Cli.Tests.TestData;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.CsvWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.CsvWriting;
|
||||||
{
|
|
||||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -28,4 +28,3 @@ namespace DiscordChatExporter.Cli.Tests.Specs.CsvWriting
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -13,8 +13,8 @@ using FluentAssertions;
|
|||||||
using JsonExtensions;
|
using JsonExtensions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs
|
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||||
{
|
|
||||||
public record DateRangeSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
public record DateRangeSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -27,8 +27,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
@@ -74,8 +73,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
@@ -120,8 +118,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
@@ -157,4 +154,3 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -12,8 +12,8 @@ using FluentAssertions;
|
|||||||
using JsonExtensions;
|
using JsonExtensions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs
|
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||||
{
|
|
||||||
public record FilterSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
public record FilterSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -25,8 +25,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
@@ -54,8 +53,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
@@ -83,8 +81,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
@@ -112,8 +109,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
@@ -132,4 +128,3 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
.ContainSingle("This has mention");
|
.ContainSingle("This has mention");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,8 +6,8 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||||
{
|
|
||||||
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -42,7 +42,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
Snowflake.Parse("885654862656843786")
|
Snowflake.Parse("885654862656843786")
|
||||||
);
|
);
|
||||||
|
|
||||||
var imageUrl = message.QuerySelector("img")?.GetAttribute("src");
|
var imageUrl = message.QuerySelector(".chatlog__attachment img")?.GetAttribute("src");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
message.Text().Should().Contain("Image attachment");
|
message.Text().Should().Contain("Image attachment");
|
||||||
@@ -90,4 +90,3 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,8 +6,8 @@ using DiscordChatExporter.Cli.Tests.TestData;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||||
{
|
|
||||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -40,4 +40,3 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,8 +6,8 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||||
{
|
|
||||||
public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -61,4 +61,3 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
iframeSrc.Should().StartWithEquivalentOf("https://www.youtube.com/embed/qOWW4OlgbvE");
|
iframeSrc.Should().StartWithEquivalentOf("https://www.youtube.com/embed/qOWW4OlgbvE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,8 +6,8 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||||
{
|
|
||||||
public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -20,7 +20,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
message.Text().Trim().Should().Be("User mention: @Tyrrrz");
|
message.Text().Trim().Should().Contain("User mention: @Tyrrrz");
|
||||||
message.InnerHtml.Should().Contain("Tyrrrz#5447");
|
message.InnerHtml.Should().Contain("Tyrrrz#5447");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
message.Text().Trim().Should().Be("Text channel mention: #mention-tests");
|
message.Text().Trim().Should().Contain("Text channel mention: #mention-tests");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -47,7 +47,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
message.Text().Trim().Should().Be("Voice channel mention: 🔊chaos-vc");
|
message.Text().Trim().Should().Contain("Voice channel mention: 🔊chaos-vc");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -60,7 +60,6 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
message.Text().Trim().Should().Be("Role mention: @Role 1");
|
message.Text().Trim().Should().Contain("Role mention: @Role 1");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,8 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||||
{
|
|
||||||
public record ReplySpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
public record ReplySpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -20,8 +20,8 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
message.Text().Trim().Should().Be("reply to original");
|
message.Text().Trim().Should().Contain("reply to original");
|
||||||
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should().Be("original");
|
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should().Contain("original");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -34,13 +34,13 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
message.Text().Trim().Should().Be("reply to deleted");
|
message.Text().Trim().Should().Contain("reply to deleted");
|
||||||
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should()
|
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should()
|
||||||
.Be("Original message was deleted or could not be loaded.");
|
.Contain("Original message was deleted or could not be loaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Reply_to_a_empty_message_with_attachment_is_rendered_correctly()
|
public async Task Reply_to_an_empty_message_with_attachment_is_rendered_correctly()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||||
@@ -49,9 +49,8 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
message.Text().Trim().Should().Be("reply to attachment");
|
message.Text().Trim().Should().Contain("reply to attachment");
|
||||||
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should()
|
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should()
|
||||||
.Be("Click to see attachment 🖼️");
|
.Contain("Click to see attachment");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||||
|
using DiscordChatExporter.Cli.Tests.TestData;
|
||||||
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||||
|
|
||||||
|
public record StickerSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_a_PNG_based_sticker_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||||
|
ChannelIds.StickerTestCases,
|
||||||
|
Snowflake.Parse("939670623158943754")
|
||||||
|
);
|
||||||
|
|
||||||
|
var container = message.QuerySelector("[title='rock']");
|
||||||
|
var sourceUrl = container?.QuerySelector("img")?.GetAttribute("src");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
container.Should().NotBeNull();
|
||||||
|
sourceUrl.Should().Be("https://discord.com/stickers/904215665597120572.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_a_Lottie_based_sticker_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||||
|
ChannelIds.StickerTestCases,
|
||||||
|
Snowflake.Parse("939670526517997590")
|
||||||
|
);
|
||||||
|
|
||||||
|
var container = message.QuerySelector("[title='Yikes']");
|
||||||
|
var sourceUrl = container?.QuerySelector("div[data-source]")?.GetAttribute("data-source");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
container.Should().NotBeNull();
|
||||||
|
sourceUrl.Should().Be("https://discord.com/stickers/816087132447178774.json");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,8 +6,8 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||||
{
|
|
||||||
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -98,4 +98,3 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(1087849);
|
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(1087849);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -5,8 +5,8 @@ using DiscordChatExporter.Cli.Tests.TestData;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||||
{
|
|
||||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -39,4 +39,3 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,8 +6,8 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||||
{
|
|
||||||
public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -55,4 +55,3 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
embedFields[2].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
embedFields[2].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,8 +6,8 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||||
{
|
|
||||||
public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -68,4 +68,3 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
message.GetProperty("content").GetString().Should().Be("Role mention: @Role 1");
|
message.GetProperty("content").GetString().Should().Be("Role mention: @Role 1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||||
|
using DiscordChatExporter.Cli.Tests.TestData;
|
||||||
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||||
|
|
||||||
|
public record StickerSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_a_PNG_based_sticker_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||||
|
ChannelIds.StickerTestCases,
|
||||||
|
Snowflake.Parse("939670623158943754")
|
||||||
|
);
|
||||||
|
|
||||||
|
var sticker = message
|
||||||
|
.GetProperty("stickers")
|
||||||
|
.EnumerateArray()
|
||||||
|
.Single();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
sticker.GetProperty("id").GetString().Should().Be("904215665597120572");
|
||||||
|
sticker.GetProperty("name").GetString().Should().Be("rock");
|
||||||
|
sticker.GetProperty("format").GetString().Should().Be("PngAnimated");
|
||||||
|
sticker.GetProperty("sourceUrl").GetString().Should().Be("https://discord.com/stickers/904215665597120572.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_a_Lottie_based_sticker_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||||
|
ChannelIds.StickerTestCases,
|
||||||
|
Snowflake.Parse("939670526517997590")
|
||||||
|
);
|
||||||
|
|
||||||
|
var sticker = message
|
||||||
|
.GetProperty("stickers")
|
||||||
|
.EnumerateArray()
|
||||||
|
.Single();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
sticker.GetProperty("id").GetString().Should().Be("816087132447178774");
|
||||||
|
sticker.GetProperty("name").GetString().Should().Be("Yikes");
|
||||||
|
sticker.GetProperty("format").GetString().Should().Be("Lottie");
|
||||||
|
sticker.GetProperty("sourceUrl").GetString().Should().Be("https://discord.com/stickers/816087132447178774.json");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,8 +10,8 @@ using DiscordChatExporter.Core.Exporting.Partitioning;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs
|
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||||
{
|
|
||||||
public record PartitioningSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
public record PartitioningSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -25,8 +25,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||||
ExportFormat = ExportFormat.HtmlDark,
|
ExportFormat = ExportFormat.HtmlDark,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
@@ -50,8 +49,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||||
ExportFormat = ExportFormat.HtmlDark,
|
ExportFormat = ExportFormat.HtmlDark,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
@@ -61,7 +59,6 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
// Assert
|
// Assert
|
||||||
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
|
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
|
||||||
.Should()
|
.Should()
|
||||||
.HaveCount(2);
|
.HaveCount(8);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,8 @@ using DiscordChatExporter.Cli.Tests.TestData;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.PlainTextWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.PlainTextWriting;
|
||||||
{
|
|
||||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -28,4 +28,3 @@ namespace DiscordChatExporter.Cli.Tests.Specs.PlainTextWriting
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -11,8 +11,8 @@ using DiscordChatExporter.Core.Exporting;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs
|
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||||
{
|
|
||||||
public record SelfContainedSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
public record SelfContainedSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -25,8 +25,7 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.SelfContainedTestCases },
|
ChannelIds = new[] { ChannelIds.SelfContainedTestCases },
|
||||||
ExportFormat = ExportFormat.HtmlDark,
|
ExportFormat = ExportFormat.HtmlDark,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
@@ -46,4 +45,3 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
.BeTrue();
|
.BeTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.TestData
|
namespace DiscordChatExporter.Cli.Tests.TestData;
|
||||||
{
|
|
||||||
public static class ChannelIds
|
public static class ChannelIds
|
||||||
{
|
{
|
||||||
public static Snowflake AttachmentTestCases { get; } = Snowflake.Parse("885587741654536192");
|
public static Snowflake AttachmentTestCases { get; } = Snowflake.Parse("885587741654536192");
|
||||||
@@ -10,6 +10,8 @@ namespace DiscordChatExporter.Cli.Tests.TestData
|
|||||||
|
|
||||||
public static Snowflake EmbedTestCases { get; } = Snowflake.Parse("866472452459462687");
|
public static Snowflake EmbedTestCases { get; } = Snowflake.Parse("866472452459462687");
|
||||||
|
|
||||||
|
public static Snowflake StickerTestCases { get; } = Snowflake.Parse("939668868253769729");
|
||||||
|
|
||||||
public static Snowflake FilterTestCases { get; } = Snowflake.Parse("866744075033641020");
|
public static Snowflake FilterTestCases { get; } = Snowflake.Parse("866744075033641020");
|
||||||
|
|
||||||
public static Snowflake MentionTestCases { get; } = Snowflake.Parse("866458801389174794");
|
public static Snowflake MentionTestCases { get; } = Snowflake.Parse("866458801389174794");
|
||||||
@@ -18,4 +20,3 @@ namespace DiscordChatExporter.Cli.Tests.TestData
|
|||||||
|
|
||||||
public static Snowflake SelfContainedTestCases { get; } = Snowflake.Parse("887441432678379560");
|
public static Snowflake SelfContainedTestCases { get; } = Snowflake.Parse("887441432678379560");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Utils
|
namespace DiscordChatExporter.Cli.Tests.Utils;
|
||||||
{
|
|
||||||
internal static class DirectoryEx
|
internal static class DirectoryEx
|
||||||
{
|
{
|
||||||
public static void DeleteIfExists(string dirPath, bool recursive = true)
|
public static void DeleteIfExists(string dirPath, bool recursive = true)
|
||||||
@@ -21,4 +21,3 @@ namespace DiscordChatExporter.Cli.Tests.Utils
|
|||||||
Directory.CreateDirectory(dirPath);
|
Directory.CreateDirectory(dirPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
using AngleSharp.Html.Dom;
|
using AngleSharp.Html.Dom;
|
||||||
using AngleSharp.Html.Parser;
|
using AngleSharp.Html.Parser;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Utils
|
namespace DiscordChatExporter.Cli.Tests.Utils;
|
||||||
{
|
|
||||||
internal static class Html
|
internal static class Html
|
||||||
{
|
{
|
||||||
private static readonly IHtmlParser Parser = new HtmlParser();
|
private static readonly IHtmlParser Parser = new HtmlParser();
|
||||||
|
|
||||||
public static IHtmlDocument Parse(string source) => Parser.ParseDocument(source);
|
public static IHtmlDocument Parse(string source) => Parser.ParseDocument(source);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -14,10 +14,10 @@ using DiscordChatExporter.Core.Exceptions;
|
|||||||
using DiscordChatExporter.Core.Exporting;
|
using DiscordChatExporter.Core.Exporting;
|
||||||
using DiscordChatExporter.Core.Exporting.Filtering;
|
using DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
using DiscordChatExporter.Core.Exporting.Partitioning;
|
using DiscordChatExporter.Core.Exporting.Partitioning;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using Gress;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Cli.Commands.Base;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands.Base
|
|
||||||
{
|
|
||||||
public abstract class ExportCommandBase : TokenCommandBase
|
public abstract class ExportCommandBase : TokenCommandBase
|
||||||
{
|
{
|
||||||
[CommandOption("output", 'o', Description = "Output file or directory path.")]
|
[CommandOption("output", 'o', Description = "Output file or directory path.")]
|
||||||
@@ -68,13 +68,21 @@ namespace DiscordChatExporter.Cli.Commands.Base
|
|||||||
await console.Output.WriteLineAsync($"Exporting {channels.Count} channel(s)...");
|
await console.Output.WriteLineAsync($"Exporting {channels.Count} channel(s)...");
|
||||||
await console.CreateProgressTicker().StartAsync(async progressContext =>
|
await console.CreateProgressTicker().StartAsync(async progressContext =>
|
||||||
{
|
{
|
||||||
await channels.ParallelForEachAsync(async channel =>
|
await Parallel.ForEachAsync(
|
||||||
|
channels,
|
||||||
|
new ParallelOptions
|
||||||
|
{
|
||||||
|
MaxDegreeOfParallelism = Math.Max(1, ParallelLimit),
|
||||||
|
CancellationToken = cancellationToken
|
||||||
|
},
|
||||||
|
async (channel, innerCancellationToken) =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await progressContext.StartTaskAsync($"{channel.Category.Name} / {channel.Name}", async progress =>
|
await progressContext.StartTaskAsync($"{channel.Category.Name} / {channel.Name}",
|
||||||
|
async progress =>
|
||||||
{
|
{
|
||||||
var guild = await Discord.GetGuildAsync(channel.GuildId, cancellationToken);
|
var guild = await Discord.GetGuildAsync(channel.GuildId, innerCancellationToken);
|
||||||
|
|
||||||
var request = new ExportRequest(
|
var request = new ExportRequest(
|
||||||
guild,
|
guild,
|
||||||
@@ -90,14 +98,20 @@ namespace DiscordChatExporter.Cli.Commands.Base
|
|||||||
DateFormat
|
DateFormat
|
||||||
);
|
);
|
||||||
|
|
||||||
await Exporter.ExportChannelAsync(request, progress, cancellationToken);
|
await Exporter.ExportChannelAsync(
|
||||||
});
|
request,
|
||||||
|
progress.ToPercentageBased(),
|
||||||
|
innerCancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch (DiscordChatExporterException ex) when (!ex.IsFatal)
|
catch (DiscordChatExporterException ex) when (!ex.IsFatal)
|
||||||
{
|
{
|
||||||
errors[channel] = ex.Message;
|
errors[channel] = ex.Message;
|
||||||
}
|
}
|
||||||
}, Math.Max(ParallelLimit, 1), cancellationToken);
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Print result
|
// Print result
|
||||||
@@ -152,5 +166,16 @@ namespace DiscordChatExporter.Cli.Commands.Base
|
|||||||
|
|
||||||
await ExecuteAsync(console, channels);
|
await ExecuteAsync(console, channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
// War in Ukraine message
|
||||||
|
console.Output.WriteLine("========================================================================");
|
||||||
|
console.Output.WriteLine("|| Ukraine is at war! Support my country in its fight for freedom ||");
|
||||||
|
console.Output.WriteLine("|| Learn more: https://tyrrrz.me ||");
|
||||||
|
console.Output.WriteLine("========================================================================");
|
||||||
|
console.Output.WriteLine("");
|
||||||
|
|
||||||
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,30 +1,23 @@
|
|||||||
using System.Threading.Tasks;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using CliFx;
|
using CliFx;
|
||||||
using CliFx.Attributes;
|
using CliFx.Attributes;
|
||||||
using CliFx.Infrastructure;
|
using CliFx.Infrastructure;
|
||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands.Base
|
namespace DiscordChatExporter.Cli.Commands.Base;
|
||||||
{
|
|
||||||
public abstract class TokenCommandBase : ICommand
|
public abstract class TokenCommandBase : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption("token", 't', IsRequired = true, EnvironmentVariable = "DISCORD_TOKEN", Description = "Authentication token.")]
|
[CommandOption("token", 't', IsRequired = true, EnvironmentVariable = "DISCORD_TOKEN", Description = "Authentication token.")]
|
||||||
public string TokenValue { get; init; } = "";
|
public string Token { get; init; } = "";
|
||||||
|
|
||||||
[CommandOption("bot", 'b', EnvironmentVariable = "DISCORD_TOKEN_BOT", Description = "Authenticate as a bot.")]
|
[CommandOption("bot", 'b', EnvironmentVariable = "DISCORD_TOKEN_BOT", Description = "This option doesn't do anything. Kept for backwards compatibility.")]
|
||||||
|
[Obsolete("This option doesn't do anything. Kept for backwards compatibility.")]
|
||||||
public bool IsBotToken { get; init; }
|
public bool IsBotToken { get; init; }
|
||||||
|
|
||||||
private AuthToken? _authToken;
|
|
||||||
private AuthToken AuthToken => _authToken ??= new AuthToken(
|
|
||||||
IsBotToken
|
|
||||||
? AuthTokenKind.Bot
|
|
||||||
: AuthTokenKind.User,
|
|
||||||
TokenValue
|
|
||||||
);
|
|
||||||
|
|
||||||
private DiscordClient? _discordClient;
|
private DiscordClient? _discordClient;
|
||||||
protected DiscordClient Discord => _discordClient ??= new DiscordClient(AuthToken);
|
protected DiscordClient Discord => _discordClient ??= new DiscordClient(Token);
|
||||||
|
|
||||||
public abstract ValueTask ExecuteAsync(IConsole console);
|
public abstract ValueTask ExecuteAsync(IConsole console);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -5,8 +5,8 @@ using CliFx.Infrastructure;
|
|||||||
using DiscordChatExporter.Cli.Commands.Base;
|
using DiscordChatExporter.Cli.Commands.Base;
|
||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
{
|
|
||||||
[Command("exportall", Description = "Export all accessible channels.")]
|
[Command("exportall", Description = "Export all accessible channels.")]
|
||||||
public class ExportAllCommand : ExportCommandBase
|
public class ExportAllCommand : ExportCommandBase
|
||||||
{
|
{
|
||||||
@@ -15,6 +15,8 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
|
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
|
await base.ExecuteAsync(console);
|
||||||
|
|
||||||
var cancellationToken = console.RegisterCancellationHandler();
|
var cancellationToken = console.RegisterCancellationHandler();
|
||||||
var channels = new List<Channel>();
|
var channels = new List<Channel>();
|
||||||
|
|
||||||
@@ -38,4 +40,3 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
await base.ExecuteAsync(console, channels);
|
await base.ExecuteAsync(console, channels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,8 +6,8 @@ using CliFx.Infrastructure;
|
|||||||
using DiscordChatExporter.Cli.Commands.Base;
|
using DiscordChatExporter.Cli.Commands.Base;
|
||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
{
|
|
||||||
[Command("export", Description = "Export one or multiple channels.")]
|
[Command("export", Description = "Export one or multiple channels.")]
|
||||||
public class ExportChannelsCommand : ExportCommandBase
|
public class ExportChannelsCommand : ExportCommandBase
|
||||||
{
|
{
|
||||||
@@ -15,7 +15,9 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
[CommandOption("channel", 'c', IsRequired = true, Description = "Channel ID(s).")]
|
[CommandOption("channel", 'c', IsRequired = true, Description = "Channel ID(s).")]
|
||||||
public IReadOnlyList<Snowflake> ChannelIds { get; init; } = Array.Empty<Snowflake>();
|
public IReadOnlyList<Snowflake> ChannelIds { get; init; } = Array.Empty<Snowflake>();
|
||||||
|
|
||||||
public override async ValueTask ExecuteAsync(IConsole console) =>
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
await base.ExecuteAsync(console);
|
||||||
await base.ExecuteAsync(console, ChannelIds);
|
await base.ExecuteAsync(console, ChannelIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,13 +6,15 @@ using DiscordChatExporter.Cli.Commands.Base;
|
|||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
{
|
|
||||||
[Command("exportdm", Description = "Export all direct message channels.")]
|
[Command("exportdm", Description = "Export all direct message channels.")]
|
||||||
public class ExportDirectMessagesCommand : ExportCommandBase
|
public class ExportDirectMessagesCommand : ExportCommandBase
|
||||||
{
|
{
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
|
await base.ExecuteAsync(console);
|
||||||
|
|
||||||
var cancellationToken = console.RegisterCancellationHandler();
|
var cancellationToken = console.RegisterCancellationHandler();
|
||||||
|
|
||||||
await console.Output.WriteLineAsync("Fetching channels...");
|
await console.Output.WriteLineAsync("Fetching channels...");
|
||||||
@@ -22,4 +24,3 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
await base.ExecuteAsync(console, textChannels);
|
await base.ExecuteAsync(console, textChannels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,8 +6,8 @@ using DiscordChatExporter.Cli.Commands.Base;
|
|||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
{
|
|
||||||
[Command("exportguild", Description = "Export all channels within specified guild.")]
|
[Command("exportguild", Description = "Export all channels within specified guild.")]
|
||||||
public class ExportGuildCommand : ExportCommandBase
|
public class ExportGuildCommand : ExportCommandBase
|
||||||
{
|
{
|
||||||
@@ -16,6 +16,8 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
|
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
|
await base.ExecuteAsync(console);
|
||||||
|
|
||||||
var cancellationToken = console.RegisterCancellationHandler();
|
var cancellationToken = console.RegisterCancellationHandler();
|
||||||
|
|
||||||
await console.Output.WriteLineAsync("Fetching channels...");
|
await console.Output.WriteLineAsync("Fetching channels...");
|
||||||
@@ -25,4 +27,3 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
await base.ExecuteAsync(console, textChannels);
|
await base.ExecuteAsync(console, textChannels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -7,8 +7,8 @@ using DiscordChatExporter.Cli.Commands.Base;
|
|||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
{
|
|
||||||
[Command("channels", Description = "Get the list of channels in a guild.")]
|
[Command("channels", Description = "Get the list of channels in a guild.")]
|
||||||
public class GetChannelsCommand : TokenCommandBase
|
public class GetChannelsCommand : TokenCommandBase
|
||||||
{
|
{
|
||||||
@@ -42,4 +42,3 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -7,8 +7,8 @@ using DiscordChatExporter.Cli.Commands.Base;
|
|||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
{
|
|
||||||
[Command("dm", Description = "Get the list of direct message channels.")]
|
[Command("dm", Description = "Get the list of direct message channels.")]
|
||||||
public class GetDirectMessageChannelsCommand : TokenCommandBase
|
public class GetDirectMessageChannelsCommand : TokenCommandBase
|
||||||
{
|
{
|
||||||
@@ -39,4 +39,3 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,8 +6,8 @@ using CliFx.Infrastructure;
|
|||||||
using DiscordChatExporter.Cli.Commands.Base;
|
using DiscordChatExporter.Cli.Commands.Base;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
{
|
|
||||||
[Command("guilds", Description = "Get the list of accessible guilds.")]
|
[Command("guilds", Description = "Get the list of accessible guilds.")]
|
||||||
public class GetGuildsCommand : TokenCommandBase
|
public class GetGuildsCommand : TokenCommandBase
|
||||||
{
|
{
|
||||||
@@ -32,4 +32,3 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ using CliFx;
|
|||||||
using CliFx.Attributes;
|
using CliFx.Attributes;
|
||||||
using CliFx.Infrastructure;
|
using CliFx.Infrastructure;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
{
|
|
||||||
[Command("guide", Description = "Explains how to obtain token, guild or channel ID.")]
|
[Command("guide", Description = "Explains how to obtain token, guild or channel ID.")]
|
||||||
public class GuideCommand : ICommand
|
public class GuideCommand : ICommand
|
||||||
{
|
{
|
||||||
@@ -15,7 +15,7 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
using (console.WithForegroundColor(ConsoleColor.White))
|
using (console.WithForegroundColor(ConsoleColor.White))
|
||||||
console.Output.WriteLine("To get user token:");
|
console.Output.WriteLine("To get user token:");
|
||||||
|
|
||||||
console.Output.WriteLine(" 1. Open Discord");
|
console.Output.WriteLine(" 1. Open Discord in your web browser and login");
|
||||||
console.Output.WriteLine(" 2. Press Ctrl+Shift+I to show developer tools");
|
console.Output.WriteLine(" 2. Press Ctrl+Shift+I to show developer tools");
|
||||||
console.Output.WriteLine(" 3. Press Ctrl+Shift+M to toggle device toolbar");
|
console.Output.WriteLine(" 3. Press Ctrl+Shift+M to toggle device toolbar");
|
||||||
console.Output.WriteLine(" 4. Navigate to the Application tab");
|
console.Output.WriteLine(" 4. Navigate to the Application tab");
|
||||||
@@ -61,11 +61,10 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
|
|
||||||
// Wiki link
|
// Wiki link
|
||||||
using (console.WithForegroundColor(ConsoleColor.White))
|
using (console.WithForegroundColor(ConsoleColor.White))
|
||||||
console.Output.WriteLine("For more information, check out the wiki:");
|
console.Output.WriteLine("If you have questions or issues, please refer to the wiki:");
|
||||||
using (console.WithForegroundColor(ConsoleColor.DarkCyan))
|
using (console.WithForegroundColor(ConsoleColor.DarkCyan))
|
||||||
console.Output.WriteLine("https://github.com/Tyrrrz/DiscordChatExporter/wiki");
|
console.Output.WriteLine("https://github.com/Tyrrrz/DiscordChatExporter/wiki");
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,9 +6,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CliFx" Version="2.0.6" />
|
<PackageReference Include="CliFx" Version="2.2.2" />
|
||||||
<PackageReference Include="Spectre.Console" Version="0.43.0" />
|
<PackageReference Include="Spectre.Console" Version="0.44.0" />
|
||||||
<PackageReference Include="Gress" Version="1.2.0" />
|
<PackageReference Include="Gress" Version="2.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
using System.Threading.Tasks;
|
using CliFx;
|
||||||
using CliFx;
|
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli
|
return await new CliApplicationBuilder()
|
||||||
{
|
|
||||||
public static class Program
|
|
||||||
{
|
|
||||||
public static async Task<int> Main(string[] args) =>
|
|
||||||
await new CliApplicationBuilder()
|
|
||||||
.AddCommandsFromThisAssembly()
|
.AddCommandsFromThisAssembly()
|
||||||
.Build()
|
.Build()
|
||||||
.RunAsync(args);
|
.RunAsync(args);
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,8 +3,8 @@ using System.Threading.Tasks;
|
|||||||
using CliFx.Infrastructure;
|
using CliFx.Infrastructure;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Utils.Extensions
|
namespace DiscordChatExporter.Cli.Utils.Extensions;
|
||||||
{
|
|
||||||
internal static class ConsoleExtensions
|
internal static class ConsoleExtensions
|
||||||
{
|
{
|
||||||
public static IAnsiConsole CreateAnsiConsole(this IConsole console) =>
|
public static IAnsiConsole CreateAnsiConsole(this IConsole console) =>
|
||||||
@@ -48,4 +48,3 @@ namespace DiscordChatExporter.Cli.Utils.Extensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using System.Net.Http.Headers;
|
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord
|
|
||||||
{
|
|
||||||
public record AuthToken(AuthTokenKind Kind, string Value)
|
|
||||||
{
|
|
||||||
public AuthenticationHeaderValue GetAuthenticationHeader() => Kind switch
|
|
||||||
{
|
|
||||||
AuthTokenKind.Bot => new AuthenticationHeaderValue("Bot", Value),
|
|
||||||
_ => new AuthenticationHeaderValue(Value)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace DiscordChatExporter.Core.Discord
|
|
||||||
{
|
|
||||||
public enum AuthTokenKind
|
|
||||||
{
|
|
||||||
User,
|
|
||||||
Bot
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,13 +6,14 @@ using DiscordChatExporter.Core.Utils;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#attachment-object
|
// https://discord.com/developers/docs/resources/channel#attachment-object
|
||||||
public partial record Attachment(
|
public partial record Attachment(
|
||||||
Snowflake Id,
|
Snowflake Id,
|
||||||
string Url,
|
string Url,
|
||||||
string FileName,
|
string FileName,
|
||||||
|
string? Description,
|
||||||
int? Width,
|
int? Width,
|
||||||
int? Height,
|
int? Height,
|
||||||
FileSize FileSize) : IHasId
|
FileSize FileSize) : IHasId
|
||||||
@@ -34,12 +35,12 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
{
|
{
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
var url = json.GetProperty("url").GetNonWhiteSpaceString();
|
var url = json.GetProperty("url").GetNonWhiteSpaceString();
|
||||||
var width = json.GetPropertyOrNull("width")?.GetInt32();
|
var width = json.GetPropertyOrNull("width")?.GetInt32OrNull();
|
||||||
var height = json.GetPropertyOrNull("height")?.GetInt32();
|
var height = json.GetPropertyOrNull("height")?.GetInt32OrNull();
|
||||||
var fileName = json.GetProperty("filename").GetNonWhiteSpaceString();
|
var fileName = json.GetProperty("filename").GetNonNullString();
|
||||||
|
var description = json.GetPropertyOrNull("description")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var fileSize = json.GetProperty("size").GetInt64().Pipe(FileSize.FromBytes);
|
var fileSize = json.GetProperty("size").GetInt64().Pipe(FileSize.FromBytes);
|
||||||
|
|
||||||
return new Attachment(id, url, fileName, width, height, fileSize);
|
return new Attachment(id, url, fileName, description, width, height, fileSize);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,8 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#channel-object
|
// https://discord.com/developers/docs/resources/channel#channel-object
|
||||||
public partial record Channel(
|
public partial record Channel(
|
||||||
Snowflake Id,
|
Snowflake Id,
|
||||||
@@ -42,31 +42,37 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
public static Channel Parse(JsonElement json, ChannelCategory? category = null, int? position = null)
|
public static Channel Parse(JsonElement json, ChannelCategory? category = null, int? positionHint = null)
|
||||||
{
|
{
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
var guildId = json.GetPropertyOrNull("guild_id")?.GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var guildId = json.GetPropertyOrNull("guild_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
|
||||||
var topic = json.GetPropertyOrNull("topic")?.GetStringOrNull();
|
var topic = json.GetPropertyOrNull("topic")?.GetStringOrNull();
|
||||||
var kind = (ChannelKind)json.GetProperty("type").GetInt32();
|
var kind = (ChannelKind)json.GetProperty("type").GetInt32();
|
||||||
|
|
||||||
var name =
|
var name =
|
||||||
// Guild channel
|
// Guild channel
|
||||||
json.GetPropertyOrNull("name")?.GetStringOrNull() ??
|
json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull() ??
|
||||||
|
|
||||||
// DM channel
|
// DM channel
|
||||||
json.GetPropertyOrNull("recipients")?.EnumerateArray().Select(User.Parse).Select(u => u.Name)
|
json.GetPropertyOrNull("recipients")?
|
||||||
|
.EnumerateArrayOrNull()?
|
||||||
|
.Select(User.Parse)
|
||||||
|
.Select(u => u.Name)
|
||||||
.Pipe(s => string.Join(", ", s)) ??
|
.Pipe(s => string.Join(", ", s)) ??
|
||||||
|
|
||||||
// Fallback
|
// Fallback
|
||||||
id.ToString();
|
id.ToString();
|
||||||
|
|
||||||
|
var position = positionHint ?? json.GetPropertyOrNull("position")?.GetInt32OrNull();
|
||||||
|
|
||||||
return new Channel(
|
return new Channel(
|
||||||
id,
|
id,
|
||||||
kind,
|
kind,
|
||||||
guildId ?? Guild.DirectMessages.Id,
|
guildId ?? Guild.DirectMessages.Id,
|
||||||
category ?? GetFallbackCategory(kind),
|
category ?? GetFallbackCategory(kind),
|
||||||
name,
|
name,
|
||||||
position ?? json.GetPropertyOrNull("position")?.GetInt32(),
|
position,
|
||||||
topic
|
topic
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,25 +3,21 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
public record ChannelCategory(Snowflake Id, string Name, int? Position) : IHasId
|
public record ChannelCategory(Snowflake Id, string Name, int? Position) : IHasId
|
||||||
{
|
{
|
||||||
public static ChannelCategory Unknown { get; } = new(Snowflake.Zero, "<unknown category>", 0);
|
public static ChannelCategory Unknown { get; } = new(Snowflake.Zero, "<unknown category>", 0);
|
||||||
|
|
||||||
public static ChannelCategory Parse(JsonElement json, int? position = null)
|
public static ChannelCategory Parse(JsonElement json, int? positionHint = null)
|
||||||
{
|
{
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
|
var position = positionHint ?? json.GetPropertyOrNull("position")?.GetInt32OrNull();
|
||||||
|
|
||||||
var name =
|
var name =
|
||||||
json.GetPropertyOrNull("name")?.GetStringOrNull() ??
|
json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull() ??
|
||||||
id.ToString();
|
id.ToString();
|
||||||
|
|
||||||
return new ChannelCategory(
|
return new ChannelCategory(id, name, position);
|
||||||
id,
|
|
||||||
name,
|
|
||||||
position ?? json.GetPropertyOrNull("position")?.GetInt32()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
|
// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
|
||||||
// Order of enum fields needs to match the order in the docs.
|
// Order of enum fields needs to match the order in the docs.
|
||||||
public enum ChannelKind
|
public enum ChannelKind
|
||||||
@@ -12,4 +12,3 @@
|
|||||||
GuildNews,
|
GuildNews,
|
||||||
GuildStore
|
GuildStore
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Common
|
namespace DiscordChatExporter.Core.Discord.Data.Common;
|
||||||
{
|
|
||||||
// Loosely based on https://github.com/omar/ByteSize (MIT license)
|
// Loosely based on https://github.com/omar/ByteSize (MIT license)
|
||||||
public readonly partial record struct FileSize(long TotalBytes)
|
public readonly partial record struct FileSize(long TotalBytes)
|
||||||
{
|
{
|
||||||
@@ -46,4 +46,3 @@ namespace DiscordChatExporter.Core.Discord.Data.Common
|
|||||||
{
|
{
|
||||||
public static FileSize FromBytes(long bytes) => new(bytes);
|
public static FileSize FromBytes(long bytes) => new(bytes);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
namespace DiscordChatExporter.Core.Discord.Data.Common
|
namespace DiscordChatExporter.Core.Discord.Data.Common;
|
||||||
{
|
|
||||||
public interface IHasId
|
public interface IHasId
|
||||||
{
|
{
|
||||||
Snowflake Id { get; }
|
Snowflake Id { get; }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Common
|
namespace DiscordChatExporter.Core.Discord.Data.Common;
|
||||||
{
|
|
||||||
public class IdBasedEqualityComparer : IEqualityComparer<IHasId>
|
public class IdBasedEqualityComparer : IEqualityComparer<IHasId>
|
||||||
{
|
{
|
||||||
public static IdBasedEqualityComparer Instance { get; } = new();
|
public static IdBasedEqualityComparer Instance { get; } = new();
|
||||||
@@ -10,4 +10,3 @@ namespace DiscordChatExporter.Core.Discord.Data.Common
|
|||||||
|
|
||||||
public int GetHashCode(IHasId obj) => obj.Id.GetHashCode();
|
public int GetHashCode(IHasId obj) => obj.Id.GetHashCode();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,8 +6,8 @@ using System.Text.Json;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#embed-object
|
// https://discord.com/developers/docs/resources/channel#embed-object
|
||||||
public partial record Embed(
|
public partial record Embed(
|
||||||
string? Title,
|
string? Title,
|
||||||
@@ -36,9 +36,9 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
public static Embed Parse(JsonElement json)
|
public static Embed Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var title = json.GetPropertyOrNull("title")?.GetStringOrNull();
|
var title = json.GetPropertyOrNull("title")?.GetStringOrNull();
|
||||||
var url = json.GetPropertyOrNull("url")?.GetStringOrNull();
|
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var timestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffset();
|
var timestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffset();
|
||||||
var color = json.GetPropertyOrNull("color")?.GetInt32().Pipe(System.Drawing.Color.FromArgb).ResetAlpha();
|
var color = json.GetPropertyOrNull("color")?.GetInt32OrNull()?.Pipe(System.Drawing.Color.FromArgb).ResetAlpha();
|
||||||
var description = json.GetPropertyOrNull("description")?.GetStringOrNull();
|
var description = json.GetPropertyOrNull("description")?.GetStringOrNull();
|
||||||
|
|
||||||
var author = json.GetPropertyOrNull("author")?.Pipe(EmbedAuthor.Parse);
|
var author = json.GetPropertyOrNull("author")?.Pipe(EmbedAuthor.Parse);
|
||||||
@@ -47,7 +47,7 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
var footer = json.GetPropertyOrNull("footer")?.Pipe(EmbedFooter.Parse);
|
var footer = json.GetPropertyOrNull("footer")?.Pipe(EmbedFooter.Parse);
|
||||||
|
|
||||||
var fields =
|
var fields =
|
||||||
json.GetPropertyOrNull("fields")?.EnumerateArray().Select(EmbedField.Parse).ToArray() ??
|
json.GetPropertyOrNull("fields")?.EnumerateArrayOrNull()?.Select(EmbedField.Parse).ToArray() ??
|
||||||
Array.Empty<EmbedField>();
|
Array.Empty<EmbedField>();
|
||||||
|
|
||||||
return new Embed(
|
return new Embed(
|
||||||
@@ -64,4 +64,3 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure
|
// https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure
|
||||||
public record EmbedAuthor(
|
public record EmbedAuthor(
|
||||||
string? Name,
|
string? Name,
|
||||||
@@ -13,11 +13,10 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
public static EmbedAuthor Parse(JsonElement json)
|
public static EmbedAuthor Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var name = json.GetPropertyOrNull("name")?.GetStringOrNull();
|
var name = json.GetPropertyOrNull("name")?.GetStringOrNull();
|
||||||
var url = json.GetPropertyOrNull("url")?.GetStringOrNull();
|
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var iconUrl = json.GetPropertyOrNull("icon_url")?.GetStringOrNull();
|
var iconUrl = json.GetPropertyOrNull("icon_url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetStringOrNull();
|
var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
|
|
||||||
return new EmbedAuthor(name, url, iconUrl, iconProxyUrl);
|
return new EmbedAuthor(name, url, iconUrl, iconProxyUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
|
// https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
|
||||||
public record EmbedField(
|
public record EmbedField(
|
||||||
string Name,
|
string Name,
|
||||||
@@ -12,11 +11,10 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
{
|
{
|
||||||
public static EmbedField Parse(JsonElement json)
|
public static EmbedField Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var name = json.GetProperty("name").GetNonWhiteSpaceString();
|
var name = json.GetProperty("name").GetNonNullString();
|
||||||
var value = json.GetProperty("value").GetNonWhiteSpaceString();
|
var value = json.GetProperty("value").GetNonNullString();
|
||||||
var isInline = json.GetPropertyOrNull("inline")?.GetBoolean() ?? false;
|
var isInline = json.GetPropertyOrNull("inline")?.GetBooleanOrNull() ?? false;
|
||||||
|
|
||||||
return new EmbedField(name, value, isInline);
|
return new EmbedField(name, value, isInline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
|
// https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
|
||||||
public record EmbedFooter(
|
public record EmbedFooter(
|
||||||
string Text,
|
string Text,
|
||||||
@@ -12,11 +11,10 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
{
|
{
|
||||||
public static EmbedFooter Parse(JsonElement json)
|
public static EmbedFooter Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var text = json.GetProperty("text").GetNonWhiteSpaceString();
|
var text = json.GetProperty("text").GetNonNullString();
|
||||||
var iconUrl = json.GetPropertyOrNull("icon_url")?.GetStringOrNull();
|
var iconUrl = json.GetPropertyOrNull("icon_url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetStringOrNull();
|
var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
|
|
||||||
return new EmbedFooter(text, iconUrl, iconProxyUrl);
|
return new EmbedFooter(text, iconUrl, iconProxyUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure
|
// https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure
|
||||||
public record EmbedImage(
|
public record EmbedImage(
|
||||||
string? Url,
|
string? Url,
|
||||||
@@ -12,12 +12,11 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
{
|
{
|
||||||
public static EmbedImage Parse(JsonElement json)
|
public static EmbedImage Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var url = json.GetPropertyOrNull("url")?.GetStringOrNull();
|
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var proxyUrl = json.GetPropertyOrNull("proxy_url")?.GetStringOrNull();
|
var proxyUrl = json.GetPropertyOrNull("proxy_url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var width = json.GetPropertyOrNull("width")?.GetInt32();
|
var width = json.GetPropertyOrNull("width")?.GetInt32OrNull();
|
||||||
var height = json.GetPropertyOrNull("height")?.GetInt32();
|
var height = json.GetPropertyOrNull("height")?.GetInt32OrNull();
|
||||||
|
|
||||||
return new EmbedImage(url, proxyUrl, width, height);
|
return new EmbedImage(url, proxyUrl, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,8 +3,8 @@ using System.Linq;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using DiscordChatExporter.Core.Utils;
|
using DiscordChatExporter.Core.Utils;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
public record PlainImageEmbedProjection(string Url)
|
public record PlainImageEmbedProjection(string Url)
|
||||||
{
|
{
|
||||||
public static PlainImageEmbedProjection? TryResolve(Embed embed)
|
public static PlainImageEmbedProjection? TryResolve(Embed embed)
|
||||||
@@ -31,4 +31,3 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
return new PlainImageEmbedProjection(embed.Url);
|
return new PlainImageEmbedProjection(embed.Url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
public partial record SpotifyTrackEmbedProjection(string TrackId)
|
public partial record SpotifyTrackEmbedProjection(string TrackId)
|
||||||
{
|
{
|
||||||
public string Url => $"https://open.spotify.com/embed/track/{TrackId}";
|
public string Url => $"https://open.spotify.com/embed/track/{TrackId}";
|
||||||
@@ -31,4 +31,3 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
return new SpotifyTrackEmbedProjection(trackId);
|
return new SpotifyTrackEmbedProjection(trackId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
public partial record YouTubeVideoEmbedProjection(string VideoId)
|
public partial record YouTubeVideoEmbedProjection(string VideoId)
|
||||||
{
|
{
|
||||||
public string Url => $"https://www.youtube.com/embed/{VideoId}";
|
public string Url => $"https://www.youtube.com/embed/{VideoId}";
|
||||||
@@ -46,4 +46,3 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
return new YouTubeVideoEmbedProjection(videoId);
|
return new YouTubeVideoEmbedProjection(videoId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,22 +1,23 @@
|
|||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using DiscordChatExporter.Core.Utils;
|
using DiscordChatExporter.Core.Utils;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/emoji#emoji-object
|
// https://discord.com/developers/docs/resources/emoji#emoji-object
|
||||||
public partial record Emoji(
|
public partial record Emoji(
|
||||||
// Only present on custom emoji
|
// Only present on custom emoji
|
||||||
string? Id,
|
Snowflake? Id,
|
||||||
// Name of custom emoji (e.g. LUL) or actual representation of standard emoji (e.g. 🙂)
|
// Name of custom emoji (e.g. LUL) or actual representation of standard emoji (e.g. 🙂)
|
||||||
string Name,
|
string Name,
|
||||||
bool IsAnimated,
|
bool IsAnimated,
|
||||||
string ImageUrl)
|
string ImageUrl)
|
||||||
{
|
{
|
||||||
// Name of custom emoji (e.g. LUL) or name of standard emoji (e.g. slight_smile)
|
// Name of custom emoji (e.g. LUL) or name of standard emoji (e.g. slight_smile)
|
||||||
public string Code => !string.IsNullOrWhiteSpace(Id)
|
public string Code => Id is not null
|
||||||
? Name
|
? Name
|
||||||
: EmojiIndex.TryGetCode(Name) ?? Name;
|
: EmojiIndex.TryGetCode(Name) ?? Name;
|
||||||
}
|
}
|
||||||
@@ -31,30 +32,41 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
.Select(r => r.Value.ToString("x"))
|
.Select(r => r.Value.ToString("x"))
|
||||||
);
|
);
|
||||||
|
|
||||||
public static string GetImageUrl(string? id, string name, bool isAnimated)
|
private static string GetImageUrl(Snowflake id, bool isAnimated) => isAnimated
|
||||||
{
|
|
||||||
// Custom emoji
|
|
||||||
if (!string.IsNullOrWhiteSpace(id))
|
|
||||||
{
|
|
||||||
return isAnimated
|
|
||||||
? $"https://cdn.discordapp.com/emojis/{id}.gif"
|
? $"https://cdn.discordapp.com/emojis/{id}.gif"
|
||||||
: $"https://cdn.discordapp.com/emojis/{id}.png";
|
: $"https://cdn.discordapp.com/emojis/{id}.png";
|
||||||
}
|
|
||||||
|
private static string GetImageUrl(string name) =>
|
||||||
|
$"https://twemoji.maxcdn.com/2/svg/{GetTwemojiName(name)}.svg";
|
||||||
|
|
||||||
|
public static string GetImageUrl(Snowflake? id, string? name, bool isAnimated)
|
||||||
|
{
|
||||||
|
// Custom emoji
|
||||||
|
if (id is not null)
|
||||||
|
return GetImageUrl(id.Value, isAnimated);
|
||||||
|
|
||||||
// Standard emoji
|
// Standard emoji
|
||||||
var twemojiName = GetTwemojiName(name);
|
if (!string.IsNullOrWhiteSpace(name))
|
||||||
return $"https://twemoji.maxcdn.com/2/svg/{twemojiName}.svg";
|
return GetImageUrl(name);
|
||||||
|
|
||||||
|
// Either ID or name should be set
|
||||||
|
throw new ApplicationException("Emoji has neither ID nor name set.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Emoji Parse(JsonElement json)
|
public static Emoji Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var id = json.GetPropertyOrNull("id")?.GetNonWhiteSpaceString();
|
var id = json.GetPropertyOrNull("id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
|
||||||
var name = json.GetProperty("name").GetNonWhiteSpaceString();
|
var name = json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var isAnimated = json.GetPropertyOrNull("animated")?.GetBoolean() ?? false;
|
var isAnimated = json.GetPropertyOrNull("animated")?.GetBooleanOrNull() ?? false;
|
||||||
|
|
||||||
var imageUrl = GetImageUrl(id, name, isAnimated);
|
var imageUrl = GetImageUrl(id, name, isAnimated);
|
||||||
|
|
||||||
return new Emoji(id, name, isAnimated, imageUrl);
|
return new Emoji(
|
||||||
}
|
id,
|
||||||
|
// Name may be missing if it's an emoji inside a reaction
|
||||||
|
name ?? "<unknown emoji>",
|
||||||
|
isAnimated,
|
||||||
|
imageUrl
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,8 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/guild#guild-object
|
// https://discord.com/developers/docs/resources/guild#guild-object
|
||||||
public record Guild(Snowflake Id, string Name, string IconUrl) : IHasId
|
public record Guild(Snowflake Id, string Name, string IconUrl) : IHasId
|
||||||
{
|
{
|
||||||
@@ -23,8 +23,8 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
public static Guild Parse(JsonElement json)
|
public static Guild Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
var name = json.GetProperty("name").GetNonWhiteSpaceString();
|
var name = json.GetProperty("name").GetNonNullString();
|
||||||
var iconHash = json.GetPropertyOrNull("icon")?.GetStringOrNull();
|
var iconHash = json.GetPropertyOrNull("icon")?.GetNonWhiteSpaceStringOrNull();
|
||||||
|
|
||||||
var iconUrl = !string.IsNullOrWhiteSpace(iconHash)
|
var iconUrl = !string.IsNullOrWhiteSpace(iconHash)
|
||||||
? GetIconUrl(id, iconHash)
|
? GetIconUrl(id, iconHash)
|
||||||
@@ -33,4 +33,3 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
return new Guild(id, name, iconUrl);
|
return new Guild(id, name, iconUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,8 +6,8 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/guild#guild-member-object
|
// https://discord.com/developers/docs/resources/guild#guild-member-object
|
||||||
public partial record Member(
|
public partial record Member(
|
||||||
User User,
|
User User,
|
||||||
@@ -28,7 +28,7 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
public static Member Parse(JsonElement json)
|
public static Member Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var user = json.GetProperty("user").Pipe(User.Parse);
|
var user = json.GetProperty("user").Pipe(User.Parse);
|
||||||
var nick = json.GetPropertyOrNull("nick")?.GetStringOrNull();
|
var nick = json.GetPropertyOrNull("nick")?.GetNonWhiteSpaceStringOrNull();
|
||||||
|
|
||||||
var roleIds = json
|
var roleIds = json
|
||||||
.GetPropertyOrNull("roles")?
|
.GetPropertyOrNull("roles")?
|
||||||
@@ -44,4 +44,3 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -7,8 +7,8 @@ using DiscordChatExporter.Core.Discord.Data.Embeds;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#message-object
|
// https://discord.com/developers/docs/resources/channel#message-object
|
||||||
public record Message(
|
public record Message(
|
||||||
Snowflake Id,
|
Snowflake Id,
|
||||||
@@ -21,6 +21,7 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
string Content,
|
string Content,
|
||||||
IReadOnlyList<Attachment> Attachments,
|
IReadOnlyList<Attachment> Attachments,
|
||||||
IReadOnlyList<Embed> Embeds,
|
IReadOnlyList<Embed> Embeds,
|
||||||
|
IReadOnlyList<Sticker> Stickers,
|
||||||
IReadOnlyList<Reaction> Reactions,
|
IReadOnlyList<Reaction> Reactions,
|
||||||
IReadOnlyList<User> MentionedUsers,
|
IReadOnlyList<User> MentionedUsers,
|
||||||
MessageReference? Reference,
|
MessageReference? Reference,
|
||||||
@@ -35,7 +36,7 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
var callEndedTimestamp = json.GetPropertyOrNull("call")?.GetPropertyOrNull("ended_timestamp")
|
var callEndedTimestamp = json.GetPropertyOrNull("call")?.GetPropertyOrNull("ended_timestamp")
|
||||||
?.GetDateTimeOffset();
|
?.GetDateTimeOffset();
|
||||||
var kind = (MessageKind)json.GetProperty("type").GetInt32();
|
var kind = (MessageKind)json.GetProperty("type").GetInt32();
|
||||||
var isPinned = json.GetPropertyOrNull("pinned")?.GetBoolean() ?? false;
|
var isPinned = json.GetPropertyOrNull("pinned")?.GetBooleanOrNull() ?? false;
|
||||||
var messageReference = json.GetPropertyOrNull("message_reference")?.Pipe(MessageReference.Parse);
|
var messageReference = json.GetPropertyOrNull("message_reference")?.Pipe(MessageReference.Parse);
|
||||||
var referencedMessage = json.GetPropertyOrNull("referenced_message")?.Pipe(Parse);
|
var referencedMessage = json.GetPropertyOrNull("referenced_message")?.Pipe(Parse);
|
||||||
|
|
||||||
@@ -53,19 +54,23 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
};
|
};
|
||||||
|
|
||||||
var attachments =
|
var attachments =
|
||||||
json.GetPropertyOrNull("attachments")?.EnumerateArray().Select(Attachment.Parse).ToArray() ??
|
json.GetPropertyOrNull("attachments")?.EnumerateArrayOrNull()?.Select(Attachment.Parse).ToArray() ??
|
||||||
Array.Empty<Attachment>();
|
Array.Empty<Attachment>();
|
||||||
|
|
||||||
var embeds =
|
var embeds =
|
||||||
json.GetPropertyOrNull("embeds")?.EnumerateArray().Select(Embed.Parse).ToArray() ??
|
json.GetPropertyOrNull("embeds")?.EnumerateArrayOrNull()?.Select(Embed.Parse).ToArray() ??
|
||||||
Array.Empty<Embed>();
|
Array.Empty<Embed>();
|
||||||
|
|
||||||
|
var stickers =
|
||||||
|
json.GetPropertyOrNull("sticker_items")?.EnumerateArrayOrNull()?.Select(Sticker.Parse).ToArray() ??
|
||||||
|
Array.Empty<Sticker>();
|
||||||
|
|
||||||
var reactions =
|
var reactions =
|
||||||
json.GetPropertyOrNull("reactions")?.EnumerateArray().Select(Reaction.Parse).ToArray() ??
|
json.GetPropertyOrNull("reactions")?.EnumerateArrayOrNull()?.Select(Reaction.Parse).ToArray() ??
|
||||||
Array.Empty<Reaction>();
|
Array.Empty<Reaction>();
|
||||||
|
|
||||||
var mentionedUsers =
|
var mentionedUsers =
|
||||||
json.GetPropertyOrNull("mentions")?.EnumerateArray().Select(User.Parse).ToArray() ??
|
json.GetPropertyOrNull("mentions")?.EnumerateArrayOrNull()?.Select(User.Parse).ToArray() ??
|
||||||
Array.Empty<User>();
|
Array.Empty<User>();
|
||||||
|
|
||||||
return new Message(
|
return new Message(
|
||||||
@@ -79,6 +84,7 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
content,
|
content,
|
||||||
attachments,
|
attachments,
|
||||||
embeds,
|
embeds,
|
||||||
|
stickers,
|
||||||
reactions,
|
reactions,
|
||||||
mentionedUsers,
|
mentionedUsers,
|
||||||
messageReference,
|
messageReference,
|
||||||
@@ -86,4 +92,3 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#message-object-message-types
|
// https://discord.com/developers/docs/resources/channel#message-object-message-types
|
||||||
public enum MessageKind
|
public enum MessageKind
|
||||||
{
|
{
|
||||||
@@ -13,4 +13,3 @@
|
|||||||
GuildMemberJoin = 7,
|
GuildMemberJoin = 7,
|
||||||
Reply = 19
|
Reply = 19
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,18 +2,17 @@ using System.Text.Json;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#message-object-message-reference-structure
|
// https://discord.com/developers/docs/resources/channel#message-object-message-reference-structure
|
||||||
public record MessageReference(Snowflake? MessageId, Snowflake? ChannelId, Snowflake? GuildId)
|
public record MessageReference(Snowflake? MessageId, Snowflake? ChannelId, Snowflake? GuildId)
|
||||||
{
|
{
|
||||||
public static MessageReference Parse(JsonElement json)
|
public static MessageReference Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var messageId = json.GetPropertyOrNull("message_id")?.GetStringOrNull()?.Pipe(Snowflake.Parse);
|
var messageId = json.GetPropertyOrNull("message_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
|
||||||
var channelId = json.GetPropertyOrNull("channel_id")?.GetStringOrNull()?.Pipe(Snowflake.Parse);
|
var channelId = json.GetPropertyOrNull("channel_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
|
||||||
var guildId = json.GetPropertyOrNull("guild_id")?.GetStringOrNull()?.Pipe(Snowflake.Parse);
|
var guildId = json.GetPropertyOrNull("guild_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
|
||||||
|
|
||||||
return new MessageReference(messageId, channelId, guildId);
|
return new MessageReference(messageId, channelId, guildId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#reaction-object
|
// https://discord.com/developers/docs/resources/channel#reaction-object
|
||||||
public record Reaction(Emoji Emoji, int Count)
|
public record Reaction(Emoji Emoji, int Count)
|
||||||
{
|
{
|
||||||
@@ -14,4 +14,3 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
return new Reaction(emoji, count);
|
return new Reaction(emoji, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,15 +4,15 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/topics/permissions#role-object
|
// https://discord.com/developers/docs/topics/permissions#role-object
|
||||||
public record Role(Snowflake Id, string Name, int Position, Color? Color) : IHasId
|
public record Role(Snowflake Id, string Name, int Position, Color? Color) : IHasId
|
||||||
{
|
{
|
||||||
public static Role Parse(JsonElement json)
|
public static Role Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
var name = json.GetProperty("name").GetNonWhiteSpaceString();
|
var name = json.GetProperty("name").GetNonNullString();
|
||||||
var position = json.GetProperty("position").GetInt32();
|
var position = json.GetProperty("position").GetInt32();
|
||||||
|
|
||||||
var color = json
|
var color = json
|
||||||
@@ -25,4 +25,3 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
return new Role(id, name, position, color);
|
return new Role(id, name, position, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
|
public record Sticker(Snowflake Id, string Name, StickerFormat Format, string SourceUrl)
|
||||||
|
{
|
||||||
|
private static string GetSourceUrl(Snowflake id, StickerFormat format)
|
||||||
|
{
|
||||||
|
var extension = format == StickerFormat.Lottie ? "json" : "png";
|
||||||
|
return $"https://discord.com/stickers/{id}.{extension}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Sticker Parse(JsonElement json)
|
||||||
|
{
|
||||||
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
|
var name = json.GetProperty("name").GetNonWhiteSpaceString();
|
||||||
|
var format = (StickerFormat)json.GetProperty("format_type").GetInt32();
|
||||||
|
|
||||||
|
var sourceUrl = GetSourceUrl(id, format);
|
||||||
|
|
||||||
|
return new Sticker(id, name, format, sourceUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
|
public enum StickerFormat
|
||||||
|
{
|
||||||
|
Png = 1,
|
||||||
|
PngAnimated = 2,
|
||||||
|
Lottie = 3
|
||||||
|
}
|
||||||
@@ -4,8 +4,8 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/user#user-object
|
// https://discord.com/developers/docs/resources/user#user-object
|
||||||
public partial record User(
|
public partial record User(
|
||||||
Snowflake Id,
|
Snowflake Id,
|
||||||
@@ -30,16 +30,16 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
? "gif"
|
? "gif"
|
||||||
: "png";
|
: "png";
|
||||||
|
|
||||||
return $"https://cdn.discordapp.com/avatars/{id}/{avatarHash}.{extension}?size=128";
|
return $"https://cdn.discordapp.com/avatars/{id}/{avatarHash}.{extension}?size=512";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static User Parse(JsonElement json)
|
public static User Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
var isBot = json.GetPropertyOrNull("bot")?.GetBoolean() ?? false;
|
var isBot = json.GetPropertyOrNull("bot")?.GetBooleanOrNull() ?? false;
|
||||||
var discriminator = json.GetProperty("discriminator").GetNonWhiteSpaceString().Pipe(int.Parse);
|
var discriminator = json.GetProperty("discriminator").GetNonWhiteSpaceString().Pipe(int.Parse);
|
||||||
var name = json.GetProperty("username").GetNonWhiteSpaceString();
|
var name = json.GetProperty("username").GetNonNullString();
|
||||||
var avatarHash = json.GetPropertyOrNull("avatar")?.GetStringOrNull();
|
var avatarHash = json.GetPropertyOrNull("avatar")?.GetNonWhiteSpaceStringOrNull();
|
||||||
|
|
||||||
var avatarUrl = !string.IsNullOrWhiteSpace(avatarHash)
|
var avatarUrl = !string.IsNullOrWhiteSpace(avatarHash)
|
||||||
? GetAvatarUrl(id, avatarHash)
|
? GetAvatarUrl(id, avatarHash)
|
||||||
@@ -48,4 +48,3 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
return new User(id, isBot, discriminator, name, avatarUrl);
|
return new User(id, isBot, discriminator, name, avatarUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -11,17 +12,41 @@ using DiscordChatExporter.Core.Discord.Data;
|
|||||||
using DiscordChatExporter.Core.Exceptions;
|
using DiscordChatExporter.Core.Exceptions;
|
||||||
using DiscordChatExporter.Core.Utils;
|
using DiscordChatExporter.Core.Utils;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
using Gress;
|
||||||
using JsonExtensions.Http;
|
using JsonExtensions.Http;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord
|
namespace DiscordChatExporter.Core.Discord;
|
||||||
{
|
|
||||||
public class DiscordClient
|
public class DiscordClient
|
||||||
{
|
{
|
||||||
private readonly AuthToken _token;
|
private readonly string _token;
|
||||||
private readonly Uri _baseUri = new("https://discord.com/api/v8/", UriKind.Absolute);
|
private readonly Uri _baseUri = new("https://discord.com/api/v9/", UriKind.Absolute);
|
||||||
|
|
||||||
public DiscordClient(AuthToken token) => _token = token;
|
private TokenKind _tokenKind = TokenKind.Unknown;
|
||||||
|
|
||||||
|
public DiscordClient(string token) => _token = token;
|
||||||
|
|
||||||
|
private async ValueTask<HttpResponseMessage> GetResponseAsync(
|
||||||
|
string url,
|
||||||
|
bool isBot,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
using var request = new HttpRequestMessage(HttpMethod.Get, new Uri(_baseUri, url));
|
||||||
|
|
||||||
|
// Don't validate because token can have invalid characters
|
||||||
|
// https://github.com/Tyrrrz/DiscordChatExporter/issues/828
|
||||||
|
request.Headers.TryAddWithoutValidation(
|
||||||
|
"Authorization",
|
||||||
|
isBot ? $"Bot {_token}" : _token
|
||||||
|
);
|
||||||
|
|
||||||
|
return await Http.Client.SendAsync(
|
||||||
|
request,
|
||||||
|
HttpCompletionOption.ResponseHeadersRead,
|
||||||
|
cancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private async ValueTask<HttpResponseMessage> GetResponseAsync(
|
private async ValueTask<HttpResponseMessage> GetResponseAsync(
|
||||||
string url,
|
string url,
|
||||||
@@ -29,14 +54,33 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
{
|
{
|
||||||
return await Http.ResponsePolicy.ExecuteAsync(async innerCancellationToken =>
|
return await Http.ResponsePolicy.ExecuteAsync(async innerCancellationToken =>
|
||||||
{
|
{
|
||||||
using var request = new HttpRequestMessage(HttpMethod.Get, new Uri(_baseUri, url));
|
if (_tokenKind == TokenKind.User)
|
||||||
request.Headers.Authorization = _token.GetAuthenticationHeader();
|
return await GetResponseAsync(url, false, innerCancellationToken);
|
||||||
|
|
||||||
return await Http.Client.SendAsync(
|
if (_tokenKind == TokenKind.Bot)
|
||||||
request,
|
return await GetResponseAsync(url, true, innerCancellationToken);
|
||||||
HttpCompletionOption.ResponseHeadersRead,
|
|
||||||
innerCancellationToken
|
// Try to authenticate as user
|
||||||
);
|
var userResponse = await GetResponseAsync(url, false, innerCancellationToken);
|
||||||
|
if (userResponse.StatusCode != HttpStatusCode.Unauthorized)
|
||||||
|
{
|
||||||
|
_tokenKind = TokenKind.User;
|
||||||
|
return userResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
userResponse.Dispose();
|
||||||
|
|
||||||
|
// Otherwise, try to authenticate as bot
|
||||||
|
var botResponse = await GetResponseAsync(url, true, innerCancellationToken);
|
||||||
|
if (botResponse.StatusCode != HttpStatusCode.Unauthorized)
|
||||||
|
{
|
||||||
|
_tokenKind = TokenKind.Bot;
|
||||||
|
return botResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The token is probably invalid altogether.
|
||||||
|
// Return the last response anyway, upstream should handle the error.
|
||||||
|
return botResponse;
|
||||||
}, cancellationToken);
|
}, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +186,7 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
|
|
||||||
foreach (var channelJson in responseOrdered)
|
foreach (var channelJson in responseOrdered)
|
||||||
{
|
{
|
||||||
var parentId = channelJson.GetPropertyOrNull("parent_id")?.GetStringOrNull();
|
var parentId = channelJson.GetPropertyOrNull("parent_id")?.GetNonWhiteSpaceStringOrNull();
|
||||||
|
|
||||||
var category = !string.IsNullOrWhiteSpace(parentId)
|
var category = !string.IsNullOrWhiteSpace(parentId)
|
||||||
? categories.GetValueOrDefault(parentId)
|
? categories.GetValueOrDefault(parentId)
|
||||||
@@ -205,7 +249,7 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
{
|
{
|
||||||
var response = await GetJsonResponseAsync($"channels/{channelId}", cancellationToken);
|
var response = await GetJsonResponseAsync($"channels/{channelId}", cancellationToken);
|
||||||
|
|
||||||
var parentId = response.GetPropertyOrNull("parent_id")?.GetStringOrNull()?.Pipe(Snowflake.Parse);
|
var parentId = response.GetPropertyOrNull("parent_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
|
||||||
|
|
||||||
var category = parentId is not null
|
var category = parentId is not null
|
||||||
? await GetChannelCategoryAsync(parentId.Value, cancellationToken)
|
? await GetChannelCategoryAsync(parentId.Value, cancellationToken)
|
||||||
@@ -233,7 +277,7 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
Snowflake channelId,
|
Snowflake channelId,
|
||||||
Snowflake? after = null,
|
Snowflake? after = null,
|
||||||
Snowflake? before = null,
|
Snowflake? before = null,
|
||||||
IProgress<double>? progress = null,
|
IProgress<Percentage>? progress = null,
|
||||||
[EnumeratorCancellation] CancellationToken cancellationToken = default)
|
[EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
// Get the last message in the specified range.
|
// Get the last message in the specified range.
|
||||||
@@ -282,16 +326,13 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
var exportedDuration = (message.Timestamp - firstMessage.Timestamp).Duration();
|
var exportedDuration = (message.Timestamp - firstMessage.Timestamp).Duration();
|
||||||
var totalDuration = (lastMessage.Timestamp - firstMessage.Timestamp).Duration();
|
var totalDuration = (lastMessage.Timestamp - firstMessage.Timestamp).Duration();
|
||||||
|
|
||||||
if (totalDuration > TimeSpan.Zero)
|
progress.Report(Percentage.FromFraction(
|
||||||
{
|
|
||||||
progress.Report(exportedDuration / totalDuration);
|
|
||||||
}
|
|
||||||
// Avoid division by zero if all messages have the exact same timestamp
|
// Avoid division by zero if all messages have the exact same timestamp
|
||||||
// (which may be the case if there's only one message in the channel)
|
// (which may be the case if there's only one message in the channel)
|
||||||
else
|
totalDuration > TimeSpan.Zero
|
||||||
{
|
? exportedDuration / totalDuration
|
||||||
progress.Report(1);
|
: 1
|
||||||
}
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return message;
|
yield return message;
|
||||||
@@ -300,4 +341,3 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,8 +3,8 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord
|
namespace DiscordChatExporter.Core.Discord;
|
||||||
{
|
|
||||||
public readonly partial record struct Snowflake(ulong Value)
|
public readonly partial record struct Snowflake(ulong Value)
|
||||||
{
|
{
|
||||||
public DateTimeOffset ToDate() => DateTimeOffset.FromUnixTimeMilliseconds(
|
public DateTimeOffset ToDate() => DateTimeOffset.FromUnixTimeMilliseconds(
|
||||||
@@ -53,4 +53,3 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
{
|
{
|
||||||
public int CompareTo(Snowflake other) => Value.CompareTo(other.Value);
|
public int CompareTo(Snowflake other) => Value.CompareTo(other.Value);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace DiscordChatExporter.Core.Discord;
|
||||||
|
|
||||||
|
public enum TokenKind
|
||||||
|
{
|
||||||
|
Unknown,
|
||||||
|
User,
|
||||||
|
Bot
|
||||||
|
}
|
||||||
@@ -5,9 +5,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Gress" Version="2.0.1" />
|
||||||
<PackageReference Include="JsonExtensions" Version="1.2.0" />
|
<PackageReference Include="JsonExtensions" Version="1.2.0" />
|
||||||
<PackageReference Include="MiniRazor.CodeGen" Version="2.2.0" />
|
<PackageReference Include="MiniRazor.CodeGen" Version="2.2.1" />
|
||||||
<PackageReference Include="Polly" Version="7.2.2" />
|
<PackageReference Include="Polly" Version="7.2.3" />
|
||||||
<PackageReference Include="Superpower" Version="3.0.0" />
|
<PackageReference Include="Superpower" Version="3.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exceptions
|
namespace DiscordChatExporter.Core.Exceptions;
|
||||||
{
|
|
||||||
public partial class DiscordChatExporterException : Exception
|
public partial class DiscordChatExporterException : Exception
|
||||||
{
|
{
|
||||||
public bool IsFatal { get; }
|
public bool IsFatal { get; }
|
||||||
@@ -42,4 +42,3 @@ Failed to perform an HTTP request.
|
|||||||
internal static DiscordChatExporterException ChannelIsEmpty() =>
|
internal static DiscordChatExporterException ChannelIsEmpty() =>
|
||||||
new("No messages found for the specified period.");
|
new("No messages found for the specified period.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -8,20 +8,19 @@ using DiscordChatExporter.Core.Discord.Data;
|
|||||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||||
using DiscordChatExporter.Core.Exceptions;
|
using DiscordChatExporter.Core.Exceptions;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
using Gress;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Core.Exporting;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting
|
|
||||||
{
|
|
||||||
public class ChannelExporter
|
public class ChannelExporter
|
||||||
{
|
{
|
||||||
private readonly DiscordClient _discord;
|
private readonly DiscordClient _discord;
|
||||||
|
|
||||||
public ChannelExporter(DiscordClient discord) => _discord = discord;
|
public ChannelExporter(DiscordClient discord) => _discord = discord;
|
||||||
|
|
||||||
public ChannelExporter(AuthToken token) : this(new DiscordClient(token)) {}
|
|
||||||
|
|
||||||
public async ValueTask ExportChannelAsync(
|
public async ValueTask ExportChannelAsync(
|
||||||
ExportRequest request,
|
ExportRequest request,
|
||||||
IProgress<double>? progress = null,
|
IProgress<Percentage>? progress = null,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
// Build context
|
// Build context
|
||||||
@@ -80,4 +79,3 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
throw DiscordChatExporterException.ChannelIsEmpty();
|
throw DiscordChatExporterException.ChannelIsEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -10,8 +10,8 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting
|
namespace DiscordChatExporter.Core.Exporting;
|
||||||
{
|
|
||||||
internal class ExportContext
|
internal class ExportContext
|
||||||
{
|
{
|
||||||
private readonly MediaDownloader _mediaDownloader;
|
private readonly MediaDownloader _mediaDownloader;
|
||||||
@@ -103,4 +103,3 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting
|
namespace DiscordChatExporter.Core.Exporting;
|
||||||
{
|
|
||||||
public enum ExportFormat
|
public enum ExportFormat
|
||||||
{
|
{
|
||||||
PlainText,
|
PlainText,
|
||||||
@@ -33,4 +33,3 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
_ => throw new ArgumentOutOfRangeException(nameof(format))
|
_ => throw new ArgumentOutOfRangeException(nameof(format))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.IO;
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
@@ -8,8 +7,8 @@ using DiscordChatExporter.Core.Exporting.Filtering;
|
|||||||
using DiscordChatExporter.Core.Exporting.Partitioning;
|
using DiscordChatExporter.Core.Exporting.Partitioning;
|
||||||
using DiscordChatExporter.Core.Utils;
|
using DiscordChatExporter.Core.Utils;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting
|
namespace DiscordChatExporter.Core.Exporting;
|
||||||
{
|
|
||||||
public partial record ExportRequest(
|
public partial record ExportRequest(
|
||||||
Guild Guild,
|
Guild Guild,
|
||||||
Channel Channel,
|
Channel Channel,
|
||||||
@@ -48,10 +47,9 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
Snowflake? after = null,
|
Snowflake? after = null,
|
||||||
Snowflake? before = null)
|
Snowflake? before = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Formats path
|
// Formats path
|
||||||
outputPath = Regex.Replace(outputPath, "%.", m =>
|
outputPath = Regex.Replace(outputPath, "%.", m =>
|
||||||
PathEx.EscapePath(m.Value switch
|
PathEx.EscapeFileName(m.Value switch
|
||||||
{
|
{
|
||||||
"%g" => guild.Id.ToString(),
|
"%g" => guild.Id.ToString(),
|
||||||
"%G" => guild.Name,
|
"%G" => guild.Name,
|
||||||
@@ -61,8 +59,8 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
"%C" => channel.Name,
|
"%C" => channel.Name,
|
||||||
"%p" => channel.Position?.ToString() ?? "0",
|
"%p" => channel.Position?.ToString() ?? "0",
|
||||||
"%P" => channel.Category.Position?.ToString() ?? "0",
|
"%P" => channel.Category.Position?.ToString() ?? "0",
|
||||||
"%a" => (after ?? Snowflake.Zero).ToDate().ToString("yyyy-MM-dd"),
|
"%a" => after?.ToDate().ToString("yyyy-MM-dd") ?? "",
|
||||||
"%b" => (before?.ToDate() ?? DateTime.Now).ToString("yyyy-MM-dd"),
|
"%b" => before?.ToDate().ToString("yyyy-MM-dd") ?? "",
|
||||||
"%%" => "%",
|
"%%" => "%",
|
||||||
_ => m.Value
|
_ => m.Value
|
||||||
})
|
})
|
||||||
@@ -94,7 +92,7 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
// Date range
|
// Date range
|
||||||
if (after is not null || before is not null)
|
if (after is not null || before is not null)
|
||||||
{
|
{
|
||||||
buffer.Append(" (");
|
buffer.Append(' ').Append('(');
|
||||||
|
|
||||||
// Both 'after' and 'before' are set
|
// Both 'after' and 'before' are set
|
||||||
if (after is not null && before is not null)
|
if (after is not null && before is not null)
|
||||||
@@ -112,16 +110,12 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
buffer.Append($"before {before.Value.ToDate():yyyy-MM-dd}");
|
buffer.Append($"before {before.Value.ToDate():yyyy-MM-dd}");
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.Append(")");
|
buffer.Append(')');
|
||||||
}
|
}
|
||||||
|
|
||||||
// File extension
|
// File extension
|
||||||
buffer.Append($".{format.GetFileExtension()}");
|
buffer.Append('.').Append(format.GetFileExtension());
|
||||||
|
|
||||||
// Replace invalid chars
|
return PathEx.EscapeFileName(buffer.ToString());
|
||||||
PathEx.EscapePath(buffer);
|
|
||||||
|
|
||||||
return buffer.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
{
|
|
||||||
internal enum BinaryExpressionKind
|
internal enum BinaryExpressionKind
|
||||||
{
|
{
|
||||||
Or,
|
Or,
|
||||||
And
|
And
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
{
|
|
||||||
internal class BinaryExpressionMessageFilter : MessageFilter
|
internal class BinaryExpressionMessageFilter : MessageFilter
|
||||||
{
|
{
|
||||||
private readonly MessageFilter _first;
|
private readonly MessageFilter _first;
|
||||||
@@ -23,4 +23,3 @@ namespace DiscordChatExporter.Core.Exporting.Filtering
|
|||||||
_ => throw new InvalidOperationException($"Unknown binary expression kind '{_kind}'.")
|
_ => throw new InvalidOperationException($"Unknown binary expression kind '{_kind}'.")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
{
|
|
||||||
internal class ContainsMessageFilter : MessageFilter
|
internal class ContainsMessageFilter : MessageFilter
|
||||||
{
|
{
|
||||||
private readonly string _text;
|
private readonly string _text;
|
||||||
@@ -31,4 +31,3 @@ namespace DiscordChatExporter.Core.Exporting.Filtering
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
{
|
|
||||||
internal class FromMessageFilter : MessageFilter
|
internal class FromMessageFilter : MessageFilter
|
||||||
{
|
{
|
||||||
private readonly string _value;
|
private readonly string _value;
|
||||||
@@ -14,4 +14,3 @@ namespace DiscordChatExporter.Core.Exporting.Filtering
|
|||||||
string.Equals(_value, message.Author.FullName, StringComparison.OrdinalIgnoreCase) ||
|
string.Equals(_value, message.Author.FullName, StringComparison.OrdinalIgnoreCase) ||
|
||||||
string.Equals(_value, message.Author.Id.ToString(), StringComparison.OrdinalIgnoreCase);
|
string.Equals(_value, message.Author.Id.ToString(), StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,8 +3,8 @@ using System.Linq;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
{
|
|
||||||
internal class HasMessageFilter : MessageFilter
|
internal class HasMessageFilter : MessageFilter
|
||||||
{
|
{
|
||||||
private readonly MessageContentMatchKind _kind;
|
private readonly MessageContentMatchKind _kind;
|
||||||
@@ -22,4 +22,3 @@ namespace DiscordChatExporter.Core.Exporting.Filtering
|
|||||||
_ => throw new InvalidOperationException($"Unknown message content match kind '{_kind}'.")
|
_ => throw new InvalidOperationException($"Unknown message content match kind '{_kind}'.")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
{
|
|
||||||
internal class MentionsMessageFilter : MessageFilter
|
internal class MentionsMessageFilter : MessageFilter
|
||||||
{
|
{
|
||||||
private readonly string _value;
|
private readonly string _value;
|
||||||
@@ -16,4 +16,3 @@ namespace DiscordChatExporter.Core.Exporting.Filtering
|
|||||||
string.Equals(_value, user.Id.ToString(), StringComparison.OrdinalIgnoreCase)
|
string.Equals(_value, user.Id.ToString(), StringComparison.OrdinalIgnoreCase)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
{
|
|
||||||
internal enum MessageContentMatchKind
|
internal enum MessageContentMatchKind
|
||||||
{
|
{
|
||||||
Link,
|
Link,
|
||||||
@@ -9,4 +9,3 @@
|
|||||||
Image,
|
Image,
|
||||||
Sound
|
Sound
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
using DiscordChatExporter.Core.Exporting.Filtering.Parsing;
|
using DiscordChatExporter.Core.Exporting.Filtering.Parsing;
|
||||||
using Superpower;
|
using Superpower;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
{
|
|
||||||
public abstract partial class MessageFilter
|
public abstract partial class MessageFilter
|
||||||
{
|
{
|
||||||
public abstract bool IsMatch(Message message);
|
public abstract bool IsMatch(Message message);
|
||||||
@@ -15,4 +15,3 @@ namespace DiscordChatExporter.Core.Exporting.Filtering
|
|||||||
|
|
||||||
public static MessageFilter Parse(string value) => FilterGrammar.Filter.Parse(value);
|
public static MessageFilter Parse(string value) => FilterGrammar.Filter.Parse(value);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
{
|
|
||||||
internal class NegatedMessageFilter : MessageFilter
|
internal class NegatedMessageFilter : MessageFilter
|
||||||
{
|
{
|
||||||
private readonly MessageFilter _filter;
|
private readonly MessageFilter _filter;
|
||||||
@@ -10,4 +10,3 @@ namespace DiscordChatExporter.Core.Exporting.Filtering
|
|||||||
|
|
||||||
public override bool IsMatch(Message message) => !_filter.IsMatch(message);
|
public override bool IsMatch(Message message) => !_filter.IsMatch(message);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
{
|
|
||||||
internal class NullMessageFilter : MessageFilter
|
internal class NullMessageFilter : MessageFilter
|
||||||
{
|
{
|
||||||
public override bool IsMatch(Message message) => true;
|
public override bool IsMatch(Message message) => true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
using Superpower;
|
using Superpower;
|
||||||
using Superpower.Parsers;
|
using Superpower.Parsers;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Filtering.Parsing
|
namespace DiscordChatExporter.Core.Exporting.Filtering.Parsing;
|
||||||
{
|
|
||||||
internal static class FilterGrammar
|
internal static class FilterGrammar
|
||||||
{
|
{
|
||||||
private static readonly TextParser<char> EscapedCharacter =
|
private static readonly TextParser<char> EscapedCharacter =
|
||||||
@@ -44,6 +44,12 @@ namespace DiscordChatExporter.Core.Exporting.Filtering.Parsing
|
|||||||
.Select(v => (MessageFilter) new MentionsMessageFilter(v))
|
.Select(v => (MessageFilter) new MentionsMessageFilter(v))
|
||||||
.Named("mentions:<value>");
|
.Named("mentions:<value>");
|
||||||
|
|
||||||
|
private static readonly TextParser<MessageFilter> ReactionFilter = Span
|
||||||
|
.EqualToIgnoreCase("reaction:")
|
||||||
|
.IgnoreThen(String)
|
||||||
|
.Select(v => (MessageFilter) new ReactionMessageFilter(v))
|
||||||
|
.Named("reaction:<value>");
|
||||||
|
|
||||||
private static readonly TextParser<MessageFilter> HasFilter = Span
|
private static readonly TextParser<MessageFilter> HasFilter = Span
|
||||||
.EqualToIgnoreCase("has:")
|
.EqualToIgnoreCase("has:")
|
||||||
.IgnoreThen(Parse.OneOf(
|
.IgnoreThen(Parse.OneOf(
|
||||||
@@ -72,6 +78,7 @@ namespace DiscordChatExporter.Core.Exporting.Filtering.Parsing
|
|||||||
GroupedFilter,
|
GroupedFilter,
|
||||||
FromFilter,
|
FromFilter,
|
||||||
MentionsFilter,
|
MentionsFilter,
|
||||||
|
ReactionFilter,
|
||||||
HasFilter,
|
HasFilter,
|
||||||
ContainsFilter
|
ContainsFilter
|
||||||
);
|
);
|
||||||
@@ -99,4 +106,3 @@ namespace DiscordChatExporter.Core.Exporting.Filtering.Parsing
|
|||||||
public static readonly TextParser<MessageFilter> Filter =
|
public static readonly TextParser<MessageFilter> Filter =
|
||||||
BinaryExpressionFilter.Token().AtEnd();
|
BinaryExpressionFilter.Token().AtEnd();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
|
|
||||||
|
internal class ReactionMessageFilter : MessageFilter
|
||||||
|
{
|
||||||
|
private readonly string _value;
|
||||||
|
|
||||||
|
public ReactionMessageFilter(string value) => _value = value;
|
||||||
|
|
||||||
|
public override bool IsMatch(Message message) => message.Reactions.Any(r =>
|
||||||
|
string.Equals(_value, r.Emoji.Id?.ToString(), StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
string.Equals(_value, r.Emoji.Name, StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
string.Equals(_value, r.Emoji.Code, StringComparison.OrdinalIgnoreCase)
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -10,8 +10,8 @@ using System.Threading.Tasks;
|
|||||||
using DiscordChatExporter.Core.Utils;
|
using DiscordChatExporter.Core.Utils;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting
|
namespace DiscordChatExporter.Core.Exporting;
|
||||||
{
|
|
||||||
internal partial class MediaDownloader
|
internal partial class MediaDownloader
|
||||||
{
|
{
|
||||||
private readonly string _workingDirPath;
|
private readonly string _workingDirPath;
|
||||||
@@ -47,7 +47,7 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
using var response = await Http.Client.GetAsync(url, cancellationToken);
|
using var response = await Http.Client.GetAsync(url, cancellationToken);
|
||||||
await using (var output = File.Create(filePath))
|
await using (var output = File.Create(filePath))
|
||||||
{
|
{
|
||||||
await response.Content.CopyToAsync(output);
|
await response.Content.CopyToAsync(output, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to set the file date according to the last-modified header
|
// Try to set the file date according to the last-modified header
|
||||||
@@ -104,7 +104,14 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
|
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
|
||||||
var fileExtension = Path.GetExtension(fileName);
|
var fileExtension = Path.GetExtension(fileName);
|
||||||
|
|
||||||
return PathEx.EscapePath(fileNameWithoutExtension.Truncate(42) + '-' + urlHash + fileExtension);
|
// Probably not a file extension, just a dot in a long file name
|
||||||
}
|
// https://github.com/Tyrrrz/DiscordChatExporter/issues/708
|
||||||
|
if (fileExtension.Length > 41)
|
||||||
|
{
|
||||||
|
fileNameWithoutExtension = fileName;
|
||||||
|
fileExtension = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return PathEx.EscapeFileName(fileNameWithoutExtension.Truncate(42) + '-' + urlHash + fileExtension);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
using DiscordChatExporter.Core.Exporting.Writers;
|
using DiscordChatExporter.Core.Exporting.Writers;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting
|
namespace DiscordChatExporter.Core.Exporting;
|
||||||
{
|
|
||||||
internal partial class MessageExporter : IAsyncDisposable
|
internal partial class MessageExporter : IAsyncDisposable
|
||||||
{
|
{
|
||||||
private readonly ExportContext _context;
|
private readonly ExportContext _context;
|
||||||
@@ -102,4 +102,3 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace DiscordChatExporter.Core.Exporting.Partitioning
|
namespace DiscordChatExporter.Core.Exporting.Partitioning;
|
||||||
{
|
|
||||||
internal class FileSizePartitionLimit : PartitionLimit
|
internal class FileSizePartitionLimit : PartitionLimit
|
||||||
{
|
{
|
||||||
private readonly long _limit;
|
private readonly long _limit;
|
||||||
@@ -9,4 +9,3 @@
|
|||||||
public override bool IsReached(long messagesWritten, long bytesWritten) =>
|
public override bool IsReached(long messagesWritten, long bytesWritten) =>
|
||||||
bytesWritten >= _limit;
|
bytesWritten >= _limit;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace DiscordChatExporter.Core.Exporting.Partitioning
|
namespace DiscordChatExporter.Core.Exporting.Partitioning;
|
||||||
{
|
|
||||||
internal class MessageCountPartitionLimit : PartitionLimit
|
internal class MessageCountPartitionLimit : PartitionLimit
|
||||||
{
|
{
|
||||||
private readonly long _limit;
|
private readonly long _limit;
|
||||||
@@ -9,4 +9,3 @@
|
|||||||
public override bool IsReached(long messagesWritten, long bytesWritten) =>
|
public override bool IsReached(long messagesWritten, long bytesWritten) =>
|
||||||
messagesWritten >= _limit;
|
messagesWritten >= _limit;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
namespace DiscordChatExporter.Core.Exporting.Partitioning
|
namespace DiscordChatExporter.Core.Exporting.Partitioning;
|
||||||
{
|
|
||||||
internal class NullPartitionLimit : PartitionLimit
|
internal class NullPartitionLimit : PartitionLimit
|
||||||
{
|
{
|
||||||
public override bool IsReached(long messagesWritten, long bytesWritten) => false;
|
public override bool IsReached(long messagesWritten, long bytesWritten) => false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Partitioning
|
namespace DiscordChatExporter.Core.Exporting.Partitioning;
|
||||||
{
|
|
||||||
public abstract partial class PartitionLimit
|
public abstract partial class PartitionLimit
|
||||||
{
|
{
|
||||||
public abstract bool IsReached(long messagesWritten, long bytesWritten);
|
public abstract bool IsReached(long messagesWritten, long bytesWritten);
|
||||||
@@ -60,4 +60,3 @@ namespace DiscordChatExporter.Core.Exporting.Partitioning
|
|||||||
public static PartitionLimit Parse(string value, IFormatProvider? formatProvider = null) =>
|
public static PartitionLimit Parse(string value, IFormatProvider? formatProvider = null) =>
|
||||||
TryParse(value, formatProvider) ?? throw new FormatException($"Invalid partition limit '{value}'.");
|
TryParse(value, formatProvider) ?? throw new FormatException($"Invalid partition limit '{value}'.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user