Compare commits

...

48 Commits

Author SHA1 Message Date
Copilot 72f9e981de Replace YouTube iframe embeds with clickable thumbnails (#1474)
* Initial plan

* Replace YouTube iframe with clickable thumbnail

- Changed YouTube embed URL from embed format to watch format
- Added ThumbnailUrl property to YouTubeVideoEmbedProjection using YouTube's standard thumbnail URL
- Updated MessageGroupTemplate to render thumbnail image with link instead of iframe
- Updated CSS to style thumbnail appropriately
- Updated test to check for anchor link and thumbnail image instead of iframe

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

* Address code review feedback

- Use hqdefault.jpg instead of maxresdefault.jpg (guaranteed to exist for all videos)
- Extract thumbnail URL logic to GetThumbnailUrl method for better testability

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

* Simplify YouTube embed test to focus on data not structure

- Remove checks for HTML structure (class names, nested elements)
- Focus on verifying YouTube URL with correct video ID exists
- Follow same pattern as other embed tests (Spotify, Twitch)

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

* Fix data-canonical-url and improve test specificity

- Use canonical (non-proxy) URL for data-canonical-url attribute
- Extract thumbnailUrl to local variable to avoid duplicate calls
- Update test to check for img with video ID in src, avoiding false positives
- Test now verifies the actual thumbnail data rather than any link

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

* Inline thumbnail URL logic directly into attributes

- Remove GetThumbnailUrl method from YouTubeVideoEmbedProjection
- Remove local variables from template
- Put coalescing logic directly in src and data-canonical-url attributes

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
2026-02-12 19:04:17 +02:00
Copilot 81e286751f Add file:// protocol to absolute asset paths in HTML exports (#1475)
* Initial plan

* Add file:// protocol prefix to absolute paths in HTML exports

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

* Improve absolute path detection for cross-platform compatibility

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

* Remove unused System.IO import

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

* Use Path.IsPathFullyQualified for absolute path detection (fixes #1473)

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
2026-02-12 13:19:12 +02:00
dependabot[bot] 225230a20f Bump the actions group with 2 updates (#1467)
Bumps the actions group with 2 updates: [actions/checkout](https://github.com/actions/checkout) and [actions/setup-dotnet](https://github.com/actions/setup-dotnet).


Updates `actions/checkout` from 6.0.1 to 6.0.2
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/8e8c483db84b4bee98b60c0593521ed34d9990e8...de0fac2e4500dabe0009e67214ff5f5447ce83dd)

Updates `actions/setup-dotnet` from 5.0.1 to 5.1.0
- [Release notes](https://github.com/actions/setup-dotnet/releases)
- [Commits](https://github.com/actions/setup-dotnet/compare/2016bd2012dba4e32de620c46fe006a3ac9f0602...baa11fbfe1d6520db94683bd5c7a3818018e4309)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 6.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: actions/setup-dotnet
  dependency-version: 5.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-10 17:28:59 +02:00
dependabot[bot] dea412ff25 Bump the nuget group with 9 updates (#1468)
Bumps AsyncKeyedLock from 7.1.8 to 8.0.1
Bumps Avalonia from 11.3.10 to 11.3.11
Bumps Avalonia.Desktop from 11.3.10 to 11.3.11
Bumps Avalonia.Diagnostics from 11.3.10 to 11.3.11
Bumps DialogHost.Avalonia from 0.10.3 to 0.10.4
Bumps Microsoft.Extensions.Configuration from 10.0.1 to 10.0.2
Bumps Microsoft.Extensions.Configuration.EnvironmentVariables from 10.0.1 to 10.0.2
Bumps Microsoft.Extensions.Configuration.UserSecrets from 10.0.1 to 10.0.2
Bumps Microsoft.Extensions.DependencyInjection from 10.0.1 to 10.0.2

---
updated-dependencies:
- dependency-name: AsyncKeyedLock
  dependency-version: 8.0.1
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: nuget
- dependency-name: Avalonia
  dependency-version: 11.3.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: nuget
- dependency-name: Avalonia.Desktop
  dependency-version: 11.3.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: nuget
- dependency-name: Avalonia.Diagnostics
  dependency-version: 11.3.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: nuget
- dependency-name: DialogHost.Avalonia
  dependency-version: 0.10.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: nuget
- dependency-name: Microsoft.Extensions.Configuration
  dependency-version: 10.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: nuget
- dependency-name: Microsoft.Extensions.Configuration.EnvironmentVariables
  dependency-version: 10.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: nuget
- dependency-name: Microsoft.Extensions.Configuration.UserSecrets
  dependency-version: 10.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: nuget
- dependency-name: Microsoft.Extensions.DependencyInjection
  dependency-version: 10.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: nuget
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-10 17:28:47 +02:00
Tyrrrz 95953f8cf0 Refactor 2026-01-01 23:56:12 +02:00
Tyrrrz 6191855e33 Fix invalid issue link in comment 2026-01-01 23:53:57 +02:00
Copilot 33a975b907 Fix case-insensitive lookup for data package index file (#1460)
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-01-01 21:19:59 +02:00
Tyrrrz 3d353bc1e6 Format 2026-01-01 20:40:37 +02:00
dependabot[bot] f555ab3f00 Bump the actions group with 5 updates (#1457)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-01 20:37:11 +02:00
dependabot[bot] a14a17db83 Bump the nuget group with 11 updates (#1458)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-01 20:36:41 +02:00
Tyrrrz 1f63d4fa26 Line breaks 2025-12-31 18:57:08 +02:00
Copilot d3d078735a Preserve original URLs for proxied embed assets (#1456)
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2025-12-31 18:54:04 +02:00
Tyrrrz 58dd40bf3e Refactor last commit 2025-12-29 20:11:05 +02:00
Copilot 7c79e0639b Fix filename sanitization for NTFS filesystems on non-Windows systems (#1455)
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2025-12-29 19:52:59 +02:00
Tyrrrz a74ba4da0c Update license year 2025-12-06 19:20:21 +02:00
Tyrrrz 8bbb8fa5ee Clean up 2025-12-03 23:37:23 +02:00
CarcaBot a91337ccac Fixed token retrieval through console (#1402) 2025-12-02 16:43:00 +02:00
Tyrrrz 303f5667bf Remove unused package 2025-12-01 20:51:03 +02:00
dependabot[bot] 934cb526e9 Bump the nuget group with 17 updates (#1445)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-01 20:47:52 +02:00
dependabot[bot] c33b742dce Bump the actions group with 2 updates (#1446)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-01 20:47:02 +02:00
Tyrrrz f0a74fbc6e Simplify 2025-11-30 19:24:37 +02:00
Tyrrrz 768e124370 Remove unnecessary extension 2025-11-30 19:23:01 +02:00
Tyrrrz 8dc7eb2937 Use markdown alerts 2025-11-24 17:58:06 +02:00
Tyrrrz 8fff0f4445 Prettify project files 2025-11-18 19:07:17 +02:00
Tyrrrz 0fc8124aa0 Cleanup the trim/aot analyzer hack 2025-11-18 00:55:23 +02:00
Tyrrrz 64ed6acf34 Don't use type aliases 2025-11-18 00:36:47 +02:00
Tyrrrz e958600073 Disable trim warnings in CLI as a workaround for C# 14 extension block issue 2025-11-16 23:28:18 +02:00
Tyrrrz 714d2e6806 Update sln 2025-11-16 20:55:00 +02:00
Tyrrrz fbbac2afaa Make use of C# 14 features 2025-11-16 20:29:39 +02:00
Tyrrrz 380dd6d511 Update to .NET 10 2025-11-11 19:46:22 +02:00
dependabot[bot] 607ec7442f Bump the actions group with 2 updates (#1440)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-11-01 13:05:14 +02:00
dependabot[bot] e6f675bcaa Bump the nuget group with 14 updates (#1441)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-11-01 13:05:05 +02:00
Tyrrrz 42ebb9928e Fix CD workflow 2025-10-04 04:46:01 +03:00
Tyrrrz 7e64aa5a8e Add default to PublishMacOSBundle to avoid error when publishing without extra args 2025-10-04 04:25:40 +03:00
dependabot[bot] a383722469 Bump the nuget group with 13 updates (#1431)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-02 16:08:07 +03:00
dependabot[bot] 8f3fe7e501 Bump the actions group with 2 updates (#1430)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-02 16:07:47 +03:00
Tyrrrz 27a434a663 Format 2025-09-02 19:55:09 +03:00
dependabot[bot] a966bee140 Bump the nuget group with 12 updates (#1429)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-02 19:50:14 +03:00
dependabot[bot] fb17e86146 Bump the actions group with 3 updates (#1428)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-02 19:49:59 +03:00
dependabot[bot] 8fcf5e5377 Bump the nuget group with 7 updates (#1417)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-01 16:59:39 +03:00
Tyrrrz 845e2a52fe Fix guilds -> servers 2025-07-09 01:10:56 +03:00
Tyrrrz 187befcf11 Remove the now unnecessary extension method 2025-07-01 19:02:48 +03:00
dependabot[bot] 9e685a0375 Bump the nuget group with 15 updates (#1408)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-01 19:00:52 +03:00
dependabot[bot] 0d98e1084d Bump docker/setup-buildx-action in the actions group (#1409)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-01 18:59:12 +03:00
Tyrrrz f149fad406 Potato potato 2025-06-26 17:50:32 +03:00
Oleksii Holub 5405e619a9 Set application name to fix macOS app menu title (#1405) 2025-06-26 00:35:32 +03:00
Tyrrrz adafaaa49d Clean up chmods 2025-06-25 19:27:26 +03:00
Oleksii Holub d071459a5b Fix crash when exporting multiple channels to drive root (#1399) 2025-06-16 20:38:10 +03:00
62 changed files with 630 additions and 496 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ The HTML format replicates Discord's interface, making it the most user-friendly
It's the best format for attachment preview and sharing.
You can open `.html` files with a web browser, such as Google Chrome.
> **Warning**:
> [!WARNING]
> If a picture is deleted, or if a user changes its avatar, the respective images will no longer be displayed.
> Export using the "Download assets" (`--media`) option to avoid this.
+3 -3
View File
@@ -27,7 +27,7 @@ Prerequisite step: Navigate to [discord.com](https://discord.com) and login.
3. Type
```js
(webpackChunkdiscord_app.push([[''],{},e=>{m=[];for(let c in e.c)m.push(e.c[c])}]),m).find(m=>m?.exports?.default?.getToken!==void 0).exports.default.getToken()
let m;webpackChunkdiscord_app.push([[Math.random()],{},e=>{for(let i in e.c){let x=e.c[i];if(x?.exports?.$8&&x.exports.LP&&x.exports.gK){m=x;break}}}]);m&&console.log("Token:",m.exports.LP());
```
into the console and press <kbd>Enter</kbd>. The console will display your user token.
@@ -120,7 +120,7 @@ Prerequisite step: Navigate to [discord.com](https://discord.com) and login.
1. Type
```js
(webpackChunkdiscord_app.push([[''],{},e=>{m=[];for(let c in e.c)m.push(e.c[c])}]),m).find(m=>m?.exports?.default?.getToken!==void 0).exports.default.getToken()
let m;webpackChunkdiscord_app.push([[Math.random()],{},e=>{for(let i in e.c){let x=e.c[i];if(x?.exports?.$8&&x.exports.LP&&x.exports.gK){m=x;break}}}]);m&&console.log("Token:",m.exports.LP());
```
into the console and press <kbd>Enter</kbd>. The console will display your user token.
@@ -306,7 +306,7 @@ If you don't have a bot token yet or if you've lost it, follow these steps to re
> **Tip**:
> As the token is only shown once, make sure to store it in a safe place. If you lose the token, you will have to reset it again.
> **Warning**:
> [!WARNING]
> Resetting the token will invalidate the old one. Any integrations relying on the old token will cease to function until they are updated.
![https://discord.com/developers/applications/](https://i.imgur.com/soiB8Qc.png)
+1 -1
View File
@@ -31,7 +31,7 @@ If you skip these steps, the "DiscordChatExporter is damaged and cant be open
Please refer to the on-screen instructions to get your token, then paste your token in the upper text box and hit ENTER or click the arrow (→).
> **Warning**:
> [!WARNING]
> **Never share your token!**
> A token gives full access to an account, treat it like a password.
+6 -6
View File
@@ -23,10 +23,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- name: Build image
run: >
@@ -36,8 +36,8 @@ jobs:
--build-arg VERSION=${{ github.ref_type == 'tag' && github.ref_name || format('999.9.9-ci-{0}', github.sha) }}
--output type=tar,dest=DiscordChatExporter.Cli.Docker.tar
- name: Upload artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
- name: Upload image
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: DiscordChatExporter.Cli.Docker
path: DiscordChatExporter.Cli.Docker.tar
@@ -55,10 +55,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- name: Login to DockerHub
run: >
+15 -24
View File
@@ -26,12 +26,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install .NET
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
with:
dotnet-version: 9.0.x
uses: actions/setup-dotnet@baa11fbfe1d6520db94683bd5c7a3818018e4309 # v5.1.0
# Build the project separately to discern between build and format errors
- name: Build
@@ -64,12 +62,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install .NET
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
with:
dotnet-version: 9.0.x
uses: actions/setup-dotnet@baa11fbfe1d6520db94683bd5c7a3818018e4309 # v5.1.0
- name: Run tests
env:
@@ -85,7 +81,7 @@ jobs:
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
- name: Upload coverage
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
@@ -121,12 +117,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install .NET
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
with:
dotnet-version: 9.0.x
uses: actions/setup-dotnet@baa11fbfe1d6520db94683bd5c7a3818018e4309 # v5.1.0
- name: Publish app
run: >
@@ -139,8 +133,8 @@ jobs:
--runtime ${{ matrix.rid }}
--self-contained
- name: Upload artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
- name: Upload app binaries
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: ${{ matrix.asset }}.${{ matrix.rid }}
path: ${{ matrix.app }}/bin/publish/
@@ -204,8 +198,8 @@ jobs:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
- name: Download app binaries
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: ${{ matrix.asset }}.${{ matrix.rid }}
path: ${{ matrix.app }}/
@@ -213,13 +207,10 @@ jobs:
- name: Set permissions
if: ${{ !startsWith(matrix.rid, 'win-') }}
run: |
if [ -f ${{ matrix.app }}/${{ matrix.asset }} ]; then
chmod +x ${{ matrix.app }}/${{ matrix.asset }}
fi
if [ -f ${{ matrix.app }}/${{ matrix.asset }}.app/Contents/MacOS/${{ matrix.asset }} ]; then
chmod +x ${{ matrix.app }}/${{ matrix.asset }}.app/Contents/MacOS/${{ matrix.asset }}
fi
[ -f ${{ matrix.app }}/${{ matrix.asset }} ] && chmod +x ${{ matrix.app }}/${{ matrix.asset }} || true
# macOS bundle
[ -f ${{ matrix.app }}/${{ matrix.asset }}.app/Contents/MacOS/${{ matrix.asset }} ] && chmod +x ${{ matrix.app }}/${{ matrix.asset }}.app/Contents/MacOS/${{ matrix.asset }} || true
- name: Create package
# Change into the artifacts directory to avoid including the directory itself in the zip archive
+1 -1
View File
@@ -9,4 +9,4 @@ bin/
obj/
# Test results
TestResults/
TestResults/
+1 -1
View File
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Version>999.9.9-dev</Version>
<Company>Tyrrrz</Company>
<Copyright>Copyright (c) Oleksii Holub</Copyright>
@@ -4,26 +4,29 @@
<IsTestProject>true</IsTestProject>
<UserSecretsId>d1fe5ae2-2a19-404d-a36e-81ba9eada1c1</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AngleSharp" Version="1.3.0" />
<PackageReference Include="AngleSharp" Version="1.4.0" />
<PackageReference Include="coverlet.collector" Version="6.0.4" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="1.0.2" PrivateAssets="all" />
<PackageReference Include="FluentAssertions" Version="8.3.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="1.2.5" PrivateAssets="all" />
<PackageReference Include="FluentAssertions" Version="8.8.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="3.0.1" PrivateAssets="all" />
<PackageReference Include="JsonExtensions" Version="1.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.2" />
<PackageReference
Include="Microsoft.Extensions.Configuration.EnvironmentVariables"
Version="9.0.5"
Version="10.0.2"
/>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0" PrivateAssets="all" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DiscordChatExporter.Cli\DiscordChatExporter.Cli.csproj" />
</ItemGroup>
+1 -1
View File
@@ -8,5 +8,5 @@ In order to run these tests locally, you need to join the test server and config
3. Add your token to user secrets: `dotnet user-secrets set DISCORD_TOKEN <token>`
4. Run the tests: `dotnet test`
> **Note**:
> [!NOTE]
> If you want to add a new test case, please let me know and I will give you the required permissions on the server.
@@ -181,8 +181,14 @@ public class HtmlEmbedSpecs
);
// Assert
var iframeUrl = message.QuerySelector("iframe")?.GetAttribute("src");
iframeUrl.Should().StartWith("https://www.youtube.com/embed/qOWW4OlgbvE");
// Check that the YouTube video thumbnail image exists with the correct video ID
var youtubeThumbnailSrc = message
.QuerySelectorAll("img")
.Select(e => e.GetAttribute("src"))
.WhereNotNull()
.FirstOrDefault(s => s.Contains("qOWW4OlgbvE", StringComparison.Ordinal));
youtubeThumbnailSrc.Should().NotBeNull();
}
[Fact]
@@ -4,13 +4,16 @@ namespace DiscordChatExporter.Cli.Tests.Utils.Extensions;
internal static class StringExtensions
{
public static string ReplaceWhiteSpace(this string str, string replacement = " ")
extension(string str)
{
var buffer = new StringBuilder(str.Length);
public string ReplaceWhiteSpace(string replacement = " ")
{
var buffer = new StringBuilder(str.Length);
foreach (var ch in str)
buffer.Append(char.IsWhiteSpace(ch) ? replacement : ch);
foreach (var ch in str)
buffer.Append(char.IsWhiteSpace(ch) ? replacement : ch);
return buffer.ToString();
return buffer.ToString();
}
}
}
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Reflection;
using PathEx = System.IO.Path;
namespace DiscordChatExporter.Cli.Tests.Utils;
@@ -23,8 +22,8 @@ internal partial class TempDir
{
public static TempDir Create()
{
var dirPath = PathEx.Combine(
PathEx.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
var dirPath = System.IO.Path.Combine(
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
?? Directory.GetCurrentDirectory(),
"Temp",
Guid.NewGuid().ToString()
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Reflection;
using PathEx = System.IO.Path;
namespace DiscordChatExporter.Cli.Tests.Utils;
@@ -23,15 +22,15 @@ internal partial class TempFile
{
public static TempFile Create()
{
var dirPath = PathEx.Combine(
PathEx.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
var dirPath = System.IO.Path.Combine(
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
?? Directory.GetCurrentDirectory(),
"Temp"
);
Directory.CreateDirectory(dirPath);
var filePath = PathEx.Combine(dirPath, Guid.NewGuid() + ".tmp");
var filePath = System.IO.Path.Combine(dirPath, Guid.NewGuid() + ".tmp");
return new TempFile(filePath);
}
+2 -2
View File
@@ -1,7 +1,7 @@
# -- Build
# Specify the platform here so that we pull the SDK image matching the host platform,
# instead of the target platform specified during build by the `--platform` option.
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0-alpine AS build
# Expose the target architecture set by the `docker build --platform` option, so that
# we can build the assembly for the correct platform.
@@ -30,7 +30,7 @@ RUN dotnet publish DiscordChatExporter.Cli \
# -- Run
# Use `runtime-deps` instead of `runtime` because we have a self-contained assembly
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/runtime-deps:9.0-alpine AS run
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/runtime-deps:10.0-alpine AS run
LABEL org.opencontainers.image.title="DiscordChatExporter.Cli"
LABEL org.opencontainers.image.description="DiscordChatExporter is an application that can be used to export message history from any Discord channel to a file."
@@ -5,13 +5,21 @@
<PublishTrimmed>true</PublishTrimmed>
<CopyOutputSymbolsToPublishDirectory>false</CopyOutputSymbolsToPublishDirectory>
</PropertyGroup>
<!-- HACK: Disable trim warnings because they seem to break when the code contains C# 14 extension blocks -->
<PropertyGroup>
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
<EnableAotAnalyzer>false</EnableAotAnalyzer>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CliFx" Version="2.3.6" />
<PackageReference Include="CSharpier.MsBuild" Version="1.0.2" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="1.2.5" PrivateAssets="all" />
<PackageReference Include="Deorcify" Version="1.1.0" PrivateAssets="all" />
<PackageReference Include="Gress" Version="2.1.1" />
<PackageReference Include="Spectre.Console" Version="0.50.0" />
<PackageReference Include="Spectre.Console" Version="0.54.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DiscordChatExporter.Core\DiscordChatExporter.Core.csproj" />
</ItemGroup>
@@ -7,32 +7,35 @@ namespace DiscordChatExporter.Cli.Utils.Extensions;
internal static class ConsoleExtensions
{
public static IAnsiConsole CreateAnsiConsole(this IConsole console) =>
AnsiConsole.Create(
new AnsiConsoleSettings
{
Ansi = AnsiSupport.Detect,
ColorSystem = ColorSystemSupport.Detect,
Out = new AnsiConsoleOutput(console.Output),
}
);
public static Status CreateStatusTicker(this IConsole console) =>
console.CreateAnsiConsole().Status().AutoRefresh(true);
public static Progress CreateProgressTicker(this IConsole console) =>
console
.CreateAnsiConsole()
.Progress()
.AutoClear(false)
.AutoRefresh(true)
.HideCompleted(false)
.Columns(
new TaskDescriptionColumn { Alignment = Justify.Left },
new ProgressBarColumn(),
new PercentageColumn()
extension(IConsole console)
{
public IAnsiConsole CreateAnsiConsole() =>
AnsiConsole.Create(
new AnsiConsoleSettings
{
Ansi = AnsiSupport.Detect,
ColorSystem = ColorSystemSupport.Detect,
Out = new AnsiConsoleOutput(console.Output),
}
);
public Status CreateStatusTicker() =>
console.CreateAnsiConsole().Status().AutoRefresh(true);
public Progress CreateProgressTicker() =>
console
.CreateAnsiConsole()
.Progress()
.AutoClear(false)
.AutoRefresh(true)
.HideCompleted(false)
.Columns(
new TaskDescriptionColumn { Alignment = Justify.Left },
new ProgressBarColumn(),
new PercentageColumn()
);
}
public static async ValueTask StartTaskAsync(
this ProgressContext context,
string description,
@@ -33,9 +33,9 @@ public partial record Channel(
public bool IsThread { get; } =
Kind
is ChannelKind.GuildNewsThread
or ChannelKind.GuildPublicThread
or ChannelKind.GuildPrivateThread;
is ChannelKind.GuildNewsThread
or ChannelKind.GuildPublicThread
or ChannelKind.GuildPrivateThread;
public bool IsEmpty { get; } = LastMessageId is null;
@@ -69,7 +69,8 @@ public partial record Channel
var guildId =
json.GetPropertyOrNull("guild_id")
?.GetNonWhiteSpaceStringOrNull()
?.Pipe(Snowflake.Parse) ?? Guild.DirectMessages.Id;
?.Pipe(Snowflake.Parse)
?? Guild.DirectMessages.Id;
var name =
// Guild channel
@@ -96,7 +97,8 @@ public partial record Channel
var isArchived =
json.GetPropertyOrNull("thread_metadata")
?.GetPropertyOrNull("archived")
?.GetBooleanOrNull() ?? false;
?.GetBooleanOrNull()
?? false;
var lastMessageId = json.GetPropertyOrNull("last_message_id")
?.GetNonWhiteSpaceStringOrNull()
@@ -45,7 +45,11 @@ public partial record Embed
var title = json.GetPropertyOrNull("title")?.GetStringOrNull();
var kind =
json.GetPropertyOrNull("type")?.GetStringOrNull()?.ParseEnumOrNull<EmbedKind>()
json.GetPropertyOrNull("type")
?.GetStringOrNull()
?.Pipe(s =>
Enum.TryParse<EmbedKind>(s, true, out var result) ? result : (EmbedKind?)null
)
?? EmbedKind.Rich;
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
@@ -63,7 +67,8 @@ public partial record Embed
json.GetPropertyOrNull("fields")
?.EnumerateArrayOrNull()
?.Select(EmbedField.Parse)
.ToArray() ?? [];
.ToArray()
?? [];
var thumbnail = json.GetPropertyOrNull("thumbnail")?.Pipe(EmbedImage.Parse);
@@ -78,7 +83,8 @@ public partial record Embed
json.GetPropertyOrNull("image")
?.Pipe(EmbedImage.Parse)
.ToSingletonEnumerable()
.ToArray() ?? [];
.ToArray()
?? [];
var video = json.GetPropertyOrNull("video")?.Pipe(EmbedVideo.Parse);
@@ -2,7 +2,10 @@
public partial record YouTubeVideoEmbedProjection(string VideoId)
{
public string Url { get; } = $"https://www.youtube.com/embed/{VideoId}";
public string Url { get; } = $"https://www.youtube.com/watch?v={VideoId}";
// Using hqdefault.jpg which is guaranteed to exist for all YouTube videos
public string ThumbnailUrl { get; } = $"https://i.ytimg.com/vi/{VideoId}/hqdefault.jpg";
}
public partial record YouTubeVideoEmbedProjection
@@ -25,7 +25,8 @@ public partial record Guild
var iconUrl =
json.GetPropertyOrNull("icon")
?.GetNonWhiteSpaceStringOrNull()
?.Pipe(h => ImageCdn.GetGuildIconUrl(id, h)) ?? ImageCdn.GetFallbackUserAvatarUrl();
?.Pipe(h => ImageCdn.GetGuildIconUrl(id, h))
?? ImageCdn.GetFallbackUserAvatarUrl();
return new Guild(id, name, iconUrl);
}
@@ -32,7 +32,8 @@ public partial record Member
?.EnumerateArray()
.Select(j => j.GetNonWhiteSpaceString())
.Select(Snowflake.Parse)
.ToArray() ?? [];
.ToArray()
?? [];
var avatarUrl = guildId is not null
? json.GetPropertyOrNull("avatar")
@@ -143,7 +143,8 @@ public partial record Message
json.GetPropertyOrNull("attachments")
?.EnumerateArrayOrNull()
?.Select(Attachment.Parse)
.ToArray() ?? [];
.ToArray()
?? [];
var embeds = NormalizeEmbeds(
json.GetPropertyOrNull("embeds")?.EnumerateArrayOrNull()?.Select(Embed.Parse).ToArray()
@@ -154,13 +155,15 @@ public partial record Message
json.GetPropertyOrNull("sticker_items")
?.EnumerateArrayOrNull()
?.Select(Sticker.Parse)
.ToArray() ?? [];
.ToArray()
?? [];
var reactions =
json.GetPropertyOrNull("reactions")
?.EnumerateArrayOrNull()
?.Select(Reaction.Parse)
.ToArray() ?? [];
.ToArray()
?? [];
var mentionedUsers =
json.GetPropertyOrNull("mentions")?.EnumerateArrayOrNull()?.Select(User.Parse).ToArray()
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@@ -40,17 +41,19 @@ public partial class DataDump
CancellationToken cancellationToken = default
)
{
using var archive = ZipFile.OpenRead(zipFilePath);
await using var archive = await ZipFile.OpenReadAsync(zipFilePath, cancellationToken);
var entry = archive.GetEntry("messages/index.json");
if (entry is null)
{
throw new InvalidOperationException(
// Use case-insensitive search to accommodate for different data dump versions
// https://github.com/Tyrrrz/DiscordChatExporter/issues/1459
var entry =
archive.Entries.FirstOrDefault(e =>
e.FullName.Equals("messages/index.json", StringComparison.OrdinalIgnoreCase)
)
?? throw new InvalidOperationException(
"Failed to locate the channel index inside the data package."
);
}
await using var stream = entry.Open();
await using var stream = await entry.OpenAsync(cancellationToken);
using var document = await JsonDocument.ParseAsync(stream, default, cancellationToken);
return Parse(document.RootElement);
@@ -13,24 +13,26 @@ public enum RateLimitPreference
public static class RateLimitPreferenceExtensions
{
internal static bool IsRespectedFor(
this RateLimitPreference rateLimitPreference,
TokenKind tokenKind
) =>
tokenKind switch
{
TokenKind.User => (rateLimitPreference & RateLimitPreference.RespectForUserTokens) != 0,
TokenKind.Bot => (rateLimitPreference & RateLimitPreference.RespectForBotTokens) != 0,
_ => throw new ArgumentOutOfRangeException(nameof(tokenKind)),
};
extension(RateLimitPreference rateLimitPreference)
{
internal bool IsRespectedFor(TokenKind tokenKind) =>
tokenKind switch
{
TokenKind.User => (rateLimitPreference & RateLimitPreference.RespectForUserTokens)
!= 0,
TokenKind.Bot => (rateLimitPreference & RateLimitPreference.RespectForBotTokens)
!= 0,
_ => throw new ArgumentOutOfRangeException(nameof(tokenKind)),
};
public static string GetDisplayName(this RateLimitPreference rateLimitPreference) =>
rateLimitPreference switch
{
RateLimitPreference.IgnoreAll => "Always ignore",
RateLimitPreference.RespectForUserTokens => "Respect for user tokens",
RateLimitPreference.RespectForBotTokens => "Respect for bot tokens",
RateLimitPreference.RespectAll => "Always respect",
_ => throw new ArgumentOutOfRangeException(nameof(rateLimitPreference)),
};
public string GetDisplayName() =>
rateLimitPreference switch
{
RateLimitPreference.IgnoreAll => "Always ignore",
RateLimitPreference.RespectForUserTokens => "Respect for user tokens",
RateLimitPreference.RespectForBotTokens => "Respect for bot tokens",
RateLimitPreference.RespectAll => "Always respect",
_ => throw new ArgumentOutOfRangeException(nameof(rateLimitPreference)),
};
}
}
@@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="AsyncKeyedLock" Version="7.1.6" />
<PackageReference Include="CSharpier.MsBuild" Version="1.0.2" PrivateAssets="all" />
<PackageReference Include="AngleSharp" Version="1.4.0" />
<PackageReference Include="AsyncKeyedLock" Version="8.0.1" />
<PackageReference Include="CSharpier.MsBuild" Version="1.2.5" PrivateAssets="all" />
<PackageReference Include="Gress" Version="2.1.1" />
<PackageReference Include="JsonExtensions" Version="1.2.0" />
<PackageReference Include="Polly" Version="8.5.2" />
<PackageReference Include="RazorBlade" Version="0.9.0" />
<PackageReference Include="Superpower" Version="3.0.0" />
<PackageReference Include="WebMarkupMin.Core" Version="2.19.0" />
<PackageReference Include="YoutubeExplode" Version="6.5.4" />
<PackageReference Include="Polly" Version="8.6.5" />
<PackageReference Include="RazorBlade" Version="0.11.0" />
<PackageReference Include="Superpower" Version="3.1.0" />
<PackageReference Include="WebMarkupMin.Core" Version="2.20.1" />
<PackageReference Include="YoutubeExplode" Version="6.5.6" />
</ItemGroup>
</Project>
@@ -75,7 +75,7 @@ internal partial class ExportAssetDownloader
return SHA256
.HashData(Encoding.UTF8.GetBytes(NormalizeUrl(url)))
.ToHex()
.Pipe(Convert.ToHexStringLower)
// 5 chars ought to be enough for anybody
.Truncate(5);
}
@@ -103,7 +103,7 @@ internal partial class ExportAssetDownloader
fileExtension = "";
}
return PathEx.EscapeFileName(
return Path.EscapeFileName(
fileNameWithoutExtension.Truncate(42) + '-' + urlHash + fileExtension
);
}
@@ -99,7 +99,8 @@ internal class ExportContext(DiscordClient discord, ExportRequest request)
?.RoleIds.Select(TryGetRole)
.WhereNotNull()
.OrderByDescending(r => r.Position)
.ToArray() ?? [];
.ToArray()
?? [];
public Color? TryGetUserColor(Snowflake id) =>
GetUserRoles(id).Where(r => r.Color is not null).Select(r => r.Color).FirstOrDefault();
@@ -13,25 +13,28 @@ public enum ExportFormat
public static class ExportFormatExtensions
{
public static string GetFileExtension(this ExportFormat format) =>
format switch
{
ExportFormat.PlainText => "txt",
ExportFormat.HtmlDark => "html",
ExportFormat.HtmlLight => "html",
ExportFormat.Csv => "csv",
ExportFormat.Json => "json",
_ => throw new ArgumentOutOfRangeException(nameof(format)),
};
extension(ExportFormat format)
{
public string GetFileExtension() =>
format switch
{
ExportFormat.PlainText => "txt",
ExportFormat.HtmlDark => "html",
ExportFormat.HtmlLight => "html",
ExportFormat.Csv => "csv",
ExportFormat.Json => "json",
_ => throw new ArgumentOutOfRangeException(nameof(format)),
};
public static string GetDisplayName(this ExportFormat format) =>
format switch
{
ExportFormat.PlainText => "TXT",
ExportFormat.HtmlDark => "HTML (Dark)",
ExportFormat.HtmlLight => "HTML (Light)",
ExportFormat.Csv => "CSV",
ExportFormat.Json => "JSON",
_ => throw new ArgumentOutOfRangeException(nameof(format)),
};
public string GetDisplayName() =>
format switch
{
ExportFormat.PlainText => "TXT",
ExportFormat.HtmlDark => "HTML (Dark)",
ExportFormat.HtmlLight => "HTML (Light)",
ExportFormat.Csv => "CSV",
ExportFormat.Json => "JSON",
_ => throw new ArgumentOutOfRangeException(nameof(format)),
};
}
}
@@ -7,7 +7,6 @@ using DiscordChatExporter.Core.Discord;
using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Exporting.Filtering;
using DiscordChatExporter.Core.Exporting.Partitioning;
using DiscordChatExporter.Core.Utils;
using DiscordChatExporter.Core.Utils.Extensions;
namespace DiscordChatExporter.Core.Exporting;
@@ -145,7 +144,7 @@ public partial class ExportRequest
// File extension
buffer.Append('.').Append(format.GetFileExtension());
return PathEx.EscapeFileName(buffer.ToString());
return Path.EscapeFileName(buffer.ToString());
}
private static string FormatPath(
@@ -159,7 +158,7 @@ public partial class ExportRequest
path,
"%.",
m =>
PathEx.EscapeFileName(
Path.EscapeFileName(
m.Value switch
{
"%g" => guild.Id.ToString(),
@@ -179,7 +178,8 @@ public partial class ExportRequest
?? "",
"%b" => before
?.ToDate()
.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) ?? "",
.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)
?? "",
"%d" => DateTimeOffset.Now.ToString(
"yyyy-MM-dd",
CultureInfo.InvariantCulture
@@ -8,14 +8,20 @@ internal static class HtmlMessageExtensions
{
// Message content is hidden if it's a link to an embedded media
// https://github.com/Tyrrrz/DiscordChatExporter/issues/682
public static bool IsContentHidden(this Message message)
extension(Message message)
{
if (message.Embeds.Count != 1)
return false;
public bool IsContentHidden()
{
if (message.Embeds.Count != 1)
return false;
var embed = message.Embeds[0];
var embed = message.Embeds[0];
return string.Equals(message.Content.Trim(), embed.Url, StringComparison.OrdinalIgnoreCase)
&& embed.Kind is EmbedKind.Image or EmbedKind.Gifv;
return string.Equals(
message.Content.Trim(),
embed.Url,
StringComparison.OrdinalIgnoreCase
) && embed.Kind is EmbedKind.Image or EmbedKind.Gifv;
}
}
}
@@ -138,6 +138,8 @@ internal class JsonMessageWriter(Stream stream, ExportContext context)
cancellationToken
)
);
_writer.WriteString("iconCanonicalUrl", embedAuthor.IconUrl);
}
_writer.WriteEndObject();
@@ -160,6 +162,8 @@ internal class JsonMessageWriter(Stream stream, ExportContext context)
cancellationToken
)
);
_writer.WriteString("canonicalUrl", embedImage.Url);
}
_writer.WriteNumber("width", embedImage.Width);
@@ -185,6 +189,8 @@ internal class JsonMessageWriter(Stream stream, ExportContext context)
cancellationToken
)
);
_writer.WriteString("canonicalUrl", embedVideo.Url);
}
_writer.WriteNumber("width", embedVideo.Width);
@@ -212,6 +218,8 @@ internal class JsonMessageWriter(Stream stream, ExportContext context)
cancellationToken
)
);
_writer.WriteString("iconCanonicalUrl", embedFooter.IconUrl);
}
_writer.WriteEndObject();
@@ -388,7 +388,7 @@
<div class="chatlog__embed-author-container">
@if (!string.IsNullOrWhiteSpace(embed.Author.IconUrl))
{
<img class="chatlog__embed-author-icon" src="@await ResolveAssetUrlAsync(embed.Author.IconProxyUrl ?? embed.Author.IconUrl)" alt="Author icon" loading="lazy" onerror="this.style.visibility='hidden'">
<img class="chatlog__embed-author-icon" src="@await ResolveAssetUrlAsync(embed.Author.IconProxyUrl ?? embed.Author.IconUrl)" alt="Author icon" loading="lazy" onerror="this.style.visibility='hidden'" data-canonical-url="@embed.Author.IconUrl">
}
@if (!string.IsNullOrWhiteSpace(embed.Author.Name))
@@ -424,9 +424,11 @@
</div>
}
@* Video player *@
@* Video thumbnail *@
<div class="chatlog__embed-youtube-container">
<iframe class="chatlog__embed-youtube" src="@youTubeVideoEmbed.Url" width="400" height="225"></iframe>
<a href="@youTubeVideoEmbed.Url">
<img class="chatlog__embed-youtube-thumbnail" src="@await ResolveAssetUrlAsync(embed.Thumbnail?.ProxyUrl ?? embed.Thumbnail?.Url ?? youTubeVideoEmbed.ThumbnailUrl)" alt="YouTube video thumbnail" loading="lazy" onerror="this.style.visibility='hidden'" data-canonical-url="@(embed.Thumbnail?.Url ?? youTubeVideoEmbed.ThumbnailUrl)">
</a>
</div>
</div>
</div>
@@ -441,9 +443,12 @@
embed.Thumbnail?.ProxyUrl ?? embed.Thumbnail?.Url ??
embed.Url;
var embedImageCanonicalUrl =
embed.Image?.Url ?? embed.Thumbnail?.Url ?? embed.Url;
<div class="chatlog__embed">
<a href="@await ResolveAssetUrlAsync(embedImageUrl)">
<img class="chatlog__embed-generic-image" src="@await ResolveAssetUrlAsync(embedImageUrl)" alt="Embedded image" loading="lazy">
<img class="chatlog__embed-generic-image" src="@await ResolveAssetUrlAsync(embedImageUrl)" alt="Embedded image" loading="lazy" data-canonical-url="@embedImageCanonicalUrl">
</a>
</div>
}
@@ -457,8 +462,10 @@
embed.Video?.ProxyUrl ?? embed.Video?.Url ??
embed.Url;
var embedVideoCanonicalUrl = embed.Video?.Url ?? embed.Url;
<div class="chatlog__embed">
<video class="chatlog__embed-generic-video" width="@embed.Video?.Width" height="@embed.Video?.Height" controls>
<video class="chatlog__embed-generic-video" width="@embed.Video?.Width" height="@embed.Video?.Height" controls data-canonical-url="@embedVideoCanonicalUrl">
<source src="@await ResolveAssetUrlAsync(embedVideoUrl)" alt="Embedded video">
</video>
</div>
@@ -470,8 +477,10 @@
embed.Video?.ProxyUrl ?? embed.Video?.Url ??
embed.Url;
var embedVideoCanonicalUrl = embed.Video?.Url ?? embed.Url;
<div class="chatlog__embed">
<video class="chatlog__embed-generic-gifv" width="@embed.Video?.Width" height="@embed.Video?.Height" loop onmouseover="this.play()" onmouseout="this.pause()">
<video class="chatlog__embed-generic-gifv" width="@embed.Video?.Width" height="@embed.Video?.Height" loop onmouseover="this.play()" onmouseout="this.pause()" data-canonical-url="@embedVideoCanonicalUrl">
<source src="@await ResolveAssetUrlAsync(embedVideoUrl)" alt="Embedded gifv">
</video>
</div>
@@ -499,7 +508,7 @@
<div class="chatlog__embed-author-container">
@if (!string.IsNullOrWhiteSpace(embed.Author.IconUrl))
{
<img class="chatlog__embed-author-icon" src="@await ResolveAssetUrlAsync(embed.Author.IconProxyUrl ?? embed.Author.IconUrl)" alt="Author icon" loading="lazy" onerror="this.style.visibility='hidden'">
<img class="chatlog__embed-author-icon" src="@await ResolveAssetUrlAsync(embed.Author.IconProxyUrl ?? embed.Author.IconUrl)" alt="Author icon" loading="lazy" onerror="this.style.visibility='hidden'" data-canonical-url="@embed.Author.IconUrl">
}
@if (!string.IsNullOrWhiteSpace(embed.Author.Name))
@@ -574,7 +583,7 @@
{
<div class="chatlog__embed-thumbnail-container">
<a class="chatlog__embed-thumbnail-link" href="@await ResolveAssetUrlAsync(embed.Thumbnail.ProxyUrl ?? embed.Thumbnail.Url)">
<img class="chatlog__embed-thumbnail" src="@await ResolveAssetUrlAsync(embed.Thumbnail.ProxyUrl ?? embed.Thumbnail.Url)" alt="Thumbnail" loading="lazy">
<img class="chatlog__embed-thumbnail" src="@await ResolveAssetUrlAsync(embed.Thumbnail.ProxyUrl ?? embed.Thumbnail.Url)" alt="Thumbnail" loading="lazy" data-canonical-url="@embed.Thumbnail.Url">
</a>
</div>
}
@@ -590,7 +599,7 @@
{
<div class="chatlog__embed-image-container">
<a class="chatlog__embed-image-link" href="@await ResolveAssetUrlAsync(image.ProxyUrl ?? image.Url)">
<img class="chatlog__embed-image" src="@await ResolveAssetUrlAsync(image.ProxyUrl ?? image.Url)" alt="Image" loading="lazy">
<img class="chatlog__embed-image" src="@await ResolveAssetUrlAsync(image.ProxyUrl ?? image.Url)" alt="Image" loading="lazy" data-canonical-url="@image.Url">
</a>
</div>
}
@@ -605,7 +614,7 @@
@* Footer icon *@
@if (!string.IsNullOrWhiteSpace(embed.Footer?.IconUrl))
{
<img class="chatlog__embed-footer-icon" src="@await ResolveAssetUrlAsync(embed.Footer.IconProxyUrl ?? embed.Footer.IconUrl)" alt="Footer icon" loading="lazy">
<img class="chatlog__embed-footer-icon" src="@await ResolveAssetUrlAsync(embed.Footer.IconProxyUrl ?? embed.Footer.IconUrl)" alt="Footer icon" loading="lazy" data-canonical-url="@embed.Footer.IconUrl">
}
<span class="chatlog__embed-footer-text">
@@ -7,37 +7,40 @@ namespace DiscordChatExporter.Core.Exporting;
internal static class PlainTextMessageExtensions
{
public static string GetFallbackContent(this Message message) =>
message.Kind switch
{
MessageKind.RecipientAdd => message.MentionedUsers.Any()
? $"Added {message.MentionedUsers.First().DisplayName} to the group."
: "Added a recipient.",
extension(Message message)
{
public string GetFallbackContent() =>
message.Kind switch
{
MessageKind.RecipientAdd => message.MentionedUsers.Any()
? $"Added {message.MentionedUsers.First().DisplayName} to the group."
: "Added a recipient.",
MessageKind.RecipientRemove => message.MentionedUsers.Any()
? message.Author.Id == message.MentionedUsers.First().Id
? "Left the group."
: $"Removed {message.MentionedUsers.First().DisplayName} from the group."
: "Removed a recipient.",
MessageKind.RecipientRemove => message.MentionedUsers.Any()
? message.Author.Id == message.MentionedUsers.First().Id
? "Left the group."
: $"Removed {message.MentionedUsers.First().DisplayName} from the group."
: "Removed a recipient.",
MessageKind.Call =>
$"Started a call that lasted {
message
.CallEndedTimestamp?
.Pipe(t => t - message.Timestamp)
.Pipe(t => t.TotalMinutes)
.ToString("n0", CultureInfo.InvariantCulture) ?? "0"
} minutes.",
MessageKind.Call =>
$"Started a call that lasted {
message
.CallEndedTimestamp?
.Pipe(t => t - message.Timestamp)
.Pipe(t => t.TotalMinutes)
.ToString("n0", CultureInfo.InvariantCulture) ?? "0"
} minutes.",
MessageKind.ChannelNameChange => !string.IsNullOrWhiteSpace(message.Content)
? $"Changed the channel name: {message.Content}"
: "Changed the channel name.",
MessageKind.ChannelNameChange => !string.IsNullOrWhiteSpace(message.Content)
? $"Changed the channel name: {message.Content}"
: "Changed the channel name.",
MessageKind.ChannelIconChange => "Changed the channel icon.",
MessageKind.ChannelPinnedMessage => "Pinned a message.",
MessageKind.ThreadCreated => "Started a thread.",
MessageKind.GuildMemberJoin => "Joined the server.",
MessageKind.ChannelIconChange => "Changed the channel icon.",
MessageKind.ChannelPinnedMessage => "Pinned a message.",
MessageKind.ThreadCreated => "Started a thread.",
MessageKind.GuildMemberJoin => "Joined the server.",
_ => message.Content,
};
_ => message.Content,
};
}
}
@@ -711,9 +711,11 @@
margin-top: 0.6rem;
}
.chatlog__embed-youtube {
border: 0;
.chatlog__embed-youtube-thumbnail {
max-width: 400px;
max-height: 225px;
border-radius: 3px;
cursor: pointer;
}
.chatlog__sticker {
@@ -6,19 +6,19 @@ namespace DiscordChatExporter.Core.Utils.Extensions;
public static class AsyncCollectionExtensions
{
private static async ValueTask<IReadOnlyList<T>> CollectAsync<T>(
this IAsyncEnumerable<T> asyncEnumerable
)
extension<T>(IAsyncEnumerable<T> asyncEnumerable)
{
var list = new List<T>();
private async ValueTask<IReadOnlyList<T>> CollectAsync()
{
var list = new List<T>();
await foreach (var i in asyncEnumerable)
list.Add(i);
await foreach (var i in asyncEnumerable)
list.Add(i);
return list;
return list;
}
public ValueTaskAwaiter<IReadOnlyList<T>> GetAwaiter() =>
asyncEnumerable.CollectAsync().GetAwaiter();
}
public static ValueTaskAwaiter<IReadOnlyList<T>> GetAwaiter<T>(
this IAsyncEnumerable<T> asyncEnumerable
) => asyncEnumerable.CollectAsync().GetAwaiter();
}
@@ -1,19 +0,0 @@
using System.Globalization;
using System.Text;
namespace DiscordChatExporter.Core.Utils.Extensions;
public static class BinaryExtensions
{
public static string ToHex(this byte[] data, bool isUpperCase = true)
{
var buffer = new StringBuilder(2 * data.Length);
foreach (var b in data)
{
buffer.Append(b.ToString(isUpperCase ? "X2" : "x2", CultureInfo.InvariantCulture));
}
return buffer.ToString();
}
}
@@ -4,25 +4,34 @@ namespace DiscordChatExporter.Core.Utils.Extensions;
public static class CollectionExtensions
{
public static IEnumerable<T> ToSingletonEnumerable<T>(this T obj)
extension<T>(T obj)
{
yield return obj;
public IEnumerable<T> ToSingletonEnumerable()
{
yield return obj;
}
}
public static IEnumerable<(T value, int index)> WithIndex<T>(this IEnumerable<T> source)
extension<T>(IEnumerable<T> source)
{
var i = 0;
foreach (var o in source)
yield return (o, i++);
public IEnumerable<(T value, int index)> WithIndex()
{
var i = 0;
foreach (var o in source)
yield return (o, i++);
}
}
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source)
extension<T>(IEnumerable<T?> source)
where T : class
{
foreach (var o in source)
public IEnumerable<T> WhereNotNull()
{
if (o is not null)
yield return o;
foreach (var o in source)
{
if (o is not null)
yield return o;
}
}
}
}
@@ -4,11 +4,14 @@ namespace DiscordChatExporter.Core.Utils.Extensions;
public static class ColorExtensions
{
public static Color WithAlpha(this Color color, int alpha) => Color.FromArgb(alpha, color);
extension(Color color)
{
public Color WithAlpha(int alpha) => Color.FromArgb(alpha, color);
public static Color ResetAlpha(this Color color) => color.WithAlpha(255);
public Color ResetAlpha() => color.WithAlpha(255);
public static int ToRgb(this Color color) => color.ToArgb() & 0xffffff;
public int ToRgb() => color.ToArgb() & 0xffffff;
public static string ToHex(this Color color) => $"#{color.R:X2}{color.G:X2}{color.B:X2}";
public string ToHex() => $"#{color.R:X2}{color.G:X2}{color.B:X2}";
}
}
@@ -5,27 +5,30 @@ namespace DiscordChatExporter.Core.Utils.Extensions;
public static class ExceptionExtensions
{
private static void PopulateChildren(this Exception exception, ICollection<Exception> children)
extension(Exception exception)
{
if (exception is AggregateException aggregateException)
private void PopulateChildren(ICollection<Exception> children)
{
foreach (var innerException in aggregateException.InnerExceptions)
if (exception is AggregateException aggregateException)
{
children.Add(innerException);
PopulateChildren(innerException, children);
foreach (var innerException in aggregateException.InnerExceptions)
{
children.Add(innerException);
PopulateChildren(innerException, children);
}
}
else if (exception.InnerException is not null)
{
children.Add(exception.InnerException);
PopulateChildren(exception.InnerException, children);
}
}
else if (exception.InnerException is not null)
public IReadOnlyList<Exception> GetSelfAndChildren()
{
children.Add(exception.InnerException);
PopulateChildren(exception.InnerException, children);
var children = new List<Exception> { exception };
PopulateChildren(exception, children);
return children;
}
}
public static IReadOnlyList<Exception> GetSelfAndChildren(this Exception exception)
{
var children = new List<Exception> { exception };
PopulateChildren(exception, children);
return children;
}
}
@@ -5,12 +5,17 @@ namespace DiscordChatExporter.Core.Utils.Extensions;
public static class GenericExtensions
{
public static TOut Pipe<TIn, TOut>(this TIn input, Func<TIn, TOut> transform) =>
transform(input);
extension<TIn>(TIn input)
{
public TOut Pipe<TOut>(Func<TIn, TOut> transform) => transform(input);
}
public static T? NullIf<T>(this T value, Func<T, bool> predicate)
where T : struct => !predicate(value) ? value : null;
extension<T>(T value)
where T : struct
{
public T? NullIf(Func<T, bool> predicate) => !predicate(value) ? value : null;
public static T? NullIfDefault<T>(this T value)
where T : struct => value.NullIf(v => EqualityComparer<T>.Default.Equals(v, default));
public T? NullIfDefault() =>
value.NullIf(v => EqualityComparer<T>.Default.Equals(v, default));
}
}
@@ -4,6 +4,9 @@ namespace DiscordChatExporter.Core.Utils.Extensions;
public static class HttpExtensions
{
public static string? TryGetValue(this HttpHeaders headers, string name) =>
headers.TryGetValues(name, out var values) ? string.Concat(values) : null;
extension(HttpHeaders headers)
{
public string? TryGetValue(string name) =>
headers.TryGetValues(name, out var values) ? string.Concat(values) : null;
}
}
@@ -0,0 +1,48 @@
using System;
using System.IO;
using System.Text;
namespace DiscordChatExporter.Core.Utils.Extensions;
public static class PathExtensions
{
// This is a union of invalid characters from Windows (NTFS/FAT32), Linux (ext4/XFS), and macOS (HFS+/APFS).
// We use this instead of Path.GetInvalidFileNameChars() because that only returns OS-specific characters,
// not filesystem-specific characters. It's possible to use, for example, an NTFS drive on Linux,
// which would make some additional characters invalid that are otherwise valid on Linux.
// https://github.com/Tyrrrz/DiscordChatExporter/issues/1452
private static readonly char[] InvalidFileNameChars =
[
'\0', // Null character - invalid on all filesystems
'/', // Path separator on Unix and Windows
'\\', // Path separator on Windows
':', // Reserved on Windows (drive letters, NTFS streams)
'*', // Wildcard on Windows
'?', // Wildcard on Windows
'"', // Reserved on Windows
'<', // Redirection on Windows
'>', // Redirection on Windows
'|', // Pipe on Windows
];
extension(Path)
{
public static string EscapeFileName(string path)
{
var buffer = new StringBuilder(path.Length);
foreach (var c in path)
buffer.Append(!InvalidFileNameChars.Contains(c) ? c : '_');
// File names cannot end with a dot on Windows
// https://github.com/Tyrrrz/DiscordChatExporter/issues/977
if (OperatingSystem.IsWindows())
{
while (buffer.Length > 0 && buffer[^1] == '.')
buffer.Remove(buffer.Length - 1, 1);
}
return buffer.ToString();
}
}
}
@@ -1,34 +1,34 @@
using System;
using System.Text;
using System.Text;
namespace DiscordChatExporter.Core.Utils.Extensions;
public static class StringExtensions
{
public static string? NullIfWhiteSpace(this string str) =>
!string.IsNullOrWhiteSpace(str) ? str : null;
public static string Truncate(this string str, int charCount) =>
str.Length > charCount ? str[..charCount] : str;
public static string ToSpaceSeparatedWords(this string str)
extension(string str)
{
var builder = new StringBuilder(str.Length * 2);
public string? NullIfWhiteSpace() => !string.IsNullOrWhiteSpace(str) ? str : null;
foreach (var c in str)
public string Truncate(int charCount) => str.Length > charCount ? str[..charCount] : str;
public string ToSpaceSeparatedWords()
{
if (char.IsUpper(c) && builder.Length > 0)
builder.Append(' ');
var builder = new StringBuilder(str.Length * 2);
builder.Append(c);
foreach (var c in str)
{
if (char.IsUpper(c) && builder.Length > 0)
builder.Append(' ');
builder.Append(c);
}
return builder.ToString();
}
return builder.ToString();
}
public static T? ParseEnumOrNull<T>(this string str, bool ignoreCase = true)
where T : struct, Enum => Enum.TryParse<T>(str, ignoreCase, out var result) ? result : null;
public static StringBuilder AppendIfNotEmpty(this StringBuilder builder, char value) =>
builder.Length > 0 ? builder.Append(value) : builder;
extension(StringBuilder builder)
{
public StringBuilder AppendIfNotEmpty(char value) =>
builder.Length > 0 ? builder.Append(value) : builder;
}
}
@@ -7,21 +7,21 @@ namespace DiscordChatExporter.Core.Utils.Extensions;
public static class SuperpowerExtensions
{
public static TextParser<string> Text(this TextParser<char[]> parser) =>
parser.Select(chars => new string(chars));
extension<T>(TextParser<T> parser)
{
public TextParser<T> Token() =>
parser.Between(Character.WhiteSpace.IgnoreMany(), Character.WhiteSpace.IgnoreMany());
public static TextParser<T> Token<T>(this TextParser<T> parser) =>
parser.Between(Character.WhiteSpace.IgnoreMany(), Character.WhiteSpace.IgnoreMany());
// Only used for debugging while writing Superpower parsers.
// From https://twitter.com/nblumhardt/status/1389349059786264578
[ExcludeFromCodeCoverage]
public static TextParser<T> Log<T>(this TextParser<T> parser, string description) =>
i =>
{
Console.WriteLine($"Trying {description} ->");
var r = parser(i);
Console.WriteLine($"Result was {r}");
return r;
};
// Only used for debugging while writing Superpower parsers.
// From https://twitter.com/nblumhardt/status/1389349059786264578
[ExcludeFromCodeCoverage]
public TextParser<T> Log(string description) =>
i =>
{
Console.WriteLine($"Trying {description} ->");
var r = parser(i);
Console.WriteLine($"Result was {r}");
return r;
};
}
}
@@ -4,14 +4,17 @@ namespace DiscordChatExporter.Core.Utils.Extensions;
public static class TimeSpanExtensions
{
public static TimeSpan Clamp(this TimeSpan value, TimeSpan min, TimeSpan max)
extension(TimeSpan value)
{
if (value < min)
return min;
public TimeSpan Clamp(TimeSpan min, TimeSpan max)
{
if (value < min)
return min;
if (value > max)
return max;
if (value > max)
return max;
return value;
return value;
}
}
}
-32
View File
@@ -1,32 +0,0 @@
using System;
using System.Collections.Frozen;
using System.IO;
using System.Text;
namespace DiscordChatExporter.Core.Utils;
public static class PathEx
{
private static readonly FrozenSet<char> InvalidFileNameChars =
[
.. Path.GetInvalidFileNameChars(),
];
public static string EscapeFileName(string path)
{
var buffer = new StringBuilder(path.Length);
foreach (var c in path)
buffer.Append(!InvalidFileNameChars.Contains(c) ? c : '_');
// File names cannot end with a dot on Windows
// https://github.com/Tyrrrz/DiscordChatExporter/issues/977
if (OperatingSystem.IsWindows())
{
while (buffer.Length > 0 && buffer[^1] == '.')
buffer.Remove(buffer.Length - 1, 1);
}
return buffer.ToString();
}
}
+14
View File
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Text;
namespace DiscordChatExporter.Core.Utils;
@@ -10,6 +11,19 @@ public static class Url
var buffer = new StringBuilder();
var position = 0;
// For absolute paths, prepend file:// protocol for proper browser handling
if (Path.IsPathFullyQualified(filePath))
{
buffer.Append("file://");
// On Windows, we need to add an extra slash before the drive letter
// e.g., file:///C:/path instead of file://C:/path
if (!filePath.StartsWith('/') && !filePath.StartsWith('\\'))
{
buffer.Append('/');
}
}
while (true)
{
if (position >= filePath.Length)
+1
View File
@@ -8,6 +8,7 @@
xmlns:materialControls="clr-namespace:Material.Styles.Controls;assembly=Material.Styles"
xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:materialStyles="clr-namespace:Material.Styles.Themes;assembly=Material.Styles"
Name="DiscordChatExporter"
ActualThemeVariantChanged="Application_OnActualThemeVariantChanged">
<Application.DataTemplates>
<framework:ViewManager />
@@ -7,32 +7,46 @@
<CopyOutputSymbolsToPublishDirectory>false</CopyOutputSymbolsToPublishDirectory>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>
<PropertyGroup>
<PublishMacOSBundle>false</PublishMacOSBundle>
</PropertyGroup>
<!-- HACK: Disable trim warnings because they seem to break when the code contains C# 14 extension blocks -->
<PropertyGroup>
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
<EnableAotAnalyzer>false</EnableAotAnalyzer>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="..\favicon.ico" Link="favicon.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AsyncImageLoader.Avalonia" Version="3.3.0" />
<PackageReference Include="Avalonia" Version="11.3.0" />
<PackageReference Include="Avalonia.Desktop" Version="11.3.0" />
<PackageReference Include="AsyncImageLoader.Avalonia" Version="3.5.0" />
<PackageReference Include="Avalonia" Version="11.3.11" />
<PackageReference Include="Avalonia.Desktop" Version="11.3.11" />
<PackageReference
Include="Avalonia.Diagnostics"
Version="11.3.0"
Version="11.3.11"
Condition="'$(Configuration)' == 'Debug'"
/>
<PackageReference Include="Cogwheel" Version="2.1.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="CSharpier.MsBuild" Version="1.0.2" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="1.2.5" PrivateAssets="all" />
<PackageReference Include="Deorcify" Version="1.1.0" PrivateAssets="all" />
<PackageReference Include="DialogHost.Avalonia" Version="0.9.2" />
<PackageReference Include="DialogHost.Avalonia" Version="0.10.4" />
<PackageReference Include="Gress" Version="2.1.1" />
<PackageReference Include="Material.Avalonia" Version="3.9.2" />
<PackageReference Include="Material.Icons.Avalonia" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.2" />
<PackageReference Include="Onova" Version="2.6.13" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DiscordChatExporter.Core\DiscordChatExporter.Core.csproj" />
</ItemGroup>
<Target Name="PublishMacOSBundle" AfterTargets="Publish" Condition="$(PublishMacOSBundle)">
<Exec
Command="pwsh -ExecutionPolicy Bypass -File $(ProjectDir)/Publish-MacOSBundle.ps1 -PublishDirPath $(PublishDir) -IconsFilePath $(ProjectDir)/../favicon.icns -FullVersion $(Version) -ShortVersion $(AssemblyVersion)"
@@ -60,7 +60,7 @@ public class DialogManager : IDisposable
}
);
return file?.Path.LocalPath;
return file?.TryGetLocalPath() ?? file?.Path.ToString();
}
public async Task<string?> PromptDirectoryPathAsync(string defaultDirPath = "")
@@ -69,19 +69,21 @@ public class DialogManager : IDisposable
Application.Current?.ApplicationLifetime?.TryGetTopLevel()
?? throw new ApplicationException("Could not find the top-level visual element.");
var startLocation = await topLevel.StorageProvider.TryGetFolderFromPathAsync(
defaultDirPath
);
var folderPickResult = await topLevel.StorageProvider.OpenFolderPickerAsync(
var result = await topLevel.StorageProvider.OpenFolderPickerAsync(
new FolderPickerOpenOptions
{
AllowMultiple = false,
SuggestedStartLocation = startLocation,
SuggestedStartLocation = await topLevel.StorageProvider.TryGetFolderFromPathAsync(
defaultDirPath
),
}
);
return folderPickResult.FirstOrDefault()?.Path.LocalPath;
var directory = result.FirstOrDefault();
if (directory is null)
return null;
return directory.TryGetLocalPath() ?? directory.Path.ToString();
}
public void Dispose() => _dialogLock.Dispose();
@@ -6,28 +6,31 @@ namespace DiscordChatExporter.Gui.Utils.Extensions;
internal static class AvaloniaExtensions
{
public static Window? TryGetMainWindow(this IApplicationLifetime lifetime) =>
lifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime
? desktopLifetime.MainWindow
: null;
public static TopLevel? TryGetTopLevel(this IApplicationLifetime lifetime) =>
lifetime.TryGetMainWindow()
?? (lifetime as ISingleViewApplicationLifetime)?.MainView?.GetVisualRoot() as TopLevel;
public static bool TryShutdown(this IApplicationLifetime lifetime, int exitCode = 0)
extension(IApplicationLifetime lifetime)
{
if (lifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
return desktopLifetime.TryShutdown(exitCode);
}
public Window? TryGetMainWindow() =>
lifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime
? desktopLifetime.MainWindow
: null;
if (lifetime is IControlledApplicationLifetime controlledLifetime)
{
controlledLifetime.Shutdown(exitCode);
return true;
}
public TopLevel? TryGetTopLevel() =>
lifetime.TryGetMainWindow()
?? (lifetime as ISingleViewApplicationLifetime)?.MainView?.GetVisualRoot() as TopLevel;
return false;
public bool TryShutdown(int exitCode = 0)
{
if (lifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
return desktopLifetime.TryShutdown(exitCode);
}
if (lifetime is IControlledApplicationLifetime controlledLifetime)
{
controlledLifetime.Shutdown(exitCode);
return true;
}
return false;
}
}
}
@@ -6,23 +6,26 @@ namespace DiscordChatExporter.Gui.Utils.Extensions;
internal static class DisposableExtensions
{
public static void DisposeAll(this IEnumerable<IDisposable> disposables)
extension(IEnumerable<IDisposable> disposables)
{
var exceptions = default(List<Exception>);
foreach (var disposable in disposables)
public void DisposeAll()
{
try
{
disposable.Dispose();
}
catch (Exception ex)
{
(exceptions ??= []).Add(ex);
}
}
var exceptions = default(List<Exception>);
if (exceptions?.Any() == true)
throw new AggregateException(exceptions);
foreach (var disposable in disposables)
{
try
{
disposable.Dispose();
}
catch (Exception ex)
{
(exceptions ??= []).Add(ex);
}
}
if (exceptions?.Any() == true)
throw new AggregateException(exceptions);
}
}
}
@@ -7,50 +7,47 @@ namespace DiscordChatExporter.Gui.Utils.Extensions;
internal static class NotifyPropertyChangedExtensions
{
public static IDisposable WatchProperty<TOwner, TProperty>(
this TOwner owner,
Expression<Func<TOwner, TProperty>> propertyExpression,
Action callback,
bool watchInitialValue = false
)
extension<TOwner>(TOwner owner)
where TOwner : INotifyPropertyChanged
{
var memberExpression = propertyExpression.Body as MemberExpression;
if (memberExpression?.Member is not PropertyInfo property)
throw new ArgumentException("Provided expression must reference a property.");
void OnPropertyChanged(object? sender, PropertyChangedEventArgs args)
public IDisposable WatchProperty<TProperty>(
Expression<Func<TOwner, TProperty>> propertyExpression,
Action callback,
bool watchInitialValue = false
)
{
if (
string.IsNullOrWhiteSpace(args.PropertyName)
|| string.Equals(args.PropertyName, property.Name, StringComparison.Ordinal)
)
var memberExpression = propertyExpression.Body as MemberExpression;
if (memberExpression?.Member is not PropertyInfo property)
throw new ArgumentException("Provided expression must reference a property.");
void OnPropertyChanged(object? sender, PropertyChangedEventArgs args)
{
callback();
if (
string.IsNullOrWhiteSpace(args.PropertyName)
|| string.Equals(args.PropertyName, property.Name, StringComparison.Ordinal)
)
{
callback();
}
}
owner.PropertyChanged += OnPropertyChanged;
if (watchInitialValue)
callback();
return Disposable.Create(() => owner.PropertyChanged -= OnPropertyChanged);
}
owner.PropertyChanged += OnPropertyChanged;
public IDisposable WatchAllProperties(Action callback, bool watchInitialValues = false)
{
void OnPropertyChanged(object? sender, PropertyChangedEventArgs args) => callback();
owner.PropertyChanged += OnPropertyChanged;
if (watchInitialValue)
callback();
if (watchInitialValues)
callback();
return Disposable.Create(() => owner.PropertyChanged -= OnPropertyChanged);
}
public static IDisposable WatchAllProperties<TOwner>(
this TOwner owner,
Action callback,
bool watchInitialValues = false
)
where TOwner : INotifyPropertyChanged
{
void OnPropertyChanged(object? sender, PropertyChangedEventArgs args) => callback();
owner.PropertyChanged += OnPropertyChanged;
if (watchInitialValues)
callback();
return Disposable.Create(() => owner.PropertyChanged -= OnPropertyChanged);
return Disposable.Create(() => owner.PropertyChanged -= OnPropertyChanged);
}
}
}
@@ -0,0 +1,17 @@
using System.Diagnostics;
namespace DiscordChatExporter.Gui.Utils.Extensions;
internal static class ProcessExtensions
{
extension(Process)
{
public static void StartShellExecute(string path)
{
using var process = new Process();
process.StartInfo = new ProcessStartInfo { FileName = path, UseShellExecute = true };
process.Start();
}
}
}
@@ -1,14 +0,0 @@
using System.Diagnostics;
namespace DiscordChatExporter.Gui.Utils;
internal static class ProcessEx
{
public static void StartShellExecute(string path)
{
using var process = new Process();
process.StartInfo = new ProcessStartInfo { FileName = path, UseShellExecute = true };
process.Start();
}
}
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -102,7 +103,7 @@ public partial class DashboardViewModel : ViewModelBase
await _dialogManager.ShowDialogAsync(_viewModelManager.CreateSettingsViewModel());
[RelayCommand]
private void ShowHelp() => ProcessEx.StartShellExecute(Program.ProjectDocumentationUrl);
private void ShowHelp() => Process.StartShellExecute(Program.ProjectDocumentationUrl);
private bool CanPullGuilds() => !IsBusy && !string.IsNullOrWhiteSpace(Token);
@@ -140,7 +141,7 @@ public partial class DashboardViewModel : ViewModelBase
catch (Exception ex)
{
var dialog = _viewModelManager.CreateMessageBoxViewModel(
"Error pulling guilds",
"Error pulling servers",
ex.ToString()
);
@@ -322,11 +323,11 @@ public partial class DashboardViewModel : ViewModelBase
}
[RelayCommand]
private void OpenDiscord() => ProcessEx.StartShellExecute("https://discord.com/app");
private void OpenDiscord() => Process.StartShellExecute("https://discord.com/app");
[RelayCommand]
private void OpenDiscordDeveloperPortal() =>
ProcessEx.StartShellExecute("https://discord.com/developers/applications");
Process.StartShellExecute("https://discord.com/developers/applications");
protected override void Dispose(bool disposing)
{
@@ -63,40 +63,40 @@ public class SettingsViewModel : DialogViewModelBase
// These items have to be non-nullable because Avalonia ComboBox doesn't allow a null value to be selected
public IReadOnlyList<string> AvailableLocales { get; } =
[
// Current locale (maps to null downstream)
"",
// Locales supported by the Discord app
"da-DK",
"de-DE",
"en-GB",
"en-US",
"es-ES",
"fr-FR",
"hr-HR",
"it-IT",
"lt-LT",
"hu-HU",
"nl-NL",
"no-NO",
"pl-PL",
"pt-BR",
"ro-RO",
"fi-FI",
"sv-SE",
"vi-VN",
"tr-TR",
"cs-CZ",
"el-GR",
"bg-BG",
"ru-RU",
"uk-UA",
"th-TH",
"zh-CN",
"ja-JP",
"zh-TW",
"ko-KR",
];
[
// Current locale (maps to null downstream)
"",
// Locales supported by the Discord app
"da-DK",
"de-DE",
"en-GB",
"en-US",
"es-ES",
"fr-FR",
"hr-HR",
"it-IT",
"lt-LT",
"hu-HU",
"nl-NL",
"no-NO",
"pl-PL",
"pt-BR",
"ro-RO",
"fi-FI",
"sv-SE",
"vi-VN",
"tr-TR",
"cs-CZ",
"el-GR",
"bg-BG",
"ru-RU",
"uk-UA",
"th-TH",
"zh-CN",
"ja-JP",
"zh-TW",
"ko-KR",
];
// This has to be non-nullable because Avalonia ComboBox doesn't allow a null value to be selected
public string Locale
@@ -5,7 +5,6 @@ using Avalonia;
using CommunityToolkit.Mvvm.Input;
using DiscordChatExporter.Gui.Framework;
using DiscordChatExporter.Gui.Services;
using DiscordChatExporter.Gui.Utils;
using DiscordChatExporter.Gui.Utils.Extensions;
using DiscordChatExporter.Gui.ViewModels.Components;
@@ -44,7 +43,7 @@ public partial class MainViewModel(
settingsService.Save();
if (await dialogManager.ShowDialogAsync(dialog) == true)
ProcessEx.StartShellExecute("https://tyrrrz.me/ukraine?source=discordchatexporter");
Process.StartShellExecute("https://tyrrrz.me/ukraine?source=discordchatexporter");
}
private async Task ShowDevelopmentBuildMessageAsync()
@@ -70,7 +69,7 @@ public partial class MainViewModel(
);
if (await dialogManager.ShowDialogAsync(dialog) == true)
ProcessEx.StartShellExecute(Program.ProjectReleasesUrl);
Process.StartShellExecute(Program.ProjectReleasesUrl);
}
private async Task CheckForUpdatesAsync()
+2
View File
@@ -9,6 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Misc", "Misc", "{EA305DD5-1
Readme.md = Readme.md
Directory.Build.props = Directory.Build.props
DiscordChatExporter.Cli.dockerfile = DiscordChatExporter.Cli.dockerfile
global.json = global.json
NuGet.config = NuGet.config
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscordChatExporter.Gui", "DiscordChatExporter.Gui\DiscordChatExporter.Gui.csproj", "{732A67AF-93DE-49DF-B10F-FD74710B7863}"
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2017-2025 Oleksii Holub
Copyright (c) 2017-2026 Oleksii Holub
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+3 -3
View File
@@ -50,14 +50,14 @@ To learn more about the war and how you can help, [click here](https://tyrrrz.me
- 📦 [AUR](https://aur.archlinux.org/packages/discord-chat-exporter-cli): `discord-chat-exporter-cli`
- 📦 [Nix](https://search.nixos.org/packages?query=discordchatexporter-cli): `discordchatexporter-cli`
> **Important**:
> [!IMPORTANT]
> To launch the GUI version of the app on MacOS, you need to first remove the downloaded file from quarantine.
> You can do that by running the following command in the terminal: `xattr -rd com.apple.quarantine DiscordChatExporter.app`.
> **Note**:
> [!NOTE]
> If you're unsure which build is right for your system, consult with [this page](https://useragent.cc) to determine your OS and CPU architecture.
> **Note**:
> [!NOTE]
> AUR and Nix packages linked above are maintained by the community.
> If you have any issues with them, please contact the corresponding maintainers.
+6
View File
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "10.0.100",
"rollForward": "latestFeature"
}
}