Compare commits

...

98 Commits

Author SHA1 Message Date
Tyrrrz fdf421df3c Update version 2022-10-08 15:38:07 +03:00
Tyrrrz 2259f19c44 Remove message content intent check due to false positives 2022-10-08 15:35:06 +03:00
Tyrrrz 8695942328 Enforce a higher version of .NET runtime
Closes #941
2022-10-02 13:42:46 +03:00
Tyrrrz 84e656ccfc Update version 2022-09-24 20:40:51 +03:00
Tyrrrz 2ba0c3b38e More refactoring around system notifications 2022-09-24 19:54:42 +03:00
Tyrrrz 7467f0aeb6 Don't fail on unknown embed kinds
Closes #936
2022-09-19 23:55:17 +03:00
Tyrrrz e38479d463 Make lowercasing in system notifications a bit safer
Closes #935
2022-09-19 16:30:19 +03:00
Tyrrrz 06a4b6a8e6 Add checks for message content intent on bot accounts
Related to #918
2022-09-16 23:04:18 +03:00
Tyrrrz cc1ad8b435 Retry on SSL exceptions 2022-09-16 22:47:02 +03:00
Tyrrrz f8dac2c9d0 Simplify token kind resolution
Extra request which makes it less efficient, but much simpler code
2022-09-16 22:46:55 +03:00
Tyrrrz b8cea0d140 Unlock dotnet version on CI 2022-09-16 18:01:53 +03:00
Tyrrrz 7996a38c5c Update version 2022-09-16 17:22:53 +03:00
Tyrrrz 9d052f9404 Improve wording in CLI exception when output path is ambiguous
Related to #929
2022-09-14 21:59:22 +03:00
Tyrrrz 3078351670 Add fallback content for thread start messages 2022-09-14 20:17:04 +03:00
Tyrrrz 4f41c4fff3 Fix styles for system notifications in HTML 2022-09-14 20:14:30 +03:00
Tyrrrz a80ee2943f Refactor 2022-09-14 02:06:11 +03:00
gan-of-culture 8612d2c84a Add HTML formatting for system messages (#926) 2022-09-13 23:51:10 +03:00
Tyrrrz 57c849d0f8 More refactoring 2022-09-13 23:27:54 +03:00
Tyrrrz 9c2a26aa82 Fix tests 2022-09-13 18:32:31 +03:00
Tyrrrz f376028d76 Add tests for gifv embeds 2022-09-13 18:09:56 +03:00
Tyrrrz da87f3c774 Hide message content if it only contains a link to a GIFV 2022-09-13 18:05:41 +03:00
Tyrrrz 61516feafa Refactor 2022-09-13 17:33:28 +03:00
gan-of-culture 8d209cd67a Improve GIF playback (#927) 2022-09-13 16:08:57 +03:00
Tyrrrz c58d7e752b Update readme 2022-09-12 16:13:28 +03:00
Ivv fcc1605455 Mention nix package in readme (#925) 2022-09-12 15:59:15 +03:00
gan-of-culture f28d662a71 Support GIF embeds when exporting to HTML (#919) 2022-09-10 23:48:52 +03:00
Tyrrrz a405ab184e Update version 2022-09-08 16:57:00 +03:00
Tyrrrz b861a69799 Recognize existing directories as valid output paths in CLI
Closes #917
2022-09-04 18:14:22 +03:00
Tyrrrz d53b4c825a Update usage guide 2022-09-02 13:29:56 +03:00
Oleksii Holub 30678e96e5 Move into maintenance mode 2022-08-26 18:01:19 +03:00
Oleksii Holub 2024d3658b Update version 2022-08-26 17:58:41 +03:00
Oleksii Holub 9453cac389 Fix regex in contains filter 2022-08-26 00:00:02 +03:00
Oleksii Holub 504c3c53cd Fail if an export command is called with multiple channels but a single-file output path
Closes #799
2022-08-25 22:11:26 +03:00
Oleksii Holub 4e358e8e6f Add support for animated guild icons
Closes #900
2022-08-25 21:38:59 +03:00
Oleksii Holub 5e852235ce Retry on all Discord server side errors
Closes #908
2022-08-25 21:32:47 +03:00
Oleksii Holub 612c6d37a4 Make contains filter match on spaces and input boundaries, as well as word boundaries
Closes #909
2022-08-25 21:26:56 +03:00
Oleksii Holub 92cf886eab Fix not being able to parse message filters that share common prefix with one of the named filters
Related to #909
2022-08-25 21:20:22 +03:00
Oleksii Holub f48af53d72 Simplify filter grammar 2022-08-25 21:07:02 +03:00
Oleksii Holub 99d721c63b Update nuget packages 2022-08-25 20:22:10 +03:00
Oleksii Holub 11414b5937 Refactor message filter grammar and add ~ as an alias for - in negated filters for better UX when using CLI 2022-08-25 20:09:06 +03:00
Oleksii Holub 6c039ebfa6 Filter out categories when displaying channels 2022-08-19 18:39:19 +03:00
TSRBerry 9cffbbc5ce Expand tilde to home directory on *nix systems in output path (#903) 2022-08-18 13:23:26 -07:00
Oleksii Holub 6f87960513 Make workflow stages less ambigious 2022-08-13 04:13:09 -07:00
Oleksii Holub e8f8c47dbd Make JS in HTML templates more consistent 2022-07-19 16:16:48 +03:00
Oleksii Holub 9aba36fce5 Update twemoji URLs 2022-07-19 15:55:58 +03:00
Oleksii Holub f29e1d2d9f Inform about a breaking change in Docker configuration
Related to #884
2022-07-10 02:42:43 -07:00
Oleksii Holub b000a72f81 Update download instructions 2022-07-06 14:08:07 +03:00
Oleksii Holub f5318e77b7 Update version 2022-07-02 13:20:03 +03:00
Oleksii Holub e171b43c22 Simplify CSS 2022-07-01 13:17:13 +03:00
Oleksii Holub 23e1850d15 Render consecutive twitter embeds as on
Closes #695
2022-06-30 20:56:44 +03:00
Oleksii Holub 057902f919 More test stuff 2022-06-30 19:07:11 +03:00
Oleksii Holub 565fb53d3b Cleanup tests 2022-06-30 18:13:14 +03:00
Oleksii Holub edba9f36a7 Hide message content in HTML when linking to an image
Closes #695
2022-06-29 21:43:43 +03:00
Oleksii Holub 356b1a6afd Don't use records for spec classes 2022-06-29 20:49:51 +03:00
Oleksii Holub 70edc8989c Add test for plain image embed 2022-06-29 20:38:48 +03:00
Oleksii Holub 2fd7e327a9 Add support for YouTube Shorts video embeds in HTML 2022-06-29 20:26:04 +03:00
Oleksii Holub 9182c3d934 Fix tests 2022-06-29 12:59:20 +03:00
Oleksii Holub 01389b7e28 Fix rendering of code blocks in HTML 2022-06-28 21:18:57 +03:00
Oleksii Holub bd0701cb82 Render quotes inline in referenced messages in HTML 2022-06-28 21:02:11 +03:00
Oleksii Holub 4283ef22b1 Add HTML minification
Closes #345
Closes #743
2022-06-28 20:20:33 +03:00
Oleksii Holub 94ef4b6981 Support listing and exporting voice channels
Closes #874
2022-06-28 18:27:01 +03:00
Oleksii Holub 7b72f473fd Pad outputs from guilds, channels, dm to have more aligned columns
Closes #877
2022-06-28 17:39:32 +03:00
Oleksii Holub 2463cb5087 Sort DMs by last message and avoid grouping them in GUI
Closes #271
2022-06-28 17:23:01 +03:00
Oleksii Holub 2c7986c4e6 Refactor IsTextChannel and IsVoiceChannel to extensions 2022-06-28 16:38:44 +03:00
Oleksii Holub 5755334492 Update war in Ukraine message in CLI 2022-06-24 12:26:35 +03:00
Oleksii Holub 26c523a3e9 Update usage instructions to direct towards the Network tab method
Closes #835
Closes #842
2022-06-24 12:25:50 +03:00
Oleksii Holub 371c7d2b75 Make TOS warning more prominent
Close #878
2022-06-24 12:14:29 +03:00
Oleksii Holub 62400f305a Make CLI attributes look tidier 2022-06-19 12:21:09 +03:00
Oleksii Holub 65a528e7fe Simplify dockerfile 2022-06-18 22:37:24 +03:00
Lucas LaBuff 47d8163a46 Add filename token for current date (#869) 2022-06-17 12:06:12 -07:00
Clint Herron 1d9224ebd8 Update guide to direct users to the Advanced section of Discord settings rather than Appearance (#867) 2022-06-16 02:01:15 -07:00
Ethan ddc7f921bd Fix Twemoji URLs with ZWJs being generated incorrectly (#865) 2022-06-11 15:46:39 -07:00
Oleksii Holub aca94ddccb Update test logger 2022-06-10 23:16:47 +03:00
Oleksii Holub 3661c42df4 Fix tests by fixing typo in last commit 2022-06-10 22:32:16 +03:00
Oleksii Holub 005c1786ec Fix tests 2022-06-10 22:23:20 +03:00
Oleksii Holub b6fbf2393e Update bootstrapper and add it to the CLI flavor too 2022-06-10 22:12:48 +03:00
Philipp C. Heckel 0e49936e38 Make messages linkable in HTML (#864) 2022-06-09 09:47:00 -07:00
Oleksii Holub 8d4e6b77c4 Fix docker workflow not tagging with version number 2022-06-01 20:06:59 +03:00
Oleksii Holub 6f47fb6a1c Update version 2022-06-01 19:55:49 +03:00
Oleksii Holub 6150720b1e Update readme 2022-05-31 12:29:31 +03:00
Oleksii Holub dcdeea19ab Update nuget packages 2022-05-29 22:43:42 +03:00
Oleksii Holub ca56d47110 Allow whitespace in sticker names 2022-05-20 20:45:42 +03:00
Oleksii Holub 17b548d679 Add test for last change 2022-05-18 20:19:46 +03:00
Andrew Kolos 20eeaa58e9 Add has:pin filter (#853)
Adds a new `has:*` filter. Specifically, `has:pin`.
The filter filters for messages that are pinned.
2022-05-18 10:11:50 -07:00
Oleksii Holub 6621c10ae0 Satisfy my OCD 2022-04-30 16:04:57 +03:00
Oleksii Holub 75214354ca Update CliFx 2022-04-22 19:48:11 +03:00
Oleksii Holub 84d99e8520 Reorganize assets 2022-04-22 17:19:51 +03:00
Oleksii Holub 4b80eabb73 Update NuGet.config 2022-04-22 17:03:03 +03:00
Oleksii Holub e6830bbd0e Plural artifacts 2022-04-22 02:10:00 +03:00
Oleksii Holub 97c751f171 Simplify workflows 2022-04-22 01:23:48 +03:00
Oleksii Holub dc814e08e7 Update readme 2022-04-22 01:14:35 +03:00
Oleksii Holub 54bf7c204a Consolidate workflows 2022-04-22 01:13:36 +03:00
Oleksii Holub 36c9983c9e Update test logger 2022-04-19 04:29:50 +03:00
Oleksii Holub 361e0489ed Update NuGet packages 2022-04-17 03:36:15 +03:00
Oleksii Holub 77436120a8 Update readme 2022-04-16 18:48:39 +03:00
Oleksii Holub 2d7ab5411f Revert "Use nightly.link for linking CI builds"
This reverts commit 1ce523b252.
2022-04-13 22:40:27 +03:00
Oleksii Holub 1ce523b252 Use nightly.link for linking CI builds 2022-04-13 22:38:41 +03:00
Oleksii Holub bb81cf06ae Rework retry policy
Fixes #832
2022-04-12 23:55:03 +03:00
101 changed files with 2298 additions and 1330 deletions

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 45 KiB

+3
View File
@@ -1,5 +1,8 @@
blank_issues_enabled: false blank_issues_enabled: false
contact_links: contact_links:
- name: ⚠ Feature request
url: https://github.com/Tyrrrz/.github/blob/master/docs/project-status.md
about: Sorry, but this project is in maintenance mode and no longer accepts new feature requests.
- name: 💬 Discord server - name: 💬 Discord server
url: https://discord.gg/2SUWKFnHSm url: https://discord.gg/2SUWKFnHSm
about: Chat with the project community. about: Chat with the project community.
@@ -1,42 +0,0 @@
name: ✨ Feature request
description: Request a new feature.
labels: [enhancement]
body:
- type: markdown
attributes:
value: |
🧐 **Guidelines:**
- Search through [existing issues](https://github.com/Tyrrrz/DiscordChatExporter/issues?q=is%3Aissue) first to ensure that this feature has not been requested before.
- Write a descriptive title for your issue. Avoid generic or vague titles such as "Some suggestions" or "Ideas for improvement".
- Keep your issue focused on one single problem. If you have multiple feature requests, please create separate issues for each of them.
- Provide as much context as possible in the details section. Include screenshots, screen recordings, links, references, or anything else you may consider relevant.
- If you want to ask a question instead of requesting a feature, please use [discussions](https://github.com/Tyrrrz/DiscordChatExporter/discussions/new) instead.
- type: dropdown
attributes:
label: Flavor
description: Is this feature request related to specific flavor(s) of DiscordChatExporter? If not applicable, leave this field blank.
multiple: true
options:
- GUI (Graphical User Interface)
- CLI (Command Line Interface)
- type: dropdown
attributes:
label: Export format
description: Is this feature request related to specific export format(s)? If not applicable, leave this field blank.
multiple: true
options:
- HTML
- TXT
- JSON
- CSV
- type: textarea
attributes:
label: Details
description: Clear and thorough explanation of the feature you have in mind.
validations:
required: true
-30
View File
@@ -1,30 +0,0 @@
name: Docker CD
on:
push:
tags:
- "*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.3
- name: Get release version
id: get_version
uses: dawidd6/action-get-tag@v1
- name: Login
run: docker login -u tyrrrz -p ${{ secrets.DOCKER_TOKEN }}
- name: Build
run: docker build -t tyrrrz/discordchatexporter:${{ steps.get_version.outputs.tag }} -t tyrrrz/discordchatexporter:stable .
- name: Deploy (version)
run: docker push tyrrrz/discordchatexporter:${{ steps.get_version.outputs.tag }}
- name: Deploy (stable)
run: docker push tyrrrz/discordchatexporter:stable
-85
View File
@@ -1,85 +0,0 @@
name: CD
on:
push:
tags:
- "*"
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.3
- name: Get release version
id: get_version
uses: dawidd6/action-get-tag@v1
- name: Install .NET
uses: actions/setup-dotnet@v1.7.2
with:
# Fixed version, workaround for https://github.com/dotnet/core/issues/7176
dotnet-version: 6.0.100
- name: Build & publish (CLI)
run: dotnet publish DiscordChatExporter.Cli/ -o DiscordChatExporter.Cli/bin/Publish/ --configuration Release
- name: Build & publish (GUI)
run: dotnet publish DiscordChatExporter.Gui/ -o DiscordChatExporter.Gui/bin/Publish/ --configuration Release
- name: Pack (CLI)
run: Compress-Archive -Path DiscordChatExporter.Cli/bin/Publish/* -DestinationPath DiscordChatExporter.Cli/bin/Publish/Archive.zip -Force
shell: pwsh
- name: Pack (GUI)
run: Compress-Archive -Path DiscordChatExporter.Gui/bin/Publish/* -DestinationPath DiscordChatExporter.Gui/bin/Publish/Archive.zip -Force
shell: pwsh
- name: Create release
id: create_release
uses: actions/create-release@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body: |
[Changelog](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/Changelog.md)
draft: false
prerelease: false
- name: Upload release asset (CLI)
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: DiscordChatExporter.Cli/bin/Publish/Archive.zip
asset_name: DiscordChatExporter.CLI.zip
asset_content_type: application/zip
- name: Upload release asset (GUI)
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: DiscordChatExporter.Gui/bin/Publish/Archive.zip
asset_name: DiscordChatExporter.zip
asset_content_type: application/zip
- name: Notify Discord
uses: satak/webrequest-action@v1.2.4
with:
url: ${{ secrets.DISCORD_WEBHOOK }}
method: POST
headers: |
{
"ContentType": "application/json; charset=UTF-8"
}
payload: |
{
"content": "**DiscordChatExporter** new version released!\nVersion: `${{ steps.get_version.outputs.tag }}`\nChangelog: <https://github.com/Tyrrrz/DiscordChatExporter/blob/${{ steps.get_version.outputs.tag }}/Changelog.md>"
}
-23
View File
@@ -1,23 +0,0 @@
name: Docker CI
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.3
- name: Login
run: docker login -u tyrrrz -p ${{ secrets.DOCKER_TOKEN }}
- name: Build
run: docker build -t tyrrrz/discordchatexporter:latest .
- name: Deploy (latest)
run: docker push tyrrrz/discordchatexporter:latest
-48
View File
@@ -1,48 +0,0 @@
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.3
- name: Install .NET
uses: actions/setup-dotnet@v1.7.2
with:
# Fixed version, workaround for https://github.com/dotnet/core/issues/7176
dotnet-version: 6.0.100
- name: Build & test
# Tests need access to secrets, so we can't run them against PRs because of limited trust
if: ${{ github.event_name != 'pull_request' }}
run: dotnet test --configuration Release --logger GitHubActions --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
env:
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
DISCORD_TOKEN_BOT: true
- name: Upload coverage
uses: codecov/codecov-action@v1.0.5
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Build & publish (CLI)
run: dotnet publish DiscordChatExporter.Cli/ -o DiscordChatExporter.Cli/bin/Publish/ --configuration Release
- name: Build & publish (GUI)
run: dotnet publish DiscordChatExporter.Gui/ -o DiscordChatExporter.Gui/bin/Publish/ --configuration Release
- name: Upload build artifacts (CLI)
uses: actions/upload-artifact@v1
with:
name: DiscordChatExporter.CLI
path: DiscordChatExporter.Cli/bin/Publish/
- name: Upload build artifact (GUI)
uses: actions/upload-artifact@v1
with:
name: DiscordChatExporter
path: DiscordChatExporter.Gui/bin/Publish/
+55
View File
@@ -0,0 +1,55 @@
name: docker
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build container
run: docker build -f DiscordChatExporter.Cli.dockerfile .
deploy-latest:
if: ${{ github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'master' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to DockerHub
run: docker login -u tyrrrz -p ${{ secrets.DOCKER_TOKEN }}
- name: Build container
run: docker build -f DiscordChatExporter.Cli.dockerfile -t tyrrrz/discordchatexporter:latest .
- name: Push container
run: docker push tyrrrz/discordchatexporter:latest
deploy-stable:
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get release version
id: get_version
uses: dawidd6/action-get-tag@v1
- name: Login to DockerHub
run: docker login -u tyrrrz -p ${{ secrets.DOCKER_TOKEN }}
- name: Build container
run: docker build -f DiscordChatExporter.Cli.dockerfile -t tyrrrz/discordchatexporter:stable -t tyrrrz/discordchatexporter:${{ steps.get_version.outputs.tag }} .
- name: Push container (stable)
run: docker push tyrrrz/discordchatexporter:stable
- name: Push container (${{ steps.get_version.outputs.tag }})
run: docker push tyrrrz/discordchatexporter:${{ steps.get_version.outputs.tag }}
+152
View File
@@ -0,0 +1,152 @@
name: main
on: [push, pull_request]
jobs:
test:
runs-on: windows-latest
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Run tests
# Tests need access to secrets, so we can't run them against PRs because of limited trust
if: ${{ github.event_name != 'pull_request' }}
run: dotnet test --configuration Release --logger GitHubActions --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
env:
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
DISCORD_TOKEN_BOT: true
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
package:
needs: test
runs-on: windows-latest
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Publish (CLI)
run: dotnet publish DiscordChatExporter.Cli/ -o DiscordChatExporter.Cli/bin/Publish/ --configuration Release
- name: Publish (GUI)
run: dotnet publish DiscordChatExporter.Gui/ -o DiscordChatExporter.Gui/bin/Publish/ --configuration Release
- name: Upload artifacts (CLI)
uses: actions/upload-artifact@v3
with:
name: DiscordChatExporter.Cli
path: DiscordChatExporter.Cli/bin/Publish/
- name: Upload artifacts (GUI)
uses: actions/upload-artifact@v3
with:
name: DiscordChatExporter
path: DiscordChatExporter.Gui/bin/Publish/
deploy:
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
needs: package
runs-on: ubuntu-latest
steps:
- name: Download artifacts (CLI)
uses: actions/download-artifact@v3
with:
name: DiscordChatExporter.Cli
path: DiscordChatExporter.Cli
- name: Download artifacts (GUI)
uses: actions/download-artifact@v3
with:
name: DiscordChatExporter
path: DiscordChatExporter.Gui
- name: Create package (CLI)
run: Compress-Archive -Path DiscordChatExporter.Cli/* -DestinationPath DiscordChatExporter.Cli.zip -Force
shell: pwsh
- name: Create package (GUI)
run: Compress-Archive -Path DiscordChatExporter.Gui/* -DestinationPath DiscordChatExporter.Gui.zip -Force
shell: pwsh
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body: |
[Changelog](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/Changelog.md)
draft: false
prerelease: false
- name: Upload release asset (CLI)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_name: DiscordChatExporter.Cli.zip
asset_path: DiscordChatExporter.Cli.zip
asset_content_type: application/zip
- name: Upload release asset (GUI)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_name: DiscordChatExporter.zip
asset_path: DiscordChatExporter.Gui.zip
asset_content_type: application/zip
notify:
needs: deploy
runs-on: ubuntu-latest
steps:
- name: Get release version
id: get_version
uses: dawidd6/action-get-tag@v1
- name: Notify Discord
uses: satak/webrequest-action@v1.2.4
with:
url: ${{ secrets.DISCORD_WEBHOOK }}
method: POST
headers: |
{
"ContentType": "application/json; charset=UTF-8"
}
payload: |
{
"content": "**DiscordChatExporter** new version released!\nVersion: `${{ steps.get_version.outputs.tag }}`\nChangelog: <https://github.com/Tyrrrz/DiscordChatExporter/blob/${{ steps.get_version.outputs.tag }}/Changelog.md>"
}
+1
View File
@@ -5,6 +5,7 @@
*.sln.docstates *.sln.docstates
.idea/ .idea/
.vs/ .vs/
.vscode/
# Build results # Build results
[Dd]ebug/ [Dd]ebug/
+60
View File
@@ -1,3 +1,63 @@
### v2.36.2 (08-Oct-2022)
- Removed the message content intent check because the heuristics turned out to be not reliable enough.
- Fixed an issue where the runtime manifest included the wrong target runtime version. This resulted in the application failing to launch for some users when upgrading from earlier versions.
### v2.36.1 (24-Sep-2022)
- Added a check which will trigger an error if the provided bot account does not have the message content intent enabled. Note, however, that this check is based on heuristics which may result in false negatives.
- Fixed an issue where certain transient HTTP errors were not retried.
- Fixed an issue which caused the export process to fail with the `IndexOutOfRangeException` exception on certain automated messages.
- Fixed an issue which caused the export process to fail on unrecognized embed types.
### v2.36 (16-Sep-2022)
- [HTML] Added support for rendering GIFV embeds. They will now render as videos that automatically play when you hover your mouse over them. (Thanks [@gan-of-culture](https://github.com/gan-of-culture))
- [HTML] Added support for rendering system notification messages, such as when a user joins a server or when a messages gets pinned. Previously, such messages were rendered as regular text messages, but now they look similar to how they're presented in the Discord client. (Thanks [@gan-of-culture](https://github.com/gan-of-culture))
- [CLI] Improved the wording of the error message that's shown when exporting multiple channels and the provided output path is ambiguous. It now mentions that you can resolve the ambiguity by adding a slash at the end of the path.
### v2.35.2 (08-Sep-2022)
- Updated usage guide to mention the need to enable "Message Content Intent" to use a bot as a medium for exporting messages.
- [CLI] Fixed an issue where passing an existing directory as the output path failed when exporting multiple channels (for example, when running `exportdm`). An ambiguous output path will now always be treated as a directory path if that directory already exists. If it doesn't exist, it will be treated as a file path, matching the previous behavior.
### v2.35.1 (26-Aug-2022)
- Added `~` character as an alias for `-` when negating a message filter. This should make it easier to use negated filters from CLI where the dash character already has other meanings.
- Extended retry logic to encompass all server-side errors from Discord API, instead of only `500 Internal Server Error`.
- [CLI] Attempt to export multiple channels will now fail if provided with an output path that is neither a directory, nor a file name template. Previously, this resulted in all channels being exported to the same file, overwriting each other.
- Fixed an issue where a text message filter didn't work if it started with a character that's also the first character in one of the named filters (e.g. `from` or `mentions`).
- Fixed an issue where a text message filter didn't work correctly if it was enclosed in parentheses.
- Fixed an issue where categories were displayed alongside regular channels in the channel list, both in GUI and in CLI (when using the `guild` command).
- [CLI] Fixed an issue where an output path starting with a tilde on Linux was not expanded properly into a full path. (Thanks [@TSRBerry](https://github.com/TSRBerry))
### v2.35 (02-Jul-2022)
- Added support for exporting text chat in voice channels. These channels are now also displayed when browsing in the GUI and in the CLI when executing the `channels` command.
- [GUI] Direct message channels are now sorted by the timestamp of their last message, similarly to how they appear in the Discord client.
- [GUI] Removed artificial grouping of direct message channels into "Private" and "Group".
- [CLI] Added runtime bootstrapper capabilities to the CLI flavor of DiscordChatExporter on Windows. Now, if you attempt to run the application without the required prerequisites installed, you will be provided with an option to install them automatically.
- [CLI] Fixed outdated information in the usage guide. (Thanks [@Clint Herron](https://github.com/HanClinto))
- [CLI] Added whitespace padding to the output of `guilds`, `channels`, and `dm` to make the tables look more uniform.
- [HTML] Added hyperlinks to message timestamps, which allows you to quickly copy a link to a specific message in the export. (Thanks [@Philipp C. Heckel](https://github.com/binwiederhier))
- [HTML] Added minification. Chat exports in HTML format are now 30-35% smaller than before.
- [HTML] Added support for rendering embeds of Twitter posts that contain multiple images. Previously, this resulted in multiple separate embeds instead of one.
- [HTML] Added support for rendering embeds of YouTube Shorts videos.
- [HTML] Text content is now hidden if the message only contains a link to an image and nothing else. The link itself is resolved as an image embed.
- [HTML] Fixed an issue where some emoji that included a zero-width-joiner rune were not rendered correctly due to a wrong Twemoji URL being generated. (Thanks [@Ethan](https://github.com/ethanndickson))
- [HTML] Fixed an issue where replies to a message that contained a quote (i.e. `>`) were not rendered correctly.
- [HTML] Fixed an issue where code blocks with language highlighting did not have the correct background color.
- Added file name template token that resolves to the current date (`%d`). (Thanks [@Lucas LaBuff](https://github.com/96-LB))
- Updated the usage guide to replace the instructions for retrieving the user token with those that appear to work for more people.
- Updated the usage guide to feature the TOS warning more prominently.
- [Docker] Changed internal working directory from `/app/out` to `/out`. This was an unintended breaking change. Please update your volume binding configuration from `-v /path/on/machine:/app/out` to `-v /path/on/machine:/out`.
### v2.34.1 (01-Jun-2022)
- Improved retry policy to handle more transient errors. This should result in fewer errors exporting a channel due to timeout.
- Added `has:pin` message filter. You can use it to limit exported messages to those that have been pinned. (Thanks [@Andrew Kolos](https://github.com/andrewkolos))
- Fixed an issue which caused the export to fail when processing stickers that have no name.
### v2.34 (10-Apr-2022) ### v2.34 (10-Apr-2022)
- [HTML] Reworked layout to be more consistent with Discord. - [HTML] Reworked layout to be more consistent with Discord.
+9 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Version>2.34</Version> <Version>2.36.2</Version>
<Company>Tyrrrz</Company> <Company>Tyrrrz</Company>
<Copyright>Copyright (c) Oleksii Holub</Copyright> <Copyright>Copyright (c) Oleksii Holub</Copyright>
<LangVersion>preview</LangVersion> <LangVersion>preview</LangVersion>
@@ -10,4 +10,12 @@
<WarningsAsErrors>nullable</WarningsAsErrors> <WarningsAsErrors>nullable</WarningsAsErrors>
</PropertyGroup> </PropertyGroup>
<!--
Even though the project builds against .NET 6, some dependencies
apparently rely on a specific version of the runtime.
-->
<PropertyGroup>
<RuntimeFrameworkVersion>6.0.9</RuntimeFrameworkVersion>
</PropertyGroup>
</Project> </Project>
@@ -3,7 +3,6 @@
<PropertyGroup> <PropertyGroup>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject> <IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);xUnit1013</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -12,14 +11,14 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AngleSharp" Version="0.16.1" /> <PackageReference Include="AngleSharp" Version="0.17.1" />
<PackageReference Include="FluentAssertions" Version="6.6.0" /> <PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="1.3.0" PrivateAssets="all" /> <PackageReference Include="GitHubActionsTestLogger" Version="2.0.1" PrivateAssets="all" />
<PackageReference Include="JsonExtensions" Version="1.2.0" /> <PackageReference Include="JsonExtensions" Version="1.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
<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.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="all" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" PrivateAssets="all" />
<PackageReference Include="coverlet.collector" Version="3.1.2" PrivateAssets="all" /> <PackageReference Include="coverlet.collector" Version="3.1.2" PrivateAssets="all" />
</ItemGroup> </ItemGroup>
@@ -46,58 +46,46 @@ public class ExportWrapperFixture : IDisposable
return await File.ReadAllTextAsync(filePath); return await File.ReadAllTextAsync(filePath);
} }
public async ValueTask<IHtmlDocument> ExportAsHtmlAsync(Snowflake channelId) public async ValueTask<IHtmlDocument> ExportAsHtmlAsync(Snowflake channelId) => Html.Parse(
{ await ExportAsync(channelId, ExportFormat.HtmlDark)
var data = await ExportAsync(channelId, ExportFormat.HtmlDark); );
return Html.Parse(data);
}
public async ValueTask<JsonElement> ExportAsJsonAsync(Snowflake channelId) public async ValueTask<JsonElement> ExportAsJsonAsync(Snowflake channelId) => Json.Parse(
{ await ExportAsync(channelId, ExportFormat.Json)
var data = await ExportAsync(channelId, ExportFormat.Json); );
return Json.Parse(data);
}
public async ValueTask<string> ExportAsPlainTextAsync(Snowflake channelId) public async ValueTask<string> ExportAsPlainTextAsync(Snowflake channelId) =>
{ await ExportAsync(channelId, ExportFormat.PlainText);
var data = await ExportAsync(channelId, ExportFormat.PlainText);
return data;
}
public async ValueTask<string> ExportAsCsvAsync(Snowflake channelId) public async ValueTask<string> ExportAsCsvAsync(Snowflake channelId) =>
{ await ExportAsync(channelId, ExportFormat.Csv);
var data = await ExportAsync(channelId, ExportFormat.Csv);
return data;
}
public async ValueTask<IReadOnlyList<IElement>> GetMessagesAsHtmlAsync(Snowflake channelId) public async ValueTask<IReadOnlyList<IElement>> GetMessagesAsHtmlAsync(Snowflake channelId) =>
{ (await ExportAsHtmlAsync(channelId))
var document = await ExportAsHtmlAsync(channelId); .QuerySelectorAll("[data-message-id]")
return document.QuerySelectorAll("[data-message-id]").ToArray(); .ToArray();
}
public async ValueTask<IReadOnlyList<JsonElement>> GetMessagesAsJsonAsync(Snowflake channelId) public async ValueTask<IReadOnlyList<JsonElement>> GetMessagesAsJsonAsync(Snowflake channelId) =>
{ (await ExportAsJsonAsync(channelId))
var document = await ExportAsJsonAsync(channelId); .GetProperty("messages")
return document.GetProperty("messages").EnumerateArray().ToArray(); .EnumerateArray()
} .ToArray();
public async ValueTask<IElement> GetMessageAsHtmlAsync(Snowflake channelId, Snowflake messageId) public async ValueTask<IElement> GetMessageAsHtmlAsync(Snowflake channelId, Snowflake messageId)
{ {
var messages = await GetMessagesAsHtmlAsync(channelId); var message = (await GetMessagesAsHtmlAsync(channelId))
.SingleOrDefault(e =>
var message = messages.SingleOrDefault(e => string.Equals(
string.Equals( e.GetAttribute("data-message-id"),
e.GetAttribute("data-message-id"), messageId.ToString(),
messageId.ToString(), StringComparison.OrdinalIgnoreCase
StringComparison.OrdinalIgnoreCase )
) );
);
if (message is null) if (message is null)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
$"Message '{messageId}' does not exist in export of channel '{channelId}'." $"Message '{messageId}' does not exist in the export of channel '{channelId}'."
); );
} }
@@ -106,20 +94,19 @@ public class ExportWrapperFixture : IDisposable
public async ValueTask<JsonElement> GetMessageAsJsonAsync(Snowflake channelId, Snowflake messageId) public async ValueTask<JsonElement> GetMessageAsJsonAsync(Snowflake channelId, Snowflake messageId)
{ {
var messages = await GetMessagesAsJsonAsync(channelId); var message = (await GetMessagesAsJsonAsync(channelId))
.SingleOrDefault(j =>
var message = messages.FirstOrDefault(j => string.Equals(
string.Equals( j.GetProperty("id").GetString(),
j.GetProperty("id").GetString(), messageId.ToString(),
messageId.ToString(), StringComparison.OrdinalIgnoreCase
StringComparison.OrdinalIgnoreCase )
) );
);
if (message.ValueKind == JsonValueKind.Undefined) if (message.ValueKind == JsonValueKind.Undefined)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
$"Message '{messageId}' does not exist in export of channel '{channelId}'." $"Message '{messageId}' does not exist in the export of channel '{channelId}'."
); );
} }
+2 -3
View File
@@ -3,12 +3,11 @@
This test suite runs against a real Discord server, specifically created to exercise different behaviors required by the test scenarios. This test suite runs against a real Discord server, specifically created to exercise different behaviors required by the test scenarios.
In order to run these tests locally, you need to join the test server and configure your authentication token. In order to run these tests locally, you need to join the test server and configure your authentication token.
1. Join the server: https://discord.gg/eRV8Vap5bm 1. [Join the test server](https://discord.gg/eRV8Vap5bm)
2. Locate your Discord authentication token 2. Locate your Discord authentication token
3. Specify your token using a file or an environment variable: 3. Specify your token using a file or an environment variable:
- **Using a file**: put your token in a new `DiscordToken.secret` file created in this directory - **Using a file**: put your token in a new `DiscordToken.secret` file created in this directory
- **Using an environment variable**: set `DISCORD_TOKEN` variable to your token - **Using an environment variable**: set `DISCORD_TOKEN` variable to your token
4. Run the tests: `dotnet test` 4. Run the tests: `dotnet test`
> If you want to have a new test case or a scenario added, please let me know in your pull request. > If you want to add a new test case, please let me know and I will give you the required permissions
Currently, it's not possible to add them by yourself.
@@ -6,13 +6,20 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.CsvWriting; namespace DiscordChatExporter.Cli.Tests.Specs.CsvWriting;
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class ContentSpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public ContentSpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task Messages_are_exported_correctly() public async Task Messages_are_exported_correctly()
{ {
// Act // Act
var document = await ExportWrapper.ExportAsCsvAsync(ChannelIds.DateRangeTestCases); var document = await _exportWrapper.ExportAsCsvAsync(ChannelIds.DateRangeTestCases);
// Assert // Assert
document.Should().ContainAll( document.Should().ContainAll(
@@ -15,14 +15,21 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs; namespace DiscordChatExporter.Cli.Tests.Specs;
public record DateRangeSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture> public class DateRangeSpecs : IClassFixture<TempOutputFixture>
{ {
private readonly TempOutputFixture _tempOutput;
public DateRangeSpecs(TempOutputFixture tempOutput)
{
_tempOutput = tempOutput;
}
[Fact] [Fact]
public async Task Messages_filtered_after_specific_date_only_include_messages_sent_after_that_date() public async Task Messages_filtered_after_specific_date_only_include_messages_sent_after_that_date()
{ {
// Arrange // Arrange
var after = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero); var after = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
var filePath = TempOutput.GetTempFilePath(); var filePath = _tempOutput.GetTempFilePath();
// Act // Act
await new ExportChannelsCommand await new ExportChannelsCommand
@@ -34,16 +41,14 @@ public record DateRangeSpecs(TempOutputFixture TempOutput) : IClassFixture<TempO
After = Snowflake.FromDate(after) After = Snowflake.FromDate(after)
}.ExecuteAsync(new FakeConsole()); }.ExecuteAsync(new FakeConsole());
var data = await File.ReadAllTextAsync(filePath); // Assert
var document = Json.Parse(data); var timestamps = Json
.Parse(await File.ReadAllTextAsync(filePath))
var timestamps = document
.GetProperty("messages") .GetProperty("messages")
.EnumerateArray() .EnumerateArray()
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset()) .Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
.ToArray(); .ToArray();
// Assert
timestamps.All(t => t > after).Should().BeTrue(); timestamps.All(t => t > after).Should().BeTrue();
timestamps.Should().BeEquivalentTo(new[] timestamps.Should().BeEquivalentTo(new[]
@@ -68,7 +73,7 @@ public record DateRangeSpecs(TempOutputFixture TempOutput) : IClassFixture<TempO
{ {
// Arrange // Arrange
var before = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero); var before = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
var filePath = TempOutput.GetTempFilePath(); var filePath = _tempOutput.GetTempFilePath();
// Act // Act
await new ExportChannelsCommand await new ExportChannelsCommand
@@ -80,16 +85,14 @@ public record DateRangeSpecs(TempOutputFixture TempOutput) : IClassFixture<TempO
Before = Snowflake.FromDate(before) Before = Snowflake.FromDate(before)
}.ExecuteAsync(new FakeConsole()); }.ExecuteAsync(new FakeConsole());
var data = await File.ReadAllTextAsync(filePath); // Assert
var document = Json.Parse(data); var timestamps = Json
.Parse(await File.ReadAllTextAsync(filePath))
var timestamps = document
.GetProperty("messages") .GetProperty("messages")
.EnumerateArray() .EnumerateArray()
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset()) .Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
.ToArray(); .ToArray();
// Assert
timestamps.All(t => t < before).Should().BeTrue(); timestamps.All(t => t < before).Should().BeTrue();
timestamps.Should().BeEquivalentTo(new[] timestamps.Should().BeEquivalentTo(new[]
@@ -113,7 +116,7 @@ public record DateRangeSpecs(TempOutputFixture TempOutput) : IClassFixture<TempO
// Arrange // Arrange
var after = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero); var after = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
var before = new DateTimeOffset(2021, 08, 01, 0, 0, 0, TimeSpan.Zero); var before = new DateTimeOffset(2021, 08, 01, 0, 0, 0, TimeSpan.Zero);
var filePath = TempOutput.GetTempFilePath(); var filePath = _tempOutput.GetTempFilePath();
// Act // Act
await new ExportChannelsCommand await new ExportChannelsCommand
@@ -126,16 +129,14 @@ public record DateRangeSpecs(TempOutputFixture TempOutput) : IClassFixture<TempO
After = Snowflake.FromDate(after) After = Snowflake.FromDate(after)
}.ExecuteAsync(new FakeConsole()); }.ExecuteAsync(new FakeConsole());
var data = await File.ReadAllTextAsync(filePath); // Assert
var document = Json.Parse(data); var timestamps = Json
.Parse(await File.ReadAllTextAsync(filePath))
var timestamps = document
.GetProperty("messages") .GetProperty("messages")
.EnumerateArray() .EnumerateArray()
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset()) .Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
.ToArray(); .ToArray();
// Assert
timestamps.All(t => t < before && t > after).Should().BeTrue(); timestamps.All(t => t < before && t > after).Should().BeTrue();
timestamps.Should().BeEquivalentTo(new[] timestamps.Should().BeEquivalentTo(new[]
@@ -14,13 +14,20 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs; namespace DiscordChatExporter.Cli.Tests.Specs;
public record FilterSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture> public class FilterSpecs : IClassFixture<TempOutputFixture>
{ {
private readonly TempOutputFixture _tempOutput;
public FilterSpecs(TempOutputFixture tempOutput)
{
_tempOutput = tempOutput;
}
[Fact] [Fact]
public async Task Messages_filtered_by_text_only_include_messages_that_contain_that_text() public async Task Messages_filtered_by_text_only_include_messages_that_contain_that_text()
{ {
// Arrange // Arrange
var filePath = TempOutput.GetTempFilePath(); var filePath = _tempOutput.GetTempFilePath();
// Act // Act
await new ExportChannelsCommand await new ExportChannelsCommand
@@ -32,11 +39,9 @@ public record FilterSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutp
MessageFilter = MessageFilter.Parse("some text") MessageFilter = MessageFilter.Parse("some text")
}.ExecuteAsync(new FakeConsole()); }.ExecuteAsync(new FakeConsole());
var data = await File.ReadAllTextAsync(filePath);
var document = Json.Parse(data);
// Assert // Assert
document Json
.Parse(await File.ReadAllTextAsync(filePath))
.GetProperty("messages") .GetProperty("messages")
.EnumerateArray() .EnumerateArray()
.Select(j => j.GetProperty("content").GetString()) .Select(j => j.GetProperty("content").GetString())
@@ -48,7 +53,7 @@ public record FilterSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutp
public async Task Messages_filtered_by_author_only_include_messages_sent_by_that_author() public async Task Messages_filtered_by_author_only_include_messages_sent_by_that_author()
{ {
// Arrange // Arrange
var filePath = TempOutput.GetTempFilePath(); var filePath = _tempOutput.GetTempFilePath();
// Act // Act
await new ExportChannelsCommand await new ExportChannelsCommand
@@ -60,11 +65,9 @@ public record FilterSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutp
MessageFilter = MessageFilter.Parse("from:Tyrrrz") MessageFilter = MessageFilter.Parse("from:Tyrrrz")
}.ExecuteAsync(new FakeConsole()); }.ExecuteAsync(new FakeConsole());
var data = await File.ReadAllTextAsync(filePath);
var document = Json.Parse(data);
// Assert // Assert
document Json
.Parse(await File.ReadAllTextAsync(filePath))
.GetProperty("messages") .GetProperty("messages")
.EnumerateArray() .EnumerateArray()
.Select(j => j.GetProperty("author").GetProperty("name").GetString()) .Select(j => j.GetProperty("author").GetProperty("name").GetString())
@@ -76,7 +79,7 @@ public record FilterSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutp
public async Task Messages_filtered_by_content_only_include_messages_that_have_that_content() public async Task Messages_filtered_by_content_only_include_messages_that_have_that_content()
{ {
// Arrange // Arrange
var filePath = TempOutput.GetTempFilePath(); var filePath = _tempOutput.GetTempFilePath();
// Act // Act
await new ExportChannelsCommand await new ExportChannelsCommand
@@ -88,11 +91,9 @@ public record FilterSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutp
MessageFilter = MessageFilter.Parse("has:image") MessageFilter = MessageFilter.Parse("has:image")
}.ExecuteAsync(new FakeConsole()); }.ExecuteAsync(new FakeConsole());
var data = await File.ReadAllTextAsync(filePath);
var document = Json.Parse(data);
// Assert // Assert
document Json
.Parse(await File.ReadAllTextAsync(filePath))
.GetProperty("messages") .GetProperty("messages")
.EnumerateArray() .EnumerateArray()
.Select(j => j.GetProperty("content").GetString()) .Select(j => j.GetProperty("content").GetString())
@@ -100,11 +101,37 @@ public record FilterSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutp
.ContainSingle("This has image"); .ContainSingle("This has image");
} }
[Fact]
public async Task Messages_filtered_by_pin_only_include_messages_that_have_been_pinned()
{
// Arrange
var filePath = _tempOutput.GetTempFilePath();
// Act
await new ExportChannelsCommand
{
Token = Secrets.DiscordToken,
ChannelIds = new[] { ChannelIds.FilterTestCases },
ExportFormat = ExportFormat.Json,
OutputPath = filePath,
MessageFilter = MessageFilter.Parse("has:pin")
}.ExecuteAsync(new FakeConsole());
// Assert
Json
.Parse(await File.ReadAllTextAsync(filePath))
.GetProperty("messages")
.EnumerateArray()
.Select(j => j.GetProperty("content").GetString())
.Should()
.ContainSingle("This is pinned");
}
[Fact] [Fact]
public async Task Messages_filtered_by_mention_only_include_messages_that_have_that_mention() public async Task Messages_filtered_by_mention_only_include_messages_that_have_that_mention()
{ {
// Arrange // Arrange
var filePath = TempOutput.GetTempFilePath(); var filePath = _tempOutput.GetTempFilePath();
// Act // Act
await new ExportChannelsCommand await new ExportChannelsCommand
@@ -116,11 +143,9 @@ public record FilterSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutp
MessageFilter = MessageFilter.Parse("mentions:Tyrrrz") MessageFilter = MessageFilter.Parse("mentions:Tyrrrz")
}.ExecuteAsync(new FakeConsole()); }.ExecuteAsync(new FakeConsole());
var data = await File.ReadAllTextAsync(filePath);
var document = Json.Parse(data);
// Assert // Assert
document Json
.Parse(await File.ReadAllTextAsync(filePath))
.GetProperty("messages") .GetProperty("messages")
.EnumerateArray() .EnumerateArray()
.Select(j => j.GetProperty("content").GetString()) .Select(j => j.GetProperty("content").GetString())
@@ -1,4 +1,5 @@
using System.Threading.Tasks; using System.Linq;
using System.Threading.Tasks;
using AngleSharp.Dom; using AngleSharp.Dom;
using DiscordChatExporter.Cli.Tests.Fixtures; using DiscordChatExporter.Cli.Tests.Fixtures;
using DiscordChatExporter.Cli.Tests.TestData; using DiscordChatExporter.Cli.Tests.TestData;
@@ -8,19 +9,24 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting; namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public AttachmentSpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task Message_with_a_generic_attachment_is_rendered_correctly() public async Task Message_with_a_generic_attachment_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.AttachmentTestCases, ChannelIds.AttachmentTestCases,
Snowflake.Parse("885587844989612074") Snowflake.Parse("885587844989612074")
); );
var fileUrl = message.QuerySelector("a")?.GetAttribute("href");
// Assert // Assert
message.Text().Should().ContainAll( message.Text().Should().ContainAll(
"Generic file attachment", "Generic file attachment",
@@ -28,45 +34,52 @@ public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixtur
"11 bytes" "11 bytes"
); );
fileUrl.Should().StartWithEquivalentOf( message
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt" .QuerySelectorAll("a")
); .Select(e => e.GetAttribute("href"))
.Should()
.Contain(
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
);
} }
[Fact] [Fact]
public async Task Message_with_an_image_attachment_is_rendered_correctly() public async Task Message_with_an_image_attachment_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.AttachmentTestCases, ChannelIds.AttachmentTestCases,
Snowflake.Parse("885654862656843786") Snowflake.Parse("885654862656843786")
); );
var imageUrl = message.QuerySelector(".chatlog__attachment img")?.GetAttribute("src");
// Assert // Assert
message.Text().Should().Contain("Image attachment"); message.Text().Should().Contain("Image attachment");
imageUrl.Should().StartWithEquivalentOf( message
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png" .QuerySelectorAll("img")
); .Select(e => e.GetAttribute("src"))
.Should()
.Contain(
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
);
} }
[Fact] [Fact]
public async Task Message_with_a_video_attachment_is_rendered_correctly() public async Task Message_with_a_video_attachment_is_rendered_correctly()
{ {
// https://github.com/Tyrrrz/DiscordChatExporter/issues/333
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.AttachmentTestCases, ChannelIds.AttachmentTestCases,
Snowflake.Parse("885655761919836171") Snowflake.Parse("885655761919836171")
); );
var videoUrl = message.QuerySelector("video source")?.GetAttribute("src");
// Assert // Assert
message.Text().Should().Contain("Video attachment"); message.Text().Should().Contain("Video attachment");
videoUrl.Should().StartWithEquivalentOf( var videoUrl = message.QuerySelector("video source")?.GetAttribute("src");
videoUrl.Should().Be(
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4" "https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
); );
} }
@@ -74,18 +87,19 @@ public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixtur
[Fact] [Fact]
public async Task Message_with_an_audio_attachment_is_rendered_correctly() public async Task Message_with_an_audio_attachment_is_rendered_correctly()
{ {
// https://github.com/Tyrrrz/DiscordChatExporter/issues/333
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.AttachmentTestCases, ChannelIds.AttachmentTestCases,
Snowflake.Parse("885656175620808734") Snowflake.Parse("885656175620808734")
); );
var audioUrl = message.QuerySelector("audio source")?.GetAttribute("src");
// Assert // Assert
message.Text().Should().Contain("Audio attachment"); message.Text().Should().Contain("Audio attachment");
audioUrl.Should().StartWithEquivalentOf( var audioUrl = message.QuerySelector("audio source")?.GetAttribute("src");
audioUrl.Should().Be(
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3" "https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
); );
} }
@@ -8,13 +8,20 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting; namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class ContentSpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public ContentSpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task Messages_are_exported_correctly() public async Task Messages_are_exported_correctly()
{ {
// Act // Act
var messages = await ExportWrapper.GetMessagesAsHtmlAsync(ChannelIds.DateRangeTestCases); var messages = await _exportWrapper.GetMessagesAsHtmlAsync(ChannelIds.DateRangeTestCases);
// Assert // Assert
messages.Select(e => e.GetAttribute("data-message-id")).Should().Equal( messages.Select(e => e.GetAttribute("data-message-id")).Should().Equal(
@@ -28,7 +35,7 @@ public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<E
"885169254029213696" "885169254029213696"
); );
messages.Select(e => e.QuerySelector(".chatlog__content")?.Text().Trim()).Should().Equal( messages.SelectMany(e => e.Text()).Should().ContainInOrder(
"Hello world", "Hello world",
"Goodbye world", "Goodbye world",
"Foo bar", "Foo bar",
@@ -1,4 +1,5 @@
using System.Threading.Tasks; using System.Linq;
using System.Threading.Tasks;
using AngleSharp.Dom; using AngleSharp.Dom;
using DiscordChatExporter.Cli.Tests.Fixtures; using DiscordChatExporter.Cli.Tests.Fixtures;
using DiscordChatExporter.Cli.Tests.TestData; using DiscordChatExporter.Cli.Tests.TestData;
@@ -8,13 +9,20 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting; namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public EmbedSpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task Message_with_an_embed_is_rendered_correctly() public async Task Message_with_an_embed_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases, ChannelIds.EmbedTestCases,
Snowflake.Parse("866769910729146400") Snowflake.Parse("866769910729146400")
); );
@@ -32,32 +40,128 @@ public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<Exp
} }
[Fact] [Fact]
public async Task Message_with_a_Spotify_track_is_rendered_using_an_iframe() public async Task Message_containing_an_image_link_is_rendered_with_an_image_embed()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/537
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases,
Snowflake.Parse("991768701126852638")
);
// Assert
message
.QuerySelectorAll("img")
.Select(e => e.GetAttribute("src"))
.Where(s => s?.EndsWith("i.redd.it/f8w05ja8s4e61.png") ?? false)
.Should()
.ContainSingle();
}
[Fact]
public async Task Message_containing_an_image_link_and_nothing_else_is_rendered_without_text_content()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/682
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases,
Snowflake.Parse("991768701126852638")
);
// Assert
var content = message.QuerySelector(".chatlog__content")?.Text();
content.Should().BeNullOrEmpty();
}
[Fact]
public async Task Message_containing_a_gifv_link_is_rendered_with_a_video_embed()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases,
Snowflake.Parse("1019234520349814794")
);
// Assert
message
.QuerySelectorAll("source")
.Select(e => e.GetAttribute("src"))
.Where(s => s?.EndsWith("media.tenor.com/DDAJeW6BQKkAAAPo/tooncasm-test-copy.mp4") ?? false)
.Should()
.ContainSingle();
}
[Fact]
public async Task Message_containing_a_gifv_link_and_nothing_else_is_rendered_without_text_content()
{
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases,
Snowflake.Parse("1019234520349814794")
);
// Assert
var content = message.QuerySelector(".chatlog__content")?.Text();
content.Should().BeNullOrEmpty();
}
[Fact]
public async Task Message_containing_a_Spotify_track_link_is_rendered_with_a_track_embed()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/657
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases, ChannelIds.EmbedTestCases,
Snowflake.Parse("867886632203976775") Snowflake.Parse("867886632203976775")
); );
var iframeSrc = message.QuerySelector("iframe")?.GetAttribute("src");
// Assert // Assert
iframeSrc.Should().StartWithEquivalentOf("https://open.spotify.com/embed/track/1LHZMWefF9502NPfArRfvP"); var iframeUrl = message.QuerySelector("iframe")?.GetAttribute("src");
iframeUrl.Should().Be("https://open.spotify.com/embed/track/1LHZMWefF9502NPfArRfvP");
} }
[Fact] [Fact]
public async Task Message_with_a_YouTube_video_is_rendered_using_an_iframe() public async Task Message_containing_a_YouTube_video_link_is_rendered_with_a_video_embed()
{ {
// https://github.com/Tyrrrz/DiscordChatExporter/issues/570
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases, ChannelIds.EmbedTestCases,
Snowflake.Parse("866472508588294165") Snowflake.Parse("866472508588294165")
); );
var iframeSrc = message.QuerySelector("iframe")?.GetAttribute("src"); // Assert
var iframeUrl = message.QuerySelector("iframe")?.GetAttribute("src");
iframeUrl.Should().Be("https://www.youtube.com/embed/qOWW4OlgbvE");
}
[Fact]
public async Task Message_containing_a_Twitter_post_link_with_multiple_images_is_rendered_as_a_single_embed()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/695
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases,
Snowflake.Parse("991757444017557665")
);
// Assert // Assert
iframeSrc.Should().StartWithEquivalentOf("https://www.youtube.com/embed/qOWW4OlgbvE"); message
.QuerySelectorAll("img")
.Select(e => e.GetAttribute("src"))
.Should()
.ContainInOrder(
"https://images-ext-1.discordapp.net/external/-n--xW3EHH_3jlrheVkMXHCM7T86b5Ty4-MzXCT4m1Q/https/pbs.twimg.com/media/FVYIzYPWAAAMBqZ.png",
"https://images-ext-2.discordapp.net/external/z5nEmGeEldV-kswydGLhqUsFHbb5AWHtdvc9XT6N5rE/https/pbs.twimg.com/media/FVYJBWJWAAMNAx2.png",
"https://images-ext-2.discordapp.net/external/gnip03SawMB6uZLagN5sRDpA_1Ap1CcEhMbJfK1z6WQ/https/pbs.twimg.com/media/FVYJHiRX0AANZcz.png",
"https://images-ext-2.discordapp.net/external/jl1v6cCbLaGmiwmKU-ZkXnF4cFsJ39f9A3-oEdqPdZs/https/pbs.twimg.com/media/FVYJNZNXwAAPnVG.png"
);
message.QuerySelectorAll(".chatlog__embed").Should().ContainSingle();
} }
} }
@@ -0,0 +1,79 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AngleSharp.Dom;
using CliFx.Infrastructure;
using DiscordChatExporter.Cli.Commands;
using DiscordChatExporter.Cli.Tests.Fixtures;
using DiscordChatExporter.Cli.Tests.Infra;
using DiscordChatExporter.Cli.Tests.TestData;
using DiscordChatExporter.Cli.Tests.Utils;
using DiscordChatExporter.Core.Exporting;
using FluentAssertions;
using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
public class GroupingSpecs : IClassFixture<TempOutputFixture>
{
private readonly TempOutputFixture _tempOutput;
public GroupingSpecs(TempOutputFixture tempOutput)
{
_tempOutput = tempOutput;
}
[Fact]
public async Task Messages_are_grouped_correctly()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/152
// Arrange
var filePath = _tempOutput.GetTempFilePath();
// Act
await new ExportChannelsCommand
{
Token = Secrets.DiscordToken,
ChannelIds = new[] { ChannelIds.GroupingTestCases },
ExportFormat = ExportFormat.HtmlDark,
OutputPath = filePath
}.ExecuteAsync(new FakeConsole());
// Assert
var messageGroups = Html
.Parse(await File.ReadAllTextAsync(filePath))
.QuerySelectorAll(".chatlog__message-group");
messageGroups.Should().HaveCount(2);
messageGroups[0]
.QuerySelectorAll(".chatlog__content")
.Select(e => e.Text())
.Should()
.ContainInOrder(
"First",
"Second",
"Third",
"Fourth",
"Fifth",
"Sixth",
"Seventh",
"Eighth",
"Ninth",
"Tenth"
);
messageGroups[1]
.QuerySelectorAll(".chatlog__content")
.Select(e => e.Text())
.Should()
.ContainInOrder(
"Eleventh",
"Twelveth",
"Thirteenth",
"Fourteenth",
"Fifteenth"
);
}
}
@@ -8,19 +8,26 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting; namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class MentionSpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public MentionSpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task User_mention_is_rendered_correctly() public async Task User_mention_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.MentionTestCases, ChannelIds.MentionTestCases,
Snowflake.Parse("866458840245076028") Snowflake.Parse("866458840245076028")
); );
// Assert // Assert
message.Text().Trim().Should().Contain("User mention: @Tyrrrz"); message.Text().Should().Contain("User mention: @Tyrrrz");
message.InnerHtml.Should().Contain("Tyrrrz#5447"); message.InnerHtml.Should().Contain("Tyrrrz#5447");
} }
@@ -28,38 +35,38 @@ public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<E
public async Task Text_channel_mention_is_rendered_correctly() public async Task Text_channel_mention_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.MentionTestCases, ChannelIds.MentionTestCases,
Snowflake.Parse("866459040480624680") Snowflake.Parse("866459040480624680")
); );
// Assert // Assert
message.Text().Trim().Should().Contain("Text channel mention: #mention-tests"); message.Text().Should().Contain("Text channel mention: #mention-tests");
} }
[Fact] [Fact]
public async Task Voice_channel_mention_is_rendered_correctly() public async Task Voice_channel_mention_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.MentionTestCases, ChannelIds.MentionTestCases,
Snowflake.Parse("866459175462633503") Snowflake.Parse("866459175462633503")
); );
// Assert // Assert
message.Text().Trim().Should().Contain("Voice channel mention: 🔊chaos-vc"); message.Text().Should().Contain("Voice channel mention: 🔊chaos-vc");
} }
[Fact] [Fact]
public async Task Role_mention_is_rendered_correctly() public async Task Role_mention_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.MentionTestCases, ChannelIds.MentionTestCases,
Snowflake.Parse("866459254693429258") Snowflake.Parse("866459254693429258")
); );
// Assert // Assert
message.Text().Trim().Should().Contain("Role mention: @Role 1"); message.Text().Should().Contain("Role mention: @Role 1");
} }
} }
@@ -8,49 +8,60 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting; namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
public record ReplySpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class ReplySpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public ReplySpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task Reply_to_a_normal_message_is_rendered_correctly() public async Task Reply_to_a_normal_message_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.ReplyTestCases, ChannelIds.ReplyTestCases,
Snowflake.Parse("866460738239725598") Snowflake.Parse("866460738239725598")
); );
// Assert // Assert
message.Text().Trim().Should().Contain("reply to original"); message.Text().Should().Contain("reply to original");
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should().Contain("original"); message.QuerySelector(".chatlog__reference-link")?.Text().Should().Contain("original");
} }
[Fact] [Fact]
public async Task Reply_to_a_deleted_message_is_rendered_correctly() public async Task Reply_to_a_deleted_message_is_rendered_correctly()
{ {
// https://github.com/Tyrrrz/DiscordChatExporter/issues/645
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.ReplyTestCases, ChannelIds.ReplyTestCases,
Snowflake.Parse("866460975388819486") Snowflake.Parse("866460975388819486")
); );
// Assert // Assert
message.Text().Trim().Should().Contain("reply to deleted"); message.Text().Should().Contain("reply to deleted");
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should() message.QuerySelector(".chatlog__reference-link")?.Text().Should().Contain(
.Contain("Original message was deleted or could not be loaded."); "Original message was deleted or could not be loaded."
);
} }
[Fact] [Fact]
public async Task Reply_to_an_empty_message_with_attachment_is_rendered_correctly() public async Task Reply_to_an_empty_message_with_attachment_is_rendered_correctly()
{ {
// https://github.com/Tyrrrz/DiscordChatExporter/issues/634
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.ReplyTestCases, ChannelIds.ReplyTestCases,
Snowflake.Parse("866462470335627294") Snowflake.Parse("866462470335627294")
); );
// Assert // Assert
message.Text().Trim().Should().Contain("reply to attachment"); message.Text().Should().Contain("reply to attachment");
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should() message.QuerySelector(".chatlog__reference-link")?.Text().Should().Contain("Click to see attachment");
.Contain("Click to see attachment");
} }
} }
@@ -7,39 +7,40 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting; namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
public record StickerSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class StickerSpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public StickerSpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task Message_with_a_PNG_based_sticker_is_rendered_correctly() public async Task Message_with_a_PNG_based_sticker_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.StickerTestCases, ChannelIds.StickerTestCases,
Snowflake.Parse("939670623158943754") Snowflake.Parse("939670623158943754")
); );
var container = message.QuerySelector("[title='rock']");
var sourceUrl = container?.QuerySelector("img")?.GetAttribute("src");
// Assert // Assert
container.Should().NotBeNull(); var stickerUrl = message.QuerySelector("[title='rock'] img")?.GetAttribute("src");
sourceUrl.Should().Be("https://discord.com/stickers/904215665597120572.png"); stickerUrl.Should().Be("https://discord.com/stickers/904215665597120572.png");
} }
[Fact] [Fact]
public async Task Message_with_a_Lottie_based_sticker_is_rendered_correctly() public async Task Message_with_a_Lottie_based_sticker_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsHtmlAsync( var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.StickerTestCases, ChannelIds.StickerTestCases,
Snowflake.Parse("939670526517997590") Snowflake.Parse("939670526517997590")
); );
var container = message.QuerySelector("[title='Yikes']");
var sourceUrl = container?.QuerySelector("div[data-source]")?.GetAttribute("data-source");
// Assert // Assert
container.Should().NotBeNull(); var stickerUrl = message.QuerySelector("[title='Yikes'] [data-source]")?.GetAttribute("data-source");
sourceUrl.Should().Be("https://discord.com/stickers/816087132447178774.json"); stickerUrl.Should().Be("https://discord.com/stickers/816087132447178774.json");
} }
} }
@@ -8,24 +8,30 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting; namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public AttachmentSpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task Message_with_a_generic_attachment_is_rendered_correctly() public async Task Message_with_a_generic_attachment_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsJsonAsync( var message = await _exportWrapper.GetMessageAsJsonAsync(
ChannelIds.AttachmentTestCases, ChannelIds.AttachmentTestCases,
Snowflake.Parse("885587844989612074") Snowflake.Parse("885587844989612074")
); );
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
// Assert // Assert
message.GetProperty("content").GetString().Should().Be("Generic file attachment"); message.GetProperty("content").GetString().Should().Be("Generic file attachment");
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
attachments.Should().HaveCount(1); attachments.Should().HaveCount(1);
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf( attachments.Single().GetProperty("url").GetString().Should().Be(
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt" "https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
); );
attachments.Single().GetProperty("fileName").GetString().Should().Be("Test.txt"); attachments.Single().GetProperty("fileName").GetString().Should().Be("Test.txt");
@@ -36,18 +42,17 @@ public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixtur
public async Task Message_with_an_image_attachment_is_rendered_correctly() public async Task Message_with_an_image_attachment_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsJsonAsync( var message = await _exportWrapper.GetMessageAsJsonAsync(
ChannelIds.AttachmentTestCases, ChannelIds.AttachmentTestCases,
Snowflake.Parse("885654862656843786") Snowflake.Parse("885654862656843786")
); );
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
// Assert // Assert
message.GetProperty("content").GetString().Should().Be("Image attachment"); message.GetProperty("content").GetString().Should().Be("Image attachment");
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
attachments.Should().HaveCount(1); attachments.Should().HaveCount(1);
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf( attachments.Single().GetProperty("url").GetString().Should().Be(
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png" "https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
); );
attachments.Single().GetProperty("fileName").GetString().Should().Be("bird-thumbnail.png"); attachments.Single().GetProperty("fileName").GetString().Should().Be("bird-thumbnail.png");
@@ -58,18 +63,17 @@ public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixtur
public async Task Message_with_a_video_attachment_is_rendered_correctly() public async Task Message_with_a_video_attachment_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsJsonAsync( var message = await _exportWrapper.GetMessageAsJsonAsync(
ChannelIds.AttachmentTestCases, ChannelIds.AttachmentTestCases,
Snowflake.Parse("885655761919836171") Snowflake.Parse("885655761919836171")
); );
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
// Assert // Assert
message.GetProperty("content").GetString().Should().Be("Video attachment"); message.GetProperty("content").GetString().Should().Be("Video attachment");
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
attachments.Should().HaveCount(1); attachments.Should().HaveCount(1);
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf( attachments.Single().GetProperty("url").GetString().Should().Be(
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4" "https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
); );
attachments.Single().GetProperty("fileName").GetString().Should().Be("file_example_MP4_640_3MG.mp4"); attachments.Single().GetProperty("fileName").GetString().Should().Be("file_example_MP4_640_3MG.mp4");
@@ -80,18 +84,17 @@ public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixtur
public async Task Message_with_an_audio_attachment_is_rendered_correctly() public async Task Message_with_an_audio_attachment_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsJsonAsync( var message = await _exportWrapper.GetMessageAsJsonAsync(
ChannelIds.AttachmentTestCases, ChannelIds.AttachmentTestCases,
Snowflake.Parse("885656175620808734") Snowflake.Parse("885656175620808734")
); );
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
// Assert // Assert
message.GetProperty("content").GetString().Should().Be("Audio attachment"); message.GetProperty("content").GetString().Should().Be("Audio attachment");
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
attachments.Should().HaveCount(1); attachments.Should().HaveCount(1);
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf( attachments.Single().GetProperty("url").GetString().Should().Be(
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3" "https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
); );
attachments.Single().GetProperty("fileName").GetString().Should().Be("file_example_MP3_1MG.mp3"); attachments.Single().GetProperty("fileName").GetString().Should().Be("file_example_MP3_1MG.mp3");
@@ -7,13 +7,20 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting; namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class ContentSpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public ContentSpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task Messages_are_exported_correctly() public async Task Messages_are_exported_correctly()
{ {
// Act // Act
var messages = await ExportWrapper.GetMessagesAsJsonAsync(ChannelIds.DateRangeTestCases); var messages = await _exportWrapper.GetMessagesAsJsonAsync(ChannelIds.DateRangeTestCases);
// Assert // Assert
messages.Select(j => j.GetProperty("id").GetString()).Should().Equal( messages.Select(j => j.GetProperty("id").GetString()).Should().Equal(
@@ -8,41 +8,47 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting; namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public EmbedSpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task Message_with_an_embed_is_rendered_correctly() public async Task Message_with_an_embed_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsJsonAsync( var message = await _exportWrapper.GetMessageAsJsonAsync(
ChannelIds.EmbedTestCases, ChannelIds.EmbedTestCases,
Snowflake.Parse("866769910729146400") Snowflake.Parse("866769910729146400")
); );
var embed = message
.GetProperty("embeds")
.EnumerateArray()
.Single();
var embedAuthor = embed.GetProperty("author");
var embedThumbnail = embed.GetProperty("thumbnail");
var embedFooter = embed.GetProperty("footer");
var embedFields = embed.GetProperty("fields").EnumerateArray().ToArray();
// Assert // Assert
var embed = message.GetProperty("embeds").EnumerateArray().Single();
embed.GetProperty("title").GetString().Should().Be("Embed title"); embed.GetProperty("title").GetString().Should().Be("Embed title");
embed.GetProperty("url").GetString().Should().Be("https://example.com"); embed.GetProperty("url").GetString().Should().Be("https://example.com");
embed.GetProperty("timestamp").GetString().Should().Be("2021-07-14T21:00:00+00:00"); embed.GetProperty("timestamp").GetString().Should().Be("2021-07-14T21:00:00+00:00");
embed.GetProperty("description").GetString().Should().Be("**Embed** _description_"); embed.GetProperty("description").GetString().Should().Be("**Embed** _description_");
embed.GetProperty("color").GetString().Should().Be("#58B9FF"); embed.GetProperty("color").GetString().Should().Be("#58B9FF");
var embedAuthor = embed.GetProperty("author");
embedAuthor.GetProperty("name").GetString().Should().Be("Embed author"); embedAuthor.GetProperty("name").GetString().Should().Be("Embed author");
embedAuthor.GetProperty("url").GetString().Should().Be("https://example.com/author"); embedAuthor.GetProperty("url").GetString().Should().Be("https://example.com/author");
embedAuthor.GetProperty("iconUrl").GetString().Should().NotBeNullOrWhiteSpace(); embedAuthor.GetProperty("iconUrl").GetString().Should().NotBeNullOrWhiteSpace();
var embedThumbnail = embed.GetProperty("thumbnail");
embedThumbnail.GetProperty("url").GetString().Should().NotBeNullOrWhiteSpace(); embedThumbnail.GetProperty("url").GetString().Should().NotBeNullOrWhiteSpace();
embedThumbnail.GetProperty("width").GetInt32().Should().Be(120); embedThumbnail.GetProperty("width").GetInt32().Should().Be(120);
embedThumbnail.GetProperty("height").GetInt32().Should().Be(120); embedThumbnail.GetProperty("height").GetInt32().Should().Be(120);
var embedFooter = embed.GetProperty("footer");
embedFooter.GetProperty("text").GetString().Should().Be("Embed footer"); embedFooter.GetProperty("text").GetString().Should().Be("Embed footer");
embedFooter.GetProperty("iconUrl").GetString().Should().NotBeNullOrWhiteSpace(); embedFooter.GetProperty("iconUrl").GetString().Should().NotBeNullOrWhiteSpace();
var embedFields = embed.GetProperty("fields").EnumerateArray().ToArray();
embedFields.Should().HaveCount(3); embedFields.Should().HaveCount(3);
embedFields[0].GetProperty("name").GetString().Should().Be("Field 1"); embedFields[0].GetProperty("name").GetString().Should().Be("Field 1");
embedFields[0].GetProperty("value").GetString().Should().Be("Value 1"); embedFields[0].GetProperty("value").GetString().Should().Be("Value 1");
@@ -8,13 +8,20 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting; namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class MentionSpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public MentionSpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task User_mention_is_rendered_correctly() public async Task User_mention_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsJsonAsync( var message = await _exportWrapper.GetMessageAsJsonAsync(
ChannelIds.MentionTestCases, ChannelIds.MentionTestCases,
Snowflake.Parse("866458840245076028") Snowflake.Parse("866458840245076028")
); );
@@ -26,14 +33,15 @@ public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<E
.GetProperty("mentions") .GetProperty("mentions")
.EnumerateArray() .EnumerateArray()
.Select(j => j.GetProperty("id").GetString()) .Select(j => j.GetProperty("id").GetString())
.Should().Contain("128178626683338752"); .Should()
.Contain("128178626683338752");
} }
[Fact] [Fact]
public async Task Text_channel_mention_is_rendered_correctly() public async Task Text_channel_mention_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsJsonAsync( var message = await _exportWrapper.GetMessageAsJsonAsync(
ChannelIds.MentionTestCases, ChannelIds.MentionTestCases,
Snowflake.Parse("866459040480624680") Snowflake.Parse("866459040480624680")
); );
@@ -46,7 +54,7 @@ public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<E
public async Task Voice_channel_mention_is_rendered_correctly() public async Task Voice_channel_mention_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsJsonAsync( var message = await _exportWrapper.GetMessageAsJsonAsync(
ChannelIds.MentionTestCases, ChannelIds.MentionTestCases,
Snowflake.Parse("866459175462633503") Snowflake.Parse("866459175462633503")
); );
@@ -59,7 +67,7 @@ public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<E
public async Task Role_mention_is_rendered_correctly() public async Task Role_mention_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsJsonAsync( var message = await _exportWrapper.GetMessageAsJsonAsync(
ChannelIds.MentionTestCases, ChannelIds.MentionTestCases,
Snowflake.Parse("866459254693429258") Snowflake.Parse("866459254693429258")
); );
@@ -8,23 +8,30 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting; namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
public record StickerSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class StickerSpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public StickerSpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task Message_with_a_PNG_based_sticker_is_rendered_correctly() public async Task Message_with_a_PNG_based_sticker_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsJsonAsync( var message = await _exportWrapper.GetMessageAsJsonAsync(
ChannelIds.StickerTestCases, ChannelIds.StickerTestCases,
Snowflake.Parse("939670623158943754") Snowflake.Parse("939670623158943754")
); );
// Assert
var sticker = message var sticker = message
.GetProperty("stickers") .GetProperty("stickers")
.EnumerateArray() .EnumerateArray()
.Single(); .Single();
// Assert
sticker.GetProperty("id").GetString().Should().Be("904215665597120572"); sticker.GetProperty("id").GetString().Should().Be("904215665597120572");
sticker.GetProperty("name").GetString().Should().Be("rock"); sticker.GetProperty("name").GetString().Should().Be("rock");
sticker.GetProperty("format").GetString().Should().Be("PngAnimated"); sticker.GetProperty("format").GetString().Should().Be("PngAnimated");
@@ -35,17 +42,17 @@ public record StickerSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<E
public async Task Message_with_a_Lottie_based_sticker_is_rendered_correctly() public async Task Message_with_a_Lottie_based_sticker_is_rendered_correctly()
{ {
// Act // Act
var message = await ExportWrapper.GetMessageAsJsonAsync( var message = await _exportWrapper.GetMessageAsJsonAsync(
ChannelIds.StickerTestCases, ChannelIds.StickerTestCases,
Snowflake.Parse("939670526517997590") Snowflake.Parse("939670526517997590")
); );
// Assert
var sticker = message var sticker = message
.GetProperty("stickers") .GetProperty("stickers")
.EnumerateArray() .EnumerateArray()
.Single(); .Single();
// Assert
sticker.GetProperty("id").GetString().Should().Be("816087132447178774"); sticker.GetProperty("id").GetString().Should().Be("816087132447178774");
sticker.GetProperty("name").GetString().Should().Be("Yikes"); sticker.GetProperty("name").GetString().Should().Be("Yikes");
sticker.GetProperty("format").GetString().Should().Be("Lottie"); sticker.GetProperty("format").GetString().Should().Be("Lottie");
@@ -12,13 +12,20 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs; namespace DiscordChatExporter.Cli.Tests.Specs;
public record PartitioningSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture> public class PartitioningSpecs : IClassFixture<TempOutputFixture>
{ {
private readonly TempOutputFixture _tempOutput;
public PartitioningSpecs(TempOutputFixture tempOutput)
{
_tempOutput = tempOutput;
}
[Fact] [Fact]
public async Task Messages_partitioned_by_count_are_split_into_multiple_files_correctly() public async Task Messages_partitioned_by_count_are_split_into_a_corresponding_number_of_files()
{ {
// Arrange // Arrange
var filePath = TempOutput.GetTempFilePath(); var filePath = _tempOutput.GetTempFilePath();
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath); var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory(); var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
@@ -39,10 +46,10 @@ public record PartitioningSpecs(TempOutputFixture TempOutput) : IClassFixture<Te
} }
[Fact] [Fact]
public async Task Messages_partitioned_by_file_size_are_split_into_multiple_files_correctly() public async Task Messages_partitioned_by_file_size_are_split_into_a_corresponding_number_of_files()
{ {
// Arrange // Arrange
var filePath = TempOutput.GetTempFilePath(); var filePath = _tempOutput.GetTempFilePath();
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath); var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory(); var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
@@ -53,7 +60,7 @@ public record PartitioningSpecs(TempOutputFixture TempOutput) : IClassFixture<Te
ChannelIds = new[] { ChannelIds.DateRangeTestCases }, ChannelIds = new[] { ChannelIds.DateRangeTestCases },
ExportFormat = ExportFormat.HtmlDark, ExportFormat = ExportFormat.HtmlDark,
OutputPath = filePath, OutputPath = filePath,
PartitionLimit = PartitionLimit.Parse("20kb") PartitionLimit = PartitionLimit.Parse("1kb")
}.ExecuteAsync(new FakeConsole()); }.ExecuteAsync(new FakeConsole());
// Assert // Assert
@@ -6,13 +6,20 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.PlainTextWriting; namespace DiscordChatExporter.Cli.Tests.Specs.PlainTextWriting;
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture> public class ContentSpecs : IClassFixture<ExportWrapperFixture>
{ {
private readonly ExportWrapperFixture _exportWrapper;
public ContentSpecs(ExportWrapperFixture exportWrapper)
{
_exportWrapper = exportWrapper;
}
[Fact] [Fact]
public async Task Messages_are_exported_correctly() public async Task Messages_are_exported_correctly()
{ {
// Act // Act
var document = await ExportWrapper.ExportAsPlainTextAsync(ChannelIds.DateRangeTestCases); var document = await _exportWrapper.ExportAsPlainTextAsync(ChannelIds.DateRangeTestCases);
// Assert // Assert
document.Should().ContainAll( document.Should().ContainAll(
@@ -13,13 +13,20 @@ using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs; namespace DiscordChatExporter.Cli.Tests.Specs;
public record SelfContainedSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture> public class SelfContainedSpecs : IClassFixture<TempOutputFixture>
{ {
private readonly TempOutputFixture _tempOutput;
public SelfContainedSpecs(TempOutputFixture tempOutput)
{
_tempOutput = tempOutput;
}
[Fact] [Fact]
public async Task Messages_in_self_contained_export_only_reference_local_file_resources() public async Task Messages_in_self_contained_export_only_reference_local_file_resources()
{ {
// Arrange // Arrange
var filePath = TempOutput.GetTempFilePath(); var filePath = _tempOutput.GetTempFilePath();
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory(); var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
// Act // Act
@@ -32,11 +39,9 @@ public record SelfContainedSpecs(TempOutputFixture TempOutput) : IClassFixture<T
ShouldDownloadMedia = true ShouldDownloadMedia = true
}.ExecuteAsync(new FakeConsole()); }.ExecuteAsync(new FakeConsole());
var data = await File.ReadAllTextAsync(filePath);
var document = Html.Parse(data);
// Assert // Assert
document Html
.Parse(await File.ReadAllTextAsync(filePath))
.QuerySelectorAll("body [src]") .QuerySelectorAll("body [src]")
.Select(e => e.GetAttribute("src")!) .Select(e => e.GetAttribute("src")!)
.Select(f => Path.GetFullPath(f, dirPath)) .Select(f => Path.GetFullPath(f, dirPath))
@@ -10,7 +10,7 @@ public static class ChannelIds
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 GroupingTestCases { get; } = Snowflake.Parse("992092091545034842");
public static Snowflake FilterTestCases { get; } = Snowflake.Parse("866744075033641020"); public static Snowflake FilterTestCases { get; } = Snowflake.Parse("866744075033641020");
@@ -19,4 +19,6 @@ public static class ChannelIds
public static Snowflake ReplyTestCases { get; } = Snowflake.Parse("866459871934677052"); public static Snowflake ReplyTestCases { get; } = Snowflake.Parse("866459871934677052");
public static Snowflake SelfContainedTestCases { get; } = Snowflake.Parse("887441432678379560"); public static Snowflake SelfContainedTestCases { get; } = Snowflake.Parse("887441432678379560");
public static Snowflake StickerTestCases { get; } = Snowflake.Parse("939668868253769729");
} }
+18
View File
@@ -0,0 +1,18 @@
# Build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
COPY favicon.ico ./
COPY NuGet.config ./
COPY Directory.Build.props ./
COPY DiscordChatExporter.Core ./DiscordChatExporter.Core
COPY DiscordChatExporter.Cli ./DiscordChatExporter.Cli
RUN dotnet publish DiscordChatExporter.Cli -c Release -o ./publish
# Run
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS run
COPY --from=build ./publish ./
WORKDIR ./out
ENTRYPOINT ["dotnet", "/DiscordChatExporter.Cli.dll"]
@@ -14,40 +14,82 @@ 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;
using Gress; 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.")] private readonly string _outputPath = Directory.GetCurrentDirectory();
public string OutputPath { get; init; } = Directory.GetCurrentDirectory();
[CommandOption("format", 'f', Description = "Export format.")] [CommandOption(
"output",
'o',
Description = "Output file or directory path. Directory path should end in a slash."
)]
public string OutputPath
{
get => _outputPath;
// Handle ~/ in paths on *nix systems
// https://github.com/Tyrrrz/DiscordChatExporter/pull/903
init => _outputPath = Path.GetFullPath(value);
}
[CommandOption(
"format",
'f',
Description = "Export format."
)]
public ExportFormat ExportFormat { get; init; } = ExportFormat.HtmlDark; public ExportFormat ExportFormat { get; init; } = ExportFormat.HtmlDark;
[CommandOption("after", Description = "Only include messages sent after this date or message ID.")] [CommandOption(
"after",
Description = "Only include messages sent after this date or message ID."
)]
public Snowflake? After { get; init; } public Snowflake? After { get; init; }
[CommandOption("before", Description = "Only include messages sent before this date or message ID.")] [CommandOption(
"before",
Description = "Only include messages sent before this date or message ID."
)]
public Snowflake? Before { get; init; } public Snowflake? Before { get; init; }
[CommandOption("partition", 'p', Description = "Split output into partitions, each limited to this number of messages (e.g. '100') or file size (e.g. '10mb').")] [CommandOption(
"partition",
'p',
Description = "Split output into partitions, each limited to this number of messages (e.g. '100') or file size (e.g. '10mb')."
)]
public PartitionLimit PartitionLimit { get; init; } = PartitionLimit.Null; public PartitionLimit PartitionLimit { get; init; } = PartitionLimit.Null;
[CommandOption("filter", Description = "Only include messages that satisfy this filter (e.g. 'from:foo#1234' or 'has:image').")] [CommandOption(
"filter",
Description = "Only include messages that satisfy this filter (e.g. 'from:foo#1234' or 'has:image')."
)]
public MessageFilter MessageFilter { get; init; } = MessageFilter.Null; public MessageFilter MessageFilter { get; init; } = MessageFilter.Null;
[CommandOption("parallel", Description = "Limits how many channels can be exported in parallel.")] [CommandOption(
"parallel",
Description = "Limits how many channels can be exported in parallel."
)]
public int ParallelLimit { get; init; } = 1; public int ParallelLimit { get; init; } = 1;
[CommandOption("media", Description = "Download referenced media content.")] [CommandOption(
"media",
Description = "Download referenced media content."
)]
public bool ShouldDownloadMedia { get; init; } public bool ShouldDownloadMedia { get; init; }
[CommandOption("reuse-media", Description = "Reuse already existing media content to skip redundant downloads.")] [CommandOption(
"reuse-media",
Description = "Reuse already existing media content to skip redundant downloads."
)]
public bool ShouldReuseMedia { get; init; } public bool ShouldReuseMedia { get; init; }
[CommandOption("dateformat", Description = "Format used when writing dates.")] [CommandOption(
"dateformat",
Description = "Format used when writing dates."
)]
public string DateFormat { get; init; } = "dd-MMM-yy hh:mm tt"; public string DateFormat { get; init; } = "dd-MMM-yy hh:mm tt";
private ChannelExporter? _channelExporter; private ChannelExporter? _channelExporter;
@@ -55,13 +97,36 @@ public abstract class ExportCommandBase : TokenCommandBase
protected async ValueTask ExecuteAsync(IConsole console, IReadOnlyList<Channel> channels) protected async ValueTask ExecuteAsync(IConsole console, IReadOnlyList<Channel> channels)
{ {
var cancellationToken = console.RegisterCancellationHandler(); // Reuse media option should only be used when the media option is set.
// https://github.com/Tyrrrz/DiscordChatExporter/issues/425
if (ShouldReuseMedia && !ShouldDownloadMedia) if (ShouldReuseMedia && !ShouldDownloadMedia)
{ {
throw new CommandException("Option --reuse-media cannot be used without --media."); throw new CommandException(
"Option --reuse-media cannot be used without --media."
);
} }
// Make sure the user does not try to export all channels into a single file.
// Output path must either be a directory, or contain template tokens.
// https://github.com/Tyrrrz/DiscordChatExporter/issues/799
// https://github.com/Tyrrrz/DiscordChatExporter/issues/917
var isValidOutputPath =
// Anything is valid when exporting a single channel
channels.Count <= 1 ||
// When using template tokens, assume the user knows what they're doing
OutputPath.Contains('%') ||
// Otherwise, require an existing directory or an unambiguous directory path
Directory.Exists(OutputPath) || PathEx.IsDirectoryPath(OutputPath);
if (!isValidOutputPath)
{
throw new CommandException(
"Attempted to export multiple channels, but the output path is neither a directory nor a template. " +
"If the provided output path is meant to be treated as a directory, make sure it ends with a slash."
);
}
var cancellationToken = console.RegisterCancellationHandler();
var errors = new ConcurrentDictionary<Channel, string>(); var errors = new ConcurrentDictionary<Channel, string>();
// Export // Export
@@ -171,8 +236,8 @@ public abstract class ExportCommandBase : TokenCommandBase
{ {
// War in Ukraine message // War in Ukraine message
console.Output.WriteLine("========================================================================"); console.Output.WriteLine("========================================================================");
console.Output.WriteLine("|| Ukraine is at war! Support my country in its fight for freedom ||"); 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("|| Learn more on my website: https://tyrrrz.me ||");
console.Output.WriteLine("========================================================================"); console.Output.WriteLine("========================================================================");
console.Output.WriteLine(""); console.Output.WriteLine("");
@@ -9,11 +9,22 @@ 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 Token { get; init; } = ""; public string Token { get; init; } = "";
[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.")] [Obsolete("This option doesn't do anything. Kept for backwards compatibility.")]
[CommandOption(
"bot",
'b',
EnvironmentVariable = "DISCORD_TOKEN_BOT",
Description = "This option doesn't do anything. Kept for backwards compatibility."
)]
public bool IsBotToken { get; init; } public bool IsBotToken { get; init; }
private DiscordClient? _discordClient; private DiscordClient? _discordClient;
@@ -10,7 +10,10 @@ 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
{ {
[CommandOption("include-dm", Description = "Include direct message channels.")] [CommandOption(
"include-dm",
Description = "Include direct message channels."
)]
public bool IncludeDirectMessages { get; init; } = true; public bool IncludeDirectMessages { get; init; } = true;
public override async ValueTask ExecuteAsync(IConsole console) public override async ValueTask ExecuteAsync(IConsole console)
@@ -28,13 +31,7 @@ public class ExportAllCommand : ExportCommandBase
continue; continue;
await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken)) await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken))
{
// Skip non-text channels
if (!channel.IsTextChannel)
continue;
channels.Add(channel); channels.Add(channel);
}
} }
await base.ExecuteAsync(console, channels); await base.ExecuteAsync(console, channels);
@@ -12,7 +12,12 @@ namespace DiscordChatExporter.Cli.Commands;
public class ExportChannelsCommand : ExportCommandBase public class ExportChannelsCommand : ExportCommandBase
{ {
// TODO: change this to plural (breaking change) // TODO: change this to plural (breaking change)
[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)
@@ -18,9 +18,11 @@ public class ExportDirectMessagesCommand : ExportCommandBase
var cancellationToken = console.RegisterCancellationHandler(); var cancellationToken = console.RegisterCancellationHandler();
await console.Output.WriteLineAsync("Fetching channels..."); await console.Output.WriteLineAsync("Fetching channels...");
var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken);
var textChannels = channels.Where(c => c.IsTextChannel).ToArray();
await base.ExecuteAsync(console, textChannels); var channels = (await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken))
.Where(c => c.Kind != ChannelKind.GuildCategory)
.ToArray();
await base.ExecuteAsync(console, channels);
} }
} }
@@ -4,6 +4,7 @@ using CliFx.Attributes;
using CliFx.Infrastructure; using CliFx.Infrastructure;
using DiscordChatExporter.Cli.Commands.Base; using DiscordChatExporter.Cli.Commands.Base;
using DiscordChatExporter.Core.Discord; using DiscordChatExporter.Core.Discord;
using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Utils.Extensions; using DiscordChatExporter.Core.Utils.Extensions;
namespace DiscordChatExporter.Cli.Commands; namespace DiscordChatExporter.Cli.Commands;
@@ -11,7 +12,12 @@ 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
{ {
[CommandOption("guild", 'g', IsRequired = true, Description = "Guild ID.")] [CommandOption(
"guild",
'g',
IsRequired = true,
Description = "Guild ID."
)]
public Snowflake GuildId { get; init; } public Snowflake GuildId { get; init; }
public override async ValueTask ExecuteAsync(IConsole console) public override async ValueTask ExecuteAsync(IConsole console)
@@ -21,9 +27,11 @@ public class ExportGuildCommand : ExportCommandBase
var cancellationToken = console.RegisterCancellationHandler(); var cancellationToken = console.RegisterCancellationHandler();
await console.Output.WriteLineAsync("Fetching channels..."); await console.Output.WriteLineAsync("Fetching channels...");
var channels = await Discord.GetGuildChannelsAsync(GuildId, cancellationToken);
var textChannels = channels.Where(c => c.IsTextChannel).ToArray();
await base.ExecuteAsync(console, textChannels); var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken))
.Where(c => c.Kind != ChannelKind.GuildCategory)
.ToArray();
await base.ExecuteAsync(console, channels);
} }
} }
@@ -5,6 +5,7 @@ using CliFx.Attributes;
using CliFx.Infrastructure; using CliFx.Infrastructure;
using DiscordChatExporter.Cli.Commands.Base; using DiscordChatExporter.Cli.Commands.Base;
using DiscordChatExporter.Core.Discord; using DiscordChatExporter.Core.Discord;
using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Utils.Extensions; using DiscordChatExporter.Core.Utils.Extensions;
namespace DiscordChatExporter.Cli.Commands; namespace DiscordChatExporter.Cli.Commands;
@@ -12,25 +13,30 @@ 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
{ {
[CommandOption("guild", 'g', IsRequired = true, Description = "Guild ID.")] [CommandOption(
"guild",
'g',
IsRequired = true,
Description = "Guild ID."
)]
public Snowflake GuildId { get; init; } public Snowflake GuildId { get; init; }
public override async ValueTask ExecuteAsync(IConsole console) public override async ValueTask ExecuteAsync(IConsole console)
{ {
var cancellationToken = console.RegisterCancellationHandler(); var cancellationToken = console.RegisterCancellationHandler();
var channels = await Discord.GetGuildChannelsAsync(GuildId, cancellationToken); var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken))
.Where(c => c.Kind != ChannelKind.GuildCategory)
var textChannels = channels
.Where(c => c.IsTextChannel)
.OrderBy(c => c.Category.Position) .OrderBy(c => c.Category.Position)
.ThenBy(c => c.Name) .ThenBy(c => c.Name)
.ToArray(); .ToArray();
foreach (var channel in textChannels) foreach (var channel in channels)
{ {
// Channel ID // Channel ID
await console.Output.WriteAsync(channel.Id.ToString()); await console.Output.WriteAsync(
channel.Id.ToString().PadRight(18, ' ')
);
// Separator // Separator
using (console.WithForegroundColor(ConsoleColor.DarkGray)) using (console.WithForegroundColor(ConsoleColor.DarkGray))
@@ -16,18 +16,18 @@ public class GetDirectMessageChannelsCommand : TokenCommandBase
{ {
var cancellationToken = console.RegisterCancellationHandler(); var cancellationToken = console.RegisterCancellationHandler();
var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken); var channels = (await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken))
.Where(c => c.Kind != ChannelKind.GuildCategory)
var textChannels = channels .OrderByDescending(c => c.LastMessageId)
.Where(c => c.IsTextChannel)
.OrderBy(c => c.Category.Position)
.ThenBy(c => c.Name) .ThenBy(c => c.Name)
.ToArray(); .ToArray();
foreach (var channel in textChannels) foreach (var channel in channels)
{ {
// Channel ID // Channel ID
await console.Output.WriteAsync(channel.Id.ToString()); await console.Output.WriteAsync(
channel.Id.ToString().PadRight(18, ' ')
);
// Separator // Separator
using (console.WithForegroundColor(ConsoleColor.DarkGray)) using (console.WithForegroundColor(ConsoleColor.DarkGray))
@@ -4,6 +4,7 @@ using System.Threading.Tasks;
using CliFx.Attributes; using CliFx.Attributes;
using CliFx.Infrastructure; using CliFx.Infrastructure;
using DiscordChatExporter.Cli.Commands.Base; using DiscordChatExporter.Cli.Commands.Base;
using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Utils.Extensions; using DiscordChatExporter.Core.Utils.Extensions;
namespace DiscordChatExporter.Cli.Commands; namespace DiscordChatExporter.Cli.Commands;
@@ -15,12 +16,17 @@ public class GetGuildsCommand : TokenCommandBase
{ {
var cancellationToken = console.RegisterCancellationHandler(); var cancellationToken = console.RegisterCancellationHandler();
var guilds = await Discord.GetUserGuildsAsync(cancellationToken); var guilds = (await Discord.GetUserGuildsAsync(cancellationToken))
// Show direct messages first
.OrderByDescending(g => g.Id == Guild.DirectMessages.Id)
.ThenBy(g => g.Name);
foreach (var guild in guilds.OrderBy(g => g.Name)) foreach (var guild in guilds)
{ {
// Guild ID // Guild ID
await console.Output.WriteAsync(guild.Id.ToString()); await console.Output.WriteAsync(
guild.Id.ToString().PadRight(18, ' ')
);
// Separator // Separator
using (console.WithForegroundColor(ConsoleColor.DarkGray)) using (console.WithForegroundColor(ConsoleColor.DarkGray))
@@ -15,15 +15,16 @@ public class GuideCommand : ICommand
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(" * Automating user accounts is technically against TOS — USE AT YOUR OWN RISK!");
console.Output.WriteLine(" 1. Open Discord in your web browser and login"); 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. Open any server or direct message channel");
console.Output.WriteLine(" 3. Press Ctrl+Shift+M to toggle device toolbar"); console.Output.WriteLine(" 3. Press Ctrl+Shift+I to show developer tools");
console.Output.WriteLine(" 4. Navigate to the Application tab"); console.Output.WriteLine(" 4. Navigate to the Network tab");
console.Output.WriteLine(" 5. On the left, expand Local Storage and select https://discord.com"); console.Output.WriteLine(" 5. Press Ctrl+R to reload");
console.Output.WriteLine(" 6. Type \"token\" into the Filter box"); console.Output.WriteLine(" 6. Search for a request containing \"messages?limit=50\" or similar");
console.Output.WriteLine(" 7. If the token key does not appear, press Ctrl+R to reload"); console.Output.WriteLine(" 7. Select the Headers tab on the right");
console.Output.WriteLine(" 8. Copy the value of the token key"); console.Output.WriteLine(" 8. Scroll down to the Request Headers section");
console.Output.WriteLine(" * Automating user accounts is technically against TOS, use at your own risk."); console.Output.WriteLine(" 9. Copy the value of the \"authorization\" header");
console.Output.WriteLine(); console.Output.WriteLine();
// Bot token // Bot token
@@ -34,6 +35,7 @@ public class GuideCommand : ICommand
console.Output.WriteLine(" 2. Open your application's settings"); console.Output.WriteLine(" 2. Open your application's settings");
console.Output.WriteLine(" 3. Navigate to the Bot section on the left"); console.Output.WriteLine(" 3. Navigate to the Bot section on the left");
console.Output.WriteLine(" 4. Under Token click Copy"); console.Output.WriteLine(" 4. Under Token click Copy");
console.Output.WriteLine(" * Your bot needs to have Message Content Intent enabled to read messages");
console.Output.WriteLine(); console.Output.WriteLine();
// Guild or channel ID // Guild or channel ID
@@ -42,7 +44,7 @@ public class GuideCommand : ICommand
console.Output.WriteLine(" 1. Open Discord"); console.Output.WriteLine(" 1. Open Discord");
console.Output.WriteLine(" 2. Open Settings"); console.Output.WriteLine(" 2. Open Settings");
console.Output.WriteLine(" 3. Go to Appearance section"); console.Output.WriteLine(" 3. Go to Advanced section");
console.Output.WriteLine(" 4. Enable Developer Mode"); console.Output.WriteLine(" 4. Enable Developer Mode");
console.Output.WriteLine(" 5. Right click on the desired guild or channel and click Copy ID"); console.Output.WriteLine(" 5. Right click on the desired guild or channel and click Copy ID");
console.Output.WriteLine(); console.Output.WriteLine();
@@ -6,9 +6,10 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CliFx" Version="2.2.2" /> <PackageReference Include="CliFx" Version="2.3.0" />
<PackageReference Include="Spectre.Console" Version="0.44.0" /> <PackageReference Include="Spectre.Console" Version="0.44.0" />
<PackageReference Include="Gress" Version="2.0.1" /> <PackageReference Include="Gress" Version="2.0.1" />
<PackageReference Include="DotnetRuntimeBootstrapper" Version="2.3.1" PrivateAssets="all" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -35,10 +35,10 @@ public partial record Attachment
{ {
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")?.GetInt32OrNull();
var height = json.GetPropertyOrNull("height")?.GetInt32OrNull();
var fileName = json.GetProperty("filename").GetNonNullString(); var fileName = json.GetProperty("filename").GetNonNullString();
var description = json.GetPropertyOrNull("description")?.GetNonWhiteSpaceStringOrNull(); var description = json.GetPropertyOrNull("description")?.GetNonWhiteSpaceStringOrNull();
var width = json.GetPropertyOrNull("width")?.GetInt32OrNull();
var height = json.GetPropertyOrNull("height")?.GetInt32OrNull();
var fileSize = json.GetProperty("size").GetInt64().Pipe(FileSize.FromBytes); var fileSize = json.GetProperty("size").GetInt64().Pipe(FileSize.FromBytes);
return new Attachment(id, url, fileName, description, width, height, fileSize); return new Attachment(id, url, fileName, description, width, height, fileSize);
@@ -14,16 +14,10 @@ public partial record Channel(
ChannelCategory Category, ChannelCategory Category,
string Name, string Name,
int? Position, int? Position,
string? Topic) : IHasId string? Topic,
Snowflake? LastMessageId) : IHasId
{ {
public bool IsTextChannel => Kind is public bool SupportsVoice => Kind is ChannelKind.GuildVoiceChat or ChannelKind.GuildStageVoice;
ChannelKind.GuildTextChat or
ChannelKind.DirectTextChat or
ChannelKind.DirectGroupTextChat or
ChannelKind.GuildNews or
ChannelKind.GuildStore;
public bool IsVoiceChannel => !IsTextChannel;
} }
public partial record Channel public partial record Channel
@@ -36,7 +30,6 @@ public partial record Channel
ChannelKind.DirectTextChat => "Private", ChannelKind.DirectTextChat => "Private",
ChannelKind.DirectGroupTextChat => "Group", ChannelKind.DirectGroupTextChat => "Group",
ChannelKind.GuildNews => "News", ChannelKind.GuildNews => "News",
ChannelKind.GuildStore => "Store",
_ => "Default" _ => "Default"
}, },
null null
@@ -45,9 +38,8 @@ public partial record Channel
public static Channel Parse(JsonElement json, ChannelCategory? category = null, int? positionHint = 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")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
var topic = json.GetPropertyOrNull("topic")?.GetStringOrNull();
var kind = (ChannelKind)json.GetProperty("type").GetInt32(); var kind = (ChannelKind)json.GetProperty("type").GetInt32();
var guildId = json.GetPropertyOrNull("guild_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
var name = var name =
// Guild channel // Guild channel
@@ -63,7 +55,16 @@ public partial record Channel
// Fallback // Fallback
id.ToString(); id.ToString();
var position = positionHint ?? json.GetPropertyOrNull("position")?.GetInt32OrNull(); var position =
positionHint ??
json.GetPropertyOrNull("position")?.GetInt32OrNull();
var topic = json.GetPropertyOrNull("topic")?.GetStringOrNull();
var lastMessageId = json
.GetPropertyOrNull("last_message_id")?
.GetNonWhiteSpaceStringOrNull()?
.Pipe(Snowflake.Parse);
return new Channel( return new Channel(
id, id,
@@ -72,7 +73,8 @@ public partial record Channel
category ?? GetFallbackCategory(kind), category ?? GetFallbackCategory(kind),
name, name,
position, position,
topic topic,
lastMessageId
); );
} }
} }
@@ -12,12 +12,15 @@ public record ChannelCategory(Snowflake Id, string Name, int? Position) : IHasId
public static ChannelCategory Parse(JsonElement json, int? positionHint = 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")?.GetNonWhiteSpaceStringOrNull() ?? json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull() ??
id.ToString(); id.ToString();
var position =
positionHint ??
json.GetPropertyOrNull("position")?.GetInt32OrNull();
return new ChannelCategory(id, name, position); return new ChannelCategory(id, name, position);
} }
} }
@@ -5,10 +5,15 @@
public enum ChannelKind public enum ChannelKind
{ {
GuildTextChat = 0, GuildTextChat = 0,
DirectTextChat, DirectTextChat = 1,
GuildVoiceChat, GuildVoiceChat = 2,
DirectGroupTextChat, DirectGroupTextChat = 3,
GuildCategory, GuildCategory = 4,
GuildNews, GuildNews = 5,
GuildStore GuildNewsThread = 10,
GuildPublicThread = 11,
GuildPrivateThread = 12,
GuildStageVoice = 13,
GuildDirectory = 14,
GuildForum = 15
} }
@@ -11,6 +11,7 @@ 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,
EmbedKind Kind,
string? Url, string? Url,
DateTimeOffset? Timestamp, DateTimeOffset? Timestamp,
Color? Color, Color? Color,
@@ -18,12 +19,10 @@ public partial record Embed(
string? Description, string? Description,
IReadOnlyList<EmbedField> Fields, IReadOnlyList<EmbedField> Fields,
EmbedImage? Thumbnail, EmbedImage? Thumbnail,
EmbedImage? Image, IReadOnlyList<EmbedImage> Images,
EmbedVideo? Video,
EmbedFooter? Footer) EmbedFooter? Footer)
{ {
public PlainImageEmbedProjection? TryGetPlainImage() =>
PlainImageEmbedProjection.TryResolve(this);
public SpotifyTrackEmbedProjection? TryGetSpotifyTrack() => public SpotifyTrackEmbedProjection? TryGetSpotifyTrack() =>
SpotifyTrackEmbedProjection.TryResolve(this); SpotifyTrackEmbedProjection.TryResolve(this);
@@ -36,22 +35,47 @@ public partial record Embed
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 kind =
json.GetPropertyOrNull("type")?.GetStringOrNull()?.ParseEnumOrNull<EmbedKind>() ??
EmbedKind.Rich;
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull(); var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
var timestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffset(); var timestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffset();
var color = json.GetPropertyOrNull("color")?.GetInt32OrNull()?.Pipe(System.Drawing.Color.FromArgb).ResetAlpha();
var description = json.GetPropertyOrNull("description")?.GetStringOrNull(); var color = json
.GetPropertyOrNull("color")?
.GetInt32OrNull()?
.Pipe(System.Drawing.Color.FromArgb)
.ResetAlpha();
var author = json.GetPropertyOrNull("author")?.Pipe(EmbedAuthor.Parse); var author = json.GetPropertyOrNull("author")?.Pipe(EmbedAuthor.Parse);
var thumbnail = json.GetPropertyOrNull("thumbnail")?.Pipe(EmbedImage.Parse); var description = json.GetPropertyOrNull("description")?.GetStringOrNull();
var image = json.GetPropertyOrNull("image")?.Pipe(EmbedImage.Parse);
var footer = json.GetPropertyOrNull("footer")?.Pipe(EmbedFooter.Parse);
var fields = var fields =
json.GetPropertyOrNull("fields")?.EnumerateArrayOrNull()?.Select(EmbedField.Parse).ToArray() ?? json.GetPropertyOrNull("fields")?.EnumerateArrayOrNull()?.Select(EmbedField.Parse).ToArray() ??
Array.Empty<EmbedField>(); Array.Empty<EmbedField>();
var thumbnail = json.GetPropertyOrNull("thumbnail")?.Pipe(EmbedImage.Parse);
// Under the Discord API model, embeds can only have at most one image.
// Because of that, embeds that are rendered with multiple images on the client
// (e.g. tweet embeds), are exposed from the API as multiple separate embeds.
// Our embed model is consistent with the user-facing side of Discord, so images
// are stored as an array. The API will only ever return one image, but we deal
// with this by merging related embeds at the end of the message parsing process.
// https://github.com/Tyrrrz/DiscordChatExporter/issues/695
var images =
json.GetPropertyOrNull("image")?.Pipe(EmbedImage.Parse).Enumerate().ToArray() ??
Array.Empty<EmbedImage>();
var video = json.GetPropertyOrNull("video")?.Pipe(EmbedVideo.Parse);
var footer = json.GetPropertyOrNull("footer")?.Pipe(EmbedFooter.Parse);
return new Embed( return new Embed(
title, title,
kind,
url, url,
timestamp, timestamp,
color, color,
@@ -59,7 +83,8 @@ public partial record Embed
description, description,
fields, fields,
thumbnail, thumbnail,
image, images,
video,
footer footer
); );
} }
@@ -0,0 +1,11 @@
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
// https://discord.com/developers/docs/resources/channel#embed-object-embed-types
public enum EmbedKind
{
Rich,
Image,
Video,
Gifv,
Link
}
@@ -0,0 +1,22 @@
using JsonExtensions.Reading;
using System.Text.Json;
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
// https://discord.com/developers/docs/resources/channel#embed-object-embed-video-structure
public record EmbedVideo(
string? Url,
string? ProxyUrl,
int? Width,
int? Height)
{
public static EmbedVideo Parse(JsonElement json)
{
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
var proxyUrl = json.GetPropertyOrNull("proxy_url")?.GetNonWhiteSpaceStringOrNull();
var width = json.GetPropertyOrNull("width")?.GetInt32OrNull();
var height = json.GetPropertyOrNull("height")?.GetInt32OrNull();
return new EmbedVideo(url, proxyUrl, width, height);
}
}
@@ -1,33 +0,0 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using DiscordChatExporter.Core.Utils;
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
public record PlainImageEmbedProjection(string Url)
{
public static PlainImageEmbedProjection? TryResolve(Embed embed)
{
if (string.IsNullOrWhiteSpace(embed.Url))
return null;
// Has to be an embed without any data (except URL and image)
if (!string.IsNullOrWhiteSpace(embed.Title) ||
embed.Timestamp is not null ||
embed.Author is not null ||
!string.IsNullOrWhiteSpace(embed.Description) ||
embed.Fields.Any() ||
embed.Footer is not null)
{
return null;
}
// Has to be an image file
var fileName = Regex.Match(embed.Url, @".+/([^?]*)").Groups[1].Value;
if (string.IsNullOrWhiteSpace(fileName) || !FileFormat.IsImage(Path.GetExtension(fileName)))
return null;
return new PlainImageEmbedProjection(embed.Url);
}
}
@@ -21,6 +21,9 @@ public partial record SpotifyTrackEmbedProjection
public static SpotifyTrackEmbedProjection? TryResolve(Embed embed) public static SpotifyTrackEmbedProjection? TryResolve(Embed embed)
{ {
if (embed.Kind != EmbedKind.Link)
return null;
if (string.IsNullOrWhiteSpace(embed.Url)) if (string.IsNullOrWhiteSpace(embed.Url))
return null; return null;
@@ -10,7 +10,7 @@ public partial record YouTubeVideoEmbedProjection(string VideoId)
public partial record YouTubeVideoEmbedProjection public partial record YouTubeVideoEmbedProjection
{ {
// Adapted from YoutubeExplode // Adapted from YoutubeExplode
// https://github.com/Tyrrrz/YoutubeExplode/blob/5be164be20019783913f76fcc98f18c65aebe9f0/YoutubeExplode/Videos/VideoId.cs#L34-L64 // https://github.com/Tyrrrz/YoutubeExplode/blob/bc700b631bd105d0be208a88116347034bdca88b/YoutubeExplode/Videos/VideoId.cs#L40-L62
private static string? TryParseVideoId(string embedUrl) private static string? TryParseVideoId(string embedUrl)
{ {
// Regular URL // Regular URL
@@ -31,11 +31,20 @@ public partial record YouTubeVideoEmbedProjection
if (!string.IsNullOrWhiteSpace(embedMatch)) if (!string.IsNullOrWhiteSpace(embedMatch))
return embedMatch; return embedMatch;
// Shorts URL
// https://www.youtube.com/shorts/sKL1vjP0tIo
var shortsMatch = Regex.Match(embedUrl, @"youtube\..+?/shorts/(.*?)(?:\?|&|/|$)").Groups[1].Value;
if (!string.IsNullOrWhiteSpace(shortsMatch))
return shortsMatch;
return null; return null;
} }
public static YouTubeVideoEmbedProjection? TryResolve(Embed embed) public static YouTubeVideoEmbedProjection? TryResolve(Embed embed)
{ {
if (embed.Kind != EmbedKind.Video)
return null;
if (string.IsNullOrWhiteSpace(embed.Url)) if (string.IsNullOrWhiteSpace(embed.Url))
return null; return null;
+18 -11
View File
@@ -11,12 +11,12 @@ namespace DiscordChatExporter.Core.Discord.Data;
public partial record Emoji( public partial record Emoji(
// Only present on custom emoji // Only present on custom emoji
Snowflake? Id, Snowflake? Id,
// Name of custom emoji (e.g. LUL) or actual representation of standard emoji (e.g. 🙂) // Name of a custom emoji (e.g. LUL) or actual representation of a 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 a custom emoji (e.g. LUL) or name of a standard emoji (e.g. slight_smile)
public string Code => Id is not null public string Code => Id is not null
? Name ? Name
: EmojiIndex.TryGetCode(Name) ?? Name; : EmojiIndex.TryGetCode(Name) ?? Name;
@@ -24,20 +24,28 @@ public partial record Emoji(
public partial record Emoji public partial record Emoji
{ {
private static string GetTwemojiName(string name) => string.Join("-", private static string GetTwemojiId(string name)
name {
.GetRunes() var runes = name.GetRunes().ToArray();
// Variant selector rune is skipped in Twemoji names
.Where(r => r.Value != 0xfe0f) // Variant selector rune is skipped in Twemoji names, except when the emoji also contains a zero-width joiner.
.Select(r => r.Value.ToString("x")) // VS = 0xfe0f; ZWJ = 0x200d.
); var filteredRunes = runes.Any(r => r.Value == 0x200d)
? runes
: runes.Where(r => r.Value != 0xfe0f);
return string.Join(
"-",
filteredRunes.Select(r => r.Value.ToString("x"))
);
}
private static string GetImageUrl(Snowflake id, bool isAnimated) => isAnimated private static string GetImageUrl(Snowflake id, bool isAnimated) => 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) => private static string GetImageUrl(string name) =>
$"https://twemoji.maxcdn.com/2/svg/{GetTwemojiName(name)}.svg"; $"https://twemoji.maxcdn.com/v/latest/svg/{GetTwemojiId(name)}.svg";
public static string GetImageUrl(Snowflake? id, string? name, bool isAnimated) public static string GetImageUrl(Snowflake? id, string? name, bool isAnimated)
{ {
@@ -58,7 +66,6 @@ public partial record Emoji
var id = json.GetPropertyOrNull("id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse); var id = json.GetPropertyOrNull("id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
var name = json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull(); var name = json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull();
var isAnimated = json.GetPropertyOrNull("animated")?.GetBooleanOrNull() ?? false; var isAnimated = json.GetPropertyOrNull("animated")?.GetBooleanOrNull() ?? false;
var imageUrl = GetImageUrl(id, name, isAnimated); var imageUrl = GetImageUrl(id, name, isAnimated);
return new Emoji( return new Emoji(
+11 -4
View File
@@ -1,4 +1,5 @@
using System.Text.Json; using System;
using System.Text.Json;
using DiscordChatExporter.Core.Discord.Data.Common; using DiscordChatExporter.Core.Discord.Data.Common;
using DiscordChatExporter.Core.Utils.Extensions; using DiscordChatExporter.Core.Utils.Extensions;
using JsonExtensions.Reading; using JsonExtensions.Reading;
@@ -17,15 +18,21 @@ public record Guild(Snowflake Id, string Name, string IconUrl) : IHasId
private static string GetDefaultIconUrl() => private static string GetDefaultIconUrl() =>
"https://cdn.discordapp.com/embed/avatars/0.png"; "https://cdn.discordapp.com/embed/avatars/0.png";
private static string GetIconUrl(Snowflake id, string iconHash) => private static string GetIconUrl(Snowflake id, string iconHash)
$"https://cdn.discordapp.com/icons/{id}/{iconHash}.png"; {
var extension = iconHash.StartsWith("a_", StringComparison.Ordinal)
? "gif"
: "png";
return $"https://cdn.discordapp.com/icons/{id}/{iconHash}.{extension}";
}
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").GetNonNullString(); var name = json.GetProperty("name").GetNonNullString();
var iconHash = json.GetPropertyOrNull("icon")?.GetNonWhiteSpaceStringOrNull();
var iconHash = json.GetPropertyOrNull("icon")?.GetNonWhiteSpaceStringOrNull();
var iconUrl = !string.IsNullOrWhiteSpace(iconHash) var iconUrl = !string.IsNullOrWhiteSpace(iconHash)
? GetIconUrl(id, iconHash) ? GetIconUrl(id, iconHash)
: GetDefaultIconUrl(); : GetDefaultIconUrl();
@@ -27,18 +27,76 @@ public record Message(
MessageReference? Reference, MessageReference? Reference,
Message? ReferencedMessage) : IHasId Message? ReferencedMessage) : IHasId
{ {
private static IReadOnlyList<Embed> NormalizeEmbeds(IReadOnlyList<Embed> embeds)
{
if (embeds.Count <= 1)
return embeds;
// Discord API doesn't support embeds with multiple images, even though the Discord client does.
// To work around this, it seems that the API returns multiple consecutive embeds with different images,
// which are then merged together on the client. We need to replicate the same behavior ourselves.
// Currently, only known case where this workaround is required is Twitter embeds.
// https://github.com/Tyrrrz/DiscordChatExporter/issues/695
var normalizedEmbeds = new List<Embed>();
for (var i = 0; i < embeds.Count; i++)
{
var embed = embeds[i];
if (embed.Url?.Contains("://twitter.com/", StringComparison.OrdinalIgnoreCase) == true)
{
// Find embeds with the same URL that only contain a single image and nothing else
var trailingEmbeds = embeds
.Skip(i + 1)
.TakeWhile(e =>
e.Url == embed.Url &&
e.Timestamp is null &&
e.Author is null &&
e.Color is null &&
string.IsNullOrWhiteSpace(e.Description) &&
!e.Fields.Any() &&
e.Images.Count == 1 &&
e.Footer is null
)
.ToArray();
if (trailingEmbeds.Any())
{
// Concatenate all images into one embed
var images = embed.Images.Concat(trailingEmbeds.SelectMany(e => e.Images)).ToArray();
normalizedEmbeds.Add(embed with { Images = images });
i += trailingEmbeds.Length;
}
else
{
normalizedEmbeds.Add(embed);
}
}
else
{
normalizedEmbeds.Add(embed);
}
}
return normalizedEmbeds;
}
public static Message Parse(JsonElement json) public static Message Parse(JsonElement json)
{ {
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse); var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
var kind = (MessageKind)json.GetProperty("type").GetInt32();
var author = json.GetProperty("author").Pipe(User.Parse); var author = json.GetProperty("author").Pipe(User.Parse);
var timestamp = json.GetProperty("timestamp").GetDateTimeOffset(); var timestamp = json.GetProperty("timestamp").GetDateTimeOffset();
var editedTimestamp = json.GetPropertyOrNull("edited_timestamp")?.GetDateTimeOffset(); var editedTimestamp = json.GetPropertyOrNull("edited_timestamp")?.GetDateTimeOffset();
var callEndedTimestamp = json.GetPropertyOrNull("call")?.GetPropertyOrNull("ended_timestamp") var callEndedTimestamp = json
?.GetDateTimeOffset(); .GetPropertyOrNull("call")?
var kind = (MessageKind)json.GetProperty("type").GetInt32(); .GetPropertyOrNull("ended_timestamp")?
.GetDateTimeOffset();
var isPinned = json.GetPropertyOrNull("pinned")?.GetBooleanOrNull() ?? false; var isPinned = json.GetPropertyOrNull("pinned")?.GetBooleanOrNull() ?? false;
var messageReference = json.GetPropertyOrNull("message_reference")?.Pipe(MessageReference.Parse);
var referencedMessage = json.GetPropertyOrNull("referenced_message")?.Pipe(Parse);
var content = kind switch var content = kind switch
{ {
@@ -49,6 +107,7 @@ public record Message(
MessageKind.ChannelNameChange => "Changed the channel name.", MessageKind.ChannelNameChange => "Changed the channel name.",
MessageKind.ChannelIconChange => "Changed the channel icon.", MessageKind.ChannelIconChange => "Changed the channel icon.",
MessageKind.ChannelPinnedMessage => "Pinned a message.", MessageKind.ChannelPinnedMessage => "Pinned a message.",
MessageKind.ThreadCreated => "Started a thread.",
MessageKind.GuildMemberJoin => "Joined the server.", MessageKind.GuildMemberJoin => "Joined the server.",
_ => json.GetPropertyOrNull("content")?.GetStringOrNull() ?? "" _ => json.GetPropertyOrNull("content")?.GetStringOrNull() ?? ""
}; };
@@ -57,9 +116,10 @@ public record Message(
json.GetPropertyOrNull("attachments")?.EnumerateArrayOrNull()?.Select(Attachment.Parse).ToArray() ?? json.GetPropertyOrNull("attachments")?.EnumerateArrayOrNull()?.Select(Attachment.Parse).ToArray() ??
Array.Empty<Attachment>(); Array.Empty<Attachment>();
var embeds = var embeds = NormalizeEmbeds(
json.GetPropertyOrNull("embeds")?.EnumerateArrayOrNull()?.Select(Embed.Parse).ToArray() ?? json.GetPropertyOrNull("embeds")?.EnumerateArrayOrNull()?.Select(Embed.Parse).ToArray() ??
Array.Empty<Embed>(); Array.Empty<Embed>()
);
var stickers = var stickers =
json.GetPropertyOrNull("sticker_items")?.EnumerateArrayOrNull()?.Select(Sticker.Parse).ToArray() ?? json.GetPropertyOrNull("sticker_items")?.EnumerateArrayOrNull()?.Select(Sticker.Parse).ToArray() ??
@@ -73,6 +133,9 @@ public record Message(
json.GetPropertyOrNull("mentions")?.EnumerateArrayOrNull()?.Select(User.Parse).ToArray() ?? json.GetPropertyOrNull("mentions")?.EnumerateArrayOrNull()?.Select(User.Parse).ToArray() ??
Array.Empty<User>(); Array.Empty<User>();
var messageReference = json.GetPropertyOrNull("message_reference")?.Pipe(MessageReference.Parse);
var referencedMessage = json.GetPropertyOrNull("referenced_message")?.Pipe(Parse);
return new Message( return new Message(
id, id,
kind, kind,
@@ -11,5 +11,11 @@ public enum MessageKind
ChannelIconChange = 5, ChannelIconChange = 5,
ChannelPinnedMessage = 6, ChannelPinnedMessage = 6,
GuildMemberJoin = 7, GuildMemberJoin = 7,
ThreadCreated = 18,
Reply = 19 Reply = 19
} }
public static class MessageKindExtensions
{
public static bool IsSystemNotification(this MessageKind c) => (int)c is >= 1 and <= 18;
}
@@ -9,9 +9,20 @@ public record MessageReference(Snowflake? MessageId, Snowflake? ChannelId, Snowf
{ {
public static MessageReference Parse(JsonElement json) public static MessageReference Parse(JsonElement json)
{ {
var messageId = json.GetPropertyOrNull("message_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse); var messageId = json
var channelId = json.GetPropertyOrNull("channel_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse); .GetPropertyOrNull("message_id")?
var guildId = json.GetPropertyOrNull("guild_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse); .GetNonWhiteSpaceStringOrNull()?
.Pipe(Snowflake.Parse);
var channelId = json
.GetPropertyOrNull("channel_id")?
.GetNonWhiteSpaceStringOrNull()?
.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);
} }
@@ -4,6 +4,7 @@ using JsonExtensions.Reading;
namespace DiscordChatExporter.Core.Discord.Data; namespace DiscordChatExporter.Core.Discord.Data;
// https://discord.com/developers/docs/resources/sticker#sticker-resource
public record Sticker(Snowflake Id, string Name, StickerFormat Format, string SourceUrl) public record Sticker(Snowflake Id, string Name, StickerFormat Format, string SourceUrl)
{ {
private static string GetSourceUrl(Snowflake id, StickerFormat format) private static string GetSourceUrl(Snowflake id, StickerFormat format)
@@ -15,9 +16,8 @@ public record Sticker(Snowflake Id, string Name, StickerFormat Format, string So
public static Sticker Parse(JsonElement json) public static Sticker 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 format = (StickerFormat)json.GetProperty("format_type").GetInt32(); var format = (StickerFormat)json.GetProperty("format_type").GetInt32();
var sourceUrl = GetSourceUrl(id, format); var sourceUrl = GetSourceUrl(id, format);
return new Sticker(id, name, format, sourceUrl); return new Sticker(id, name, format, sourceUrl);
@@ -39,8 +39,8 @@ public partial record User
var isBot = json.GetPropertyOrNull("bot")?.GetBooleanOrNull() ?? 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").GetNonNullString(); var name = json.GetProperty("username").GetNonNullString();
var avatarHash = json.GetPropertyOrNull("avatar")?.GetNonWhiteSpaceStringOrNull();
var avatarHash = json.GetPropertyOrNull("avatar")?.GetNonWhiteSpaceStringOrNull();
var avatarUrl = !string.IsNullOrWhiteSpace(avatarHash) var avatarUrl = !string.IsNullOrWhiteSpace(avatarHash)
? GetAvatarUrl(id, avatarHash) ? GetAvatarUrl(id, avatarHash)
: GetDefaultAvatarUrl(discriminator); : GetDefaultAvatarUrl(discriminator);
@@ -3,7 +3,6 @@ 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;
@@ -23,65 +22,67 @@ public class DiscordClient
private readonly string _token; private readonly string _token;
private readonly Uri _baseUri = new("https://discord.com/api/v9/", UriKind.Absolute); private readonly Uri _baseUri = new("https://discord.com/api/v9/", UriKind.Absolute);
private TokenKind _tokenKind = TokenKind.Unknown; private TokenKind? _resolvedTokenKind;
public DiscordClient(string token) => _token = token; public DiscordClient(string token) => _token = token;
private async ValueTask<HttpResponseMessage> GetResponseAsync( private async ValueTask<HttpResponseMessage> GetResponseAsync(
string url, string url,
bool isBot, TokenKind tokenKind,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
using var request = new HttpRequestMessage(HttpMethod.Get, new Uri(_baseUri, url)); return await Http.ResponseResiliencePolicy.ExecuteAsync(async innerCancellationToken =>
{
using var request = new HttpRequestMessage(HttpMethod.Get, new Uri(_baseUri, url));
// Don't validate because token can have invalid characters // Don't validate because token can have invalid characters
// https://github.com/Tyrrrz/DiscordChatExporter/issues/828 // https://github.com/Tyrrrz/DiscordChatExporter/issues/828
request.Headers.TryAddWithoutValidation( request.Headers.TryAddWithoutValidation(
"Authorization", "Authorization",
isBot ? $"Bot {_token}" : _token tokenKind == TokenKind.Bot
); ? $"Bot {_token}"
: _token
);
return await Http.Client.SendAsync( return await Http.Client.SendAsync(
request, request,
HttpCompletionOption.ResponseHeadersRead, HttpCompletionOption.ResponseHeadersRead,
innerCancellationToken
);
}, cancellationToken);
}
private async ValueTask<TokenKind> GetTokenKindAsync(CancellationToken cancellationToken = default)
{
// Try authenticating as a user
using var userResponse = await GetResponseAsync(
"users/@me",
TokenKind.User,
cancellationToken cancellationToken
); );
if (userResponse.StatusCode != HttpStatusCode.Unauthorized)
return TokenKind.User;
// Try authenticating as a bot
using var botResponse = await GetResponseAsync(
"users/@me",
TokenKind.Bot,
cancellationToken
);
if (botResponse.StatusCode != HttpStatusCode.Unauthorized)
return TokenKind.Bot;
throw DiscordChatExporterException.Unauthorized();
} }
private async ValueTask<HttpResponseMessage> GetResponseAsync( private async ValueTask<HttpResponseMessage> GetResponseAsync(
string url, string url,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await Http.ResponsePolicy.ExecuteAsync(async innerCancellationToken => var tokenKind = _resolvedTokenKind ??= await GetTokenKindAsync(cancellationToken);
{ return await GetResponseAsync(url, tokenKind, cancellationToken);
if (_tokenKind == TokenKind.User)
return await GetResponseAsync(url, false, innerCancellationToken);
if (_tokenKind == TokenKind.Bot)
return await GetResponseAsync(url, true, 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);
} }
private async ValueTask<JsonElement> GetJsonResponseAsync( private async ValueTask<JsonElement> GetJsonResponseAsync(
@@ -182,6 +183,8 @@ public class DiscordClient
.Select((j, index) => ChannelCategory.Parse(j, index + 1)) .Select((j, index) => ChannelCategory.Parse(j, index + 1))
.ToDictionary(j => j.Id.ToString(), StringComparer.Ordinal); .ToDictionary(j => j.Id.ToString(), StringComparer.Ordinal);
// Discord positions are not deterministic, so we need to normalize them
// because the user may refer to the channel position via file name template.
var position = 0; var position = 0;
foreach (var channelJson in responseOrdered) foreach (var channelJson in responseOrdered)
@@ -49,7 +49,15 @@ public partial record struct Snowflake
public static Snowflake Parse(string str) => Parse(str, null); public static Snowflake Parse(string str) => Parse(str, null);
} }
public partial record struct Snowflake : IComparable<Snowflake> public partial record struct Snowflake : IComparable<Snowflake>, IComparable
{ {
public int CompareTo(Snowflake other) => Value.CompareTo(other.Value); public int CompareTo(Snowflake other) => Value.CompareTo(other.Value);
public int CompareTo(object? obj)
{
if (obj is not Snowflake other)
throw new ArgumentException($"Object must be of type {nameof(Snowflake)}.");
return Value.CompareTo(other.Value);
}
} }
@@ -2,7 +2,6 @@
public enum TokenKind public enum TokenKind
{ {
Unknown,
User, User,
Bot Bot
} }
@@ -7,9 +7,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Gress" Version="2.0.1" /> <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.1" /> <PackageReference Include="MiniRazor.CodeGen" Version="2.2.2" />
<PackageReference Include="Polly" Version="7.2.3" /> <PackageReference Include="Polly" Version="7.2.3" />
<PackageReference Include="Superpower" Version="3.0.0" /> <PackageReference Include="Superpower" Version="3.0.0" />
<PackageReference Include="WebMarkupMin.Core" Version="2.12.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -42,7 +42,7 @@ internal class ExportContext
{ {
"unix" => date.ToUnixTimeSeconds().ToString(), "unix" => date.ToUnixTimeSeconds().ToString(),
"unixms" => date.ToUnixTimeMilliseconds().ToString(), "unixms" => date.ToUnixTimeMilliseconds().ToString(),
var dateFormat => date.ToLocalString(dateFormat) var format => date.ToLocalString(format)
}; };
public Member? TryGetMember(Snowflake id) => Members.FirstOrDefault(m => m.Id == id); public Member? TryGetMember(Snowflake id) => Members.FirstOrDefault(m => m.Id == id);
@@ -1,4 +1,5 @@
using System.IO; using System;
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;
@@ -61,6 +62,7 @@ public partial record ExportRequest
"%P" => channel.Category.Position?.ToString() ?? "0", "%P" => channel.Category.Position?.ToString() ?? "0",
"%a" => after?.ToDate().ToString("yyyy-MM-dd") ?? "", "%a" => after?.ToDate().ToString("yyyy-MM-dd") ?? "",
"%b" => before?.ToDate().ToString("yyyy-MM-dd") ?? "", "%b" => before?.ToDate().ToString("yyyy-MM-dd") ?? "",
"%d" => DateTimeOffset.Now.ToString("yyyy-MM-dd"),
"%%" => "%", "%%" => "%",
_ => m.Value _ => m.Value
}) })
@@ -10,11 +10,19 @@ internal class ContainsMessageFilter : MessageFilter
public ContainsMessageFilter(string text) => _text = text; public ContainsMessageFilter(string text) => _text = text;
// Match content within word boundaries, between spaces, or as the whole input.
// For example, "max" shouldn't match on content "our maximum effort",
// but should match on content "our max effort".
// Also, "(max)" should match on content "our (max) effort", even though
// parentheses are not considered word characters.
// https://github.com/Tyrrrz/DiscordChatExporter/issues/909
private bool IsMatch(string? content) => private bool IsMatch(string? content) =>
!string.IsNullOrWhiteSpace(content) && !string.IsNullOrWhiteSpace(content) &&
Regex.IsMatch( Regex.IsMatch(
content, content,
"\\b" + Regex.Escape(_text) + "\\b", @"(?:\b|\s|^)" +
Regex.Escape(_text) +
@"(?:\b|\s|$)",
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant RegexOptions.IgnoreCase | RegexOptions.CultureInvariant
); );
@@ -19,6 +19,7 @@ internal class HasMessageFilter : MessageFilter
MessageContentMatchKind.Video => message.Attachments.Any(file => file.IsVideo), MessageContentMatchKind.Video => message.Attachments.Any(file => file.IsVideo),
MessageContentMatchKind.Image => message.Attachments.Any(file => file.IsImage), MessageContentMatchKind.Image => message.Attachments.Any(file => file.IsImage),
MessageContentMatchKind.Sound => message.Attachments.Any(file => file.IsAudio), MessageContentMatchKind.Sound => message.Attachments.Any(file => file.IsAudio),
MessageContentMatchKind.Pin => message.IsPinned,
_ => throw new InvalidOperationException($"Unknown message content match kind '{_kind}'.") _ => throw new InvalidOperationException($"Unknown message content match kind '{_kind}'.")
}; };
} }
@@ -7,5 +7,6 @@ internal enum MessageContentMatchKind
File, File,
Video, Video,
Image, Image,
Sound Sound,
Pin
} }
@@ -15,94 +15,107 @@ internal static class FilterGrammar
from close in Character.EqualTo(open) from close in Character.EqualTo(open)
select value; select value;
private static readonly TextParser<char> FreeCharacter =
Character.Matching(c =>
!char.IsWhiteSpace(c) &&
// Avoid all special tokens used by the grammar
c is not ('(' or ')' or '"' or '\'' or '-' or '|' or '&'),
"any character except whitespace or `(`, `)`, `\"`, `'`, `-`, `|`, `&`"
);
private static readonly TextParser<string> UnquotedString = private static readonly TextParser<string> UnquotedString =
Parse.OneOf(EscapedCharacter, FreeCharacter).AtLeastOnce().Text(); Parse.OneOf(
EscapedCharacter,
// Avoid whitespace as it's treated as an implicit 'and' operator.
// Also avoid all special tokens used by other parsers.
Character.ExceptIn(' ', '(', ')', '"', '\'', '-', '~', '|', '&')
).AtLeastOnce().Text();
private static readonly TextParser<string> String = private static readonly TextParser<string> String =
Parse.OneOf(QuotedString, UnquotedString).Named("text string"); Parse.OneOf(QuotedString, UnquotedString).Named("text string");
private static readonly TextParser<MessageFilter> ContainsFilter = private static readonly TextParser<MessageFilter> ContainsFilter =
String.Select(v => (MessageFilter) new ContainsMessageFilter(v)); String.Select(v => (MessageFilter)new ContainsMessageFilter(v));
private static readonly TextParser<MessageFilter> FromFilter = Span private static readonly TextParser<MessageFilter> FromFilter =
.EqualToIgnoreCase("from:") Span
.IgnoreThen(String) .EqualToIgnoreCase("from:")
.Select(v => (MessageFilter) new FromMessageFilter(v)) .Try()
.Named("from:<value>"); .IgnoreThen(String)
.Select(v => (MessageFilter)new FromMessageFilter(v))
.Named("from:<value>");
private static readonly TextParser<MessageFilter> MentionsFilter = Span private static readonly TextParser<MessageFilter> MentionsFilter =
.EqualToIgnoreCase("mentions:") Span
.IgnoreThen(String) .EqualToIgnoreCase("mentions:")
.Select(v => (MessageFilter) new MentionsMessageFilter(v)) .Try()
.Named("mentions:<value>"); .IgnoreThen(String)
.Select(v => (MessageFilter)new MentionsMessageFilter(v))
.Named("mentions:<value>");
private static readonly TextParser<MessageFilter> ReactionFilter = Span private static readonly TextParser<MessageFilter> ReactionFilter =
.EqualToIgnoreCase("reaction:") Span
.IgnoreThen(String) .EqualToIgnoreCase("reaction:")
.Select(v => (MessageFilter) new ReactionMessageFilter(v)) .Try()
.Named("reaction:<value>"); .IgnoreThen(String)
.Select(v => (MessageFilter)new ReactionMessageFilter(v))
.Named("reaction:<value>");
private static readonly TextParser<MessageFilter> HasFilter = Span private static readonly TextParser<MessageFilter> HasFilter =
.EqualToIgnoreCase("has:") Span
.IgnoreThen(Parse.OneOf( .EqualToIgnoreCase("has:")
Span.EqualToIgnoreCase("link").IgnoreThen(Parse.Return(MessageContentMatchKind.Link)), .Try()
Span.EqualToIgnoreCase("embed").IgnoreThen(Parse.Return(MessageContentMatchKind.Embed)), .IgnoreThen(Parse.OneOf(
Span.EqualToIgnoreCase("file").IgnoreThen(Parse.Return(MessageContentMatchKind.File)), Span.EqualToIgnoreCase("link").IgnoreThen(Parse.Return(MessageContentMatchKind.Link)),
Span.EqualToIgnoreCase("video").IgnoreThen(Parse.Return(MessageContentMatchKind.Video)), Span.EqualToIgnoreCase("embed").IgnoreThen(Parse.Return(MessageContentMatchKind.Embed)),
Span.EqualToIgnoreCase("image").IgnoreThen(Parse.Return(MessageContentMatchKind.Image)), Span.EqualToIgnoreCase("file").IgnoreThen(Parse.Return(MessageContentMatchKind.File)),
Span.EqualToIgnoreCase("sound").IgnoreThen(Parse.Return(MessageContentMatchKind.Sound)) Span.EqualToIgnoreCase("video").IgnoreThen(Parse.Return(MessageContentMatchKind.Video)),
)) Span.EqualToIgnoreCase("image").IgnoreThen(Parse.Return(MessageContentMatchKind.Image)),
.Select(k => (MessageFilter) new HasMessageFilter(k)) Span.EqualToIgnoreCase("sound").IgnoreThen(Parse.Return(MessageContentMatchKind.Sound)),
.Named("has:<value>"); Span.EqualToIgnoreCase("pin").IgnoreThen(Parse.Return(MessageContentMatchKind.Pin))
))
.Select(k => (MessageFilter)new HasMessageFilter(k))
.Named("has:<value>");
private static readonly TextParser<MessageFilter> NegatedFilter = Character // Make sure that property-based filters like 'has:link' don't prevent text like 'hello' from being parsed.
.EqualTo('-') // https://github.com/Tyrrrz/DiscordChatExporter/issues/909#issuecomment-1227575455
.IgnoreThen(Parse.Ref(() => StandaloneFilter!)) private static readonly TextParser<MessageFilter> PrimitiveFilter =
.Select(f => (MessageFilter) new NegatedMessageFilter(f)); Parse.OneOf(
FromFilter,
MentionsFilter,
ReactionFilter,
HasFilter,
ContainsFilter
);
private static readonly TextParser<MessageFilter> GroupedFilter = private static readonly TextParser<MessageFilter> GroupedFilter =
from open in Character.EqualTo('(') from open in Character.EqualTo('(')
from content in Parse.Ref(() => BinaryExpressionFilter!).Token() from content in Parse.Ref(() => ChainedFilter!).Token()
from close in Character.EqualTo(')') from close in Character.EqualTo(')')
select content; select content;
private static readonly TextParser<MessageFilter> StandaloneFilter = Parse.OneOf( private static readonly TextParser<MessageFilter> NegatedFilter =
GroupedFilter, Character
FromFilter, // Dash is annoying to use from CLI due to conflicts with options, so we provide tilde as an alias
MentionsFilter, .In('-', '~')
ReactionFilter, .IgnoreThen(Parse.OneOf(GroupedFilter, PrimitiveFilter))
HasFilter, .Select(f => (MessageFilter)new NegatedMessageFilter(f));
ContainsFilter
);
private static readonly TextParser<MessageFilter> UnaryExpressionFilter = Parse.OneOf( private static readonly TextParser<MessageFilter> ChainedFilter =
NegatedFilter, Parse.Chain(
StandaloneFilter // Operator
); Parse.OneOf(
// Explicit operator
private static readonly TextParser<MessageFilter> BinaryExpressionFilter = Parse.Chain( Character.In('|', '&').Token().Try(),
Parse.OneOf( // Implicit operator (resolves to 'and')
// Explicit operator Character.EqualTo(' ').AtLeastOnce().IgnoreThen(Parse.Return(' '))
Character.In('|', '&').Token().Try(), ),
// Implicit operator (resolves to 'and') // Operand
Character.WhiteSpace.AtLeastOnce().IgnoreThen(Parse.Return(' ')) Parse.OneOf(
), NegatedFilter,
UnaryExpressionFilter, GroupedFilter,
(op, left, right) => op switch PrimitiveFilter
{ ),
'|' => new BinaryExpressionMessageFilter(left, right, BinaryExpressionKind.Or), // Reducer
_ => new BinaryExpressionMessageFilter(left, right, BinaryExpressionKind.And) (op, left, right) => op switch
} {
); '|' => new BinaryExpressionMessageFilter(left, right, BinaryExpressionKind.Or),
_ => new BinaryExpressionMessageFilter(left, right, BinaryExpressionKind.And)
}
);
public static readonly TextParser<MessageFilter> Filter = public static readonly TextParser<MessageFilter> Filter =
BinaryExpressionFilter.Token().AtEnd(); ChainedFilter.Token().AtEnd();
} }
@@ -35,45 +35,42 @@ internal partial class MediaDownloader
var filePath = Path.Combine(_workingDirPath, fileName); var filePath = Path.Combine(_workingDirPath, fileName);
// Reuse existing files if we're allowed to // Reuse existing files if we're allowed to
if (_reuseMedia && File.Exists(filePath)) if (!_reuseMedia || !File.Exists(filePath))
return _pathCache[url] = filePath;
Directory.CreateDirectory(_workingDirPath);
// This retries on IOExceptions which is dangerous as we're also working with files
await Http.ExceptionPolicy.ExecuteAsync(async () =>
{ {
// Download the file Directory.CreateDirectory(_workingDirPath);
using var response = await Http.Client.GetAsync(url, cancellationToken);
await using (var output = File.Create(filePath))
{
await response.Content.CopyToAsync(output, cancellationToken);
}
// Try to set the file date according to the last-modified header await Http.ResiliencePolicy.ExecuteAsync(async () =>
try
{ {
var lastModified = response.Content.Headers.TryGetValue("Last-Modified")?.Pipe(s => // Download the file
DateTimeOffset.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None, out var date) using var response = await Http.Client.GetAsync(url, cancellationToken);
? date await using (var output = File.Create(filePath))
: (DateTimeOffset?) null await response.Content.CopyToAsync(output, cancellationToken);
);
if (lastModified is not null) // Try to set the file date according to the last-modified header
try
{ {
File.SetCreationTimeUtc(filePath, lastModified.Value.UtcDateTime); var lastModified = response.Content.Headers.TryGetValue("Last-Modified")?.Pipe(s =>
File.SetLastWriteTimeUtc(filePath, lastModified.Value.UtcDateTime); DateTimeOffset.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None, out var date)
File.SetLastAccessTimeUtc(filePath, lastModified.Value.UtcDateTime); ? date
: (DateTimeOffset?) null
);
if (lastModified is not null)
{
File.SetCreationTimeUtc(filePath, lastModified.Value.UtcDateTime);
File.SetLastWriteTimeUtc(filePath, lastModified.Value.UtcDateTime);
File.SetLastAccessTimeUtc(filePath, lastModified.Value.UtcDateTime);
}
} }
} catch
catch {
{ // This can apparently fail for some reason.
// This can apparently fail for some reason. // https://github.com/Tyrrrz/DiscordChatExporter/issues/585
// https://github.com/Tyrrrz/DiscordChatExporter/issues/585 // Updating file dates is not a critical task, so we'll just
// Updating file dates is not a critical task, so we'll just // ignore exceptions thrown here.
// ignore exceptions thrown here. }
} });
}); }
return _pathCache[url] = filePath; return _pathCache[url] = filePath;
} }
@@ -0,0 +1,22 @@
using System;
using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Discord.Data.Embeds;
namespace DiscordChatExporter.Core.Exporting.Writers.Html;
internal static class MessageExtensions
{
// 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)
{
if (message.Embeds.Count != 1)
return false;
var embed = message.Embeds[0];
return
string.Equals(message.Content.Trim(), embed.Url, StringComparison.OrdinalIgnoreCase) &&
embed.Kind is EmbedKind.Image or EmbedKind.Gifv;
}
}
@@ -2,6 +2,7 @@
@using System.Linq @using System.Linq
@using System.Threading.Tasks @using System.Threading.Tasks
@using DiscordChatExporter.Core.Discord.Data @using DiscordChatExporter.Core.Discord.Data
@using DiscordChatExporter.Core.Discord.Data.Embeds
@using DiscordChatExporter.Core.Exporting.Writers.Html; @using DiscordChatExporter.Core.Exporting.Writers.Html;
@using DiscordChatExporter.Core.Utils.Extensions @using DiscordChatExporter.Core.Utils.Extensions
@@ -9,8 +10,6 @@
@inherits MiniRazor.TemplateBase<MessageGroupTemplateContext> @inherits MiniRazor.TemplateBase<MessageGroupTemplateContext>
@{ @{
var firstMessage = Model.Messages.First();
ValueTask<string> ResolveUrlAsync(string url) => Model.ExportContext.ResolveMediaUrlAsync(url); ValueTask<string> ResolveUrlAsync(string url) => Model.ExportContext.ResolveMediaUrlAsync(url);
string FormatDate(DateTimeOffset date) => Model.ExportContext.FormatDate(date); string FormatDate(DateTimeOffset date) => Model.ExportContext.FormatDate(date);
@@ -19,6 +18,8 @@
string FormatEmbedMarkdown(string markdown) => Model.FormatMarkdown(markdown, false); string FormatEmbedMarkdown(string markdown) => Model.FormatMarkdown(markdown, false);
var firstMessage = Model.Messages.First();
var userMember = Model.ExportContext.TryGetMember(firstMessage.Author.Id); var userMember = Model.ExportContext.TryGetMember(firstMessage.Author.Id);
var userColor = Model.ExportContext.TryGetUserColor(firstMessage.Author.Id); var userColor = Model.ExportContext.TryGetUserColor(firstMessage.Author.Id);
@@ -43,422 +44,482 @@
} }
<div class="chatlog__message-group"> <div class="chatlog__message-group">
@for (var i = 0; i < Model.Messages.Count; i++) @foreach (var (message, i) in Model.Messages.WithIndex())
{ {
var isFirst = i == 0; var isFirst = i == 0;
var message = Model.Messages[i];
<div id="chatlog__message-container-@message.Id" class="chatlog__message-container @(message.IsPinned ? "chatlog__message-container--pinned" : null)" data-message-id="@message.Id"> <div id="chatlog__message-container-@message.Id" class="chatlog__message-container @(message.IsPinned ? "chatlog__message-container--pinned" : null)" data-message-id="@message.Id">
<div class="chatlog__message"> <div class="chatlog__message">
@{/* Left side */} @{/* System notification */}
<div class="chatlog__message-aside"> @if (message.Kind.IsSystemNotification())
@if (isFirst) {
{ // System notifications are grouped even if the message author is different.
// Reference symbol // That's why we have to update the user values with the author of the current message.
if (message.Reference is not null) userMember = Model.ExportContext.TryGetMember(message.Author.Id);
{ userColor = Model.ExportContext.TryGetUserColor(message.Author.Id);
<div class="chatlog__reference-symbol"></div> userNick = message.Author.IsBot
} ? message.Author.Name
: userMember?.Nick ?? message.Author.Name;
// Avatar <div class="chatlog__message-aside">
<img class="chatlog__avatar" src="@await ResolveUrlAsync(message.Author.AvatarUrl)" alt="Avatar" loading="lazy"> <svg class="chatlog__system-notification-icon"><use href="#@message.Kind.ToString().ToDashCase().ToLowerInvariant()-icon"></use></svg>
} </div>
else
{
<div class="chatlog__short-timestamp" title="@FormatDate(message.Timestamp)">@message.Timestamp.ToLocalString("t")</div>
}
</div>
@{/* Right side */} <div class="chatlog__message-primary">
<div class="chatlog__message-primary"> @{/* Author name */}
@if (isFirst) <span class="chatlog__system-notification-author" style="@(userColor is not null ? $"color: rgb({userColor.Value.R}, {userColor.Value.G}, {userColor.Value.B})" : null)" title="@message.Author.FullName" data-user-id="@message.Author.Id">@userNick</span>
{
// Reference
if (message.Reference is not null)
{
<div class="chatlog__reference">
@if (message.ReferencedMessage is not null)
{
<img class="chatlog__reference-avatar" src="@await ResolveUrlAsync(message.ReferencedMessage.Author.AvatarUrl)" alt="Avatar" loading="lazy">
<div class="chatlog__reference-author" style="@(referencedUserColor is not null ? $"color: rgb({referencedUserColor.Value.R}, {referencedUserColor.Value.G}, {referencedUserColor.Value.B})" : null)" title="@message.ReferencedMessage.Author.FullName">@referencedUserNick</div>
<div class="chatlog__reference-content">
<span class="chatlog__reference-link" onclick="scrollToMessage(event, '@message.ReferencedMessage.Id')">
@if (!string.IsNullOrWhiteSpace(message.ReferencedMessage.Content))
{
@Raw(FormatEmbedMarkdown(message.ReferencedMessage.Content))
}
else if (message.ReferencedMessage.Attachments.Any() || message.ReferencedMessage.Embeds.Any())
{
<em>Click to see attachment</em>
<span>🖼️</span>
}
else
{
<em>Click to see original message</em>
}
</span>
@if (message.ReferencedMessage.EditedTimestamp is not null) @{/* System notification content */}
{ <span class="chatlog__system-notification-content">
<span class="chatlog__reference-edited-timestamp" title="@FormatDate(message.ReferencedMessage.EditedTimestamp.Value)">(edited)</span> @if (message.Kind == MessageKind.ChannelPinnedMessage && message.Reference is not null)
}
</div>
}
else
{
<div class="chatlog__reference-unknown">
Original message was deleted or could not be loaded.
</div>
}
</div>
}
// Header
<div class="chatlog__header">
@{/* Author name */}
<span class="chatlog__author" style="@(userColor is not null ? $"color: rgb({userColor.Value.R}, {userColor.Value.G}, {userColor.Value.B})" : null)" title="@message.Author.FullName" data-user-id="@message.Author.Id">@userNick</span>
@{/* Bot label */}
@if (message.Author.IsBot)
{ {
<span class="chatlog__bot-label">BOT</span> <span> pinned</span>
} <a class="chatlog__system-notification-link" href="#chatlog__message-container-@message.Reference.MessageId"> a message</a>
<span> to this channel.</span>
@{/* Timestamp */}
<span class="chatlog__timestamp">@FormatDate(message.Timestamp)</span>
</div>
}
@{/* Content */}
@if (!string.IsNullOrWhiteSpace(message.Content) || message.EditedTimestamp is not null)
{
<div class="chatlog__content chatlog__markdown">
@{/* Text */}
<span class="chatlog__markdown-preserve">@Raw(FormatMarkdown(message.Content))</span>
@{/* Edited timestamp */}
@if (message.EditedTimestamp is not null)
{
<span class="chatlog__edited-timestamp" title="@FormatDate(message.EditedTimestamp.Value)">(edited)</span>
}
</div>
}
@{/* Attachments */}
@foreach (var attachment in message.Attachments)
{
<div class="chatlog__attachment @(attachment.IsSpoiler ? "chatlog__attachment--hidden" : "")" onclick="@(attachment.IsSpoiler ? "showSpoiler(event, this)" : "")">
@{/* Spoiler caption */}
@if (attachment.IsSpoiler)
{
<div class="chatlog__attachment-spoiler-caption">SPOILER</div>
}
@{/* Attachment preview */}
@if (attachment.IsImage)
{
<a href="@await ResolveUrlAsync(attachment.Url)">
<img class="chatlog__attachment-media" src="@await ResolveUrlAsync(attachment.Url)" alt="@(attachment.Description ?? "Image attachment")" title="Image: @attachment.FileName (@attachment.FileSize)" loading="lazy">
</a>
}
else if (attachment.IsVideo)
{
<video class="chatlog__attachment-media" controls>
<source src="@await ResolveUrlAsync(attachment.Url)" alt="@(attachment.Description ?? "Video attachment")" title="Video: @attachment.FileName (@attachment.FileSize)">
</video>
}
else if (attachment.IsAudio)
{
<audio class="chatlog__attachment-media" controls>
<source src="@await ResolveUrlAsync(attachment.Url)" alt="@(attachment.Description ?? "Audio attachment")" title="Audio: @attachment.FileName (@attachment.FileSize)">
</audio>
} }
else else
{ {
<div class="chatlog__attachment-generic"> <span>@message.Content.ToLowerInvariant()</span>
<svg class="chatlog__attachment-generic-icon"> }
<use href="#attachment-icon"/> </span>
</svg>
<div class="chatlog__attachment-generic-name"> @{/* Timestamp */}
<a href="@await ResolveUrlAsync(attachment.Url)"> <span class="chatlog__system-notification-timestamp">
@attachment.FileName <a href="#chatlog__message-container-@message.Id">@FormatDate(message.Timestamp)</a>
</a> </span>
</div> </div>
<div class="chatlog__attachment-generic-size"> }
@attachment.FileSize // Regular message
</div> else
{
<div class="chatlog__message-aside">
@if (isFirst)
{
// Reference symbol
if (message.Reference is not null)
{
<div class="chatlog__reference-symbol"></div>
}
// Avatar
<img class="chatlog__avatar" src="@await ResolveUrlAsync(message.Author.AvatarUrl)" alt="Avatar" loading="lazy">
}
else
{
<div class="chatlog__short-timestamp" title="@FormatDate(message.Timestamp)">@message.Timestamp.ToLocalString("t")</div>
}
</div>
<div class="chatlog__message-primary">
@if (isFirst)
{
// Reference
if (message.Reference is not null)
{
<div class="chatlog__reference">
@if (message.ReferencedMessage is not null)
{
<img class="chatlog__reference-avatar" src="@await ResolveUrlAsync(message.ReferencedMessage.Author.AvatarUrl)" alt="Avatar" loading="lazy">
<div class="chatlog__reference-author" style="@(referencedUserColor is not null ? $"color: rgb({referencedUserColor.Value.R}, {referencedUserColor.Value.G}, {referencedUserColor.Value.B})" : null)" title="@message.ReferencedMessage.Author.FullName">@referencedUserNick</div>
<div class="chatlog__reference-content">
<span class="chatlog__reference-link" onclick="scrollToMessage(event, '@message.ReferencedMessage.Id')">
@if (!string.IsNullOrWhiteSpace(message.ReferencedMessage.Content) && !message.ReferencedMessage.IsContentHidden())
{
<!--wmm:ignore-->@Raw(FormatEmbedMarkdown(message.ReferencedMessage.Content))<!--/wmm:ignore-->
}
else if (message.ReferencedMessage.Attachments.Any() || message.ReferencedMessage.Embeds.Any())
{
<em>Click to see attachment</em>
<span>🖼️</span>
}
else
{
<em>Click to see original message</em>
}
</span>
@if (message.ReferencedMessage.EditedTimestamp is not null)
{
<span class="chatlog__reference-edited-timestamp" title="@FormatDate(message.ReferencedMessage.EditedTimestamp.Value)">(edited)</span>
}
</div>
}
else
{
<div class="chatlog__reference-unknown">
Original message was deleted or could not be loaded.
</div>
}
</div> </div>
} }
</div>
}
@{/* Embeds */} // Header
@foreach (var embed in message.Embeds) <div class="chatlog__header">
{ @{/* Author name */}
// Plain image embed <span class="chatlog__author" style="@(userColor is not null ? $"color: rgb({userColor.Value.R}, {userColor.Value.G}, {userColor.Value.B})" : null)" title="@message.Author.FullName" data-user-id="@message.Author.Id">@userNick</span>
if (embed.TryGetPlainImage() is { } plainImageEmbed)
{ @{/* Bot label */}
<div class="chatlog__embed"> @if (message.Author.IsBot)
<a href="@await ResolveUrlAsync(plainImageEmbed.Url)">
<img class="chatlog__embed-plainimage" src="@await ResolveUrlAsync(plainImageEmbed.Url)" alt="Embedded image" loading="lazy">
</a>
</div>
}
// Spotify embed
else if (embed.TryGetSpotifyTrack() is { } spotifyTrackEmbed)
{
<div class="chatlog__embed">
<div class="chatlog__embed-spotify-container">
<iframe class="chatlog__embed-spotify" src="@spotifyTrackEmbed.Url" width="400" height="80" allowtransparency="true" allow="encrypted-media"></iframe>
</div>
</div>
}
// YouTube embed
else if (embed.TryGetYouTubeVideo() is { } youTubeVideoEmbed)
{
<div class="chatlog__embed">
@{/* Color pill */}
@if (embed.Color is not null)
{ {
<div class="chatlog__embed-color-pill" style="background-color: rgba(@embed.Color.Value.R, @embed.Color.Value.G, @embed.Color.Value.B, @embed.Color.Value.A)"></div> <span class="chatlog__bot-label">BOT</span>
}
@{/* Timestamp */}
<span class="chatlog__timestamp"><a href="#chatlog__message-container-@message.Id">@FormatDate(message.Timestamp)</a></span>
</div>
}
@{/* Content */}
@if ((!string.IsNullOrWhiteSpace(message.Content) && !message.IsContentHidden()) || message.EditedTimestamp is not null)
{
<div class="chatlog__content chatlog__markdown">
@{/* Text */}
@if (!string.IsNullOrWhiteSpace(message.Content) && !message.IsContentHidden())
{
<span class="chatlog__markdown-preserve"><!--wmm:ignore-->@Raw(FormatMarkdown(message.Content))<!--/wmm:ignore--></span>
}
@{/* Edited timestamp */}
@if (message.EditedTimestamp is not null)
{
<span class="chatlog__edited-timestamp" title="@FormatDate(message.EditedTimestamp.Value)">(edited)</span>
}
</div>
}
@{/* Attachments */}
@foreach (var attachment in message.Attachments)
{
<div class="chatlog__attachment @(attachment.IsSpoiler ? "chatlog__attachment--hidden" : null)" onclick="@(attachment.IsSpoiler ? "showSpoiler(event, this)" : null)">
@{/* Spoiler caption */}
@if (attachment.IsSpoiler)
{
<div class="chatlog__attachment-spoiler-caption">SPOILER</div>
}
@{/* Attachment preview */}
@if (attachment.IsImage)
{
<a href="@await ResolveUrlAsync(attachment.Url)">
<img class="chatlog__attachment-media" src="@await ResolveUrlAsync(attachment.Url)" alt="@(attachment.Description ?? "Image attachment")" title="Image: @attachment.FileName (@attachment.FileSize)" loading="lazy">
</a>
}
else if (attachment.IsVideo)
{
<video class="chatlog__attachment-media" controls>
<source src="@await ResolveUrlAsync(attachment.Url)" alt="@(attachment.Description ?? "Video attachment")" title="Video: @attachment.FileName (@attachment.FileSize)">
</video>
}
else if (attachment.IsAudio)
{
<audio class="chatlog__attachment-media" controls>
<source src="@await ResolveUrlAsync(attachment.Url)" alt="@(attachment.Description ?? "Audio attachment")" title="Audio: @attachment.FileName (@attachment.FileSize)">
</audio>
} }
else else
{ {
<div class="chatlog__embed-color-pill chatlog__embed-color-pill--default"></div> <div class="chatlog__attachment-generic">
<svg class="chatlog__attachment-generic-icon">
<use href="#attachment-icon"/>
</svg>
<div class="chatlog__attachment-generic-name">
<a href="@await ResolveUrlAsync(attachment.Url)">
@attachment.FileName
</a>
</div>
<div class="chatlog__attachment-generic-size">
@attachment.FileSize
</div>
</div>
} }
</div>
}
<div class="chatlog__embed-content-container"> @{/* Embeds */}
<div class="chatlog__embed-content"> @foreach (var embed in message.Embeds)
<div class="chatlog__embed-text"> {
@{/* Embed author */} // Spotify embed
@if (embed.Author is not null) if (embed.TryGetSpotifyTrack() is { } spotifyTrackEmbed)
{ {
<div class="chatlog__embed-author-container"> <div class="chatlog__embed">
@if (!string.IsNullOrWhiteSpace(embed.Author.IconUrl)) <div class="chatlog__embed-spotify-container">
{ <iframe class="chatlog__embed-spotify" src="@spotifyTrackEmbed.Url" width="400" height="80" allowtransparency="true" allow="encrypted-media"></iframe>
<img class="chatlog__embed-author-icon" src="@await ResolveUrlAsync(embed.Author.IconProxyUrl ?? embed.Author.IconUrl)" alt="Author icon" loading="lazy" onerror="this.style.visibility='hidden'"> </div>
} </div>
}
// YouTube embed
else if (embed.TryGetYouTubeVideo() is { } youTubeVideoEmbed)
{
<div class="chatlog__embed">
@{/* Color pill */}
@if (embed.Color is not null)
{
<div class="chatlog__embed-color-pill" style="background-color: rgba(@embed.Color.Value.R, @embed.Color.Value.G, @embed.Color.Value.B, @embed.Color.Value.A)"></div>
}
else
{
<div class="chatlog__embed-color-pill chatlog__embed-color-pill--default"></div>
}
@if (!string.IsNullOrWhiteSpace(embed.Author.Name)) <div class="chatlog__embed-content-container">
{ <div class="chatlog__embed-content">
if (!string.IsNullOrWhiteSpace(embed.Author.Url)) <div class="chatlog__embed-text">
@{/* Embed author */}
@if (embed.Author is not null)
{
<div class="chatlog__embed-author-container">
@if (!string.IsNullOrWhiteSpace(embed.Author.IconUrl))
{ {
<a class="chatlog__embed-author-link" href="@embed.Author.Url"> <img class="chatlog__embed-author-icon" src="@await ResolveUrlAsync(embed.Author.IconProxyUrl ?? embed.Author.IconUrl)" alt="Author icon" loading="lazy" onerror="this.style.visibility='hidden'">
}
@if (!string.IsNullOrWhiteSpace(embed.Author.Name))
{
if (!string.IsNullOrWhiteSpace(embed.Author.Url))
{
<a class="chatlog__embed-author-link" href="@embed.Author.Url">
<div class="chatlog__embed-author">@embed.Author.Name</div>
</a>
}
else
{
<div class="chatlog__embed-author">@embed.Author.Name</div> <div class="chatlog__embed-author">@embed.Author.Name</div>
}
}
</div>
}
@{/* Embed title */}
@if (!string.IsNullOrWhiteSpace(embed.Title))
{
<div class="chatlog__embed-title">
@if (!string.IsNullOrWhiteSpace(embed.Url))
{
<a class="chatlog__embed-title-link" href="@embed.Url">
<div class="chatlog__markdown chatlog__markdown-preserve"><!--wmm:ignore-->@Raw(FormatEmbedMarkdown(embed.Title))<!--/wmm:ignore--></div>
</a> </a>
} }
else else
{ {
<div class="chatlog__embed-author">@embed.Author.Name</div> <div class="chatlog__markdown chatlog__markdown-preserve"><!--wmm:ignore-->@Raw(FormatEmbedMarkdown(embed.Title))<!--/wmm:ignore--></div>
} }
} </div>
</div> }
}
@{/* Embed title */} @{/* Video player */}
@if (!string.IsNullOrWhiteSpace(embed.Title)) <div class="chatlog__embed-youtube-container">
{ <iframe class="chatlog__embed-youtube" src="@youTubeVideoEmbed.Url" width="400" height="225"></iframe>
<div class="chatlog__embed-title">
@if (!string.IsNullOrWhiteSpace(embed.Url))
{
<a class="chatlog__embed-title-link" href="@embed.Url">
<div class="chatlog__markdown chatlog__markdown-preserve">@Raw(FormatEmbedMarkdown(embed.Title))</div>
</a>
}
else
{
<div class="chatlog__markdown chatlog__markdown-preserve">@Raw(FormatEmbedMarkdown(embed.Title))</div>
}
</div> </div>
}
@{/* Video player */}
<div class="chatlog__embed-youtube-container">
<iframe class="chatlog__embed-youtube" src="@youTubeVideoEmbed.Url" width="400" height="225"></iframe>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> }
} // Generic image embed
// Generic embed else if (embed.Kind == EmbedKind.Image && !string.IsNullOrWhiteSpace(embed.Url))
else {
{ <div class="chatlog__embed">
<div class="chatlog__embed"> <a href="@await ResolveUrlAsync(embed.Url)">
@{/* Color pill */} <img class="chatlog__embed-generic-image" src="@await ResolveUrlAsync(embed.Url)" alt="Embedded image" loading="lazy">
@if (embed.Color is not null) </a>
{ </div>
<div class="chatlog__embed-color-pill" style="background-color: rgba(@embed.Color.Value.R, @embed.Color.Value.G, @embed.Color.Value.B, @embed.Color.Value.A)"></div> }
} // Generic gifv embed
else else if (embed.Kind == EmbedKind.Gifv && !string.IsNullOrWhiteSpace(embed.Video?.Url))
{ {
<div class="chatlog__embed-color-pill chatlog__embed-color-pill--default"></div> <div class="chatlog__embed">
} <video class="chatlog__embed-generic-gifv" loop width="@embed.Video.Width" height="@embed.Video.Height" onmouseover="this.play()" onmouseout="this.pause()">
<source src="@await ResolveUrlAsync(embed.Video.ProxyUrl ?? embed.Video.Url)" alt="Embedded video">
</video>
</div>
}
// Rich embed
else
{
<div class="chatlog__embed">
@{/* Color pill */}
@if (embed.Color is not null)
{
<div class="chatlog__embed-color-pill" style="background-color: rgba(@embed.Color.Value.R, @embed.Color.Value.G, @embed.Color.Value.B, @embed.Color.Value.A)"></div>
}
else
{
<div class="chatlog__embed-color-pill chatlog__embed-color-pill--default"></div>
}
<div class="chatlog__embed-content-container"> <div class="chatlog__embed-content-container">
<div class="chatlog__embed-content"> <div class="chatlog__embed-content">
<div class="chatlog__embed-text"> <div class="chatlog__embed-text">
@{/* Embed author */} @{/* Embed author */}
@if (embed.Author is not null) @if (embed.Author is not null)
{ {
<div class="chatlog__embed-author-container"> <div class="chatlog__embed-author-container">
@if (!string.IsNullOrWhiteSpace(embed.Author.IconUrl)) @if (!string.IsNullOrWhiteSpace(embed.Author.IconUrl))
{
<img class="chatlog__embed-author-icon" src="@await ResolveUrlAsync(embed.Author.IconProxyUrl ?? embed.Author.IconUrl)" alt="Author icon" loading="lazy" onerror="this.style.visibility='hidden'">
}
@if (!string.IsNullOrWhiteSpace(embed.Author.Name))
{
if (!string.IsNullOrWhiteSpace(embed.Author.Url))
{ {
<a class="chatlog__embed-author-link" href="@embed.Author.Url"> <img class="chatlog__embed-author-icon" src="@await ResolveUrlAsync(embed.Author.IconProxyUrl ?? embed.Author.IconUrl)" alt="Author icon" loading="lazy" onerror="this.style.visibility='hidden'">
}
@if (!string.IsNullOrWhiteSpace(embed.Author.Name))
{
if (!string.IsNullOrWhiteSpace(embed.Author.Url))
{
<a class="chatlog__embed-author-link" href="@embed.Author.Url">
<div class="chatlog__embed-author">@embed.Author.Name</div>
</a>
}
else
{
<div class="chatlog__embed-author">@embed.Author.Name</div> <div class="chatlog__embed-author">@embed.Author.Name</div>
}
}
</div>
}
@{/* Embed title */}
@if (!string.IsNullOrWhiteSpace(embed.Title))
{
<div class="chatlog__embed-title">
@if (!string.IsNullOrWhiteSpace(embed.Url))
{
<a class="chatlog__embed-title-link" href="@embed.Url">
<div class="chatlog__markdown chatlog__markdown-preserve"><!--wmm:ignore-->@Raw(FormatEmbedMarkdown(embed.Title))<!--/wmm:ignore--></div>
</a> </a>
} }
else else
{ {
<div class="chatlog__embed-author">@embed.Author.Name</div> <div class="chatlog__markdown chatlog__markdown-preserve"><!--wmm:ignore-->@Raw(FormatEmbedMarkdown(embed.Title))<!--/wmm:ignore--></div>
} }
} </div>
</div> }
}
@{/* Embed title */} @{/* Embed description */}
@if (!string.IsNullOrWhiteSpace(embed.Title)) @if (!string.IsNullOrWhiteSpace(embed.Description))
{
<div class="chatlog__embed-description">
<div class="chatlog__markdown chatlog__markdown-preserve"><!--wmm:ignore-->@Raw(FormatEmbedMarkdown(embed.Description))<!--/wmm:ignore--></div>
</div>
}
@{/* Embed fields */}
@if (embed.Fields.Any())
{
<div class="chatlog__embed-fields">
@foreach (var field in embed.Fields)
{
<div class="chatlog__embed-field @(field.IsInline ? "chatlog__embed-field--inline" : null)">
@if (!string.IsNullOrWhiteSpace(field.Name))
{
<div class="chatlog__embed-field-name">
<div class="chatlog__markdown chatlog__markdown-preserve"><!--wmm:ignore-->@Raw(FormatEmbedMarkdown(field.Name))<!--/wmm:ignore--></div>
</div>
}
@if (!string.IsNullOrWhiteSpace(field.Value))
{
<div class="chatlog__embed-field-value">
<div class="chatlog__markdown chatlog__markdown-preserve"><!--wmm:ignore-->@Raw(FormatEmbedMarkdown(field.Value))<!--/wmm:ignore--></div>
</div>
}
</div>
}
</div>
}
</div>
@{/* Embed content */}
@if (embed.Thumbnail is not null && !string.IsNullOrWhiteSpace(embed.Thumbnail.Url))
{ {
<div class="chatlog__embed-title"> <div class="chatlog__embed-thumbnail-container">
@if (!string.IsNullOrWhiteSpace(embed.Url)) <a class="chatlog__embed-thumbnail-link" href="@await ResolveUrlAsync(embed.Thumbnail.ProxyUrl ?? embed.Thumbnail.Url)">
{ <img class="chatlog__embed-thumbnail" src="@await ResolveUrlAsync(embed.Thumbnail.ProxyUrl ?? embed.Thumbnail.Url)" alt="Thumbnail" loading="lazy">
<a class="chatlog__embed-title-link" href="@embed.Url"> </a>
<div class="chatlog__markdown chatlog__markdown-preserve">@Raw(FormatEmbedMarkdown(embed.Title))</div>
</a>
}
else
{
<div class="chatlog__markdown chatlog__markdown-preserve">@Raw(FormatEmbedMarkdown(embed.Title))</div>
}
</div>
}
@{/* Embed description */}
@if (!string.IsNullOrWhiteSpace(embed.Description))
{
<div class="chatlog__embed-description">
<div class="chatlog__markdown chatlog__markdown-preserve">@Raw(FormatEmbedMarkdown(embed.Description))</div>
</div>
}
@{/* Embed fields */}
@if (embed.Fields.Any())
{
<div class="chatlog__embed-fields">
@foreach (var field in embed.Fields)
{
<div class="chatlog__embed-field @(field.IsInline ? "chatlog__embed-field--inline" : null)">
@if (!string.IsNullOrWhiteSpace(field.Name))
{
<div class="chatlog__embed-field-name">
<div class="chatlog__markdown chatlog__markdown-preserve">@Raw(FormatEmbedMarkdown(field.Name))</div>
</div>
}
@if (!string.IsNullOrWhiteSpace(field.Value))
{
<div class="chatlog__embed-field-value">
<div class="chatlog__markdown chatlog__markdown-preserve">@Raw(FormatEmbedMarkdown(field.Value))</div>
</div>
}
</div>
}
</div> </div>
} }
</div> </div>
@{/* Embed content */} @{/* Embed images */}
@if (embed.Thumbnail is not null && !string.IsNullOrWhiteSpace(embed.Thumbnail.Url)) @if (embed.Images.Any())
{ {
<div class="chatlog__embed-thumbnail-container"> <div class="chatlog__embed-images @(embed.Images.Count == 1 ? "chatlog__embed-images--single" : null)">
<a class="chatlog__embed-thumbnail-link" href="@await ResolveUrlAsync(embed.Thumbnail.ProxyUrl ?? embed.Thumbnail.Url)"> @foreach (var image in embed.Images)
<img class="chatlog__embed-thumbnail" src="@await ResolveUrlAsync(embed.Thumbnail.ProxyUrl ?? embed.Thumbnail.Url)" alt="Thumbnail" loading="lazy"> {
</a> if (!string.IsNullOrWhiteSpace(image.Url))
{
<div class="chatlog__embed-image-container">
<a class="chatlog__embed-image-link" href="@await ResolveUrlAsync(image.ProxyUrl ?? image.Url)">
<img class="chatlog__embed-image" src="@await ResolveUrlAsync(image.ProxyUrl ?? image.Url)" alt="Image" loading="lazy">
</a>
</div>
}
}
</div>
}
@{/* Embed footer & icon */}
@if (embed.Footer is not null || embed.Timestamp is not null)
{
<div class="chatlog__embed-footer">
@{/* Footer icon */}
@if (!string.IsNullOrWhiteSpace(embed.Footer?.IconUrl))
{
<img class="chatlog__embed-footer-icon" src="@await ResolveUrlAsync(embed.Footer.IconProxyUrl ?? embed.Footer.IconUrl)" alt="Footer icon" loading="lazy">
}
<span class="chatlog__embed-footer-text">
@{/* Footer text */}
@if (!string.IsNullOrWhiteSpace(embed.Footer?.Text))
{
@embed.Footer.Text
}
@if (!string.IsNullOrWhiteSpace(embed.Footer?.Text) && embed.Timestamp is not null)
{
@(" • ")
}
@{/* Embed timestamp */}
@if (embed.Timestamp is not null)
{
@FormatDate(embed.Timestamp.Value)
}
</span>
</div> </div>
} }
</div> </div>
@{/* Embed image */}
@if (embed.Image is not null && !string.IsNullOrWhiteSpace(embed.Image.Url))
{
<div class="chatlog__embed-image-container">
<a class="chatlog__embed-image-link" href="@await ResolveUrlAsync(embed.Image.ProxyUrl ?? embed.Image.Url)">
<img class="chatlog__embed-image" src="@await ResolveUrlAsync(embed.Image.ProxyUrl ?? embed.Image.Url)" alt="Image" loading="lazy">
</a>
</div>
}
@{/* Embed footer & icon */}
@if (embed.Footer is not null || embed.Timestamp is not null)
{
<div class="chatlog__embed-footer">
@{/* Footer icon */}
@if (!string.IsNullOrWhiteSpace(embed.Footer?.IconUrl))
{
<img class="chatlog__embed-footer-icon" src="@await ResolveUrlAsync(embed.Footer.IconProxyUrl ?? embed.Footer.IconUrl)" alt="Footer icon" loading="lazy">
}
<span class="chatlog__embed-footer-text">
@{/* Footer text */}
@if (!string.IsNullOrWhiteSpace(embed.Footer?.Text))
{
@embed.Footer.Text
}
@if (!string.IsNullOrWhiteSpace(embed.Footer?.Text) && embed.Timestamp is not null)
{
@(" • ")
}
@{/* Embed timestamp */}
@if (embed.Timestamp is not null)
{
@FormatDate(embed.Timestamp.Value)
}
</span>
</div>
}
</div> </div>
}
}
@{/* Stickers */}
@foreach (var sticker in message.Stickers)
{
<div class="chatlog__sticker" title="@sticker.Name">
@if (sticker.Format is StickerFormat.Png or StickerFormat.PngAnimated)
{
<img class="chatlog__sticker--media" src="@await ResolveUrlAsync(sticker.SourceUrl)" alt="Sticker">
}
else if (sticker.Format == StickerFormat.Lottie)
{
<div class="chatlog__sticker--media" data-source="@await ResolveUrlAsync(sticker.SourceUrl)"></div>
}
</div> </div>
} }
}
@{/* Stickers */} @{/* Message reactions */}
@foreach (var sticker in message.Stickers) @if (message.Reactions.Any())
{ {
<div class="chatlog__sticker" title="@sticker.Name"> <div class="chatlog__reactions">
@if (sticker.Format is StickerFormat.Png or StickerFormat.PngAnimated) @foreach (var reaction in message.Reactions)
{ {
<img class="chatlog__sticker--media" src="@await ResolveUrlAsync(sticker.SourceUrl)" alt="Sticker"> <div class="chatlog__reaction" title="@reaction.Emoji.Code">
} <img class="chatlog__emoji chatlog__emoji--small" alt="@reaction.Emoji.Name" src="@await ResolveUrlAsync(reaction.Emoji.ImageUrl)" loading="lazy">
else if (sticker.Format == StickerFormat.Lottie) <span class="chatlog__reaction-count">@reaction.Count</span>
{ </div>
<div class="chatlog__sticker--media" data-source="@await ResolveUrlAsync(sticker.SourceUrl)"></div> }
} </div>
</div> }
} </div>
}
@{/* Message reactions */}
@if (message.Reactions.Any())
{
<div class="chatlog__reactions">
@foreach (var reaction in message.Reactions)
{
<div class="chatlog__reaction" title="@reaction.Emoji.Code">
<img class="chatlog__emoji chatlog__emoji--small" alt="@reaction.Emoji.Name" src="@await ResolveUrlAsync(reaction.Emoji.ImageUrl)" loading="lazy">
<span class="chatlog__reaction-count">@reaction.Count</span>
</div>
}
</div>
}
</div>
</div> </div>
</div> </div>
} }
@@ -4,7 +4,9 @@
@inherits MiniRazor.TemplateBase<PostambleTemplateContext> @inherits MiniRazor.TemplateBase<PostambleTemplateContext>
@{/* Close elements opened by preamble */} @{/* Close elements opened by preamble */}
<!--wmm:ignore-->
</div> </div>
<!--/wmm:ignore-->
<div class="postamble"> <div class="postamble">
<div class="postamble__entry">Exported @Model.MessagesWritten.ToString("N0") message(s)</div> <div class="postamble__entry">Exported @Model.MessagesWritten.ToString("N0") message(s)</div>
@@ -69,6 +69,7 @@
font-family: Whitney, "Helvetica Neue", Helvetica, Arial, sans-serif; font-family: Whitney, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 17px; font-size: 17px;
font-weight: @Themed("400", "500"); font-weight: @Themed("400", "500");
scroll-behavior: smooth;
} }
a { a {
@@ -229,7 +230,11 @@
pointer-events: none; pointer-events: none;
} }
.chatlog__reference-link .hljs { .chatlog__reference-link .chatlog__markdown-quote {
display: inline;
}
.chatlog__reference-link .chatlog__markdown-pre {
display: inline; display: inline;
} }
@@ -250,6 +255,38 @@
unicode-bidi: bidi-override; unicode-bidi: bidi-override;
} }
.chatlog__system-notification-icon {
width: 18px;
height: 18px;
}
.chatlog__system-notification-author {
font-weight: @Themed("500", "600");
color: @Themed("#ffffff", "#2f3136");
}
.chatlog__system-notification-content {
color: @Themed("#96989d", "#5e6772")
}
.chatlog__system-notification-link {
font-weight: 500;
color: @Themed("#ffffff", "#2f3136");
}
.chatlog__system-notification-timestamp {
margin-left: 0.3rem;
color: @Themed("#a3a6aa", "#5e6772");
font-size: 0.75rem;
font-weight: 500;
direction: ltr;
unicode-bidi: bidi-override;
}
.chatlog__system-notification-timestamp a {
color: inherit;
}
.chatlog__header { .chatlog__header {
margin-bottom: 0.1rem; margin-bottom: 0.1rem;
} }
@@ -281,6 +318,10 @@
unicode-bidi: bidi-override; unicode-bidi: bidi-override;
} }
.chatlog__timestamp a {
color: inherit;
}
.chatlog__content { .chatlog__content {
padding-right: 1rem; padding-right: 1rem;
font-size: 0.95rem; font-size: 0.95rem;
@@ -492,13 +533,24 @@
border-radius: 3px; border-radius: 3px;
} }
.chatlog__embed-image-container { .chatlog__embed-images {
display: grid;
margin-top: 0.6rem; margin-top: 0.6rem;
grid-template-columns: repeat(2, 1fr);
gap: 0.25rem;
}
.chatlog__embed-images--single {
display: block;
} }
.chatlog__embed-image { .chatlog__embed-image {
object-fit: cover;
object-position: center;
max-width: 500px; max-width: 500px;
max-height: 400px; max-height: 400px;
width: 100%;
height: 100%;
border-radius: 3px; border-radius: 3px;
} }
@@ -521,7 +573,14 @@
font-weight: 500; font-weight: 500;
} }
.chatlog__embed-plainimage { .chatlog__embed-generic-image {
max-width: 45vw;
max-height: 500px;
vertical-align: top;
border-radius: 3px;
}
.chatlog__embed-generic-gifv {
max-width: 45vw; max-width: 45vw;
max-height: 500px; max-height: 500px;
vertical-align: top; vertical-align: top;
@@ -624,9 +683,11 @@
.chatlog__markdown-pre { .chatlog__markdown-pre {
background-color: @Themed("#2f3136", "#f9f9f9"); background-color: @Themed("#2f3136", "#f9f9f9");
font-family: "Consolas", "Courier New", Courier, monospace; font-family: "Consolas", "Courier New", Courier, monospace;
font-size: 0.85rem;
} }
.chatlog__markdown-pre--multiline { .chatlog__markdown-pre--multiline {
display: block;
margin-top: 0.25rem; margin-top: 0.25rem;
padding: 0.5rem; padding: 0.5rem;
border: 2px solid @Themed("#282b30", "#f3f3f3"); border: 2px solid @Themed("#282b30", "#f3f3f3");
@@ -635,14 +696,14 @@
} }
.chatlog__markdown-pre--multiline.hljs { .chatlog__markdown-pre--multiline.hljs {
background-color: inherit; background-color: @Themed("#2f3136", "#f9f9f9");
color: inherit; color: @Themed("#b9bbbe", "#657b83");
} }
.chatlog__markdown-pre--inline { .chatlog__markdown-pre--inline {
display: inline-block;
padding: 2px; padding: 2px;
border-radius: 3px; border-radius: 3px;
font-size: 0.85rem;
} }
.chatlog__markdown-mention { .chatlog__markdown-mention {
@@ -704,18 +765,17 @@
<script> <script>
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.chatlog__sticker--media[data-source]').forEach(e => { document.querySelectorAll('.chatlog__sticker--media[data-source]').forEach(e => {
const imageDataUrl = e.getAttribute('data-source');
const anim = lottie.loadAnimation({ const anim = lottie.loadAnimation({
container: e, container: e,
renderer: 'svg', renderer: 'svg',
loop: true, loop: true,
autoplay: true, autoplay: true,
path: imageDataUrl path: e.getAttribute('data-source')
}); });
anim.addEventListener('data_failed', () => anim.addEventListener(
e.innerHTML = '<strong>[Sticker cannot be rendered]</strong>' 'data_failed',
() => e.innerHTML = '<strong>[Sticker cannot be rendered]</strong>'
); );
}); });
}); });
@@ -724,7 +784,7 @@
@{/* Scripts */} @{/* Scripts */}
<script> <script>
function scrollToMessage(event, id) { function scrollToMessage(event, id) {
var element = document.getElementById('chatlog__message-container-' + id); const element = document.getElementById('chatlog__message-container-' + id);
if (!element) if (!element)
return; return;
@@ -736,9 +796,10 @@
behavior: 'smooth' behavior: 'smooth'
}); });
window.setTimeout(function() { window.setTimeout(
element.classList.remove('chatlog__message-container--highlighted'); () => element.classList.remove('chatlog__message-container--highlighted'),
}, 2000); 2000
);
} }
function showSpoiler(event, element) { function showSpoiler(event, element) {
@@ -758,13 +819,24 @@
</script> </script>
@{/* Icons */} @{/* Icons */}
<svg style="display: none"> <svg style="display: none" xmlns="http://www.w3.org/2000/svg">
<symbol id="attachment-icon" viewBox="0 0 720 960"> <defs>
<path fill="#f4f5fb" d="M50,935a25,25,0,0,1-25-25V50A25,25,0,0,1,50,25H519.6L695,201.32V910a25,25,0,0,1-25,25Z"/> <symbol id="attachment-icon" viewBox="0 0 720 960">
<path fill="#7789c4" d="M509.21,50,670,211.63V910H50V50H509.21M530,0H50A50,50,0,0,0,0,50V910a50,50,0,0,0,50,50H670a50,50,0,0,0,50-50h0V191Z"/> <path fill="#f4f5fb" d="M50,935a25,25,0,0,1-25-25V50A25,25,0,0,1,50,25H519.6L695,201.32V910a25,25,0,0,1-25,25Z" />
<path fill="#f4f5fb" d="M530,215a25,25,0,0,1-25-25V50a25,25,0,0,1,16.23-23.41L693.41,198.77A25,25,0,0,1,670,215Z"/> <path fill="#7789c4" d="M509.21,50,670,211.63V910H50V50H509.21M530,0H50A50,50,0,0,0,0,50V910a50,50,0,0,0,50,50H670a50,50,0,0,0,50-50h0V191Z" />
<path fill="#7789c4" d="M530,70.71,649.29,190H530V70.71M530,0a50,50,0,0,0-50,50V190a50,50,0,0,0,50,50H670a50,50,0,0,0,50-50Z"/> <path fill="#f4f5fb" d="M530,215a25,25,0,0,1-25-25V50a25,25,0,0,1,16.23-23.41L693.41,198.77A25,25,0,0,1,670,215Z" />
</symbol> <path fill="#7789c4" d="M530,70.71,649.29,190H530V70.71M530,0a50,50,0,0,0-50,50V190a50,50,0,0,0,50,50H670a50,50,0,0,0,50-50Z" />
</symbol>
<symbol id="channel-pinned-message-icon" viewBox="0 0 18 18">
<path fill="#b9bbbe" d="m16.908 8.39684-8.29587-8.295827-1.18584 1.184157 1.18584 1.18584-4.14834 4.1475v.00167l-1.18583-1.18583-1.185 1.18583 3.55583 3.55502-4.740831 4.74 1.185001 1.185 4.74083-4.74 3.55581 3.555 1.185-1.185-1.185-1.185 4.1475-4.14836h.0009l1.185 1.185z" />
</symbol>
<symbol id="call-icon" viewBox="0 0 18 18">
<path fill="#3ba55c" fill-rule="evenodd" d="M17.7163041 15.36645368c-.0190957.02699568-1.9039523 2.6680735-2.9957762 2.63320406-3.0676659-.09785935-6.6733809-3.07188394-9.15694343-5.548738C3.08002193 9.9740657.09772497 6.3791404 0 3.3061316v-.024746C0 2.2060575 2.61386252.3152347 2.64082114.2972376c.7110335-.4971705 1.4917101-.3149497 1.80959713.1372281.19320342.2744561 2.19712724 3.2811005 2.42290565 3.6489167.09884826.1608492.14714912.3554431.14714912.5702838 0 .2744561-.07975258.5770327-.23701117.8751101-.1527655.2902036-.65262318 1.1664385-.89862055 1.594995.2673396.3768148.94804468 1.26429792 2.351016 2.66357424 1.39173858 1.39027775 2.28923588 2.07641807 2.67002628 2.34187563.4302146-.2452108 1.3086162-.74238132 1.5972981-.89423205.5447887-.28682915 1.0907006-.31944893 1.4568885-.08661115.3459689.2182151 3.3383754 2.21027167 3.6225641 2.41611376.2695862.19234426.4144887.5399137.4144887.91672846 0 .2969525-.089862.61190215-.2808189.88523346" />
</symbol>
<symbol id="guild-member-join-icon" viewBox="0 0 18 18">
<path fill="#3ba55c" d="m0 8h14.2l-3.6-3.6 1.4-1.4 6 6-6 6-1.4-1.4 3.6-3.6h-14.2" />
</symbol>
</defs>
</svg> </svg>
</head> </head>
<body> <body>
@@ -803,4 +875,6 @@
</div> </div>
@{/* Preamble cuts off at this point */} @{/* Preamble cuts off at this point */}
<!--wmm:ignore-->
<div class="chatlog"> <div class="chatlog">
<!--/wmm:ignore-->
@@ -6,6 +6,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using DiscordChatExporter.Core.Discord.Data; using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Exporting.Writers.Html; using DiscordChatExporter.Core.Exporting.Writers.Html;
using WebMarkupMin.Core;
namespace DiscordChatExporter.Core.Exporting.Writers; namespace DiscordChatExporter.Core.Exporting.Writers;
@@ -14,6 +15,7 @@ internal class HtmlMessageWriter : MessageWriter
private readonly TextWriter _writer; private readonly TextWriter _writer;
private readonly string _themeName; private readonly string _themeName;
private readonly HtmlMinifier _minifier = new();
private readonly List<Message> _messageGroup = new(); private readonly List<Message> _messageGroup = new();
public HtmlMessageWriter(Stream stream, ExportContext context, string themeName) public HtmlMessageWriter(Stream stream, ExportContext context, string themeName)
@@ -25,21 +27,50 @@ internal class HtmlMessageWriter : MessageWriter
private bool CanJoinGroup(Message message) private bool CanJoinGroup(Message message)
{ {
var lastMessage = _messageGroup.LastOrDefault(); // If the group is empty, any message can join it
if (lastMessage is null) if (_messageGroup.LastOrDefault() is not { } lastMessage)
return true; return true;
return // Reply messages cannot join existing groups because they need to appear first
// Must be from the same author if (message.Kind == MessageKind.Reply)
lastMessage.Author.Id == message.Author.Id && return false;
// Author's name must not have changed between messages
string.Equals(lastMessage.Author.FullName, message.Author.FullName, StringComparison.Ordinal) && // Grouping for system notifications
// Duration between messages must be 7 minutes or less if (message.Kind.IsSystemNotification())
(message.Timestamp - lastMessage.Timestamp).Duration().TotalMinutes <= 7 && {
// Other message must not be a reply // Can only be grouped with other system notifications
message.Reference is null; if (!lastMessage.Kind.IsSystemNotification())
return false;
}
// Grouping for normal messages
else
{
// Can only be grouped with other normal messages
if (lastMessage.Kind.IsSystemNotification())
return false;
// Messages must be within 7 minutes of each other
if ((message.Timestamp - lastMessage.Timestamp).Duration().TotalMinutes > 7)
return false;
// Messages must be from the same author
if (message.Author.Id != lastMessage.Author.Id)
return false;
// If the user changed their name after the last message, their new messages
// cannot join an existing group.
if (!string.Equals(message.Author.FullName, lastMessage.Author.FullName, StringComparison.Ordinal))
return false;
}
return true;
} }
// Use <!--wmm:ignore--> to preserve blocks of code inside the templates
private string Minify(string html) => _minifier
.Minify(html, false)
.MinifiedContent;
public override async ValueTask WritePreambleAsync(CancellationToken cancellationToken = default) public override async ValueTask WritePreambleAsync(CancellationToken cancellationToken = default)
{ {
var templateContext = new PreambleTemplateContext(Context, _themeName); var templateContext = new PreambleTemplateContext(Context, _themeName);
@@ -47,7 +78,9 @@ internal class HtmlMessageWriter : MessageWriter
// We are not writing directly to output because Razor // We are not writing directly to output because Razor
// does not actually do asynchronous writes to stream. // does not actually do asynchronous writes to stream.
await _writer.WriteLineAsync( await _writer.WriteLineAsync(
await PreambleTemplate.RenderAsync(templateContext, cancellationToken) Minify(
await PreambleTemplate.RenderAsync(templateContext, cancellationToken)
)
); );
} }
@@ -60,7 +93,9 @@ internal class HtmlMessageWriter : MessageWriter
// We are not writing directly to output because Razor // We are not writing directly to output because Razor
// does not actually do asynchronous writes to stream. // does not actually do asynchronous writes to stream.
await _writer.WriteLineAsync( await _writer.WriteLineAsync(
await MessageGroupTemplate.RenderAsync(templateContext, cancellationToken) Minify(
await MessageGroupTemplate.RenderAsync(templateContext, cancellationToken)
)
); );
} }
@@ -71,7 +106,7 @@ internal class HtmlMessageWriter : MessageWriter
await base.WriteMessageAsync(message, cancellationToken); await base.WriteMessageAsync(message, cancellationToken);
// If the message can be grouped, buffer it for now // If the message can be grouped, buffer it for now
if (CanJoinGroup( message)) if (CanJoinGroup(message))
{ {
_messageGroup.Add(message); _messageGroup.Add(message);
} }
@@ -96,7 +131,9 @@ internal class HtmlMessageWriter : MessageWriter
// We are not writing directly to output because Razor // We are not writing directly to output because Razor
// does not actually do asynchronous writes to stream. // does not actually do asynchronous writes to stream.
await _writer.WriteLineAsync( await _writer.WriteLineAsync(
await PostambleTemplate.RenderAsync(templateContext, cancellationToken) Minify(
await PostambleTemplate.RenderAsync(templateContext, cancellationToken)
)
); );
} }
@@ -20,6 +20,7 @@ internal class JsonMessageWriter : MessageWriter
{ {
_writer = new Utf8JsonWriter(stream, new JsonWriterOptions _writer = new Utf8JsonWriter(stream, new JsonWriterOptions
{ {
// https://github.com/Tyrrrz/DiscordChatExporter/issues/450
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
Indented = true, Indented = true,
// Validation errors may mask actual failures // Validation errors may mask actual failures
@@ -50,7 +51,7 @@ internal class JsonMessageWriter : MessageWriter
EmbedAuthor embedAuthor, EmbedAuthor embedAuthor,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
_writer.WriteStartObject("author"); _writer.WriteStartObject();
_writer.WriteString("name", embedAuthor.Name); _writer.WriteString("name", embedAuthor.Name);
_writer.WriteString("url", embedAuthor.Url); _writer.WriteString("url", embedAuthor.Url);
@@ -62,27 +63,11 @@ internal class JsonMessageWriter : MessageWriter
await _writer.FlushAsync(cancellationToken); await _writer.FlushAsync(cancellationToken);
} }
private async ValueTask WriteEmbedThumbnailAsync(
EmbedImage embedThumbnail,
CancellationToken cancellationToken = default)
{
_writer.WriteStartObject("thumbnail");
if (!string.IsNullOrWhiteSpace(embedThumbnail.Url))
_writer.WriteString("url", await Context.ResolveMediaUrlAsync(embedThumbnail.ProxyUrl ?? embedThumbnail.Url, cancellationToken));
_writer.WriteNumber("width", embedThumbnail.Width);
_writer.WriteNumber("height", embedThumbnail.Height);
_writer.WriteEndObject();
await _writer.FlushAsync(cancellationToken);
}
private async ValueTask WriteEmbedImageAsync( private async ValueTask WriteEmbedImageAsync(
EmbedImage embedImage, EmbedImage embedImage,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
_writer.WriteStartObject("image"); _writer.WriteStartObject();
if (!string.IsNullOrWhiteSpace(embedImage.Url)) if (!string.IsNullOrWhiteSpace(embedImage.Url))
_writer.WriteString("url", await Context.ResolveMediaUrlAsync(embedImage.ProxyUrl ?? embedImage.Url, cancellationToken)); _writer.WriteString("url", await Context.ResolveMediaUrlAsync(embedImage.ProxyUrl ?? embedImage.Url, cancellationToken));
@@ -98,7 +83,7 @@ internal class JsonMessageWriter : MessageWriter
EmbedFooter embedFooter, EmbedFooter embedFooter,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
_writer.WriteStartObject("footer"); _writer.WriteStartObject();
_writer.WriteString("text", embedFooter.Text); _writer.WriteString("text", embedFooter.Text);
@@ -138,16 +123,37 @@ internal class JsonMessageWriter : MessageWriter
_writer.WriteString("color", embed.Color.Value.ToHex()); _writer.WriteString("color", embed.Color.Value.ToHex());
if (embed.Author is not null) if (embed.Author is not null)
{
_writer.WritePropertyName("author");
await WriteEmbedAuthorAsync(embed.Author, cancellationToken); await WriteEmbedAuthorAsync(embed.Author, cancellationToken);
}
if (embed.Thumbnail is not null) if (embed.Thumbnail is not null)
await WriteEmbedThumbnailAsync(embed.Thumbnail, cancellationToken); {
_writer.WritePropertyName("thumbnail");
await WriteEmbedImageAsync(embed.Thumbnail, cancellationToken);
}
if (embed.Image is not null) // Legacy: backwards-compatibility for old embeds with a single image
await WriteEmbedImageAsync(embed.Image, cancellationToken); if (embed.Images.Count > 0)
{
_writer.WritePropertyName("image");
await WriteEmbedImageAsync(embed.Images[0], cancellationToken);
}
if (embed.Footer is not null) if (embed.Footer is not null)
{
_writer.WritePropertyName("footer");
await WriteEmbedFooterAsync(embed.Footer, cancellationToken); await WriteEmbedFooterAsync(embed.Footer, cancellationToken);
}
// Images
_writer.WriteStartArray("images");
foreach (var image in embed.Images)
await WriteEmbedImageAsync(image, cancellationToken);
_writer.WriteEndArray();
// Fields // Fields
_writer.WriteStartArray("fields"); _writer.WriteStartArray("fields");
@@ -76,9 +76,9 @@ internal partial class HtmlMarkdownVisitor : MarkdownVisitor
protected override MarkdownNode VisitInlineCodeBlock(InlineCodeBlockNode inlineCodeBlock) protected override MarkdownNode VisitInlineCodeBlock(InlineCodeBlockNode inlineCodeBlock)
{ {
_buffer _buffer
.Append("<span class=\"chatlog__markdown-pre chatlog__markdown-pre--inline\">") .Append("<code class=\"chatlog__markdown-pre chatlog__markdown-pre--inline\">")
.Append(HtmlEncode(inlineCodeBlock.Code)) .Append(HtmlEncode(inlineCodeBlock.Code))
.Append("</span>"); .Append("</code>");
return base.VisitInlineCodeBlock(inlineCodeBlock); return base.VisitInlineCodeBlock(inlineCodeBlock);
} }
@@ -90,9 +90,9 @@ internal partial class HtmlMarkdownVisitor : MarkdownVisitor
: "nohighlight"; : "nohighlight";
_buffer _buffer
.Append($"<div class=\"chatlog__markdown-pre chatlog__markdown-pre--multiline {highlightCssClass}\">") .Append($"<code class=\"chatlog__markdown-pre chatlog__markdown-pre--multiline {highlightCssClass}\">")
.Append(HtmlEncode(multiLineCodeBlock.Code)) .Append(HtmlEncode(multiLineCodeBlock.Code))
.Append("</div>"); .Append("</code>");
return base.VisitMultiLineCodeBlock(multiLineCodeBlock); return base.VisitMultiLineCodeBlock(multiLineCodeBlock);
} }
@@ -158,7 +158,7 @@ internal partial class HtmlMarkdownVisitor : MarkdownVisitor
else if (mention.Kind == MentionKind.Channel) else if (mention.Kind == MentionKind.Channel)
{ {
var channel = mention.TargetId?.Pipe(_context.TryGetChannel); var channel = mention.TargetId?.Pipe(_context.TryGetChannel);
var symbol = channel?.IsVoiceChannel == true ? "🔊" : "#"; var symbol = channel?.SupportsVoice == true ? "🔊" : "#";
var name = channel?.Name ?? "deleted-channel"; var name = channel?.Name ?? "deleted-channel";
_buffer _buffer
@@ -52,13 +52,13 @@ internal partial class PlainTextMarkdownVisitor : MarkdownVisitor
} }
else if (mention.Kind == MentionKind.Channel) else if (mention.Kind == MentionKind.Channel)
{ {
var channel =mention.TargetId?.Pipe(_context.TryGetChannel); var channel = mention.TargetId?.Pipe(_context.TryGetChannel);
var name = channel?.Name ?? "deleted-channel"; var name = channel?.Name ?? "deleted-channel";
_buffer.Append($"#{name}"); _buffer.Append($"#{name}");
// Voice channel marker // Voice channel marker
if (channel?.IsVoiceChannel == true) if (channel?.SupportsVoice == true)
_buffer.Append(" [voice]"); _buffer.Append(" [voice]");
} }
else if (mention.Kind == MentionKind.Role) else if (mention.Kind == MentionKind.Role)
@@ -88,8 +88,11 @@ internal class PlainTextMessageWriter : MessageWriter
if (!string.IsNullOrWhiteSpace(embed.Thumbnail?.Url)) if (!string.IsNullOrWhiteSpace(embed.Thumbnail?.Url))
await _writer.WriteLineAsync(await Context.ResolveMediaUrlAsync(embed.Thumbnail.ProxyUrl ?? embed.Thumbnail.Url, cancellationToken)); await _writer.WriteLineAsync(await Context.ResolveMediaUrlAsync(embed.Thumbnail.ProxyUrl ?? embed.Thumbnail.Url, cancellationToken));
if (!string.IsNullOrWhiteSpace(embed.Image?.Url)) foreach (var image in embed.Images)
await _writer.WriteLineAsync(await Context.ResolveMediaUrlAsync(embed.Image.ProxyUrl ?? embed.Image.Url, cancellationToken)); {
if (!string.IsNullOrWhiteSpace(image.Url))
await _writer.WriteLineAsync(await Context.ResolveMediaUrlAsync(image.ProxyUrl ?? image.Url, cancellationToken));
}
if (!string.IsNullOrWhiteSpace(embed.Footer?.Text)) if (!string.IsNullOrWhiteSpace(embed.Footer?.Text))
await _writer.WriteLineAsync(embed.Footer.Text); await _writer.WriteLineAsync(embed.Footer.Text);
@@ -6,13 +6,13 @@ namespace DiscordChatExporter.Core.Markdown;
internal record EmojiNode( internal record EmojiNode(
// Only present on custom emoji // Only present on custom emoji
Snowflake? Id, Snowflake? Id,
// Name of custom emoji (e.g. LUL) or actual representation of standard emoji (e.g. 🙂) // Name of a custom emoji (e.g. LUL) or actual representation of a standard emoji (e.g. 🙂)
string Name, string Name,
bool IsAnimated) : MarkdownNode bool IsAnimated) : MarkdownNode
{ {
public bool IsCustomEmoji => Id is not null; public bool IsCustomEmoji => Id is not null;
// Name of custom emoji (e.g. LUL) or name of standard emoji (e.g. slight_smile) // Name of a custom emoji (e.g. LUL) or name of a standard emoji (e.g. slight_smile)
public string Code => IsCustomEmoji public string Code => IsCustomEmoji
? Name ? Name
: EmojiIndex.TryGetCode(Name) ?? Name; : EmojiIndex.TryGetCode(Name) ?? Name;
@@ -0,0 +1,18 @@
using System.Collections.Generic;
namespace DiscordChatExporter.Core.Utils.Extensions;
public static class CollectionExtensions
{
public static IEnumerable<T> Enumerate<T>(this T obj)
{
yield return obj;
}
public static IEnumerable<(T value, int index)> WithIndex<T>(this IEnumerable<T> source)
{
var i = 0;
foreach (var o in source)
yield return (o, i++);
}
}
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
namespace DiscordChatExporter.Core.Utils.Extensions;
public static class ExceptionExtensions
{
private static void PopulateChildren(this Exception exception, ICollection<Exception> children)
{
if (exception is AggregateException aggregateException)
{
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);
}
}
public static IReadOnlyList<Exception> GetSelfAndChildren(this Exception exception)
{
var children = new List<Exception> {exception};
PopulateChildren(exception, children);
return children;
}
public static HttpStatusCode? TryGetStatusCode(this HttpRequestException ex) =>
// This is extremely frail, but there's no other way
Regex
.Match(ex.Message, @": (\d+) \(")
.Groups[1]
.Value
.NullIfWhiteSpace()?
.Pipe(s => (HttpStatusCode) int.Parse(s, CultureInfo.InvariantCulture));
}
@@ -1,5 +1,7 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
namespace DiscordChatExporter.Core.Utils.Extensions; namespace DiscordChatExporter.Core.Utils.Extensions;
@@ -25,6 +27,14 @@ public static class StringExtensions
} }
} }
public static string ToDashCase(this string str) =>
Regex.Replace(str, @"(\p{Ll})(\p{Lu})", "$1-$2");
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) => public static StringBuilder AppendIfNotEmpty(this StringBuilder builder, char value) =>
builder.Length > 0 builder.Length > 0
? builder.Append(value) ? builder.Append(value)
+23 -29
View File
@@ -1,9 +1,9 @@
using System; using System;
using System.Globalization; using System.Linq;
using System.IO;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Text.RegularExpressions; using System.Net.Sockets;
using System.Security.Authentication;
using System.Threading.Tasks; using System.Threading.Tasks;
using DiscordChatExporter.Core.Utils.Extensions; using DiscordChatExporter.Core.Utils.Extensions;
using Polly; using Polly;
@@ -14,13 +14,27 @@ public static class Http
{ {
public static HttpClient Client { get; } = new(); public static HttpClient Client { get; } = new();
public static IAsyncPolicy<HttpResponseMessage> ResponsePolicy { get; } = private static bool IsRetryableStatusCode(HttpStatusCode statusCode) =>
statusCode is HttpStatusCode.TooManyRequests or HttpStatusCode.RequestTimeout ||
// Treat all server-side errors as retryable.
// https://github.com/Tyrrrz/DiscordChatExporter/issues/908
(int)statusCode >= 500;
private static bool IsRetryableException(Exception exception) =>
exception.GetSelfAndChildren().Any(ex =>
ex is TimeoutException or SocketException or AuthenticationException ||
ex is HttpRequestException hrex && IsRetryableStatusCode(hrex.TryGetStatusCode() ?? HttpStatusCode.OK)
);
public static IAsyncPolicy ResiliencePolicy { get; } =
Policy Policy
.Handle<IOException>() .Handle<Exception>(IsRetryableException)
.Or<HttpRequestException>() .WaitAndRetryAsync(4, i => TimeSpan.FromSeconds(Math.Pow(2, i) + 1));
.OrResult<HttpResponseMessage>(m => m.StatusCode == HttpStatusCode.TooManyRequests)
.OrResult(m => m.StatusCode == HttpStatusCode.RequestTimeout) public static IAsyncPolicy<HttpResponseMessage> ResponseResiliencePolicy { get; } =
.OrResult(m => m.StatusCode >= HttpStatusCode.InternalServerError) Policy
.Handle<Exception>(IsRetryableException)
.OrResult<HttpResponseMessage>(m => IsRetryableStatusCode(m.StatusCode))
.WaitAndRetryAsync( .WaitAndRetryAsync(
8, 8,
(i, result, _) => (i, result, _) =>
@@ -43,24 +57,4 @@ public static class Http
}, },
(_, _, _, _) => Task.CompletedTask (_, _, _, _) => Task.CompletedTask
); );
private static HttpStatusCode? TryGetStatusCodeFromException(HttpRequestException ex) =>
// This is extremely frail, but there's no other way
Regex
.Match(ex.Message, @": (\d+) \(")
.Groups[1]
.Value
.NullIfWhiteSpace()?
.Pipe(s => (HttpStatusCode) int.Parse(s, CultureInfo.InvariantCulture));
public static IAsyncPolicy ExceptionPolicy { get; } =
Policy
.Handle<IOException>() // dangerous
.Or<HttpRequestException>(ex =>
TryGetStatusCodeFromException(ex) is
HttpStatusCode.TooManyRequests or
HttpStatusCode.RequestTimeout or
HttpStatusCode.InternalServerError
)
.WaitAndRetryAsync(4, i => TimeSpan.FromSeconds(Math.Pow(2, i) + 1));
} }
+4
View File
@@ -17,4 +17,8 @@ public static class PathEx
return buffer.ToString(); return buffer.ToString();
} }
public static bool IsDirectoryPath(string path) =>
path.EndsWith(Path.DirectorySeparatorChar) ||
path.EndsWith(Path.AltDirectorySeparatorChar);
} }
@@ -0,0 +1,20 @@
using System;
using System.Globalization;
using System.Windows.Data;
using DiscordChatExporter.Core.Discord;
namespace DiscordChatExporter.Gui.Converters;
[ValueConversion(typeof(Snowflake?), typeof(DateTimeOffset?))]
public class SnowflakeToDateTimeOffsetConverter : IValueConverter
{
public static SnowflakeToDateTimeOffsetConverter Instance { get; } = new();
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is Snowflake snowflake
? snowflake.ToDate()
: null;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
throw new NotSupportedException();
}
@@ -14,15 +14,15 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Gress" Version="2.0.1" /> <PackageReference Include="Gress" Version="2.0.1" />
<PackageReference Include="MaterialDesignColors" Version="2.0.5" /> <PackageReference Include="MaterialDesignColors" Version="2.0.6" />
<PackageReference Include="MaterialDesignThemes" Version="4.4.0" /> <PackageReference Include="MaterialDesignThemes" Version="4.5.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" /> <PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" /> <PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
<PackageReference Include="Onova" Version="2.6.2" /> <PackageReference Include="Onova" Version="2.6.2" />
<PackageReference Include="Stylet" Version="1.3.6" /> <PackageReference Include="Stylet" Version="1.3.6" />
<PackageReference Include="Tyrrrz.Settings" Version="1.3.4" /> <PackageReference Include="Tyrrrz.Settings" Version="1.3.4" />
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" PrivateAssets="all" /> <PackageReference Include="PropertyChanged.Fody" Version="3.4.1" PrivateAssets="all" />
<PackageReference Include="DotnetRuntimeBootstrapper" Version="2.2.0" PrivateAssets="all" /> <PackageReference Include="DotnetRuntimeBootstrapper" Version="2.3.1" PrivateAssets="all" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -45,7 +45,8 @@ public partial class SettingsService
try try
{ {
return Registry.CurrentUser.OpenSubKey( return Registry.CurrentUser.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", false "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
false
)?.GetValue("AppsUseLightTheme") is 0; )?.GetValue("AppsUseLightTheme") is 0;
} }
catch catch
@@ -44,6 +44,8 @@ public class DashboardViewModel : PropertyChangedBase
public Guild? SelectedGuild { get; set; } public Guild? SelectedGuild { get; set; }
public bool IsDirectMessageGuildSelected => SelectedGuild?.Id == Guild.DirectMessages.Id;
public IReadOnlyList<Channel>? AvailableChannels => SelectedGuild is not null public IReadOnlyList<Channel>? AvailableChannels => SelectedGuild is not null
? GuildChannelMap?[SelectedGuild] ? GuildChannelMap?[SelectedGuild]
: null; : null;
@@ -104,8 +106,9 @@ public class DashboardViewModel : PropertyChangedBase
var guildChannelMap = new Dictionary<Guild, IReadOnlyList<Channel>>(); var guildChannelMap = new Dictionary<Guild, IReadOnlyList<Channel>>();
await foreach (var guild in discord.GetUserGuildsAsync()) await foreach (var guild in discord.GetUserGuildsAsync())
{ {
var channels = await discord.GetGuildChannelsAsync(guild.Id); guildChannelMap[guild] = (await discord.GetGuildChannelsAsync(guild.Id))
guildChannelMap[guild] = channels.Where(c => c.IsTextChannel).ToArray(); .Where(c => c.Kind != ChannelKind.GuildCategory)
.ToArray();
} }
_discord = discord; _discord = discord;
@@ -8,6 +8,8 @@
xmlns:components="clr-namespace:DiscordChatExporter.Gui.ViewModels.Components" xmlns:components="clr-namespace:DiscordChatExporter.Gui.ViewModels.Components"
xmlns:converters="clr-namespace:DiscordChatExporter.Gui.Converters" xmlns:converters="clr-namespace:DiscordChatExporter.Gui.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:data="clr-namespace:DiscordChatExporter.Core.Discord.Data;assembly=DiscordChatExporter.Core"
xmlns:globalization="clr-namespace:System.Globalization;assembly=System.Runtime"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:s="https://github.com/canton7/Stylet" xmlns:s="https://github.com/canton7/Stylet"
@@ -16,6 +18,14 @@
Loaded="{s:Action OnViewLoaded}" Loaded="{s:Action OnViewLoaded}"
mc:Ignorable="d"> mc:Ignorable="d">
<UserControl.Resources> <UserControl.Resources>
<!-- Sort DMs by last message -->
<CollectionViewSource x:Key="AvailableDirectMessageChannelsViewSource" Source="{Binding AvailableChannels, Mode=OneWay}">
<CollectionViewSource.SortDescriptions>
<componentModel:SortDescription Direction="Descending" PropertyName="LastMessageId" />
<componentModel:SortDescription Direction="Ascending" PropertyName="Name" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
<!-- Sort guild channels by position -->
<CollectionViewSource x:Key="AvailableChannelsViewSource" Source="{Binding AvailableChannels, Mode=OneWay}"> <CollectionViewSource x:Key="AvailableChannelsViewSource" Source="{Binding AvailableChannels, Mode=OneWay}">
<CollectionViewSource.GroupDescriptions> <CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Category.Name" /> <PropertyGroupDescription PropertyName="Category.Name" />
@@ -125,30 +135,25 @@
Grid.Row="2" Grid.Row="2"
Background="{DynamicResource MaterialDesignCardBackground}" Background="{DynamicResource MaterialDesignCardBackground}"
IsEnabled="{Binding IsBusy, Converter={x:Static converters:InverseBoolConverter.Instance}}"> IsEnabled="{Binding IsBusy, Converter={x:Static converters:InverseBoolConverter.Instance}}">
<Grid.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontWeight" Value="Light" />
</Style>
</Grid.Resources>
<!-- Placeholder / usage instructions --> <!-- Placeholder / usage instructions -->
<Grid Visibility="{Binding AvailableGuilds, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}}"> <Grid Visibility="{Binding AvailableGuilds, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}}">
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"> <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<TextBlock <TextBlock
Margin="32,16" Margin="32,16"
FontSize="14" FontSize="14"
FontWeight="Light"
LineHeight="20"> LineHeight="20">
<Run FontSize="18" Text="Please provide authentication token to continue" />
<LineBreak />
<LineBreak />
<!-- User token --> <!-- User token -->
<InlineUIContainer> <InlineUIContainer>
<materialDesign:PackIcon <materialDesign:PackIcon
Margin="1,0,0,-2" Margin="0,0,2,-2"
Foreground="{DynamicResource PrimaryHueMidBrush}" Foreground="{DynamicResource PrimaryHueMidBrush}"
Kind="Account" /> Kind="Account" />
</InlineUIContainer> </InlineUIContainer>
<Run FontSize="16" Text="Authenticate using your personal account" /> <Run FontSize="16" FontWeight="SemiBold" Text="To get token for your personal account:" />
<LineBreak />
<Run Text="* Automating user accounts is technically against TOS —" />
<Run FontWeight="SemiBold" Text="use at your own risk" /><Run Text="!" />
<LineBreak /> <LineBreak />
<Run Text="1. Open Discord in your" /> <Run Text="1. Open Discord in your" />
<Hyperlink Command="{s:Action OpenDiscord}"> <Hyperlink Command="{s:Action OpenDiscord}">
@@ -156,49 +161,46 @@
</Hyperlink> </Hyperlink>
<Run Text="and login" /> <Run Text="and login" />
<LineBreak /> <LineBreak />
<Run Text="2. Press" /> <Run Text="2. Open any server or direct message channel" />
<LineBreak />
<Run Text="3. Press" />
<Run FontWeight="SemiBold" Text="Ctrl+Shift+I" /> <Run FontWeight="SemiBold" Text="Ctrl+Shift+I" />
<Run Text="to show developer tools" /> <Run Text="to show developer tools" />
<LineBreak /> <LineBreak />
<Run Text="3. Press" />
<Run FontWeight="SemiBold" Text="Ctrl+Shift+M" />
<Run Text="to toggle device toolbar" />
<LineBreak />
<Run Text="4. Navigate to the" /> <Run Text="4. Navigate to the" />
<Run FontWeight="SemiBold" Text="Application" /> <Run FontWeight="SemiBold" Text="Network" />
<Run Text="tab" /> <Run Text="tab" />
<LineBreak /> <LineBreak />
<Run Text="5. On the left, expand" /> <Run Text="5. Press" />
<Run FontWeight="SemiBold" Text="Local Storage" />
<Run Text="and select" />
<Run FontWeight="SemiBold" Text="https://discord.com" />
<LineBreak />
<Run Text="6. Type" />
<Run FontWeight="SemiBold" Text="token" />
<Run Text="into the" />
<Run FontWeight="SemiBold" Text="Filter" />
<Run Text="box" />
<LineBreak />
<Run Text="7. If the token key does not appear, press" />
<Run FontWeight="SemiBold" Text="Ctrl+R" /> <Run FontWeight="SemiBold" Text="Ctrl+R" />
<Run Text="to reload" /> <Run Text="to reload" />
<LineBreak /> <LineBreak />
<Run Text="8. Copy the value of the" /> <Run Text="6. Search for a request containing" />
<Run FontWeight="SemiBold" Text="token" /> <Run FontWeight="SemiBold" Text="messages?limit=50" />
<Run Text="key" /> <Run Text="or similar" />
<LineBreak /> <LineBreak />
<Run Text="* Automating user accounts is technically against TOS, use at your own risk!" /> <Run Text="7. Select the" />
<Run FontWeight="SemiBold" Text="Headers" />
<Run Text=" tab on the right" />
<LineBreak />
<Run Text="8. Scroll down to the" />
<Run FontWeight="SemiBold" Text="Request Headers" />
<Run Text="section" />
<LineBreak />
<Run Text="9. Copy the value of the" />
<Run FontWeight="SemiBold" Text="authorization" />
<Run Text="header" />
<LineBreak /> <LineBreak />
<LineBreak /> <LineBreak />
<!-- Bot token --> <!-- Bot token -->
<InlineUIContainer> <InlineUIContainer>
<materialDesign:PackIcon <materialDesign:PackIcon
Margin="1,0,0,-2" Margin="0,0,2,-2"
Foreground="{DynamicResource PrimaryHueMidBrush}" Foreground="{DynamicResource PrimaryHueMidBrush}"
Kind="Robot" /> Kind="Robot" />
</InlineUIContainer> </InlineUIContainer>
<Run FontSize="16" Text="Authenticate using a bot account" /> <Run FontSize="16" FontWeight="SemiBold" Text="To get token for a bot account:" />
<LineBreak /> <LineBreak />
<Run Text="1. Open Discord" /> <Run Text="1. Open Discord" />
<Hyperlink Command="{s:Action OpenDiscordDeveloperPortal}"> <Hyperlink Command="{s:Action OpenDiscordDeveloperPortal}">
@@ -216,10 +218,14 @@
<Run Text="click" /> <Run Text="click" />
<Run FontWeight="SemiBold" Text="Copy" /> <Run FontWeight="SemiBold" Text="Copy" />
<LineBreak /> <LineBreak />
<Run Text="* Your bot needs to have" />
<Run FontWeight="SemiBold" Text="Message Content Intent" />
<Run Text="enabled to read messages" />
<LineBreak />
<LineBreak /> <LineBreak />
<Run FontSize="16" Text="If you have questions or issues, please refer to the" /> <Run Text="If you have questions or issues, please refer to the" />
<Hyperlink Command="{s:Action ShowHelp}" FontSize="16">wiki</Hyperlink><Run FontSize="16" Text="." /> <Hyperlink Command="{s:Action ShowHelp}">wiki</Hyperlink><Run Text="." />
</TextBlock> </TextBlock>
</ScrollViewer> </ScrollViewer>
</Grid> </Grid>
@@ -276,13 +282,24 @@
<Border Grid.Column="1"> <Border Grid.Column="1">
<ListBox <ListBox
HorizontalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Source={StaticResource AvailableChannelsViewSource}}"
SelectionMode="Extended" SelectionMode="Extended"
TextSearch.TextPath="Model.Name" TextSearch.TextPath="Model.Name"
VirtualizingPanel.IsVirtualizingWhenGrouping="True"> VirtualizingPanel.IsVirtualizingWhenGrouping="True">
<b:Interaction.Behaviors> <b:Interaction.Behaviors>
<behaviors:ChannelMultiSelectionListBoxBehavior SelectedItems="{Binding SelectedChannels}" /> <behaviors:ChannelMultiSelectionListBoxBehavior SelectedItems="{Binding SelectedChannels}" />
</b:Interaction.Behaviors> </b:Interaction.Behaviors>
<ListBox.Style>
<Style BasedOn="{StaticResource {x:Type ListBox}}" TargetType="{x:Type ListBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsDirectMessageGuildSelected}" Value="True">
<Setter Property="ItemsSource" Value="{Binding Source={StaticResource AvailableDirectMessageChannelsViewSource}}" />
</DataTrigger>
<DataTrigger Binding="{Binding IsDirectMessageGuildSelected}" Value="False">
<Setter Property="ItemsSource" Value="{Binding Source={StaticResource AvailableChannelsViewSource}}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.Style>
<ListBox.GroupStyle> <ListBox.GroupStyle>
<GroupStyle> <GroupStyle>
<GroupStyle.ContainerStyle> <GroupStyle.ContainerStyle>
@@ -308,7 +325,7 @@
</GroupStyle> </GroupStyle>
</ListBox.GroupStyle> </ListBox.GroupStyle>
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate DataType="{x:Type data:Channel}">
<Grid Margin="-8" Background="Transparent"> <Grid Margin="-8" Background="Transparent">
<Grid.InputBindings> <Grid.InputBindings>
<MouseBinding Command="{s:Action ExportChannels}" MouseAction="LeftDoubleClick" /> <MouseBinding Command="{s:Action ExportChannels}" MouseAction="LeftDoubleClick" />
@@ -318,13 +335,31 @@
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.ToolTip>
<TextBlock>
<Run Text="Last message sent on:" />
<Run FontWeight="SemiBold" Text="{Binding LastMessageId, Converter={x:Static converters:SnowflakeToDateTimeOffsetConverter.Instance}, ConverterCulture={x:Static globalization:CultureInfo.CurrentCulture}, TargetNullValue=never}" />
</TextBlock>
</Grid.ToolTip>
<!-- Channel icon --> <!-- Channel icon -->
<materialDesign:PackIcon <materialDesign:PackIcon
Grid.Column="0" Grid.Column="0"
Margin="16,7,0,6" Margin="16,7,0,6"
VerticalAlignment="Center" VerticalAlignment="Center">
Kind="Pound" /> <materialDesign:PackIcon.Style>
<Style TargetType="{x:Type materialDesign:PackIcon}">
<Style.Triggers>
<DataTrigger Binding="{Binding SupportsVoice}" Value="True">
<Setter Property="Kind" Value="VolumeHigh" />
</DataTrigger>
<DataTrigger Binding="{Binding SupportsVoice}" Value="False">
<Setter Property="Kind" Value="Pound" />
</DataTrigger>
</Style.Triggers>
</Style>
</materialDesign:PackIcon.Style>
</materialDesign:PackIcon>
<!-- Channel name --> <!-- Channel name -->
<TextBlock <TextBlock
@@ -5,6 +5,7 @@
xmlns:converters="clr-namespace:DiscordChatExporter.Gui.Converters" xmlns:converters="clr-namespace:DiscordChatExporter.Gui.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dialogs="clr-namespace:DiscordChatExporter.Gui.ViewModels.Dialogs" xmlns:dialogs="clr-namespace:DiscordChatExporter.Gui.ViewModels.Dialogs"
xmlns:globalization="clr-namespace:System.Globalization;assembly=System.Runtime"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:s="https://github.com/canton7/Stylet" xmlns:s="https://github.com/canton7/Stylet"
@@ -86,7 +87,7 @@
Style="{DynamicResource MaterialDesignOutlinedComboBox}"> Style="{DynamicResource MaterialDesignOutlinedComboBox}">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Converter={x:Static converters:ExportFormatToStringConverter.Instance}}" /> <TextBlock Text="{Binding Converter={x:Static converters:ExportFormatToStringConverter.Instance}, ConverterCulture={x:Static globalization:CultureInfo.CurrentCulture}}" />
</DataTemplate> </DataTemplate>
</ComboBox.ItemTemplate> </ComboBox.ItemTemplate>
</ComboBox> </ComboBox>
@@ -110,8 +111,8 @@
Margin="16,8,16,4" Margin="16,8,16,4"
materialDesign:HintAssist.Hint="After (date)" materialDesign:HintAssist.Hint="After (date)"
materialDesign:HintAssist.IsFloating="True" materialDesign:HintAssist.IsFloating="True"
DisplayDateEnd="{Binding BeforeDate, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}" DisplayDateEnd="{Binding BeforeDate, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}, ConverterCulture={x:Static globalization:CultureInfo.CurrentCulture}}"
SelectedDate="{Binding AfterDate, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}" SelectedDate="{Binding AfterDate, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}, ConverterCulture={x:Static globalization:CultureInfo.CurrentCulture}}"
Style="{DynamicResource MaterialDesignOutlinedDatePicker}" Style="{DynamicResource MaterialDesignOutlinedDatePicker}"
ToolTip="Only include messages sent after this date" /> ToolTip="Only include messages sent after this date" />
<DatePicker <DatePicker
@@ -120,8 +121,8 @@
Margin="16,8,16,4" Margin="16,8,16,4"
materialDesign:HintAssist.Hint="Before (date)" materialDesign:HintAssist.Hint="Before (date)"
materialDesign:HintAssist.IsFloating="True" materialDesign:HintAssist.IsFloating="True"
DisplayDateStart="{Binding AfterDate, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}" DisplayDateStart="{Binding AfterDate, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}, ConverterCulture={x:Static globalization:CultureInfo.CurrentCulture}}"
SelectedDate="{Binding BeforeDate, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}" SelectedDate="{Binding BeforeDate, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}, ConverterCulture={x:Static globalization:CultureInfo.CurrentCulture}}"
Style="{DynamicResource MaterialDesignOutlinedDatePicker}" Style="{DynamicResource MaterialDesignOutlinedDatePicker}"
ToolTip="Only include messages sent before this date" /> ToolTip="Only include messages sent before this date" />
<materialDesign:TimePicker <materialDesign:TimePicker
@@ -132,7 +133,7 @@
materialDesign:HintAssist.IsFloating="True" materialDesign:HintAssist.IsFloating="True"
Is24Hours="{x:Static utils:Internationalization.Is24Hours}" Is24Hours="{x:Static utils:Internationalization.Is24Hours}"
IsEnabled="{Binding IsAfterDateSet}" IsEnabled="{Binding IsAfterDateSet}"
SelectedTime="{Binding AfterTime, Converter={x:Static converters:TimeSpanToDateTimeConverter.Instance}}" SelectedTime="{Binding AfterTime, Converter={x:Static converters:TimeSpanToDateTimeConverter.Instance}, ConverterCulture={x:Static globalization:CultureInfo.CurrentCulture}}"
Style="{DynamicResource MaterialDesignOutlinedTimePicker}" Style="{DynamicResource MaterialDesignOutlinedTimePicker}"
ToolTip="Only include messages sent after this time" /> ToolTip="Only include messages sent after this time" />
<materialDesign:TimePicker <materialDesign:TimePicker
@@ -143,7 +144,7 @@
materialDesign:HintAssist.IsFloating="True" materialDesign:HintAssist.IsFloating="True"
Is24Hours="{x:Static utils:Internationalization.Is24Hours}" Is24Hours="{x:Static utils:Internationalization.Is24Hours}"
IsEnabled="{Binding IsBeforeDateSet}" IsEnabled="{Binding IsBeforeDateSet}"
SelectedTime="{Binding BeforeTime, Converter={x:Static converters:TimeSpanToDateTimeConverter.Instance}}" SelectedTime="{Binding BeforeTime, Converter={x:Static converters:TimeSpanToDateTimeConverter.Instance}, ConverterCulture={x:Static globalization:CultureInfo.CurrentCulture}}"
Style="{DynamicResource MaterialDesignOutlinedTimePicker}" Style="{DynamicResource MaterialDesignOutlinedTimePicker}"
ToolTip="Only include messages sent before this time" /> ToolTip="Only include messages sent before this time" />
</Grid> </Grid>
+1 -1
View File
@@ -9,7 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
License.txt = License.txt License.txt = License.txt
Readme.md = Readme.md Readme.md = Readme.md
Directory.Build.props = Directory.Build.props Directory.Build.props = Directory.Build.props
Dockerfile = Dockerfile DiscordChatExporter.Cli.dockerfile = DiscordChatExporter.Cli.dockerfile
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscordChatExporter.Gui", "DiscordChatExporter.Gui\DiscordChatExporter.Gui.csproj", "{732A67AF-93DE-49DF-B10F-FD74710B7863}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscordChatExporter.Gui", "DiscordChatExporter.Gui\DiscordChatExporter.Gui.csproj", "{732A67AF-93DE-49DF-B10F-FD74710B7863}"
-20
View File
@@ -1,20 +0,0 @@
# Build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY favicon.ico ./
COPY NuGet.config ./
COPY Directory.Build.props ./
COPY DiscordChatExporter.Core DiscordChatExporter.Core
COPY DiscordChatExporter.Cli DiscordChatExporter.Cli
RUN dotnet publish DiscordChatExporter.Cli -o DiscordChatExporter.Cli/publish -c Release
# Run
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS run
WORKDIR /app
COPY --from=build /src/DiscordChatExporter.Cli/publish ./
WORKDIR /app/out
ENTRYPOINT ["dotnet", "/app/DiscordChatExporter.Cli.dll"]
+4 -1
View File
@@ -2,6 +2,9 @@
<configuration> <configuration>
<packageSources> <packageSources>
<clear /> <clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources> </packageSources>
<config>
<add key="defaultPushSource" value="https://api.nuget.org/v3/index.json" />
</config>
</configuration> </configuration>
+26 -15
View File
@@ -1,7 +1,7 @@
# DiscordChatExporter # DiscordChatExporter
[![Made in Ukraine](https://img.shields.io/badge/made_in-ukraine-ffd700.svg?labelColor=0057b7)](https://vshymanskyy.github.io/StandWithUkraine) [![Made in Ukraine](https://img.shields.io/badge/made_in-ukraine-ffd700.svg?labelColor=0057b7)](https://vshymanskyy.github.io/StandWithUkraine)
[![Build](https://img.shields.io/github/workflow/status/Tyrrrz/DiscordChatExporter/CI/master)](https://github.com/Tyrrrz/DiscordChatExporter/actions) [![Build](https://img.shields.io/github/workflow/status/Tyrrrz/DiscordChatExporter/main/master)](https://github.com/Tyrrrz/DiscordChatExporter/actions)
[![Coverage](https://img.shields.io/codecov/c/github/Tyrrrz/DiscordChatExporter/master)](https://codecov.io/gh/Tyrrrz/DiscordChatExporter) [![Coverage](https://img.shields.io/codecov/c/github/Tyrrrz/DiscordChatExporter/master)](https://codecov.io/gh/Tyrrrz/DiscordChatExporter)
[![Release](https://img.shields.io/github/release/Tyrrrz/DiscordChatExporter.svg)](https://github.com/Tyrrrz/DiscordChatExporter/releases) [![Release](https://img.shields.io/github/release/Tyrrrz/DiscordChatExporter.svg)](https://github.com/Tyrrrz/DiscordChatExporter/releases)
[![Downloads](https://img.shields.io/github/downloads/Tyrrrz/DiscordChatExporter/total.svg)](https://github.com/Tyrrrz/DiscordChatExporter/releases) [![Downloads](https://img.shields.io/github/downloads/Tyrrrz/DiscordChatExporter/total.svg)](https://github.com/Tyrrrz/DiscordChatExporter/releases)
@@ -9,14 +9,16 @@
[![Donate](https://img.shields.io/badge/donate-$$$-8a2be2.svg)](https://tyrrrz.me/donate) [![Donate](https://img.shields.io/badge/donate-$$$-8a2be2.svg)](https://tyrrrz.me/donate)
[![Fuck Russia](https://img.shields.io/badge/fuck-russia-e4181c.svg?labelColor=000000)](https://twitter.com/tyrrrz/status/1495972128977571848) [![Fuck Russia](https://img.shields.io/badge/fuck-russia-e4181c.svg?labelColor=000000)](https://twitter.com/tyrrrz/status/1495972128977571848)
> 🟢 **Project status**: active<sup>[[?]](https://github.com/Tyrrrz/.github/blob/master/docs/project-status.md)</sup> > 🟡 **Project status**: maintenance mode<sup>[[?]](https://github.com/Tyrrrz/.github/blob/master/docs/project-status.md)</sup>
**DiscordChatExporter** can be used to export message history from a [Discord](https://discord.com) channel to a file. **DiscordChatExporter** can be used to export message history from a [Discord](https://discord.com) channel to a file.
It works with direct messages, group messages, and server channels, and supports Discord's dialect of markdown as well as all other rich media features. It works with direct messages, group messages, and server channels, and supports Discord's dialect of markdown as well as all other rich media features.
> ❔ If you have questions or issues, **please refer to the [wiki](https://github.com/Tyrrrz/DiscordChatExporter/wiki)**. > ❔ If you have questions or issues, **please refer to the [wiki](https://github.com/Tyrrrz/DiscordChatExporter/wiki)**.
## Terms of use > 💬 If you want to chat, **join my [Discord server](https://discord.gg/2SUWKFnHSm)**.
## Terms of use<sup>[[?]](https://github.com/Tyrrrz/.github/blob/master/docs/why-so-political.md)</sup>
By using this project or its source code, for any purpose and in any shape or form, you grant your **implicit agreement** to all the following statements: By using this project or its source code, for any purpose and in any shape or form, you grant your **implicit agreement** to all the following statements:
@@ -46,7 +48,7 @@ The following table lists all available download options:
<td> <td>
<ul> <ul>
<li>🟢 <b><a href="https://github.com/Tyrrrz/DiscordChatExporter/releases/latest">Stable release</a></b> (<code>DiscordChatExporter.zip</code>)</li> <li>🟢 <b><a href="https://github.com/Tyrrrz/DiscordChatExporter/releases/latest">Stable release</a></b> (<code>DiscordChatExporter.zip</code>)</li>
<li>🟠 <a href="https://github.com/Tyrrrz/DiscordChatExporter/actions/workflows/CI.yml">CI build</a> (<code>DiscordChatExporter.zip</code>)</li> <li>🟠 <a href="https://github.com/Tyrrrz/DiscordChatExporter/actions/workflows/main.yml">CI build</a> (<code>DiscordChatExporter.zip</code>)</li>
</ul> </ul>
</td> </td>
<td> <td>
@@ -59,10 +61,11 @@ The following table lists all available download options:
<td><b>CLI</b></td> <td><b>CLI</b></td>
<td> <td>
<ul> <ul>
<li>🟢 <b><a href="https://github.com/Tyrrrz/DiscordChatExporter/releases/latest">Stable release</a></b> (<code>DiscordChatExporter.CLI.zip</code>) ⚙️</li> <li>🟢 <b><a href="https://github.com/Tyrrrz/DiscordChatExporter/releases/latest">Stable release</a></b> (<code>DiscordChatExporter.CLI.zip</code></li>
<li>🟠 <a href="https://github.com/Tyrrrz/DiscordChatExporter/actions/workflows/CI.yml">CI build</a> (<code>DiscordChatExporter.CLI.zip</code>) ⚙️</li> <li>🟠 <a href="https://github.com/Tyrrrz/DiscordChatExporter/actions/workflows/main.yml">CI build</a> (<code>DiscordChatExporter.CLI.zip</code>)</li>
<li>🐋 <a href="https://hub.docker.com/r/tyrrrz/discordchatexporter">Docker</a> (<code>tyrrrz/discordchatexporter</code>)</li> <li>🐋 <a href="https://hub.docker.com/r/tyrrrz/discordchatexporter">Docker</a> (<code>tyrrrz/discordchatexporter</code>)</li>
<li>📦 <a href="https://aur.archlinux.org/packages/discord-chat-exporter-cli">AUR</a> (<code>discord-chat-exporter-cli</code>) 🦄</li> <li>📦 <a href="https://aur.archlinux.org/packages/discord-chat-exporter-cli">AUR</a> (<code>discord-chat-exporter-cli</code>)</li>
<li>📦 <a href="https://search.nixos.org/packages?query=discordchatexporter-cli">Nix</a> (<code>discordchatexporter-cli</code>)</li>
</ul> </ul>
</td> </td>
<td> <td>
@@ -76,12 +79,20 @@ The following table lists all available download options:
</tbody> </tbody>
</table> </table>
- ⚙️ - Requires .NET runtime to be installed manually: > **Note**:
- [.NET v6.0 Runtime for **Windows x64**](https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-desktop-6.0.0-windows-x64-installer) > AUR and Nix packages linked above are maintained by the community.
- [.NET v6.0 Runtime for **Windows x86**](https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-desktop-6.0.0-windows-x86-installer) > If you have any issues with them, please contact the corresponding maintainers.
- [.NET v6.0 Runtime for **macOS x64**](https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-6.0.0-macos-x64-installer)
- [.NET v6.0 Runtime for **Linux**](https://docs.microsoft.com/en-us/dotnet/core/install/linux) (find your distro) > **Warning**:
- 🦄 - Community-maintained resource > To run **DiscordChatExporter** on macOS and Linux, you need to make sure that **.NET Runtime v6** is installed.
> You can download it here:
>
> - [.NET Runtime v6 for **macOS x64**](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-6.0.6-macos-x64-installer)
> - [.NET Runtime v6 for **macOS Arm64**](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-6.0.6-macos-arm64-installer)
> - [.NET Runtime v6 for **Linux**](https://docs.microsoft.com/en-us/dotnet/core/install/linux) (find the correct download for your distro)
>
> This should not be necessary if you install **DiscordChatExporter** using a package manager, as it should take care of the dependencies for you.
> This is also not necessary if you are running **DiscordChatExporter** via Docker, because the image already contains the runtime.
## Features ## Features
@@ -95,5 +106,5 @@ The following table lists all available download options:
## Screenshots ## Screenshots
![channel list](.screenshots/list.png) ![channel list](.assets/list.png)
![rendered output](.screenshots/output.png) ![rendered output](.assets/output.png)

Some files were not shown because too many files have changed in this diff Show More