mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-07-11 16:31:57 +02:00
Compare commits
167 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7996a38c5c | |||
| 9d052f9404 | |||
| 3078351670 | |||
| 4f41c4fff3 | |||
| a80ee2943f | |||
| 8612d2c84a | |||
| 57c849d0f8 | |||
| 9c2a26aa82 | |||
| f376028d76 | |||
| da87f3c774 | |||
| 61516feafa | |||
| 8d209cd67a | |||
| c58d7e752b | |||
| fcc1605455 | |||
| f28d662a71 | |||
| a405ab184e | |||
| b861a69799 | |||
| d53b4c825a | |||
| 30678e96e5 | |||
| 2024d3658b | |||
| 9453cac389 | |||
| 504c3c53cd | |||
| 4e358e8e6f | |||
| 5e852235ce | |||
| 612c6d37a4 | |||
| 92cf886eab | |||
| f48af53d72 | |||
| 99d721c63b | |||
| 11414b5937 | |||
| 6c039ebfa6 | |||
| 9cffbbc5ce | |||
| 6f87960513 | |||
| e8f8c47dbd | |||
| 9aba36fce5 | |||
| f29e1d2d9f | |||
| b000a72f81 | |||
| f5318e77b7 | |||
| e171b43c22 | |||
| 23e1850d15 | |||
| 057902f919 | |||
| 565fb53d3b | |||
| edba9f36a7 | |||
| 356b1a6afd | |||
| 70edc8989c | |||
| 2fd7e327a9 | |||
| 9182c3d934 | |||
| 01389b7e28 | |||
| bd0701cb82 | |||
| 4283ef22b1 | |||
| 94ef4b6981 | |||
| 7b72f473fd | |||
| 2463cb5087 | |||
| 2c7986c4e6 | |||
| 5755334492 | |||
| 26c523a3e9 | |||
| 371c7d2b75 | |||
| 62400f305a | |||
| 65a528e7fe | |||
| 47d8163a46 | |||
| 1d9224ebd8 | |||
| ddc7f921bd | |||
| aca94ddccb | |||
| 3661c42df4 | |||
| 005c1786ec | |||
| b6fbf2393e | |||
| 0e49936e38 | |||
| 8d4e6b77c4 | |||
| 6f47fb6a1c | |||
| 6150720b1e | |||
| dcdeea19ab | |||
| ca56d47110 | |||
| 17b548d679 | |||
| 20eeaa58e9 | |||
| 6621c10ae0 | |||
| 75214354ca | |||
| 84d99e8520 | |||
| 4b80eabb73 | |||
| e6830bbd0e | |||
| 97c751f171 | |||
| dc814e08e7 | |||
| 54bf7c204a | |||
| 36c9983c9e | |||
| 361e0489ed | |||
| 77436120a8 | |||
| 2d7ab5411f | |||
| 1ce523b252 | |||
| bb81cf06ae | |||
| f7f6ac9494 | |||
| 481958f4d3 | |||
| 5e3502cbc5 | |||
| 3b03c30865 | |||
| c9e16a7f74 | |||
| f9b6793d47 | |||
| cfbd267d3a | |||
| 2b6f01bf6f | |||
| a44d43eefc | |||
| 0e138bac7d | |||
| 71876febf8 | |||
| 489c786c1e | |||
| eb0c61e173 | |||
| 9341c21963 | |||
| 704c483074 | |||
| 1f0e667085 | |||
| 0b72b73d1d | |||
| 32dd1689d0 | |||
| 2e4d19671a | |||
| 5b4d88ca26 | |||
| 65cc3954b6 | |||
| ffe5544f9c | |||
| bf1ad07a9c | |||
| 338566c1d6 | |||
| 91ea7a443c | |||
| aea96d5eba | |||
| e29f08264c | |||
| ad84ecf6a4 | |||
| ae57a0ff7c | |||
| 1daff4178d | |||
| 3a2b119618 | |||
| 5f27426f44 | |||
| a893ebda68 | |||
| 9221966171 | |||
| 67325b610a | |||
| 3186ce90c8 | |||
| 168d7c8ec9 | |||
| daa1b3f6b3 | |||
| e2780d6666 | |||
| b996215e36 | |||
| 08d9af534b | |||
| bef110a193 | |||
| 12555e576f | |||
| afb4bc67ae | |||
| f80a5fe644 | |||
| b7dca87fb9 | |||
| 8ecc2940b0 | |||
| 407c2bd2ae | |||
| 5b563d4f00 | |||
| ecb615ecf1 | |||
| 7c212ef893 | |||
| 36b4a45f3a | |||
| 51cc132e5d | |||
| cf83cbd89c | |||
| d51d0d4872 | |||
| 2467caac9f | |||
| bd98f4cb6a | |||
| fc7191d74c | |||
| 6c484d1f88 | |||
| c36b8df8e7 | |||
| 0408096746 | |||
| 40d833cd57 | |||
| 0de1f47310 | |||
| e31ff55e33 | |||
| 81525a1076 | |||
| 65ab003ff5 | |||
| 2156c6cd0c | |||
| e97151cd19 | |||
| 271a478a0e | |||
| b40a88c4d3 | |||
| f03f5f8072 | |||
| bfa5d10761 | |||
| 7a9e25c1f0 | |||
| 4599e64f0a | |||
| 4389b4e0bc | |||
| 008bb2f591 | |||
| b8567d384f | |||
| a06b448f4a | |||
| ba4ece9325 | |||
| 880f400e2c |
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
@@ -1,3 +0,0 @@
|
|||||||
github: Tyrrrz
|
|
||||||
patreon: Tyrrrz
|
|
||||||
custom: ['buymeacoffee.com/Tyrrrz', 'tyrrrz.me/donate']
|
|
||||||
@@ -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
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<!--
|
|
||||||
|
|
||||||
**Important:**
|
|
||||||
|
|
||||||
Please make sure that there is an existing issue that describes the problem solved by your pull request. If there isn't one, consider creating it first.
|
|
||||||
An open issue offers a good place to iron out requirements, discuss possible solutions, and ask questions.
|
|
||||||
|
|
||||||
Remember to also:
|
|
||||||
|
|
||||||
- Keep your pull request focused and as small as possible. If you want to contribute multiple unrelated changes, please create separate pull requests for them.
|
|
||||||
- Follow the coding style and conventions already established by the project. When in doubt about which style to use, ask in the comments to your pull request.
|
|
||||||
- If you want to start a discussion regarding a specific change you've made, add a review comment to your own code. This can be used to highlight something important or to seek further input from others.
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- Please specify the issue addressed by this pull request -->
|
|
||||||
Closes #ISSUE_NUMBER
|
|
||||||
@@ -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
|
|
||||||
@@ -1,84 +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:
|
|
||||||
dotnet-version: 6.0.x
|
|
||||||
|
|
||||||
- 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>"
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
@@ -1,47 +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:
|
|
||||||
dotnet-version: 6.0.x
|
|
||||||
|
|
||||||
- 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
|
|
||||||
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/
|
|
||||||
@@ -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 }}
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
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:
|
||||||
|
# Fixed version, workaround for https://github.com/dotnet/core/issues/7176
|
||||||
|
dotnet-version: 6.0.100
|
||||||
|
|
||||||
|
- 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:
|
||||||
|
# Fixed version, workaround for https://github.com/dotnet/core/issues/7176
|
||||||
|
dotnet-version: 6.0.100
|
||||||
|
|
||||||
|
- 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>"
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
*.sln.docstates
|
*.sln.docstates
|
||||||
.idea/
|
.idea/
|
||||||
.vs/
|
.vs/
|
||||||
|
.vscode/
|
||||||
|
|
||||||
# Build results
|
# Build results
|
||||||
[Dd]ebug/
|
[Dd]ebug/
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 33 KiB |
@@ -1,3 +1,94 @@
|
|||||||
|
### 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)
|
||||||
|
|
||||||
|
- [HTML] Reworked layout to be more consistent with Discord.
|
||||||
|
- [HTML] Changed user profile picture dimensions from `128x128` to `512x512`. (Thanks [@Chris Helder](https://github.com/TheDude53))
|
||||||
|
- [HTML] Improved image scaling for Chromium-based browsers. This should result in higher quality images across the entire export.
|
||||||
|
- [HTML] Hovering over messages will now show short timestamps on the left, indicating the time that the individual messages of the group were sent.
|
||||||
|
- [HTML] Using "download media" option will now also download scripts, styles, fonts, and other similar resources used by the export.
|
||||||
|
- [HTML] Image attachments will now use the provided description as alt text.
|
||||||
|
- [HTML] Fixed a few layout inconsistencies related to embeds.
|
||||||
|
- [GUI] Added a few clickable links to the usage guide to make the process of locating tokens easier.
|
||||||
|
|
||||||
|
### v2.33.2 (07-Mar-2022)
|
||||||
|
|
||||||
|
- Actually fixed it this time.
|
||||||
|
|
||||||
|
### v2.33.1 (07-Mar-2022)
|
||||||
|
|
||||||
|
- Fixed an issue where the application silently failed to run if the system didn't have .NET Runtime 6.0.2 installed. If you continue seeing this issue, please uninstall all existing .NET runtimes from your computer and then try running the application again.
|
||||||
|
|
||||||
|
### v2.33 (06-Mar-2022)
|
||||||
|
|
||||||
|
- Added messages informing about war in Ukraine and available ways to help.
|
||||||
|
- Added support for rendering stickers in HTML and JSON. Lottie-based stickers currently cannot be displayed in HTML exports (see [#803](https://github.com/Tyrrrz/DiscordChatExporter/issues/803)).
|
||||||
|
- Added a new `reaction:` message filter which can be used to check if someone reacted to a message with a specific emoji. You can either pass the emoji name (e.g. `reaction:LUL`) or its ID (e.g. `reaction:41771983429993937`).
|
||||||
|
- [GUI] Added auto-detection for dark mode. If your system is configured to prefer dark mode in applications, DiscordChatExporter will use it by default instead of light mode.
|
||||||
|
- Fixed an issue which caused the export process to crash when downloading media files with extremely long file extensions. (Thanks [@Tomlacko](https://github.com/Tomlacko))
|
||||||
|
- Fixed an issue which caused the export process to crash on invalid mentions.
|
||||||
|
- [GUI] Fixed an issue where the time pickers used to specify export ranges always displayed time in 12-hour format, instead of respecting the system locale.
|
||||||
|
|
||||||
|
### v2.32 (27-Jan-2022)
|
||||||
|
|
||||||
|
- Token kind (user or bot) is now detected automatically. Removed the button to switch token kind in GUI. Option `-b|--bot` in CLI is now deprecated and does nothing.
|
||||||
|
- Updated user token extraction guide to reflect the fact that devtools are no longer accessible in the desktop version of Discord client. The recommended workaround is to open Discord in browser. (Thanks [@Dhananjay-JSR](https://github.com/Dhananjay-JSR))
|
||||||
|
- Fixed an issue which caused an error when parsing invalid date timestamps. Such timestamps are now rendered as "Invalid date", similarly to how the Discord client does it.
|
||||||
|
- Fixed an issue which caused an error when parsing certain embed fields.
|
||||||
|
- Fixed an issue which caused an error when parsing a mention to a user that has no username.
|
||||||
|
- [GUI] Minor visual fixes.
|
||||||
|
|
||||||
|
### v2.31.1 (15-Dec-2021)
|
||||||
|
|
||||||
|
- Fixed an issue which caused an error when parsing certain custom emoji reactions.
|
||||||
|
- [GUI] Improved user interface.
|
||||||
|
|
||||||
### v2.31 (06-Dec-2021)
|
### v2.31 (06-Dec-2021)
|
||||||
|
|
||||||
- Changed target runtime of the application (both GUI and CLI) from .NET 3.1 to .NET 6. Those using the GUI version will not need to take any action as the application should install the necessary prerequisites automatically. Those using the CLI version will need to download and install .NET 6 runtime manually [from here](https://dotnet.microsoft.com/download/dotnet/6.0) (look for ".NET Runtime 6.0.x" section on the right and choose the distribution appropriate for your system).
|
- Changed target runtime of the application (both GUI and CLI) from .NET 3.1 to .NET 6. Those using the GUI version will not need to take any action as the application should install the necessary prerequisites automatically. Those using the CLI version will need to download and install .NET 6 runtime manually [from here](https://dotnet.microsoft.com/download/dotnet/6.0) (look for ".NET Runtime 6.0.x" section on the right and choose the distribution appropriate for your system).
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Version>2.31</Version>
|
<Version>2.36</Version>
|
||||||
<Company>Tyrrrz</Company>
|
<Company>Tyrrrz</Company>
|
||||||
<Copyright>Copyright (c) Alexey Golub</Copyright>
|
<Copyright>Copyright (c) Oleksii Holub</Copyright>
|
||||||
<LangVersion>preview</LangVersion>
|
<LangVersion>preview</LangVersion>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<WarningsAsErrors>nullable</WarningsAsErrors>
|
<WarningsAsErrors>nullable</WarningsAsErrors>
|
||||||
|
|||||||
@@ -3,9 +3,6 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>true</IsTestProject>
|
<IsTestProject>true</IsTestProject>
|
||||||
<CollectCoverage>true</CollectCoverage>
|
|
||||||
<CoverletOutputFormat>opencover</CoverletOutputFormat>
|
|
||||||
<NoWarn>$(NoWarn);xUnit1013</NoWarn>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -14,15 +11,15 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AngleSharp" Version="0.16.1" />
|
<PackageReference Include="AngleSharp" Version="0.17.1" />
|
||||||
<PackageReference Include="FluentAssertions" Version="6.2.0" />
|
<PackageReference Include="FluentAssertions" Version="6.7.0" />
|
||||||
<PackageReference Include="GitHubActionsTestLogger" Version="1.2.0" />
|
<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.0.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
|
||||||
<PackageReference Include="coverlet.msbuild" Version="3.1.0" PrivateAssets="all" />
|
|
||||||
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="xunit" Version="2.4.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" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using DiscordChatExporter.Core.Exporting;
|
using DiscordChatExporter.Core.Exporting;
|
||||||
using JsonExtensions;
|
using JsonExtensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Fixtures
|
namespace DiscordChatExporter.Cli.Tests.Fixtures;
|
||||||
|
|
||||||
|
public class ExportWrapperFixture : IDisposable
|
||||||
{
|
{
|
||||||
public class ExportWrapperFixture : IDisposable
|
|
||||||
{
|
|
||||||
private string DirPath { get; } = Path.Combine(
|
private string DirPath { get; } = Path.Combine(
|
||||||
Path.GetDirectoryName(typeof(ExportWrapperFixture).Assembly.Location) ?? Directory.GetCurrentDirectory(),
|
Path.GetDirectoryName(typeof(ExportWrapperFixture).Assembly.Location) ?? Directory.GetCurrentDirectory(),
|
||||||
"ExportCache",
|
"ExportCache",
|
||||||
@@ -36,8 +36,7 @@ namespace DiscordChatExporter.Cli.Tests.Fixtures
|
|||||||
{
|
{
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { channelId },
|
ChannelIds = new[] { channelId },
|
||||||
ExportFormat = format,
|
ExportFormat = format,
|
||||||
OutputPath = filePath
|
OutputPath = filePath
|
||||||
@@ -47,47 +46,35 @@ namespace DiscordChatExporter.Cli.Tests.Fixtures
|
|||||||
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(),
|
||||||
@@ -98,7 +85,7 @@ namespace DiscordChatExporter.Cli.Tests.Fixtures
|
|||||||
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}'."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,9 +94,8 @@ namespace DiscordChatExporter.Cli.Tests.Fixtures
|
|||||||
|
|
||||||
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(),
|
||||||
@@ -120,7 +106,7 @@ namespace DiscordChatExporter.Cli.Tests.Fixtures
|
|||||||
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}'."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,5 +114,4 @@ namespace DiscordChatExporter.Cli.Tests.Fixtures
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() => DirectoryEx.DeleteIfExists(DirPath);
|
public void Dispose() => DirectoryEx.DeleteIfExists(DirPath);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using DiscordChatExporter.Cli.Tests.Utils;
|
using DiscordChatExporter.Cli.Tests.Utils;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Fixtures
|
namespace DiscordChatExporter.Cli.Tests.Fixtures;
|
||||||
|
|
||||||
|
public class TempOutputFixture : IDisposable
|
||||||
{
|
{
|
||||||
public class TempOutputFixture : IDisposable
|
|
||||||
{
|
|
||||||
public string DirPath { get; } = Path.Combine(
|
public string DirPath { get; } = Path.Combine(
|
||||||
Path.GetDirectoryName(typeof(TempOutputFixture).Assembly.Location) ?? Directory.GetCurrentDirectory(),
|
Path.GetDirectoryName(typeof(TempOutputFixture).Assembly.Location) ?? Directory.GetCurrentDirectory(),
|
||||||
"Temp",
|
"Temp",
|
||||||
@@ -19,5 +19,4 @@ namespace DiscordChatExporter.Cli.Tests.Fixtures
|
|||||||
public string GetTempFilePath() => GetTempFilePath(Guid.NewGuid() + ".tmp");
|
public string GetTempFilePath() => GetTempFilePath(Guid.NewGuid() + ".tmp");
|
||||||
|
|
||||||
public void Dispose() => DirectoryEx.DeleteIfExists(DirPath);
|
public void Dispose() => DirectoryEx.DeleteIfExists(DirPath);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Infra
|
namespace DiscordChatExporter.Cli.Tests.Infra;
|
||||||
|
|
||||||
|
internal static class Secrets
|
||||||
{
|
{
|
||||||
internal static class Secrets
|
|
||||||
{
|
|
||||||
private static readonly Lazy<string> DiscordTokenLazy = new(() =>
|
private static readonly Lazy<string> DiscordTokenLazy = new(() =>
|
||||||
{
|
{
|
||||||
var fromEnvironment = Environment.GetEnvironmentVariable("DISCORD_TOKEN");
|
var fromEnvironment = Environment.GetEnvironmentVariable("DISCORD_TOKEN");
|
||||||
@@ -22,25 +22,5 @@ namespace DiscordChatExporter.Cli.Tests.Infra
|
|||||||
throw new InvalidOperationException("Discord token not provided for tests.");
|
throw new InvalidOperationException("Discord token not provided for tests.");
|
||||||
});
|
});
|
||||||
|
|
||||||
private static readonly Lazy<bool> IsDiscordTokenBotLazy = new(() =>
|
|
||||||
{
|
|
||||||
var fromEnvironment = Environment.GetEnvironmentVariable("DISCORD_TOKEN_BOT");
|
|
||||||
if (!string.IsNullOrWhiteSpace(fromEnvironment))
|
|
||||||
return string.Equals(fromEnvironment, "true", StringComparison.OrdinalIgnoreCase);
|
|
||||||
|
|
||||||
var secretFilePath = Path.Combine(
|
|
||||||
Path.GetDirectoryName(typeof(Secrets).Assembly.Location) ?? Directory.GetCurrentDirectory(),
|
|
||||||
"DiscordTokenBot.secret"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (File.Exists(secretFilePath))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
public static string DiscordToken => DiscordTokenLazy.Value;
|
public static string DiscordToken => DiscordTokenLazy.Value;
|
||||||
|
|
||||||
public static bool IsDiscordTokenBot => IsDiscordTokenBotLazy.Value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -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.
|
|
||||||
@@ -4,15 +4,22 @@ using DiscordChatExporter.Cli.Tests.TestData;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.CsvWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.CsvWriting;
|
||||||
|
|
||||||
|
public class ContentSpecs : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : 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(
|
||||||
@@ -27,5 +34,4 @@ namespace DiscordChatExporter.Cli.Tests.Specs.CsvWriting
|
|||||||
"Yeet"
|
"Yeet"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -13,38 +13,42 @@ using FluentAssertions;
|
|||||||
using JsonExtensions;
|
using JsonExtensions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs
|
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||||
|
|
||||||
|
public class DateRangeSpecs : IClassFixture<TempOutputFixture>
|
||||||
{
|
{
|
||||||
public record DateRangeSpecs(TempOutputFixture TempOutput) : 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
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
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[]
|
||||||
@@ -69,29 +73,26 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
{
|
{
|
||||||
// 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
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
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[]
|
||||||
@@ -115,13 +116,12 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
// 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
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
@@ -129,16 +129,14 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
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[]
|
||||||
@@ -156,5 +154,4 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
.WhenTypeIs<DateTimeOffset>();
|
.WhenTypeIs<DateTimeOffset>();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -12,32 +12,36 @@ using FluentAssertions;
|
|||||||
using JsonExtensions;
|
using JsonExtensions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs
|
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||||
|
|
||||||
|
public class FilterSpecs : IClassFixture<TempOutputFixture>
|
||||||
{
|
{
|
||||||
public record FilterSpecs(TempOutputFixture TempOutput) : 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
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
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())
|
||||||
@@ -49,24 +53,21 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
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
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
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())
|
||||||
@@ -78,24 +79,21 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
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
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
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())
|
||||||
@@ -104,32 +102,54 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Messages_filtered_by_mention_only_include_messages_that_have_that_mention()
|
public async Task Messages_filtered_by_pin_only_include_messages_that_have_been_pinned()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var filePath = TempOutput.GetTempFilePath();
|
var filePath = _tempOutput.GetTempFilePath();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
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]
|
||||||
|
public async Task Messages_filtered_by_mention_only_include_messages_that_have_that_mention()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var filePath = _tempOutput.GetTempFilePath();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await new ExportChannelsCommand
|
||||||
|
{
|
||||||
|
Token = Secrets.DiscordToken,
|
||||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||||
ExportFormat = ExportFormat.Json,
|
ExportFormat = ExportFormat.Json,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
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())
|
||||||
.Should()
|
.Should()
|
||||||
.ContainSingle("This has mention");
|
.ContainSingle("This has mention");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
@@ -6,21 +7,26 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||||
|
|
||||||
|
public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : 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,7 +34,11 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
"11 bytes"
|
"11 bytes"
|
||||||
);
|
);
|
||||||
|
|
||||||
fileUrl.Should().StartWithEquivalentOf(
|
message
|
||||||
|
.QuerySelectorAll("a")
|
||||||
|
.Select(e => e.GetAttribute("href"))
|
||||||
|
.Should()
|
||||||
|
.Contain(
|
||||||
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
|
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -37,17 +47,19 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
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("img")?.GetAttribute("src");
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
message.Text().Should().Contain("Image attachment");
|
message.Text().Should().Contain("Image attachment");
|
||||||
|
|
||||||
imageUrl.Should().StartWithEquivalentOf(
|
message
|
||||||
|
.QuerySelectorAll("img")
|
||||||
|
.Select(e => e.GetAttribute("src"))
|
||||||
|
.Should()
|
||||||
|
.Contain(
|
||||||
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
|
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -55,18 +67,19 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
[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,20 +87,20 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
[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"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,15 +6,22 @@ using DiscordChatExporter.Cli.Tests.TestData;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||||
|
|
||||||
|
public class ContentSpecs : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : 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 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
"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",
|
||||||
@@ -39,5 +46,4 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
"Yeet"
|
"Yeet"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
@@ -6,15 +7,22 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||||
|
|
||||||
|
public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : 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,33 +40,128 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
}
|
}
|
||||||
|
|
||||||
[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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,21 +6,28 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||||
|
|
||||||
|
public class MentionSpecs : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
public record MentionSpecs(ExportWrapperFixture ExportWrapper) : 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().Be("User mention: @Tyrrrz");
|
message.Text().Should().Contain("User mention: @Tyrrrz");
|
||||||
message.InnerHtml.Should().Contain("Tyrrrz#5447");
|
message.InnerHtml.Should().Contain("Tyrrrz#5447");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,39 +35,38 @@ namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
|||||||
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().Be("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().Be("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().Be("Role mention: @Role 1");
|
message.Text().Should().Contain("Role mention: @Role 1");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,52 +6,62 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||||
|
|
||||||
|
public class ReplySpecs : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
public record ReplySpecs(ExportWrapperFixture ExportWrapper) : 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().Be("reply to original");
|
message.Text().Should().Contain("reply to original");
|
||||||
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should().Be("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().Be("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(
|
||||||
.Be("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_a_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().Be("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");
|
||||||
.Be("Click to see attachment 🖼️");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||||
|
using DiscordChatExporter.Cli.Tests.TestData;
|
||||||
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||||
|
|
||||||
|
public class StickerSpecs : IClassFixture<ExportWrapperFixture>
|
||||||
|
{
|
||||||
|
private readonly ExportWrapperFixture _exportWrapper;
|
||||||
|
|
||||||
|
public StickerSpecs(ExportWrapperFixture exportWrapper)
|
||||||
|
{
|
||||||
|
_exportWrapper = exportWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_a_PNG_based_sticker_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||||
|
ChannelIds.StickerTestCases,
|
||||||
|
Snowflake.Parse("939670623158943754")
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var stickerUrl = message.QuerySelector("[title='rock'] img")?.GetAttribute("src");
|
||||||
|
stickerUrl.Should().Be("https://discord.com/stickers/904215665597120572.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_a_Lottie_based_sticker_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||||
|
ChannelIds.StickerTestCases,
|
||||||
|
Snowflake.Parse("939670526517997590")
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var stickerUrl = message.QuerySelector("[title='Yikes'] [data-source]")?.GetAttribute("data-source");
|
||||||
|
stickerUrl.Should().Be("https://discord.com/stickers/816087132447178774.json");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,26 +6,32 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||||
|
|
||||||
|
public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : 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 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
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 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
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,22 +84,20 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
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");
|
||||||
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(1087849);
|
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(1087849);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -5,15 +5,22 @@ using DiscordChatExporter.Cli.Tests.TestData;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||||
|
|
||||||
|
public class ContentSpecs : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : 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(
|
||||||
@@ -38,5 +45,4 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
"Yeet"
|
"Yeet"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,43 +6,49 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||||
|
|
||||||
|
public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : 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");
|
||||||
@@ -54,5 +60,4 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
embedFields[2].GetProperty("value").GetString().Should().Be("Value 3");
|
embedFields[2].GetProperty("value").GetString().Should().Be("Value 3");
|
||||||
embedFields[2].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
embedFields[2].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,15 +6,22 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||||
|
|
||||||
|
public class MentionSpecs : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
public record MentionSpecs(ExportWrapperFixture ExportWrapper) : 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 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
.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 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
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 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
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")
|
||||||
);
|
);
|
||||||
@@ -67,5 +75,4 @@ namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
|||||||
// Assert
|
// Assert
|
||||||
message.GetProperty("content").GetString().Should().Be("Role mention: @Role 1");
|
message.GetProperty("content").GetString().Should().Be("Role mention: @Role 1");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||||
|
using DiscordChatExporter.Cli.Tests.TestData;
|
||||||
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||||
|
|
||||||
|
public class StickerSpecs : IClassFixture<ExportWrapperFixture>
|
||||||
|
{
|
||||||
|
private readonly ExportWrapperFixture _exportWrapper;
|
||||||
|
|
||||||
|
public StickerSpecs(ExportWrapperFixture exportWrapper)
|
||||||
|
{
|
||||||
|
_exportWrapper = exportWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_a_PNG_based_sticker_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||||
|
ChannelIds.StickerTestCases,
|
||||||
|
Snowflake.Parse("939670623158943754")
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var sticker = message
|
||||||
|
.GetProperty("stickers")
|
||||||
|
.EnumerateArray()
|
||||||
|
.Single();
|
||||||
|
|
||||||
|
sticker.GetProperty("id").GetString().Should().Be("904215665597120572");
|
||||||
|
sticker.GetProperty("name").GetString().Should().Be("rock");
|
||||||
|
sticker.GetProperty("format").GetString().Should().Be("PngAnimated");
|
||||||
|
sticker.GetProperty("sourceUrl").GetString().Should().Be("https://discord.com/stickers/904215665597120572.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_a_Lottie_based_sticker_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||||
|
ChannelIds.StickerTestCases,
|
||||||
|
Snowflake.Parse("939670526517997590")
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var sticker = message
|
||||||
|
.GetProperty("stickers")
|
||||||
|
.EnumerateArray()
|
||||||
|
.Single();
|
||||||
|
|
||||||
|
sticker.GetProperty("id").GetString().Should().Be("816087132447178774");
|
||||||
|
sticker.GetProperty("name").GetString().Should().Be("Yikes");
|
||||||
|
sticker.GetProperty("format").GetString().Should().Be("Lottie");
|
||||||
|
sticker.GetProperty("sourceUrl").GetString().Should().Be("https://discord.com/stickers/816087132447178774.json");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,23 +10,29 @@ using DiscordChatExporter.Core.Exporting.Partitioning;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs
|
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||||
|
|
||||||
|
public class PartitioningSpecs : IClassFixture<TempOutputFixture>
|
||||||
{
|
{
|
||||||
public record PartitioningSpecs(TempOutputFixture TempOutput) : 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();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||||
ExportFormat = ExportFormat.HtmlDark,
|
ExportFormat = ExportFormat.HtmlDark,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
@@ -40,28 +46,26 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
}
|
}
|
||||||
|
|
||||||
[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();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||||
ExportFormat = ExportFormat.HtmlDark,
|
ExportFormat = ExportFormat.HtmlDark,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
PartitionLimit = PartitionLimit.Parse("20kb")
|
PartitionLimit = PartitionLimit.Parse("1kb")
|
||||||
}.ExecuteAsync(new FakeConsole());
|
}.ExecuteAsync(new FakeConsole());
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
|
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
|
||||||
.Should()
|
.Should()
|
||||||
.HaveCount(2);
|
.HaveCount(8);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,15 +4,22 @@ using DiscordChatExporter.Cli.Tests.TestData;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs.PlainTextWriting
|
namespace DiscordChatExporter.Cli.Tests.Specs.PlainTextWriting;
|
||||||
|
|
||||||
|
public class ContentSpecs : IClassFixture<ExportWrapperFixture>
|
||||||
{
|
{
|
||||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : 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(
|
||||||
@@ -27,5 +34,4 @@ namespace DiscordChatExporter.Cli.Tests.Specs.PlainTextWriting
|
|||||||
"Yeet"
|
"Yeet"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -11,33 +11,37 @@ using DiscordChatExporter.Core.Exporting;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Specs
|
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||||
|
|
||||||
|
public class SelfContainedSpecs : IClassFixture<TempOutputFixture>
|
||||||
{
|
{
|
||||||
public record SelfContainedSpecs(TempOutputFixture TempOutput) : 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
|
||||||
await new ExportChannelsCommand
|
await new ExportChannelsCommand
|
||||||
{
|
{
|
||||||
TokenValue = Secrets.DiscordToken,
|
Token = Secrets.DiscordToken,
|
||||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
|
||||||
ChannelIds = new[] { ChannelIds.SelfContainedTestCases },
|
ChannelIds = new[] { ChannelIds.SelfContainedTestCases },
|
||||||
ExportFormat = ExportFormat.HtmlDark,
|
ExportFormat = ExportFormat.HtmlDark,
|
||||||
OutputPath = filePath,
|
OutputPath = filePath,
|
||||||
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))
|
||||||
@@ -45,5 +49,4 @@ namespace DiscordChatExporter.Cli.Tests.Specs
|
|||||||
.Should()
|
.Should()
|
||||||
.BeTrue();
|
.BeTrue();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.TestData
|
namespace DiscordChatExporter.Cli.Tests.TestData;
|
||||||
|
|
||||||
|
public static class ChannelIds
|
||||||
{
|
{
|
||||||
public static class ChannelIds
|
|
||||||
{
|
|
||||||
public static Snowflake AttachmentTestCases { get; } = Snowflake.Parse("885587741654536192");
|
public static Snowflake AttachmentTestCases { get; } = Snowflake.Parse("885587741654536192");
|
||||||
|
|
||||||
public static Snowflake DateRangeTestCases { get; } = Snowflake.Parse("866674248747319326");
|
public static Snowflake DateRangeTestCases { get; } = Snowflake.Parse("866674248747319326");
|
||||||
|
|
||||||
public static Snowflake EmbedTestCases { get; } = Snowflake.Parse("866472452459462687");
|
public static Snowflake EmbedTestCases { get; } = Snowflake.Parse("866472452459462687");
|
||||||
|
|
||||||
|
public static Snowflake GroupingTestCases { get; } = Snowflake.Parse("992092091545034842");
|
||||||
|
|
||||||
public static Snowflake FilterTestCases { get; } = Snowflake.Parse("866744075033641020");
|
public static Snowflake FilterTestCases { get; } = Snowflake.Parse("866744075033641020");
|
||||||
|
|
||||||
public static Snowflake MentionTestCases { get; } = Snowflake.Parse("866458801389174794");
|
public static Snowflake MentionTestCases { get; } = Snowflake.Parse("866458801389174794");
|
||||||
@@ -17,5 +19,6 @@ namespace DiscordChatExporter.Cli.Tests.TestData
|
|||||||
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");
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Utils
|
namespace DiscordChatExporter.Cli.Tests.Utils;
|
||||||
|
|
||||||
|
internal static class DirectoryEx
|
||||||
{
|
{
|
||||||
internal static class DirectoryEx
|
|
||||||
{
|
|
||||||
public static void DeleteIfExists(string dirPath, bool recursive = true)
|
public static void DeleteIfExists(string dirPath, bool recursive = true)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -20,5 +20,4 @@ namespace DiscordChatExporter.Cli.Tests.Utils
|
|||||||
DeleteIfExists(dirPath);
|
DeleteIfExists(dirPath);
|
||||||
Directory.CreateDirectory(dirPath);
|
Directory.CreateDirectory(dirPath);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
using AngleSharp.Html.Dom;
|
using AngleSharp.Html.Dom;
|
||||||
using AngleSharp.Html.Parser;
|
using AngleSharp.Html.Parser;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Utils
|
namespace DiscordChatExporter.Cli.Tests.Utils;
|
||||||
|
|
||||||
|
internal static class Html
|
||||||
{
|
{
|
||||||
internal static class Html
|
|
||||||
{
|
|
||||||
private static readonly IHtmlParser Parser = new HtmlParser();
|
private static readonly IHtmlParser Parser = new HtmlParser();
|
||||||
|
|
||||||
public static IHtmlDocument Parse(string source) => Parser.ParseDocument(source);
|
public static IHtmlDocument Parse(string source) => Parser.ParseDocument(source);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -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.Extensions;
|
using DiscordChatExporter.Core.Utils;
|
||||||
|
using Gress;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands.Base
|
namespace DiscordChatExporter.Cli.Commands.Base;
|
||||||
|
|
||||||
|
public abstract class ExportCommandBase : TokenCommandBase
|
||||||
{
|
{
|
||||||
public abstract class ExportCommandBase : TokenCommandBase
|
private readonly string _outputPath = Directory.GetCurrentDirectory();
|
||||||
{
|
|
||||||
[CommandOption("output", 'o', Description = "Output file or directory path.")]
|
|
||||||
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,26 +97,57 @@ namespace DiscordChatExporter.Cli.Commands.Base
|
|||||||
|
|
||||||
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
|
||||||
await console.Output.WriteLineAsync($"Exporting {channels.Count} channel(s)...");
|
await console.Output.WriteLineAsync($"Exporting {channels.Count} channel(s)...");
|
||||||
await console.CreateProgressTicker().StartAsync(async progressContext =>
|
await console.CreateProgressTicker().StartAsync(async progressContext =>
|
||||||
{
|
{
|
||||||
await channels.ParallelForEachAsync(async channel =>
|
await Parallel.ForEachAsync(
|
||||||
|
channels,
|
||||||
|
new ParallelOptions
|
||||||
|
{
|
||||||
|
MaxDegreeOfParallelism = Math.Max(1, ParallelLimit),
|
||||||
|
CancellationToken = cancellationToken
|
||||||
|
},
|
||||||
|
async (channel, innerCancellationToken) =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await progressContext.StartTaskAsync($"{channel.Category.Name} / {channel.Name}", async progress =>
|
await progressContext.StartTaskAsync($"{channel.Category.Name} / {channel.Name}",
|
||||||
|
async progress =>
|
||||||
{
|
{
|
||||||
var guild = await Discord.GetGuildAsync(channel.GuildId, cancellationToken);
|
var guild = await Discord.GetGuildAsync(channel.GuildId, innerCancellationToken);
|
||||||
|
|
||||||
var request = new ExportRequest(
|
var request = new ExportRequest(
|
||||||
guild,
|
guild,
|
||||||
@@ -90,14 +163,20 @@ namespace DiscordChatExporter.Cli.Commands.Base
|
|||||||
DateFormat
|
DateFormat
|
||||||
);
|
);
|
||||||
|
|
||||||
await Exporter.ExportChannelAsync(request, progress, cancellationToken);
|
await Exporter.ExportChannelAsync(
|
||||||
});
|
request,
|
||||||
|
progress.ToPercentageBased(),
|
||||||
|
innerCancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch (DiscordChatExporterException ex) when (!ex.IsFatal)
|
catch (DiscordChatExporterException ex) when (!ex.IsFatal)
|
||||||
{
|
{
|
||||||
errors[channel] = ex.Message;
|
errors[channel] = ex.Message;
|
||||||
}
|
}
|
||||||
}, Math.Max(ParallelLimit, 1), cancellationToken);
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Print result
|
// Print result
|
||||||
@@ -152,5 +231,16 @@ namespace DiscordChatExporter.Cli.Commands.Base
|
|||||||
|
|
||||||
await ExecuteAsync(console, channels);
|
await ExecuteAsync(console, channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
// War in Ukraine message
|
||||||
|
console.Output.WriteLine("========================================================================");
|
||||||
|
console.Output.WriteLine("|| Ukraine is at war! Support my country in its fight for freedom~ ||");
|
||||||
|
console.Output.WriteLine("|| Learn more on my website: https://tyrrrz.me ||");
|
||||||
|
console.Output.WriteLine("========================================================================");
|
||||||
|
console.Output.WriteLine("");
|
||||||
|
|
||||||
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,30 +1,34 @@
|
|||||||
using System.Threading.Tasks;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using CliFx;
|
using CliFx;
|
||||||
using CliFx.Attributes;
|
using CliFx.Attributes;
|
||||||
using CliFx.Infrastructure;
|
using CliFx.Infrastructure;
|
||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands.Base
|
namespace DiscordChatExporter.Cli.Commands.Base;
|
||||||
{
|
|
||||||
public abstract class TokenCommandBase : ICommand
|
|
||||||
{
|
|
||||||
[CommandOption("token", 't', IsRequired = true, EnvironmentVariable = "DISCORD_TOKEN", Description = "Authentication token.")]
|
|
||||||
public string TokenValue { get; init; } = "";
|
|
||||||
|
|
||||||
[CommandOption("bot", 'b', EnvironmentVariable = "DISCORD_TOKEN_BOT", Description = "Authenticate as a bot.")]
|
public abstract class TokenCommandBase : ICommand
|
||||||
|
{
|
||||||
|
[CommandOption(
|
||||||
|
"token",
|
||||||
|
't',
|
||||||
|
IsRequired = true,
|
||||||
|
EnvironmentVariable = "DISCORD_TOKEN",
|
||||||
|
Description = "Authentication token."
|
||||||
|
)]
|
||||||
|
public string Token { get; init; } = "";
|
||||||
|
|
||||||
|
[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 AuthToken? _authToken;
|
|
||||||
private AuthToken AuthToken => _authToken ??= new AuthToken(
|
|
||||||
IsBotToken
|
|
||||||
? AuthTokenKind.Bot
|
|
||||||
: AuthTokenKind.User,
|
|
||||||
TokenValue
|
|
||||||
);
|
|
||||||
|
|
||||||
private DiscordClient? _discordClient;
|
private DiscordClient? _discordClient;
|
||||||
protected DiscordClient Discord => _discordClient ??= new DiscordClient(AuthToken);
|
protected DiscordClient Discord => _discordClient ??= new DiscordClient(Token);
|
||||||
|
|
||||||
public abstract ValueTask ExecuteAsync(IConsole console);
|
public abstract ValueTask ExecuteAsync(IConsole console);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -5,16 +5,21 @@ using CliFx.Infrastructure;
|
|||||||
using DiscordChatExporter.Cli.Commands.Base;
|
using DiscordChatExporter.Cli.Commands.Base;
|
||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
|
|
||||||
|
[Command("exportall", Description = "Export all accessible channels.")]
|
||||||
|
public class ExportAllCommand : ExportCommandBase
|
||||||
{
|
{
|
||||||
[Command("exportall", Description = "Export all accessible channels.")]
|
[CommandOption(
|
||||||
public class ExportAllCommand : ExportCommandBase
|
"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)
|
||||||
{
|
{
|
||||||
|
await base.ExecuteAsync(console);
|
||||||
|
|
||||||
var cancellationToken = console.RegisterCancellationHandler();
|
var cancellationToken = console.RegisterCancellationHandler();
|
||||||
var channels = new List<Channel>();
|
var channels = new List<Channel>();
|
||||||
|
|
||||||
@@ -26,16 +31,9 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
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);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,16 +6,23 @@ using CliFx.Infrastructure;
|
|||||||
using DiscordChatExporter.Cli.Commands.Base;
|
using DiscordChatExporter.Cli.Commands.Base;
|
||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
|
|
||||||
|
[Command("export", Description = "Export one or multiple channels.")]
|
||||||
|
public class ExportChannelsCommand : ExportCommandBase
|
||||||
{
|
{
|
||||||
[Command("export", Description = "Export one or multiple channels.")]
|
|
||||||
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)
|
||||||
|
{
|
||||||
|
await base.ExecuteAsync(console);
|
||||||
await base.ExecuteAsync(console, ChannelIds);
|
await base.ExecuteAsync(console, ChannelIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,20 +6,23 @@ using DiscordChatExporter.Cli.Commands.Base;
|
|||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
|
|
||||||
|
[Command("exportdm", Description = "Export all direct message channels.")]
|
||||||
|
public class ExportDirectMessagesCommand : ExportCommandBase
|
||||||
{
|
{
|
||||||
[Command("exportdm", Description = "Export all direct message channels.")]
|
|
||||||
public class ExportDirectMessagesCommand : ExportCommandBase
|
|
||||||
{
|
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
|
await base.ExecuteAsync(console);
|
||||||
|
|
||||||
var cancellationToken = console.RegisterCancellationHandler();
|
var cancellationToken = console.RegisterCancellationHandler();
|
||||||
|
|
||||||
await console.Output.WriteLineAsync("Fetching channels...");
|
await console.Output.WriteLineAsync("Fetching channels...");
|
||||||
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,25 +4,34 @@ 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;
|
||||||
|
|
||||||
|
[Command("exportguild", Description = "Export all channels within specified guild.")]
|
||||||
|
public class ExportGuildCommand : ExportCommandBase
|
||||||
{
|
{
|
||||||
[Command("exportguild", Description = "Export all channels within specified guild.")]
|
[CommandOption(
|
||||||
public class ExportGuildCommand : ExportCommandBase
|
"guild",
|
||||||
{
|
'g',
|
||||||
[CommandOption("guild", 'g', IsRequired = true, Description = "Guild ID.")]
|
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)
|
||||||
{
|
{
|
||||||
|
await base.ExecuteAsync(console);
|
||||||
|
|
||||||
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,32 +5,38 @@ 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;
|
||||||
|
|
||||||
|
[Command("channels", Description = "Get the list of channels in a guild.")]
|
||||||
|
public class GetChannelsCommand : TokenCommandBase
|
||||||
{
|
{
|
||||||
[Command("channels", Description = "Get the list of channels in a guild.")]
|
[CommandOption(
|
||||||
public class GetChannelsCommand : TokenCommandBase
|
"guild",
|
||||||
{
|
'g',
|
||||||
[CommandOption("guild", 'g', IsRequired = true, Description = "Guild ID.")]
|
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))
|
||||||
@@ -41,5 +47,4 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
await console.Output.WriteLineAsync($"{channel.Category.Name} / {channel.Name}");
|
await console.Output.WriteLineAsync($"{channel.Category.Name} / {channel.Name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -7,27 +7,27 @@ using DiscordChatExporter.Cli.Commands.Base;
|
|||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
|
|
||||||
|
[Command("dm", Description = "Get the list of direct message channels.")]
|
||||||
|
public class GetDirectMessageChannelsCommand : TokenCommandBase
|
||||||
{
|
{
|
||||||
[Command("dm", Description = "Get the list of direct message channels.")]
|
|
||||||
public class GetDirectMessageChannelsCommand : TokenCommandBase
|
|
||||||
{
|
|
||||||
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(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))
|
||||||
@@ -38,5 +38,4 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
await console.Output.WriteLineAsync($"{channel.Category.Name} / {channel.Name}");
|
await console.Output.WriteLineAsync($"{channel.Category.Name} / {channel.Name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,23 +4,29 @@ 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;
|
||||||
|
|
||||||
|
[Command("guilds", Description = "Get the list of accessible guilds.")]
|
||||||
|
public class GetGuildsCommand : TokenCommandBase
|
||||||
{
|
{
|
||||||
[Command("guilds", Description = "Get the list of accessible guilds.")]
|
|
||||||
public class GetGuildsCommand : TokenCommandBase
|
|
||||||
{
|
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
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))
|
||||||
@@ -31,5 +37,4 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
await console.Output.WriteLineAsync(guild.Name);
|
await console.Output.WriteLineAsync(guild.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,26 +4,27 @@ using CliFx;
|
|||||||
using CliFx.Attributes;
|
using CliFx.Attributes;
|
||||||
using CliFx.Infrastructure;
|
using CliFx.Infrastructure;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
|
|
||||||
|
[Command("guide", Description = "Explains how to obtain token, guild or channel ID.")]
|
||||||
|
public class GuideCommand : ICommand
|
||||||
{
|
{
|
||||||
[Command("guide", Description = "Explains how to obtain token, guild or channel ID.")]
|
|
||||||
public class GuideCommand : ICommand
|
|
||||||
{
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
// User token
|
// User token
|
||||||
using (console.WithForegroundColor(ConsoleColor.White))
|
using (console.WithForegroundColor(ConsoleColor.White))
|
||||||
console.Output.WriteLine("To get user token:");
|
console.Output.WriteLine("To get user token:");
|
||||||
|
|
||||||
console.Output.WriteLine(" 1. Open Discord");
|
console.Output.WriteLine(" * Automating user accounts is technically against TOS — USE AT YOUR OWN RISK!");
|
||||||
console.Output.WriteLine(" 2. Press Ctrl+Shift+I to show developer tools");
|
console.Output.WriteLine(" 1. Open Discord in your web browser and login");
|
||||||
console.Output.WriteLine(" 3. Press Ctrl+Shift+M to toggle device toolbar");
|
console.Output.WriteLine(" 2. Open any server or direct message channel");
|
||||||
console.Output.WriteLine(" 4. Navigate to the Application tab");
|
console.Output.WriteLine(" 3. Press Ctrl+Shift+I to show developer tools");
|
||||||
console.Output.WriteLine(" 5. On the left, expand Local Storage and select https://discord.com");
|
console.Output.WriteLine(" 4. Navigate to the Network tab");
|
||||||
console.Output.WriteLine(" 6. Type \"token\" into the Filter box");
|
console.Output.WriteLine(" 5. Press Ctrl+R to reload");
|
||||||
console.Output.WriteLine(" 7. If the token key does not appear, press Ctrl+R to reload");
|
console.Output.WriteLine(" 6. Search for a request containing \"messages?limit=50\" or similar");
|
||||||
console.Output.WriteLine(" 8. Copy the value of the token key");
|
console.Output.WriteLine(" 7. Select the Headers tab on the right");
|
||||||
console.Output.WriteLine(" * Automating user accounts is technically against TOS, use at your own risk.");
|
console.Output.WriteLine(" 8. Scroll down to the Request Headers section");
|
||||||
|
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 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
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 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
|
|
||||||
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();
|
||||||
@@ -61,11 +63,10 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
|
|
||||||
// Wiki link
|
// Wiki link
|
||||||
using (console.WithForegroundColor(ConsoleColor.White))
|
using (console.WithForegroundColor(ConsoleColor.White))
|
||||||
console.Output.WriteLine("For more information, check out the wiki:");
|
console.Output.WriteLine("If you have questions or issues, please refer to the wiki:");
|
||||||
using (console.WithForegroundColor(ConsoleColor.DarkCyan))
|
using (console.WithForegroundColor(ConsoleColor.DarkCyan))
|
||||||
console.Output.WriteLine("https://github.com/Tyrrrz/DiscordChatExporter/wiki");
|
console.Output.WriteLine("https://github.com/Tyrrrz/DiscordChatExporter/wiki");
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,9 +6,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CliFx" Version="2.0.6" />
|
<PackageReference Include="CliFx" Version="2.3.0" />
|
||||||
<PackageReference Include="Spectre.Console" Version="0.43.0" />
|
<PackageReference Include="Spectre.Console" Version="0.44.0" />
|
||||||
<PackageReference Include="Gress" Version="1.2.0" />
|
<PackageReference Include="Gress" Version="2.0.1" />
|
||||||
|
<PackageReference Include="DotnetRuntimeBootstrapper" Version="2.3.1" PrivateAssets="all" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
using System.Threading.Tasks;
|
using CliFx;
|
||||||
using CliFx;
|
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli
|
return await new CliApplicationBuilder()
|
||||||
{
|
|
||||||
public static class Program
|
|
||||||
{
|
|
||||||
public static async Task<int> Main(string[] args) =>
|
|
||||||
await new CliApplicationBuilder()
|
|
||||||
.AddCommandsFromThisAssembly()
|
.AddCommandsFromThisAssembly()
|
||||||
.Build()
|
.Build()
|
||||||
.RunAsync(args);
|
.RunAsync(args);
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,10 +3,10 @@ using System.Threading.Tasks;
|
|||||||
using CliFx.Infrastructure;
|
using CliFx.Infrastructure;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Utils.Extensions
|
namespace DiscordChatExporter.Cli.Utils.Extensions;
|
||||||
|
|
||||||
|
internal static class ConsoleExtensions
|
||||||
{
|
{
|
||||||
internal static class ConsoleExtensions
|
|
||||||
{
|
|
||||||
public static IAnsiConsole CreateAnsiConsole(this IConsole console) =>
|
public static IAnsiConsole CreateAnsiConsole(this IConsole console) =>
|
||||||
AnsiConsole.Create(new AnsiConsoleSettings
|
AnsiConsole.Create(new AnsiConsoleSettings
|
||||||
{
|
{
|
||||||
@@ -47,5 +47,4 @@ namespace DiscordChatExporter.Cli.Utils.Extensions
|
|||||||
progressTask.StopTask();
|
progressTask.StopTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using System.Net.Http.Headers;
|
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord
|
|
||||||
{
|
|
||||||
public record AuthToken(AuthTokenKind Kind, string Value)
|
|
||||||
{
|
|
||||||
public AuthenticationHeaderValue GetAuthenticationHeader() => Kind switch
|
|
||||||
{
|
|
||||||
AuthTokenKind.Bot => new AuthenticationHeaderValue("Bot", Value),
|
|
||||||
_ => new AuthenticationHeaderValue(Value)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace DiscordChatExporter.Core.Discord
|
|
||||||
{
|
|
||||||
public enum AuthTokenKind
|
|
||||||
{
|
|
||||||
User,
|
|
||||||
Bot
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,17 +6,18 @@ using DiscordChatExporter.Core.Utils;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#attachment-object
|
// https://discord.com/developers/docs/resources/channel#attachment-object
|
||||||
public partial record Attachment(
|
public partial record Attachment(
|
||||||
Snowflake Id,
|
Snowflake Id,
|
||||||
string Url,
|
string Url,
|
||||||
string FileName,
|
string FileName,
|
||||||
|
string? Description,
|
||||||
int? Width,
|
int? Width,
|
||||||
int? Height,
|
int? Height,
|
||||||
FileSize FileSize) : IHasId
|
FileSize FileSize) : IHasId
|
||||||
{
|
{
|
||||||
public string FileExtension => Path.GetExtension(FileName);
|
public string FileExtension => Path.GetExtension(FileName);
|
||||||
|
|
||||||
public bool IsImage => FileFormat.IsImage(FileExtension);
|
public bool IsImage => FileFormat.IsImage(FileExtension);
|
||||||
@@ -26,20 +27,20 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
public bool IsAudio => FileFormat.IsAudio(FileExtension);
|
public bool IsAudio => FileFormat.IsAudio(FileExtension);
|
||||||
|
|
||||||
public bool IsSpoiler => FileName.StartsWith("SPOILER_", StringComparison.Ordinal);
|
public bool IsSpoiler => FileName.StartsWith("SPOILER_", StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial record Attachment
|
public partial record Attachment
|
||||||
{
|
{
|
||||||
public static Attachment Parse(JsonElement json)
|
public static Attachment Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
var url = json.GetProperty("url").GetNonWhiteSpaceString();
|
var url = json.GetProperty("url").GetNonWhiteSpaceString();
|
||||||
var width = json.GetPropertyOrNull("width")?.GetInt32();
|
var fileName = json.GetProperty("filename").GetNonNullString();
|
||||||
var height = json.GetPropertyOrNull("height")?.GetInt32();
|
var description = json.GetPropertyOrNull("description")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var fileName = json.GetProperty("filename").GetNonWhiteSpaceString();
|
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, width, height, fileSize);
|
return new Attachment(id, url, fileName, description, width, height, fileSize);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,30 +4,24 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#channel-object
|
// https://discord.com/developers/docs/resources/channel#channel-object
|
||||||
public partial record Channel(
|
public partial record Channel(
|
||||||
Snowflake Id,
|
Snowflake Id,
|
||||||
ChannelKind Kind,
|
ChannelKind Kind,
|
||||||
Snowflake GuildId,
|
Snowflake GuildId,
|
||||||
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
|
{
|
||||||
ChannelKind.GuildTextChat or
|
public bool SupportsVoice => Kind is ChannelKind.GuildVoiceChat or ChannelKind.GuildStageVoice;
|
||||||
ChannelKind.DirectTextChat or
|
}
|
||||||
ChannelKind.DirectGroupTextChat or
|
|
||||||
ChannelKind.GuildNews or
|
|
||||||
ChannelKind.GuildStore;
|
|
||||||
|
|
||||||
public bool IsVoiceChannel => !IsTextChannel;
|
public partial record Channel
|
||||||
}
|
{
|
||||||
|
|
||||||
public partial record Channel
|
|
||||||
{
|
|
||||||
private static ChannelCategory GetFallbackCategory(ChannelKind channelKind) => new(
|
private static ChannelCategory GetFallbackCategory(ChannelKind channelKind) => new(
|
||||||
Snowflake.Zero,
|
Snowflake.Zero,
|
||||||
channelKind switch
|
channelKind switch
|
||||||
@@ -36,37 +30,51 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
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
|
||||||
);
|
);
|
||||||
|
|
||||||
public static Channel Parse(JsonElement json, ChannelCategory? category = null, int? position = null)
|
public static Channel Parse(JsonElement json, ChannelCategory? category = null, int? positionHint = null)
|
||||||
{
|
{
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
var guildId = json.GetPropertyOrNull("guild_id")?.GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
|
||||||
var 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
|
||||||
json.GetPropertyOrNull("name")?.GetStringOrNull() ??
|
json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull() ??
|
||||||
|
|
||||||
// DM channel
|
// DM channel
|
||||||
json.GetPropertyOrNull("recipients")?.EnumerateArray().Select(User.Parse).Select(u => u.Name)
|
json.GetPropertyOrNull("recipients")?
|
||||||
|
.EnumerateArrayOrNull()?
|
||||||
|
.Select(User.Parse)
|
||||||
|
.Select(u => u.Name)
|
||||||
.Pipe(s => string.Join(", ", s)) ??
|
.Pipe(s => string.Join(", ", s)) ??
|
||||||
|
|
||||||
// Fallback
|
// Fallback
|
||||||
id.ToString();
|
id.ToString();
|
||||||
|
|
||||||
|
var position =
|
||||||
|
positionHint ??
|
||||||
|
json.GetPropertyOrNull("position")?.GetInt32OrNull();
|
||||||
|
|
||||||
|
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,
|
||||||
kind,
|
kind,
|
||||||
guildId ?? Guild.DirectMessages.Id,
|
guildId ?? Guild.DirectMessages.Id,
|
||||||
category ?? GetFallbackCategory(kind),
|
category ?? GetFallbackCategory(kind),
|
||||||
name,
|
name,
|
||||||
position ?? json.GetPropertyOrNull("position")?.GetInt32(),
|
position,
|
||||||
topic
|
topic,
|
||||||
|
lastMessageId
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,25 +3,24 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
|
public record ChannelCategory(Snowflake Id, string Name, int? Position) : IHasId
|
||||||
{
|
{
|
||||||
public record ChannelCategory(Snowflake Id, string Name, int? Position) : IHasId
|
|
||||||
{
|
|
||||||
public static ChannelCategory Unknown { get; } = new(Snowflake.Zero, "<unknown category>", 0);
|
public static ChannelCategory Unknown { get; } = new(Snowflake.Zero, "<unknown category>", 0);
|
||||||
|
|
||||||
public static ChannelCategory Parse(JsonElement json, int? position = null)
|
public static ChannelCategory Parse(JsonElement json, int? positionHint = null)
|
||||||
{
|
{
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
|
|
||||||
var name =
|
var name =
|
||||||
json.GetPropertyOrNull("name")?.GetStringOrNull() ??
|
json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull() ??
|
||||||
id.ToString();
|
id.ToString();
|
||||||
|
|
||||||
return new ChannelCategory(
|
var position =
|
||||||
id,
|
positionHint ??
|
||||||
name,
|
json.GetPropertyOrNull("position")?.GetInt32OrNull();
|
||||||
position ?? json.GetPropertyOrNull("position")?.GetInt32()
|
|
||||||
);
|
return new ChannelCategory(id, name, position);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,19 @@
|
|||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
|
// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
|
||||||
|
// Order of enum fields needs to match the order in the docs.
|
||||||
|
public enum ChannelKind
|
||||||
{
|
{
|
||||||
// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
|
|
||||||
// Order of enum fields needs to match the order in the docs.
|
|
||||||
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
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Common
|
namespace DiscordChatExporter.Core.Discord.Data.Common;
|
||||||
|
|
||||||
|
// Loosely based on https://github.com/omar/ByteSize (MIT license)
|
||||||
|
public readonly partial record struct FileSize(long TotalBytes)
|
||||||
{
|
{
|
||||||
// Loosely based on https://github.com/omar/ByteSize (MIT license)
|
|
||||||
public readonly partial record struct FileSize(long TotalBytes)
|
|
||||||
{
|
|
||||||
public double TotalKiloBytes => TotalBytes / 1024.0;
|
public double TotalKiloBytes => TotalBytes / 1024.0;
|
||||||
public double TotalMegaBytes => TotalKiloBytes / 1024.0;
|
public double TotalMegaBytes => TotalKiloBytes / 1024.0;
|
||||||
public double TotalGigaBytes => TotalMegaBytes / 1024.0;
|
public double TotalGigaBytes => TotalMegaBytes / 1024.0;
|
||||||
@@ -40,10 +40,9 @@ namespace DiscordChatExporter.Core.Discord.Data.Common
|
|||||||
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public override string ToString() => $"{GetLargestWholeNumberValue():0.##} {GetLargestWholeNumberSymbol()}";
|
public override string ToString() => $"{GetLargestWholeNumberValue():0.##} {GetLargestWholeNumberSymbol()}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial record struct FileSize
|
public partial record struct FileSize
|
||||||
{
|
{
|
||||||
public static FileSize FromBytes(long bytes) => new(bytes);
|
public static FileSize FromBytes(long bytes) => new(bytes);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
namespace DiscordChatExporter.Core.Discord.Data.Common
|
namespace DiscordChatExporter.Core.Discord.Data.Common;
|
||||||
|
|
||||||
|
public interface IHasId
|
||||||
{
|
{
|
||||||
public interface IHasId
|
|
||||||
{
|
|
||||||
Snowflake Id { get; }
|
Snowflake Id { get; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Common
|
namespace DiscordChatExporter.Core.Discord.Data.Common;
|
||||||
|
|
||||||
|
public class IdBasedEqualityComparer : IEqualityComparer<IHasId>
|
||||||
{
|
{
|
||||||
public class IdBasedEqualityComparer : IEqualityComparer<IHasId>
|
|
||||||
{
|
|
||||||
public static IdBasedEqualityComparer Instance { get; } = new();
|
public static IdBasedEqualityComparer Instance { get; } = new();
|
||||||
|
|
||||||
public bool Equals(IHasId? x, IHasId? y) => x?.Id == y?.Id;
|
public bool Equals(IHasId? x, IHasId? y) => x?.Id == y?.Id;
|
||||||
|
|
||||||
public int GetHashCode(IHasId obj) => obj.Id.GetHashCode();
|
public int GetHashCode(IHasId obj) => obj.Id.GetHashCode();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,11 +6,12 @@ using System.Text.Json;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#embed-object
|
// https://discord.com/developers/docs/resources/channel#embed-object
|
||||||
public partial record Embed(
|
public partial record Embed(
|
||||||
string? Title,
|
string? Title,
|
||||||
|
EmbedKind Kind,
|
||||||
string? Url,
|
string? Url,
|
||||||
DateTimeOffset? Timestamp,
|
DateTimeOffset? Timestamp,
|
||||||
Color? Color,
|
Color? Color,
|
||||||
@@ -18,40 +19,63 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
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);
|
||||||
|
|
||||||
public YouTubeVideoEmbedProjection? TryGetYouTubeVideo() =>
|
public YouTubeVideoEmbedProjection? TryGetYouTubeVideo() =>
|
||||||
YouTubeVideoEmbedProjection.TryResolve(this);
|
YouTubeVideoEmbedProjection.TryResolve(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial record Embed
|
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 url = json.GetPropertyOrNull("url")?.GetStringOrNull();
|
|
||||||
|
var kind =
|
||||||
|
json.GetPropertyOrNull("type")?.GetStringOrNull()?.Pipe(s => Enum.Parse<EmbedKind>(s, true)) ??
|
||||||
|
EmbedKind.Rich;
|
||||||
|
|
||||||
|
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var timestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffset();
|
var timestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffset();
|
||||||
var color = json.GetPropertyOrNull("color")?.GetInt32().Pipe(System.Drawing.Color.FromArgb).ResetAlpha();
|
|
||||||
var 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")?.EnumerateArray().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,9 +83,9 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
description,
|
description,
|
||||||
fields,
|
fields,
|
||||||
thumbnail,
|
thumbnail,
|
||||||
image,
|
images,
|
||||||
|
video,
|
||||||
footer
|
footer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,22 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure
|
// https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure
|
||||||
public record EmbedAuthor(
|
public record EmbedAuthor(
|
||||||
string? Name,
|
string? Name,
|
||||||
string? Url,
|
string? Url,
|
||||||
string? IconUrl,
|
string? IconUrl,
|
||||||
string? IconProxyUrl)
|
string? IconProxyUrl)
|
||||||
{
|
{
|
||||||
public static EmbedAuthor Parse(JsonElement json)
|
public static EmbedAuthor Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var name = json.GetPropertyOrNull("name")?.GetStringOrNull();
|
var name = json.GetPropertyOrNull("name")?.GetStringOrNull();
|
||||||
var url = json.GetPropertyOrNull("url")?.GetStringOrNull();
|
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var iconUrl = json.GetPropertyOrNull("icon_url")?.GetStringOrNull();
|
var iconUrl = json.GetPropertyOrNull("icon_url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetStringOrNull();
|
var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
|
|
||||||
return new EmbedAuthor(name, url, iconUrl, iconProxyUrl);
|
return new EmbedAuthor(name, url, iconUrl, iconProxyUrl);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,20 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
|
// https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
|
||||||
public record EmbedField(
|
public record EmbedField(
|
||||||
string Name,
|
string Name,
|
||||||
string Value,
|
string Value,
|
||||||
bool IsInline)
|
bool IsInline)
|
||||||
{
|
{
|
||||||
public static EmbedField Parse(JsonElement json)
|
public static EmbedField Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var name = json.GetProperty("name").GetNonWhiteSpaceString();
|
var name = json.GetProperty("name").GetNonNullString();
|
||||||
var value = json.GetProperty("value").GetNonWhiteSpaceString();
|
var value = json.GetProperty("value").GetNonNullString();
|
||||||
var isInline = json.GetPropertyOrNull("inline")?.GetBoolean() ?? false;
|
var isInline = json.GetPropertyOrNull("inline")?.GetBooleanOrNull() ?? false;
|
||||||
|
|
||||||
return new EmbedField(name, value, isInline);
|
return new EmbedField(name, value, isInline);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,20 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
|
// https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
|
||||||
public record EmbedFooter(
|
public record EmbedFooter(
|
||||||
string Text,
|
string Text,
|
||||||
string? IconUrl,
|
string? IconUrl,
|
||||||
string? IconProxyUrl)
|
string? IconProxyUrl)
|
||||||
{
|
{
|
||||||
public static EmbedFooter Parse(JsonElement json)
|
public static EmbedFooter Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var text = json.GetProperty("text").GetNonWhiteSpaceString();
|
var text = json.GetProperty("text").GetNonNullString();
|
||||||
var iconUrl = json.GetPropertyOrNull("icon_url")?.GetStringOrNull();
|
var iconUrl = json.GetPropertyOrNull("icon_url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetStringOrNull();
|
var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
|
|
||||||
return new EmbedFooter(text, iconUrl, iconProxyUrl);
|
return new EmbedFooter(text, iconUrl, iconProxyUrl);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,22 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure
|
// https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure
|
||||||
public record EmbedImage(
|
public record EmbedImage(
|
||||||
string? Url,
|
string? Url,
|
||||||
string? ProxyUrl,
|
string? ProxyUrl,
|
||||||
int? Width,
|
int? Width,
|
||||||
int? Height)
|
int? Height)
|
||||||
{
|
{
|
||||||
public static EmbedImage Parse(JsonElement json)
|
public static EmbedImage Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var url = json.GetPropertyOrNull("url")?.GetStringOrNull();
|
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var proxyUrl = json.GetPropertyOrNull("proxy_url")?.GetStringOrNull();
|
var proxyUrl = json.GetPropertyOrNull("proxy_url")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var width = json.GetPropertyOrNull("width")?.GetInt32();
|
var width = json.GetPropertyOrNull("width")?.GetInt32OrNull();
|
||||||
var height = json.GetPropertyOrNull("height")?.GetInt32();
|
var height = json.GetPropertyOrNull("height")?.GetInt32OrNull();
|
||||||
|
|
||||||
return new EmbedImage(url, proxyUrl, width, height);
|
return new EmbedImage(url, proxyUrl, width, height);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
|
|
||||||
|
// https://discord.com/developers/docs/resources/channel#embed-object-embed-types
|
||||||
|
public enum EmbedKind
|
||||||
|
{
|
||||||
|
Rich,
|
||||||
|
Image,
|
||||||
|
Video,
|
||||||
|
Gifv,
|
||||||
|
Article,
|
||||||
|
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,34 +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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
public partial record SpotifyTrackEmbedProjection(string TrackId)
|
|
||||||
{
|
|
||||||
public string Url => $"https://open.spotify.com/embed/track/{TrackId}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public partial record SpotifyTrackEmbedProjection
|
public partial record SpotifyTrackEmbedProjection(string TrackId)
|
||||||
{
|
{
|
||||||
|
public string Url => $"https://open.spotify.com/embed/track/{TrackId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial record SpotifyTrackEmbedProjection
|
||||||
|
{
|
||||||
private static string? TryParseTrackId(string embedUrl)
|
private static string? TryParseTrackId(string embedUrl)
|
||||||
{
|
{
|
||||||
// https://open.spotify.com/track/1LHZMWefF9502NPfArRfvP?si=3efac6ce9be04f0a
|
// https://open.spotify.com/track/1LHZMWefF9502NPfArRfvP?si=3efac6ce9be04f0a
|
||||||
@@ -21,6 +21,9 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@@ -30,5 +33,4 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
|
|
||||||
return new SpotifyTrackEmbedProjection(trackId);
|
return new SpotifyTrackEmbedProjection(trackId);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||||
{
|
|
||||||
public partial record YouTubeVideoEmbedProjection(string VideoId)
|
|
||||||
{
|
|
||||||
public string Url => $"https://www.youtube.com/embed/{VideoId}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public partial record YouTubeVideoEmbedProjection
|
public partial record YouTubeVideoEmbedProjection(string VideoId)
|
||||||
{
|
{
|
||||||
|
public string Url => $"https://www.youtube.com/embed/{VideoId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
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 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
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;
|
||||||
|
|
||||||
@@ -45,5 +54,4 @@ namespace DiscordChatExporter.Core.Discord.Data.Embeds
|
|||||||
|
|
||||||
return new YouTubeVideoEmbedProjection(videoId);
|
return new YouTubeVideoEmbedProjection(videoId);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,60 +1,79 @@
|
|||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using DiscordChatExporter.Core.Utils;
|
using DiscordChatExporter.Core.Utils;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/emoji#emoji-object
|
// https://discord.com/developers/docs/resources/emoji#emoji-object
|
||||||
public partial record Emoji(
|
public partial record Emoji(
|
||||||
// Only present on custom emoji
|
// Only present on custom emoji
|
||||||
string? Id,
|
Snowflake? Id,
|
||||||
// Name of custom emoji (e.g. LUL) or actual representation of standard emoji (e.g. 🙂)
|
// Name of 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 => !string.IsNullOrWhiteSpace(Id)
|
public string Code => Id is not null
|
||||||
? Name
|
? Name
|
||||||
: EmojiIndex.TryGetCode(Name) ?? Name;
|
: EmojiIndex.TryGetCode(Name) ?? Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial record Emoji
|
||||||
|
{
|
||||||
|
private static string GetTwemojiId(string name)
|
||||||
|
{
|
||||||
|
var runes = name.GetRunes().ToArray();
|
||||||
|
|
||||||
|
// Variant selector rune is skipped in Twemoji names, except when the emoji also contains a zero-width joiner.
|
||||||
|
// 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"))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial record Emoji
|
private static string GetImageUrl(Snowflake id, bool isAnimated) => isAnimated
|
||||||
{
|
|
||||||
private static string GetTwemojiName(string name) => string.Join("-",
|
|
||||||
name
|
|
||||||
.GetRunes()
|
|
||||||
// Variant selector rune is skipped in Twemoji names
|
|
||||||
.Where(r => r.Value != 0xfe0f)
|
|
||||||
.Select(r => r.Value.ToString("x"))
|
|
||||||
);
|
|
||||||
|
|
||||||
public static string GetImageUrl(string? id, string name, bool isAnimated)
|
|
||||||
{
|
|
||||||
// Custom emoji
|
|
||||||
if (!string.IsNullOrWhiteSpace(id))
|
|
||||||
{
|
|
||||||
return isAnimated
|
|
||||||
? $"https://cdn.discordapp.com/emojis/{id}.gif"
|
? $"https://cdn.discordapp.com/emojis/{id}.gif"
|
||||||
: $"https://cdn.discordapp.com/emojis/{id}.png";
|
: $"https://cdn.discordapp.com/emojis/{id}.png";
|
||||||
}
|
|
||||||
|
private static string GetImageUrl(string name) =>
|
||||||
|
$"https://twemoji.maxcdn.com/v/latest/svg/{GetTwemojiId(name)}.svg";
|
||||||
|
|
||||||
|
public static string GetImageUrl(Snowflake? id, string? name, bool isAnimated)
|
||||||
|
{
|
||||||
|
// Custom emoji
|
||||||
|
if (id is not null)
|
||||||
|
return GetImageUrl(id.Value, isAnimated);
|
||||||
|
|
||||||
// Standard emoji
|
// Standard emoji
|
||||||
var twemojiName = GetTwemojiName(name);
|
if (!string.IsNullOrWhiteSpace(name))
|
||||||
return $"https://twemoji.maxcdn.com/2/svg/{twemojiName}.svg";
|
return GetImageUrl(name);
|
||||||
|
|
||||||
|
// Either ID or name should be set
|
||||||
|
throw new ApplicationException("Emoji has neither ID nor name set.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Emoji Parse(JsonElement json)
|
public static Emoji Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var id = json.GetPropertyOrNull("id")?.GetNonWhiteSpaceString();
|
var id = json.GetPropertyOrNull("id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
|
||||||
var name = json.GetProperty("name").GetNonWhiteSpaceString();
|
var name = json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var isAnimated = json.GetPropertyOrNull("animated")?.GetBoolean() ?? false;
|
var isAnimated = json.GetPropertyOrNull("animated")?.GetBooleanOrNull() ?? false;
|
||||||
|
|
||||||
var imageUrl = GetImageUrl(id, name, isAnimated);
|
var imageUrl = GetImageUrl(id, name, isAnimated);
|
||||||
|
|
||||||
return new Emoji(id, name, isAnimated, imageUrl);
|
return new Emoji(
|
||||||
}
|
id,
|
||||||
|
// Name may be missing if it's an emoji inside a reaction
|
||||||
|
name ?? "<unknown emoji>",
|
||||||
|
isAnimated,
|
||||||
|
imageUrl
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
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;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
|
// https://discord.com/developers/docs/resources/guild#guild-object
|
||||||
|
public record Guild(Snowflake Id, string Name, string IconUrl) : IHasId
|
||||||
{
|
{
|
||||||
// https://discord.com/developers/docs/resources/guild#guild-object
|
|
||||||
public record Guild(Snowflake Id, string Name, string IconUrl) : IHasId
|
|
||||||
{
|
|
||||||
public static Guild DirectMessages { get; } = new(
|
public static Guild DirectMessages { get; } = new(
|
||||||
Snowflake.Zero,
|
Snowflake.Zero,
|
||||||
"Direct Messages",
|
"Direct Messages",
|
||||||
@@ -17,20 +18,25 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
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").GetNonWhiteSpaceString();
|
var name = json.GetProperty("name").GetNonNullString();
|
||||||
var iconHash = json.GetPropertyOrNull("icon")?.GetStringOrNull();
|
|
||||||
|
|
||||||
|
var iconHash = json.GetPropertyOrNull("icon")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var iconUrl = !string.IsNullOrWhiteSpace(iconHash)
|
var iconUrl = !string.IsNullOrWhiteSpace(iconHash)
|
||||||
? GetIconUrl(id, iconHash)
|
? GetIconUrl(id, iconHash)
|
||||||
: GetDefaultIconUrl();
|
: GetDefaultIconUrl();
|
||||||
|
|
||||||
return new Guild(id, name, iconUrl);
|
return new Guild(id, name, iconUrl);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,19 +6,19 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/guild#guild-member-object
|
// https://discord.com/developers/docs/resources/guild#guild-member-object
|
||||||
public partial record Member(
|
public partial record Member(
|
||||||
User User,
|
User User,
|
||||||
string Nick,
|
string Nick,
|
||||||
IReadOnlyList<Snowflake> RoleIds) : IHasId
|
IReadOnlyList<Snowflake> RoleIds) : IHasId
|
||||||
{
|
{
|
||||||
public Snowflake Id => User.Id;
|
public Snowflake Id => User.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial record Member
|
public partial record Member
|
||||||
{
|
{
|
||||||
public static Member CreateForUser(User user) => new(
|
public static Member CreateForUser(User user) => new(
|
||||||
user,
|
user,
|
||||||
user.Name,
|
user.Name,
|
||||||
@@ -28,7 +28,7 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
public static Member Parse(JsonElement json)
|
public static Member Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var user = json.GetProperty("user").Pipe(User.Parse);
|
var user = json.GetProperty("user").Pipe(User.Parse);
|
||||||
var nick = json.GetPropertyOrNull("nick")?.GetStringOrNull();
|
var nick = json.GetPropertyOrNull("nick")?.GetNonWhiteSpaceStringOrNull();
|
||||||
|
|
||||||
var roleIds = json
|
var roleIds = json
|
||||||
.GetPropertyOrNull("roles")?
|
.GetPropertyOrNull("roles")?
|
||||||
@@ -43,5 +43,4 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
roleIds
|
roleIds
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -7,10 +7,10 @@ using DiscordChatExporter.Core.Discord.Data.Embeds;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/channel#message-object
|
// https://discord.com/developers/docs/resources/channel#message-object
|
||||||
public record Message(
|
public record Message(
|
||||||
Snowflake Id,
|
Snowflake Id,
|
||||||
MessageKind Kind,
|
MessageKind Kind,
|
||||||
User Author,
|
User Author,
|
||||||
@@ -21,23 +21,82 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
string Content,
|
string Content,
|
||||||
IReadOnlyList<Attachment> Attachments,
|
IReadOnlyList<Attachment> Attachments,
|
||||||
IReadOnlyList<Embed> Embeds,
|
IReadOnlyList<Embed> Embeds,
|
||||||
|
IReadOnlyList<Sticker> Stickers,
|
||||||
IReadOnlyList<Reaction> Reactions,
|
IReadOnlyList<Reaction> Reactions,
|
||||||
IReadOnlyList<User> MentionedUsers,
|
IReadOnlyList<User> MentionedUsers,
|
||||||
MessageReference? Reference,
|
MessageReference? Reference,
|
||||||
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")?
|
||||||
var isPinned = json.GetPropertyOrNull("pinned")?.GetBoolean() ?? false;
|
.GetDateTimeOffset();
|
||||||
var messageReference = json.GetPropertyOrNull("message_reference")?.Pipe(MessageReference.Parse);
|
|
||||||
var referencedMessage = json.GetPropertyOrNull("referenced_message")?.Pipe(Parse);
|
var isPinned = json.GetPropertyOrNull("pinned")?.GetBooleanOrNull() ?? false;
|
||||||
|
|
||||||
var content = kind switch
|
var content = kind switch
|
||||||
{
|
{
|
||||||
@@ -48,26 +107,35 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
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() ?? ""
|
||||||
};
|
};
|
||||||
|
|
||||||
var attachments =
|
var attachments =
|
||||||
json.GetPropertyOrNull("attachments")?.EnumerateArray().Select(Attachment.Parse).ToArray() ??
|
json.GetPropertyOrNull("attachments")?.EnumerateArrayOrNull()?.Select(Attachment.Parse).ToArray() ??
|
||||||
Array.Empty<Attachment>();
|
Array.Empty<Attachment>();
|
||||||
|
|
||||||
var embeds =
|
var embeds = NormalizeEmbeds(
|
||||||
json.GetPropertyOrNull("embeds")?.EnumerateArray().Select(Embed.Parse).ToArray() ??
|
json.GetPropertyOrNull("embeds")?.EnumerateArrayOrNull()?.Select(Embed.Parse).ToArray() ??
|
||||||
Array.Empty<Embed>();
|
Array.Empty<Embed>()
|
||||||
|
);
|
||||||
|
|
||||||
|
var stickers =
|
||||||
|
json.GetPropertyOrNull("sticker_items")?.EnumerateArrayOrNull()?.Select(Sticker.Parse).ToArray() ??
|
||||||
|
Array.Empty<Sticker>();
|
||||||
|
|
||||||
var reactions =
|
var reactions =
|
||||||
json.GetPropertyOrNull("reactions")?.EnumerateArray().Select(Reaction.Parse).ToArray() ??
|
json.GetPropertyOrNull("reactions")?.EnumerateArrayOrNull()?.Select(Reaction.Parse).ToArray() ??
|
||||||
Array.Empty<Reaction>();
|
Array.Empty<Reaction>();
|
||||||
|
|
||||||
var mentionedUsers =
|
var mentionedUsers =
|
||||||
json.GetPropertyOrNull("mentions")?.EnumerateArray().Select(User.Parse).ToArray() ??
|
json.GetPropertyOrNull("mentions")?.EnumerateArrayOrNull()?.Select(User.Parse).ToArray() ??
|
||||||
Array.Empty<User>();
|
Array.Empty<User>();
|
||||||
|
|
||||||
|
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,
|
||||||
@@ -79,11 +147,11 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
content,
|
content,
|
||||||
attachments,
|
attachments,
|
||||||
embeds,
|
embeds,
|
||||||
|
stickers,
|
||||||
reactions,
|
reactions,
|
||||||
mentionedUsers,
|
mentionedUsers,
|
||||||
messageReference,
|
messageReference,
|
||||||
referencedMessage
|
referencedMessage
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
|
// https://discord.com/developers/docs/resources/channel#message-object-message-types
|
||||||
|
public enum MessageKind
|
||||||
{
|
{
|
||||||
// https://discord.com/developers/docs/resources/channel#message-object-message-types
|
|
||||||
public enum MessageKind
|
|
||||||
{
|
|
||||||
Default = 0,
|
Default = 0,
|
||||||
RecipientAdd = 1,
|
RecipientAdd = 1,
|
||||||
RecipientRemove = 2,
|
RecipientRemove = 2,
|
||||||
@@ -11,6 +11,12 @@
|
|||||||
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) =>
|
||||||
|
c is not MessageKind.Default and not MessageKind.Reply;
|
||||||
}
|
}
|
||||||
@@ -2,18 +2,28 @@ using System.Text.Json;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
|
// https://discord.com/developers/docs/resources/channel#message-object-message-reference-structure
|
||||||
|
public record MessageReference(Snowflake? MessageId, Snowflake? ChannelId, Snowflake? GuildId)
|
||||||
{
|
{
|
||||||
// https://discord.com/developers/docs/resources/channel#message-object-message-reference-structure
|
|
||||||
public record MessageReference(Snowflake? MessageId, Snowflake? ChannelId, Snowflake? GuildId)
|
|
||||||
{
|
|
||||||
public static MessageReference Parse(JsonElement json)
|
public static MessageReference Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var messageId = json.GetPropertyOrNull("message_id")?.GetStringOrNull()?.Pipe(Snowflake.Parse);
|
var messageId = json
|
||||||
var channelId = json.GetPropertyOrNull("channel_id")?.GetStringOrNull()?.Pipe(Snowflake.Parse);
|
.GetPropertyOrNull("message_id")?
|
||||||
var guildId = json.GetPropertyOrNull("guild_id")?.GetStringOrNull()?.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);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
|
// https://discord.com/developers/docs/resources/channel#reaction-object
|
||||||
|
public record Reaction(Emoji Emoji, int Count)
|
||||||
{
|
{
|
||||||
// https://discord.com/developers/docs/resources/channel#reaction-object
|
|
||||||
public record Reaction(Emoji Emoji, int Count)
|
|
||||||
{
|
|
||||||
public static Reaction Parse(JsonElement json)
|
public static Reaction Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var emoji = json.GetProperty("emoji").Pipe(Emoji.Parse);
|
var emoji = json.GetProperty("emoji").Pipe(Emoji.Parse);
|
||||||
@@ -13,5 +13,4 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
|
|
||||||
return new Reaction(emoji, count);
|
return new Reaction(emoji, count);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,15 +4,15 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
|
// https://discord.com/developers/docs/topics/permissions#role-object
|
||||||
|
public record Role(Snowflake Id, string Name, int Position, Color? Color) : IHasId
|
||||||
{
|
{
|
||||||
// https://discord.com/developers/docs/topics/permissions#role-object
|
|
||||||
public record Role(Snowflake Id, string Name, int Position, Color? Color) : IHasId
|
|
||||||
{
|
|
||||||
public static Role Parse(JsonElement json)
|
public static Role Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
var name = json.GetProperty("name").GetNonWhiteSpaceString();
|
var name = json.GetProperty("name").GetNonNullString();
|
||||||
var position = json.GetProperty("position").GetInt32();
|
var position = json.GetProperty("position").GetInt32();
|
||||||
|
|
||||||
var color = json
|
var color = json
|
||||||
@@ -24,5 +24,4 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
|
|
||||||
return new Role(id, name, position, color);
|
return new Role(id, name, position, color);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
|
// https://discord.com/developers/docs/resources/sticker#sticker-resource
|
||||||
|
public record Sticker(Snowflake Id, string Name, StickerFormat Format, string SourceUrl)
|
||||||
|
{
|
||||||
|
private static string GetSourceUrl(Snowflake id, StickerFormat format)
|
||||||
|
{
|
||||||
|
var extension = format == StickerFormat.Lottie ? "json" : "png";
|
||||||
|
return $"https://discord.com/stickers/{id}.{extension}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Sticker Parse(JsonElement json)
|
||||||
|
{
|
||||||
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
|
var name = json.GetProperty("name").GetNonNullString();
|
||||||
|
var format = (StickerFormat)json.GetProperty("format_type").GetInt32();
|
||||||
|
var sourceUrl = GetSourceUrl(id, format);
|
||||||
|
|
||||||
|
return new Sticker(id, name, format, sourceUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
|
public enum StickerFormat
|
||||||
|
{
|
||||||
|
Png = 1,
|
||||||
|
PngAnimated = 2,
|
||||||
|
Lottie = 3
|
||||||
|
}
|
||||||
@@ -4,23 +4,23 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
|||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord.Data
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
{
|
|
||||||
// https://discord.com/developers/docs/resources/user#user-object
|
// https://discord.com/developers/docs/resources/user#user-object
|
||||||
public partial record User(
|
public partial record User(
|
||||||
Snowflake Id,
|
Snowflake Id,
|
||||||
bool IsBot,
|
bool IsBot,
|
||||||
int Discriminator,
|
int Discriminator,
|
||||||
string Name,
|
string Name,
|
||||||
string AvatarUrl) : IHasId
|
string AvatarUrl) : IHasId
|
||||||
{
|
{
|
||||||
public string DiscriminatorFormatted => $"{Discriminator:0000}";
|
public string DiscriminatorFormatted => $"{Discriminator:0000}";
|
||||||
|
|
||||||
public string FullName => $"{Name}#{DiscriminatorFormatted}";
|
public string FullName => $"{Name}#{DiscriminatorFormatted}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial record User
|
public partial record User
|
||||||
{
|
{
|
||||||
private static string GetDefaultAvatarUrl(int discriminator) =>
|
private static string GetDefaultAvatarUrl(int discriminator) =>
|
||||||
$"https://cdn.discordapp.com/embed/avatars/{discriminator % 5}.png";
|
$"https://cdn.discordapp.com/embed/avatars/{discriminator % 5}.png";
|
||||||
|
|
||||||
@@ -30,22 +30,21 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|||||||
? "gif"
|
? "gif"
|
||||||
: "png";
|
: "png";
|
||||||
|
|
||||||
return $"https://cdn.discordapp.com/avatars/{id}/{avatarHash}.{extension}?size=128";
|
return $"https://cdn.discordapp.com/avatars/{id}/{avatarHash}.{extension}?size=512";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static User Parse(JsonElement json)
|
public static User Parse(JsonElement json)
|
||||||
{
|
{
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
var isBot = json.GetPropertyOrNull("bot")?.GetBoolean() ?? false;
|
var isBot = json.GetPropertyOrNull("bot")?.GetBooleanOrNull() ?? false;
|
||||||
var discriminator = json.GetProperty("discriminator").GetNonWhiteSpaceString().Pipe(int.Parse);
|
var discriminator = json.GetProperty("discriminator").GetNonWhiteSpaceString().Pipe(int.Parse);
|
||||||
var name = json.GetProperty("username").GetNonWhiteSpaceString();
|
var name = json.GetProperty("username").GetNonNullString();
|
||||||
var avatarHash = json.GetPropertyOrNull("avatar")?.GetStringOrNull();
|
|
||||||
|
|
||||||
|
var avatarHash = json.GetPropertyOrNull("avatar")?.GetNonWhiteSpaceStringOrNull();
|
||||||
var avatarUrl = !string.IsNullOrWhiteSpace(avatarHash)
|
var avatarUrl = !string.IsNullOrWhiteSpace(avatarHash)
|
||||||
? GetAvatarUrl(id, avatarHash)
|
? GetAvatarUrl(id, avatarHash)
|
||||||
: GetDefaultAvatarUrl(discriminator);
|
: GetDefaultAvatarUrl(discriminator);
|
||||||
|
|
||||||
return new User(id, isBot, discriminator, name, avatarUrl);
|
return new User(id, isBot, discriminator, name, avatarUrl);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -11,32 +11,75 @@ using DiscordChatExporter.Core.Discord.Data;
|
|||||||
using DiscordChatExporter.Core.Exceptions;
|
using DiscordChatExporter.Core.Exceptions;
|
||||||
using DiscordChatExporter.Core.Utils;
|
using DiscordChatExporter.Core.Utils;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
using Gress;
|
||||||
using JsonExtensions.Http;
|
using JsonExtensions.Http;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord
|
namespace DiscordChatExporter.Core.Discord;
|
||||||
{
|
|
||||||
public class DiscordClient
|
|
||||||
{
|
|
||||||
private readonly AuthToken _token;
|
|
||||||
private readonly Uri _baseUri = new("https://discord.com/api/v8/", UriKind.Absolute);
|
|
||||||
|
|
||||||
public DiscordClient(AuthToken token) => _token = token;
|
public class DiscordClient
|
||||||
|
{
|
||||||
|
private readonly string _token;
|
||||||
|
private readonly Uri _baseUri = new("https://discord.com/api/v9/", UriKind.Absolute);
|
||||||
|
|
||||||
|
private TokenKind _tokenKind = TokenKind.Unknown;
|
||||||
|
|
||||||
|
public DiscordClient(string token) => _token = token;
|
||||||
|
|
||||||
|
private async ValueTask<HttpResponseMessage> GetResponseAsync(
|
||||||
|
string url,
|
||||||
|
bool isBot,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
using var request = new HttpRequestMessage(HttpMethod.Get, new Uri(_baseUri, url));
|
||||||
|
|
||||||
|
// Don't validate because token can have invalid characters
|
||||||
|
// https://github.com/Tyrrrz/DiscordChatExporter/issues/828
|
||||||
|
request.Headers.TryAddWithoutValidation(
|
||||||
|
"Authorization",
|
||||||
|
isBot ? $"Bot {_token}" : _token
|
||||||
|
);
|
||||||
|
|
||||||
|
return await Http.Client.SendAsync(
|
||||||
|
request,
|
||||||
|
HttpCompletionOption.ResponseHeadersRead,
|
||||||
|
cancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private async ValueTask<HttpResponseMessage> GetResponseAsync(
|
private async ValueTask<HttpResponseMessage> GetResponseAsync(
|
||||||
string url,
|
string url,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return await Http.ResponsePolicy.ExecuteAsync(async innerCancellationToken =>
|
return await Http.ResponseResiliencePolicy.ExecuteAsync(async innerCancellationToken =>
|
||||||
{
|
{
|
||||||
using var request = new HttpRequestMessage(HttpMethod.Get, new Uri(_baseUri, url));
|
if (_tokenKind == TokenKind.User)
|
||||||
request.Headers.Authorization = _token.GetAuthenticationHeader();
|
return await GetResponseAsync(url, false, innerCancellationToken);
|
||||||
|
|
||||||
return await Http.Client.SendAsync(
|
if (_tokenKind == TokenKind.Bot)
|
||||||
request,
|
return await GetResponseAsync(url, true, innerCancellationToken);
|
||||||
HttpCompletionOption.ResponseHeadersRead,
|
|
||||||
innerCancellationToken
|
// Try to authenticate as user
|
||||||
);
|
var userResponse = await GetResponseAsync(url, false, innerCancellationToken);
|
||||||
|
if (userResponse.StatusCode != HttpStatusCode.Unauthorized)
|
||||||
|
{
|
||||||
|
_tokenKind = TokenKind.User;
|
||||||
|
return userResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
userResponse.Dispose();
|
||||||
|
|
||||||
|
// Otherwise, try to authenticate as bot
|
||||||
|
var botResponse = await GetResponseAsync(url, true, innerCancellationToken);
|
||||||
|
if (botResponse.StatusCode != HttpStatusCode.Unauthorized)
|
||||||
|
{
|
||||||
|
_tokenKind = TokenKind.Bot;
|
||||||
|
return botResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The token is probably invalid altogether.
|
||||||
|
// Return the last response anyway, upstream should handle the error.
|
||||||
|
return botResponse;
|
||||||
}, cancellationToken);
|
}, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,11 +181,13 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
.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)
|
||||||
{
|
{
|
||||||
var parentId = channelJson.GetPropertyOrNull("parent_id")?.GetStringOrNull();
|
var parentId = channelJson.GetPropertyOrNull("parent_id")?.GetNonWhiteSpaceStringOrNull();
|
||||||
|
|
||||||
var category = !string.IsNullOrWhiteSpace(parentId)
|
var category = !string.IsNullOrWhiteSpace(parentId)
|
||||||
? categories.GetValueOrDefault(parentId)
|
? categories.GetValueOrDefault(parentId)
|
||||||
@@ -205,7 +250,7 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
{
|
{
|
||||||
var response = await GetJsonResponseAsync($"channels/{channelId}", cancellationToken);
|
var response = await GetJsonResponseAsync($"channels/{channelId}", cancellationToken);
|
||||||
|
|
||||||
var parentId = response.GetPropertyOrNull("parent_id")?.GetStringOrNull()?.Pipe(Snowflake.Parse);
|
var parentId = response.GetPropertyOrNull("parent_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
|
||||||
|
|
||||||
var category = parentId is not null
|
var category = parentId is not null
|
||||||
? await GetChannelCategoryAsync(parentId.Value, cancellationToken)
|
? await GetChannelCategoryAsync(parentId.Value, cancellationToken)
|
||||||
@@ -233,7 +278,7 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
Snowflake channelId,
|
Snowflake channelId,
|
||||||
Snowflake? after = null,
|
Snowflake? after = null,
|
||||||
Snowflake? before = null,
|
Snowflake? before = null,
|
||||||
IProgress<double>? progress = null,
|
IProgress<Percentage>? progress = null,
|
||||||
[EnumeratorCancellation] CancellationToken cancellationToken = default)
|
[EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
// Get the last message in the specified range.
|
// Get the last message in the specified range.
|
||||||
@@ -282,16 +327,13 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
var exportedDuration = (message.Timestamp - firstMessage.Timestamp).Duration();
|
var exportedDuration = (message.Timestamp - firstMessage.Timestamp).Duration();
|
||||||
var totalDuration = (lastMessage.Timestamp - firstMessage.Timestamp).Duration();
|
var totalDuration = (lastMessage.Timestamp - firstMessage.Timestamp).Duration();
|
||||||
|
|
||||||
if (totalDuration > TimeSpan.Zero)
|
progress.Report(Percentage.FromFraction(
|
||||||
{
|
|
||||||
progress.Report(exportedDuration / totalDuration);
|
|
||||||
}
|
|
||||||
// Avoid division by zero if all messages have the exact same timestamp
|
// Avoid division by zero if all messages have the exact same timestamp
|
||||||
// (which may be the case if there's only one message in the channel)
|
// (which may be the case if there's only one message in the channel)
|
||||||
else
|
totalDuration > TimeSpan.Zero
|
||||||
{
|
? exportedDuration / totalDuration
|
||||||
progress.Report(1);
|
: 1
|
||||||
}
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return message;
|
yield return message;
|
||||||
@@ -299,5 +341,4 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,20 +3,20 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord
|
namespace DiscordChatExporter.Core.Discord;
|
||||||
|
|
||||||
|
public readonly partial record struct Snowflake(ulong Value)
|
||||||
{
|
{
|
||||||
public readonly partial record struct Snowflake(ulong Value)
|
|
||||||
{
|
|
||||||
public DateTimeOffset ToDate() => DateTimeOffset.FromUnixTimeMilliseconds(
|
public DateTimeOffset ToDate() => DateTimeOffset.FromUnixTimeMilliseconds(
|
||||||
(long)((Value >> 22) + 1420070400000UL)
|
(long)((Value >> 22) + 1420070400000UL)
|
||||||
).ToLocalTime();
|
).ToLocalTime();
|
||||||
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public override string ToString() => Value.ToString(CultureInfo.InvariantCulture);
|
public override string ToString() => Value.ToString(CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial record struct Snowflake
|
public partial record struct Snowflake
|
||||||
{
|
{
|
||||||
public static Snowflake Zero { get; } = new(0);
|
public static Snowflake Zero { get; } = new(0);
|
||||||
|
|
||||||
public static Snowflake FromDate(DateTimeOffset date) => new(
|
public static Snowflake FromDate(DateTimeOffset date) => new(
|
||||||
@@ -47,10 +47,17 @@ namespace DiscordChatExporter.Core.Discord
|
|||||||
TryParse(str, formatProvider) ?? throw new FormatException($"Invalid snowflake '{str}'.");
|
TryParse(str, formatProvider) ?? throw new FormatException($"Invalid snowflake '{str}'.");
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace DiscordChatExporter.Core.Discord;
|
||||||
|
|
||||||
|
public enum TokenKind
|
||||||
|
{
|
||||||
|
Unknown,
|
||||||
|
User,
|
||||||
|
Bot
|
||||||
|
}
|
||||||
@@ -5,10 +5,12 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Gress" Version="2.0.1" />
|
||||||
<PackageReference Include="JsonExtensions" Version="1.2.0" />
|
<PackageReference Include="JsonExtensions" Version="1.2.0" />
|
||||||
<PackageReference Include="MiniRazor.CodeGen" Version="2.2.0" />
|
<PackageReference Include="MiniRazor.CodeGen" Version="2.2.2" />
|
||||||
<PackageReference Include="Polly" Version="7.2.2" />
|
<PackageReference Include="Polly" Version="7.2.3" />
|
||||||
<PackageReference Include="Superpower" Version="3.0.0" />
|
<PackageReference Include="Superpower" Version="3.0.0" />
|
||||||
|
<PackageReference Include="WebMarkupMin.Core" Version="2.12.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exceptions
|
namespace DiscordChatExporter.Core.Exceptions;
|
||||||
|
|
||||||
|
public partial class DiscordChatExporterException : Exception
|
||||||
{
|
{
|
||||||
public partial class DiscordChatExporterException : Exception
|
|
||||||
{
|
|
||||||
public bool IsFatal { get; }
|
public bool IsFatal { get; }
|
||||||
|
|
||||||
public DiscordChatExporterException(string message, bool isFatal = false)
|
public DiscordChatExporterException(string message, bool isFatal = false)
|
||||||
@@ -12,10 +12,10 @@ namespace DiscordChatExporter.Core.Exceptions
|
|||||||
{
|
{
|
||||||
IsFatal = isFatal;
|
IsFatal = isFatal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class DiscordChatExporterException
|
public partial class DiscordChatExporterException
|
||||||
{
|
{
|
||||||
internal static DiscordChatExporterException FailedHttpRequest(HttpResponseMessage response)
|
internal static DiscordChatExporterException FailedHttpRequest(HttpResponseMessage response)
|
||||||
{
|
{
|
||||||
var message = $@"
|
var message = $@"
|
||||||
@@ -41,5 +41,4 @@ Failed to perform an HTTP request.
|
|||||||
|
|
||||||
internal static DiscordChatExporterException ChannelIsEmpty() =>
|
internal static DiscordChatExporterException ChannelIsEmpty() =>
|
||||||
new("No messages found for the specified period.");
|
new("No messages found for the specified period.");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -8,20 +8,19 @@ using DiscordChatExporter.Core.Discord.Data;
|
|||||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||||
using DiscordChatExporter.Core.Exceptions;
|
using DiscordChatExporter.Core.Exceptions;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
using Gress;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting
|
namespace DiscordChatExporter.Core.Exporting;
|
||||||
|
|
||||||
|
public class ChannelExporter
|
||||||
{
|
{
|
||||||
public class ChannelExporter
|
|
||||||
{
|
|
||||||
private readonly DiscordClient _discord;
|
private readonly DiscordClient _discord;
|
||||||
|
|
||||||
public ChannelExporter(DiscordClient discord) => _discord = discord;
|
public ChannelExporter(DiscordClient discord) => _discord = discord;
|
||||||
|
|
||||||
public ChannelExporter(AuthToken token) : this(new DiscordClient(token)) {}
|
|
||||||
|
|
||||||
public async ValueTask ExportChannelAsync(
|
public async ValueTask ExportChannelAsync(
|
||||||
ExportRequest request,
|
ExportRequest request,
|
||||||
IProgress<double>? progress = null,
|
IProgress<Percentage>? progress = null,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
// Build context
|
// Build context
|
||||||
@@ -79,5 +78,4 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
if (!exportedAnything)
|
if (!exportedAnything)
|
||||||
throw DiscordChatExporterException.ChannelIsEmpty();
|
throw DiscordChatExporterException.ChannelIsEmpty();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -10,10 +10,10 @@ using DiscordChatExporter.Core.Discord;
|
|||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting
|
namespace DiscordChatExporter.Core.Exporting;
|
||||||
|
|
||||||
|
internal class ExportContext
|
||||||
{
|
{
|
||||||
internal class ExportContext
|
|
||||||
{
|
|
||||||
private readonly MediaDownloader _mediaDownloader;
|
private readonly MediaDownloader _mediaDownloader;
|
||||||
|
|
||||||
public ExportRequest Request { get; }
|
public ExportRequest Request { get; }
|
||||||
@@ -102,5 +102,4 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting
|
namespace DiscordChatExporter.Core.Exporting;
|
||||||
|
|
||||||
|
public enum ExportFormat
|
||||||
{
|
{
|
||||||
public enum ExportFormat
|
|
||||||
{
|
|
||||||
PlainText,
|
PlainText,
|
||||||
HtmlDark,
|
HtmlDark,
|
||||||
HtmlLight,
|
HtmlLight,
|
||||||
Csv,
|
Csv,
|
||||||
Json
|
Json
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ExportFormatExtensions
|
public static class ExportFormatExtensions
|
||||||
{
|
{
|
||||||
public static string GetFileExtension(this ExportFormat format) => format switch
|
public static string GetFileExtension(this ExportFormat format) => format switch
|
||||||
{
|
{
|
||||||
ExportFormat.PlainText => "txt",
|
ExportFormat.PlainText => "txt",
|
||||||
@@ -32,5 +32,4 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
ExportFormat.Json => "JSON",
|
ExportFormat.Json => "JSON",
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(format))
|
_ => throw new ArgumentOutOfRangeException(nameof(format))
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -8,9 +8,9 @@ using DiscordChatExporter.Core.Exporting.Filtering;
|
|||||||
using DiscordChatExporter.Core.Exporting.Partitioning;
|
using DiscordChatExporter.Core.Exporting.Partitioning;
|
||||||
using DiscordChatExporter.Core.Utils;
|
using DiscordChatExporter.Core.Utils;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting
|
namespace DiscordChatExporter.Core.Exporting;
|
||||||
{
|
|
||||||
public partial record ExportRequest(
|
public partial record ExportRequest(
|
||||||
Guild Guild,
|
Guild Guild,
|
||||||
Channel Channel,
|
Channel Channel,
|
||||||
string OutputPath,
|
string OutputPath,
|
||||||
@@ -22,7 +22,7 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
bool ShouldDownloadMedia,
|
bool ShouldDownloadMedia,
|
||||||
bool ShouldReuseMedia,
|
bool ShouldReuseMedia,
|
||||||
string DateFormat)
|
string DateFormat)
|
||||||
{
|
{
|
||||||
private string? _outputBaseFilePath;
|
private string? _outputBaseFilePath;
|
||||||
public string OutputBaseFilePath => _outputBaseFilePath ??= GetOutputBaseFilePath(
|
public string OutputBaseFilePath => _outputBaseFilePath ??= GetOutputBaseFilePath(
|
||||||
Guild,
|
Guild,
|
||||||
@@ -36,10 +36,10 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
public string OutputBaseDirPath => Path.GetDirectoryName(OutputBaseFilePath) ?? OutputPath;
|
public string OutputBaseDirPath => Path.GetDirectoryName(OutputBaseFilePath) ?? OutputPath;
|
||||||
|
|
||||||
public string OutputMediaDirPath => $"{OutputBaseFilePath}_Files{Path.DirectorySeparatorChar}";
|
public string OutputMediaDirPath => $"{OutputBaseFilePath}_Files{Path.DirectorySeparatorChar}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial record ExportRequest
|
public partial record ExportRequest
|
||||||
{
|
{
|
||||||
private static string GetOutputBaseFilePath(
|
private static string GetOutputBaseFilePath(
|
||||||
Guild guild,
|
Guild guild,
|
||||||
Channel channel,
|
Channel channel,
|
||||||
@@ -48,10 +48,9 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
Snowflake? after = null,
|
Snowflake? after = null,
|
||||||
Snowflake? before = null)
|
Snowflake? before = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Formats path
|
// Formats path
|
||||||
outputPath = Regex.Replace(outputPath, "%.", m =>
|
outputPath = Regex.Replace(outputPath, "%.", m =>
|
||||||
PathEx.EscapePath(m.Value switch
|
PathEx.EscapeFileName(m.Value switch
|
||||||
{
|
{
|
||||||
"%g" => guild.Id.ToString(),
|
"%g" => guild.Id.ToString(),
|
||||||
"%G" => guild.Name,
|
"%G" => guild.Name,
|
||||||
@@ -61,8 +60,9 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
"%C" => channel.Name,
|
"%C" => channel.Name,
|
||||||
"%p" => channel.Position?.ToString() ?? "0",
|
"%p" => channel.Position?.ToString() ?? "0",
|
||||||
"%P" => channel.Category.Position?.ToString() ?? "0",
|
"%P" => channel.Category.Position?.ToString() ?? "0",
|
||||||
"%a" => (after ?? Snowflake.Zero).ToDate().ToString("yyyy-MM-dd"),
|
"%a" => after?.ToDate().ToString("yyyy-MM-dd") ?? "",
|
||||||
"%b" => (before?.ToDate() ?? DateTime.Now).ToString("yyyy-MM-dd"),
|
"%b" => before?.ToDate().ToString("yyyy-MM-dd") ?? "",
|
||||||
|
"%d" => DateTimeOffset.Now.ToString("yyyy-MM-dd"),
|
||||||
"%%" => "%",
|
"%%" => "%",
|
||||||
_ => m.Value
|
_ => m.Value
|
||||||
})
|
})
|
||||||
@@ -94,7 +94,7 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
// Date range
|
// Date range
|
||||||
if (after is not null || before is not null)
|
if (after is not null || before is not null)
|
||||||
{
|
{
|
||||||
buffer.Append(" (");
|
buffer.Append(' ').Append('(');
|
||||||
|
|
||||||
// Both 'after' and 'before' are set
|
// Both 'after' and 'before' are set
|
||||||
if (after is not null && before is not null)
|
if (after is not null && before is not null)
|
||||||
@@ -112,16 +112,12 @@ namespace DiscordChatExporter.Core.Exporting
|
|||||||
buffer.Append($"before {before.Value.ToDate():yyyy-MM-dd}");
|
buffer.Append($"before {before.Value.ToDate():yyyy-MM-dd}");
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.Append(")");
|
buffer.Append(')');
|
||||||
}
|
}
|
||||||
|
|
||||||
// File extension
|
// File extension
|
||||||
buffer.Append($".{format.GetFileExtension()}");
|
buffer.Append('.').Append(format.GetFileExtension());
|
||||||
|
|
||||||
// Replace invalid chars
|
return PathEx.EscapeFileName(buffer.ToString());
|
||||||
PathEx.EscapePath(buffer);
|
|
||||||
|
|
||||||
return buffer.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
|
|
||||||
|
internal enum BinaryExpressionKind
|
||||||
{
|
{
|
||||||
internal enum BinaryExpressionKind
|
|
||||||
{
|
|
||||||
Or,
|
Or,
|
||||||
And
|
And
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
|
|
||||||
|
internal class BinaryExpressionMessageFilter : MessageFilter
|
||||||
{
|
{
|
||||||
internal class BinaryExpressionMessageFilter : MessageFilter
|
|
||||||
{
|
|
||||||
private readonly MessageFilter _first;
|
private readonly MessageFilter _first;
|
||||||
private readonly MessageFilter _second;
|
private readonly MessageFilter _second;
|
||||||
private readonly BinaryExpressionKind _kind;
|
private readonly BinaryExpressionKind _kind;
|
||||||
@@ -22,5 +22,4 @@ namespace DiscordChatExporter.Core.Exporting.Filtering
|
|||||||
BinaryExpressionKind.And => _first.IsMatch(message) && _second.IsMatch(message),
|
BinaryExpressionKind.And => _first.IsMatch(message) && _second.IsMatch(message),
|
||||||
_ => throw new InvalidOperationException($"Unknown binary expression kind '{_kind}'.")
|
_ => throw new InvalidOperationException($"Unknown binary expression kind '{_kind}'.")
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,19 +2,27 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
|
|
||||||
|
internal class ContainsMessageFilter : MessageFilter
|
||||||
{
|
{
|
||||||
internal class ContainsMessageFilter : MessageFilter
|
|
||||||
{
|
|
||||||
private readonly string _text;
|
private readonly string _text;
|
||||||
|
|
||||||
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
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -30,5 +38,4 @@ namespace DiscordChatExporter.Core.Exporting.Filtering
|
|||||||
IsMatch(f.Value)
|
IsMatch(f.Value)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Exporting.Filtering
|
namespace DiscordChatExporter.Core.Exporting.Filtering;
|
||||||
|
|
||||||
|
internal class FromMessageFilter : MessageFilter
|
||||||
{
|
{
|
||||||
internal class FromMessageFilter : MessageFilter
|
|
||||||
{
|
|
||||||
private readonly string _value;
|
private readonly string _value;
|
||||||
|
|
||||||
public FromMessageFilter(string value) => _value = value;
|
public FromMessageFilter(string value) => _value = value;
|
||||||
@@ -13,5 +13,4 @@ namespace DiscordChatExporter.Core.Exporting.Filtering
|
|||||||
string.Equals(_value, message.Author.Name, StringComparison.OrdinalIgnoreCase) ||
|
string.Equals(_value, message.Author.Name, StringComparison.OrdinalIgnoreCase) ||
|
||||||
string.Equals(_value, message.Author.FullName, StringComparison.OrdinalIgnoreCase) ||
|
string.Equals(_value, message.Author.FullName, StringComparison.OrdinalIgnoreCase) ||
|
||||||
string.Equals(_value, message.Author.Id.ToString(), StringComparison.OrdinalIgnoreCase);
|
string.Equals(_value, message.Author.Id.ToString(), StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user