mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-07-07 06:39:33 +02:00
Compare commits
300 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e2c78eabf | |||
| 7df7614cd0 | |||
| 5b65e4ce5d | |||
| 597ec1e7b0 | |||
| b9fa38d2b2 | |||
| 91ba79e6ec | |||
| 56df93305e | |||
| c69e39800d | |||
| f505ff3f1e | |||
| b844e48016 | |||
| 36fc6490f3 | |||
| 013a03a4f2 | |||
| e216c07580 | |||
| d1244208b6 | |||
| 6e56f29404 | |||
| 4edcdf0955 | |||
| 7d458cd3fd | |||
| 57eb32d9c0 | |||
| 506bc0176b | |||
| 67b31c5f68 | |||
| d9c06bacda | |||
| db45b49af7 | |||
| fc07f8da6c | |||
| b138908eb3 | |||
| 2c4f812d4f | |||
| 324d6bab20 | |||
| e5d5f1c85f | |||
| 49c4b12512 | |||
| 57e2dc9313 | |||
| 07b72b9023 | |||
| f3830247fe | |||
| a8f89ec292 | |||
| 0bdbd44492 | |||
| db23971b08 | |||
| 90bf4975b9 | |||
| c2f9868746 | |||
| ec840e76ae | |||
| b672c30071 | |||
| e752269467 | |||
| 5b1b720503 | |||
| 3dc3e3fa01 | |||
| 001ea7e495 | |||
| 9639b6c550 | |||
| 950658c737 | |||
| 560a069c35 | |||
| 1131f8659d | |||
| 38be44debb | |||
| 4b243f2252 | |||
| a31175b2e8 | |||
| 913255f04f | |||
| 873d055191 | |||
| dabed24c16 | |||
| fdf421df3c | |||
| 2259f19c44 | |||
| 8695942328 | |||
| 84e656ccfc | |||
| 2ba0c3b38e | |||
| 7467f0aeb6 | |||
| e38479d463 | |||
| 06a4b6a8e6 | |||
| cc1ad8b435 | |||
| f8dac2c9d0 | |||
| b8cea0d140 | |||
| 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 | |||
| 8e7baee8a5 | |||
| f7c4b80a2d | |||
| a0e7d8e3af | |||
| 72b0bb37f4 | |||
| 6c70ff0963 | |||
| 9def32d67e | |||
| 4974fe5292 | |||
| 1db2bb4170 | |||
| 720e53caab | |||
| da9536bd1b | |||
| d8de3bf779 | |||
| 7c88a21543 | |||
| 2393a6a472 | |||
| 214d5e3bdb | |||
| f456297881 | |||
| 092f0cade9 | |||
| fc6cfcfcc6 | |||
| 46450367e3 | |||
| 21d89afa70 | |||
| 2f3e165988 | |||
| b64dff1eab | |||
| acfe102e7f | |||
| ea31b1b270 | |||
| af11064a85 | |||
| 402b5cc7d0 | |||
| 44f64a2cb3 | |||
| 471d0d01cf | |||
| 67313f2b22 | |||
| 301bca0633 | |||
| 6b8170ab89 | |||
| e849c9516c | |||
| 524d0a1bb2 | |||
| f0a4410ee0 | |||
| a98772e46e | |||
| b6fdea11a2 | |||
| fcca052165 | |||
| ac7ebd6f91 | |||
| 9303383662 | |||
| 7fa908ce34 | |||
| 345dc568c0 | |||
| 5c0b657e0e | |||
| 265cb71dfd | |||
| 0a6fea1ce9 | |||
| ebb36de354 | |||
| 48539084f7 | |||
| 9ec95670c5 | |||
| a449c02dd5 | |||
| 89b1f9924b | |||
| 99f94425c2 | |||
| ab71b035fc | |||
| fdc3c1b012 | |||
| 6fa6df981e | |||
| eec4123b98 | |||
| 6fa7cbe568 | |||
| aae3790a5f | |||
| 28b2039a33 | |||
| f40589dea6 | |||
| bb4db21b87 | |||
| 38bc259ab6 | |||
| 530e2c50a9 | |||
| 63c92047a1 | |||
| 7d9d3ca5fb | |||
| cad6baba48 | |||
| 9c25bceabf | |||
| 28de1053f6 | |||
| ec0494c038 | |||
| d735d2acd3 | |||
| 85d53d0e94 | |||
| daa8c0a735 | |||
| d4eba75036 |
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"xamlstyler.console": {
|
||||
"version": "3.2003.9",
|
||||
"commands": [
|
||||
"xstyler"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
# Docker usage instructions
|
||||
|
||||
Docker distribution of DiscordChatExporter provides a way to run the app in a virtualized and isolated environment. Due to the nature of Docker, you also don't need to install any prerequisites otherwise required by DCE.
|
||||
|
||||
Note that only the CLI flavor of DiscordChatExporter is available for use with Docker.
|
||||
|
||||
### Pulling
|
||||
|
||||
This will download the [Docker image from the registry](https://hub.docker.com/r/tyrrrz/discordchatexporter) to your computer. You can run this command again to update when a new version is released.
|
||||
|
||||
```
|
||||
docker pull tyrrrz/discordchatexporter:stable
|
||||
```
|
||||
|
||||
Note the `:stable` tag. DiscordChatExporter images are tagged according to the following patterns:
|
||||
|
||||
- `stable`: Latest stable version release and maps to the latest GitHub release. This tag is updated with release of each new version. Recommended for personal use.
|
||||
- `latest`: Built from the latest commit and maps to the latest CI build on GitHub. This tag is updated with each new commit to `master` branch. Not recommended for everyday use, but you can use it if you want to try out some features that haven't been officially released yet.
|
||||
- `x.y.z` (e.g. `2.30.1`): Fixed version release and maps to the corresponding tag on GitHub. This tag is never updated once that version has been released. Recommended for use in various automation scenarios.
|
||||
|
||||
You can see all available tags [here](https://hub.docker.com/r/tyrrrz/discordchatexporter/tags?page=1&ordering=name).
|
||||
|
||||
### Usage
|
||||
|
||||
To run the CLI in Docker and render help text:
|
||||
|
||||
```
|
||||
docker run --rm tyrrrz/discordchatexporter:stable
|
||||
```
|
||||
|
||||
To export a channel:
|
||||
|
||||
```
|
||||
docker run --rm -v /path/on/machine:/out tyrrrz/discordchatexporter:stable export -t TOKEN -c CHANNELID
|
||||
```
|
||||
|
||||
If you want colored output, real-time progress reporting, and some other stuff, pass `-it` (interactive) option:
|
||||
|
||||
```
|
||||
docker run --rm -it -v /path/on/machine:/out tyrrrz/discordchatexporter:stable export -t TOKEN -c CHANNELID
|
||||
```
|
||||
|
||||
Note the `-v /path/on/machine:/out` option, which instructs Docker to bind the `/out` directory inside the container to a path on your host machine. Replace `/path/on/machine` with the directory you want the files to be saved at.
|
||||
|
||||
**If you are running SELinux, you will need to add the `:z` option after `/out`, e.g.:**
|
||||
|
||||
```
|
||||
docker run --rm -v /path/on/machine:/out:z tyrrrz/discordchatexporter:stable export -t TOKEN -c CHANNELID
|
||||
```
|
||||
|
||||
For more information, refer to the [Docker docs SELinux labels for bind mounts page](https://docs.docker.com/storage/bind-mounts/#configure-the-selinux-label).
|
||||
|
||||
You can also use the current working directory as the output directory by specifying:
|
||||
|
||||
- `-v $PWD:/out` in Mac/Linux
|
||||
- `-v $pwd.Path:/out` in PowerShell
|
||||
|
||||
For more information, please refer to the [Dockerfile](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/Dockerfile) and [Docker documentation](https://docs.docker.com/engine/reference/run/).<br>
|
||||
To get your Token and Channel IDs, please refer to [this page](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md).
|
||||
|
||||
### Environment variables
|
||||
|
||||
DiscordChatExpoter CLI accepts environment variables as fallbacks for the `--token` and `--bot` options.
|
||||
|
||||
- `DISCORD_TOKEN` to set the token
|
||||
- `DISCORD_TOKEN_BOT` to set whether it's a bot token (`true` or `false`)
|
||||
|
||||
You can use these variables either with the `--env` Docker option or with a combination of the `--env-file` Docker option and a `.env` file.
|
||||
Please refer to the Docker documentation for more information:
|
||||
|
||||
- [Docker run - Set environment variables](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file)
|
||||
|
||||
### Permission issues with Linux hosts
|
||||
|
||||
When bounding volumes between the container and the host, files mirrored from the Docker container will be owned by the Docker user (in most setups this is `root`). Please refer to this [issue comment](https://github.com/Tyrrrz/DiscordChatExporter/issues/800#issuecomment-1030471970) for instructions on how to override this behavior.
|
||||
|
||||
### Build Docker images for arm on Raspberry Pi
|
||||
|
||||
If you use the Docker image on arm (for example Raspberry Pi), you'd build the image as below.
|
||||
|
||||
```bash
|
||||
$ git clone https://github.com/Tyrrrz/DiscordChatExporter.git
|
||||
$ cd DiscordChatExporter
|
||||
$ docker build -f DiscordChatExporter.Cli.dockerfile -t tyrrrz/discordchatexporter:latest .
|
||||
```
|
||||
|
||||
After a while, some images are built like below.
|
||||
|
||||
```bash
|
||||
$ docker image ls
|
||||
REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
tyrrrz/discordchatexporter latest 7c9ead725177 49 seconds ago 199MB
|
||||
<none> <none> 57f9f49d05af About a minute ago 678MB
|
||||
mcr.microsoft.com/dotnet/sdk 5.0 72af6071941e 4 days ago 641MB
|
||||
mcr.microsoft.com/dotnet/runtime 3.1 6229bebd5a11 4 days ago 197MB
|
||||
```
|
||||
|
||||
Among these, two images (`tyrrrz/discordchatexporter:latest` and `mcr.microsoft.com/dotnet/runtime:3.1`) are required, so you may delete the other two images.
|
||||
|
||||
Now you can execute DiscordChatExporter:
|
||||
|
||||
```bash
|
||||
$ docker run --rm tyrrrz/discordchatexporter:latest
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Special thanks to [@simnalamburt](https://github.com/simnalamburt) (dockerize) and [@Nimja](https://github.com/nimja) (better instructions)
|
||||
@@ -0,0 +1,66 @@
|
||||
# Install .NET Core runtime
|
||||
|
||||
**.NET v7.0 Runtime** is required by **DiscordChatExporter v2.37 and newer**.
|
||||
If you are using GUI flavor of DiscordChatExporter, the runtime will be installed automatically (since v2.27.1).
|
||||
If you are using the CLI from Docker, installing the runtime on the host machine is not needed.
|
||||
|
||||
- Install
|
||||
- [Windows and macOS](#windows-and-macos)
|
||||
- [Linux](#linux)
|
||||
- [Docker](#docker)
|
||||
- [Verify installation](#Verify-installation-optional)
|
||||
|
||||
## Windows and macOS
|
||||
|
||||
**Download from the direct links:**
|
||||
|
||||
- [.NET v7.0 Runtime for **Windows x64**](https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-desktop-7.0.1-windows-x64-installer)
|
||||
- [.NET v7.0 Runtime for **Windows x86**](https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-desktop-7.0.1-windows-x86-installer)
|
||||
- [.NET v7.0 Runtime for **Macs with Apple silicon**](https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-7.0.1-macos-arm64-installer)
|
||||
- [.NET v7.0 Runtime for **Macs with an Intel processor**](https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-7.0.1-macos-x64-installer)
|
||||
|
||||
> 💡 [How can I tell if my computer is running a 32-bit (x86) or a 64-bit (x64) version of Windows?](https://support.microsoft.com/help/15056/windows-32-64-bit-faq)
|
||||
> 💡 [Is my Mac using an Intel processor or Apple silicon?](https://support.apple.com/HT211814)
|
||||
|
||||
**Otherwise:**
|
||||
[Check out the latest version in this page](https://dotnet.microsoft.com/download/dotnet/7.0).
|
||||
Look for the download link in the '**.NET Runtime**' section, under **Installers**:
|
||||
|
||||
[](https://dotnet.microsoft.com/download/dotnet/7.0)
|
||||
|
||||
## Linux
|
||||
|
||||
**You only need to install .NET Core <u>Runtime</u> v7.0**
|
||||
|
||||
Check out the instructions for your distro:
|
||||
|
||||
- [Ubuntu](https://docs.microsoft.com/dotnet/core/install/linux-ubuntu#supported-distributions)
|
||||
- [Debian](https://docs.microsoft.com/dotnet/core/install/linux-debian#supported-distributions)
|
||||
- [Fedora](https://docs.microsoft.com/dotnet/core/install/linux-fedora#supported-distributions)
|
||||
|
||||
For other distros, please check the _'Install on Linux'_ menu on the left of [this page](https://docs.microsoft.com/dotnet/core/install/linux).
|
||||
|
||||
## Docker
|
||||
|
||||
Installing .NET Runtime is not needed. Please refer to the [Docker usage instructions](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Docker.md) page for more information.
|
||||
|
||||
## Verify installation (optional)
|
||||
|
||||
You can check which version of **.NET Core** is installed by following these instructions:
|
||||
|
||||
#### Step 1
|
||||
|
||||
**Windows:** Open Command Prompt (aka `cmd`)
|
||||
**macOS and Linux:** Open `Terminal`
|
||||
|
||||
#### Step 2
|
||||
|
||||
Run: `dotnet --info`
|
||||
If **.NET Core Runtime** is correctly installed, the command will output the following:
|
||||
|
||||
```
|
||||
|
||||
.NET runtimes installed:
|
||||
Microsoft.NETCore.App 7.0.x [C:\path\to\dotnet\shared\Microsoft.NETCore.App]
|
||||
Microsoft.WindowsDesktop.App 7.0.x [C:\path\to\dotnet\shared\Microsoft.WindowsDesktop.App]
|
||||
```
|
||||
@@ -0,0 +1,493 @@
|
||||
# GUI, CLI and Formats explained
|
||||
|
||||
# Getting started
|
||||
|
||||
Welcome to the getting started page!
|
||||
Here you'll learn how to use every **DiscordChatExporter** (DCE for short) feature.
|
||||
For other things you can do with DCE, check out the [Guides](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Readme.md#Guides) section.
|
||||
|
||||
If you still have unanswered questions after reading this page or if you have encountered a problem, please visit our [FAQ & Troubleshooting](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Troubleshooting.md) section.
|
||||
|
||||
The information presented on this page is valid for **all** platforms.
|
||||
|
||||
# GUI or CLI?
|
||||
|
||||

|
||||
**DCE** has two different versions:
|
||||
|
||||
- **Graphical User Interface** (**GUI**) - it's the preferred version for newcomers as it is easy to use.
|
||||
You can get it by [downloading](https://github.com/Tyrrrz/DiscordChatExporter/releases/latest) the `DiscordChatExporter.zip` file.
|
||||
- **Command Line Interface** (**CLI**) - offers greater flexibility and more features for advanced users, such as export scheduling, ID lists, and more specific date ranges.
|
||||
You can get it by [downloading](https://github.com/Tyrrrz/DiscordChatExporter/releases/latest) the `DiscordChatExporter.CLI.zip` file.
|
||||
|
||||
If you're not comfortable with **Windows'** Command Line (cmd), please choose the GUI.
|
||||
[**macOS**](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/MacOS.md), [**Linux**](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Linux.md) and [**Docker**](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Docker.md) users can only use the CLI version.
|
||||
|
||||
**(Skip to [Using the CLI](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#using-the-cli) or [File Formats](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#file-formats))**
|
||||
|
||||
# Using the GUI
|
||||
|
||||
### Video tutorial
|
||||
|
||||
[](https://youtube.com/watch?v=jjtu0VQXV7I)
|
||||
|
||||
> Video by [NoIntro Tutorials](https://youtube.com/channel/UCFezKSxdNKJe77-hYiuXu3Q).
|
||||
|
||||
### Guide
|
||||
|
||||
**1.** After extracting the `.zip`, open `DiscordChatExporter.exe`
|
||||
|
||||
**2.** Please refer to the on-screen instructions to get your token, then paste your token in the upper text box and hit ENTER or click the arrow (→).
|
||||
**NEVER SHARE YOUR TOKEN**. A token gives <u>full access</u> to an account, treat it like a password.
|
||||
|
||||
<img src="https://i.imgur.com/SuLQ5tZ.png" height="400"/>
|
||||
|
||||
**3.** DCE will display your Direct Messages and a sidebar with your server list. Select the channel you would like to export, then click the  button to continue.
|
||||
|
||||
> 💡 Tip: You can export multiple channels at once by holding `CTRL` or `SHIFT` while selecting.
|
||||
> You can also double-click a channel to export it without clicking the  button.
|
||||
|
||||
<img src="https://i.imgur.com/JHMFRh2.png" height="400"/>
|
||||
|
||||
**4.** In this screen you can customize the following:
|
||||
|
||||
- **Export format** - HTML (Dark), HTML (Light), TXT, CSV and JSON
|
||||
|
||||
Click the menu button (☰) to see more options:
|
||||
|
||||
- **Date range (after/before)** (Optional) - If set, only messages sent in the provided date range will be exported. Only one value (either after or before) is required if you want to use this option.
|
||||
> Please note that the time defaults to **12:00 AM** (midnight/00:00). This means that if you choose to export between Sep 17th and Sep 18th, messages from Sep 18th won't be exported.
|
||||
- **Filter** (Optional) - Special notation for filtering the messages that get included in the export. See [Message filters](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Message-filters.md) for more info.
|
||||
- **Messages per partition** (Optional) - Split output into partitions, each limited to this number of messages (e.g. 100) or file size (e.g. 10mb). For example, a channel with 36 messages set to be partitioned every 10 messages will output 4 files.
|
||||
- **Download assets** (Optional) - If this option is set, the export will include additional files such as user avatars, attached files, images, etc.
|
||||
Only files that are referenced by the export are downloaded, which means that, for example, user avatars will not be downloaded when using the plain text (TXT) export format.
|
||||
A folder containing the assets will be created along with the exported chat. They must be kept together.
|
||||
|
||||
**5.** Click `EXPORT` to export.
|
||||
|
||||
<img src="https://i.imgur.com/KPgMH2D.png" height="400"/><img src="https://i.imgur.com/mtUFojS.png" height="400"/>
|
||||
|
||||
### Settings
|
||||
|
||||
**Auto-updates**
|
||||
Perform automatic updates on every launch.
|
||||
Default: Enabled
|
||||
|
||||
> 💡 Tip: Keep this option enabled to receive the latest features and bug fixes!
|
||||
|
||||
**Dark mode**
|
||||
Use darker colors in the UI (User Interface).
|
||||
Default: Disabled
|
||||
|
||||
**Save token**
|
||||
Persist last used token between sessions.
|
||||
Default: Enabled
|
||||
|
||||
**Reuse downloaded assets**
|
||||
Reuse already downloaded assets to skip redundant requests.
|
||||
Default: Disabled
|
||||
|
||||
**Date format**
|
||||
You can customize how dates are formatted in the exported files in the settings menu ().
|
||||
|
||||
- The default one is `17-Sep-19 11:34 PM` - `dd-MMM-yy hh:mm tt`
|
||||
- To change it to `09-17-19 11:34 PM` use `MM-dd-yy hh:mm tt`
|
||||
- To change it to `17/09/2019 23:34` use `dd/MM/yyyy HH:mm`
|
||||
- To change it to `2019-09-17 23:34:05.6534` use `yyyy-MM-dd HH:mm:ss.ffff`
|
||||
- To change it to UTC `2019-09-18 04:34:05Z` use `u`
|
||||
- To display the time zone, add `K`. E.g. to change it to `17-Sep-19 11:34 PM (UTC-05:00)` use `dd-MMM-yy hh:mm tt (UTCK)`
|
||||
- To change it to Unix time `1568694845` use `unix`
|
||||
- To change it to Unix time in milliseconds `1568694845653` use `unixms`
|
||||
|
||||
More info about .NET date formats [here](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings).
|
||||
|
||||
**Parallel limit**
|
||||
The number of channels can be exported at the same time.
|
||||
Default: 1
|
||||
|
||||
> 💡 Tip: Try to keep this number low so that your account doesn't get flagged.
|
||||
|
||||
**(Skip to [File Formats](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#file-formats))**
|
||||
|
||||
# Using the CLI
|
||||
|
||||
> Make sure you have [.NET Core installed](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Dotnet.md) before attempting to run the commands below.
|
||||
> **Docker** users, please refer to the [Docker usage instructions](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Docker.md).
|
||||
|
||||
**1.** After extracting the `.zip`, open Command Prompt, aka `cmd` (`Terminal` on **macOS** and **Linux**).
|
||||
|
||||
**2.** Change the current directory to DCE's folder with `cd C:\path\to\directory`, then press ENTER to run the command.
|
||||
|
||||
**Windows** users can quickly get the directory's path by clicking the address bar while inside the folder.
|
||||

|
||||
**macOS** users can select the `.exe`, hit Command+I (⌘I), and copy what's after `Where:` to get the directory
|
||||

|
||||
You can also drag and drop the folder on **every platform**.
|
||||

|
||||
|
||||
**3.** Now we're ready to run the commands. The examples on this page follow the Windows file path format, change the file paths according to your system.
|
||||
|
||||
Let's do the following to list DCE's options:
|
||||
|
||||
Type the following in Command Prompt (Terminal), then press ENTER to run it:
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll
|
||||
```
|
||||
|
||||
> **Docker** users, please refer to the [Docker usage instructions](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Docker.md).
|
||||
|
||||
## DCE.CLI commands
|
||||
|
||||
| Command | Description |
|
||||
| ------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
|
||||
| [export](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#export) | Exports a channel |
|
||||
| [exportdm](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#exportdm) | Exports all direct message channels |
|
||||
| [exportguild](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#exportguild) | Exports all channels within the specified server |
|
||||
| [exportall](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#exportall) | Exports all accessible channels |
|
||||
| [channels](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#channels) | Outputs the list of channels in the given server |
|
||||
| [dm](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#dm) | Outputs the list of direct message channels |
|
||||
| [guilds](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#guilds) | Outputs the list of accessible servers |
|
||||
| [guide](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#guide) | Explains how to obtain token, guild, and channel ID |
|
||||
|
||||
To use the commands, you'll need a token. For the instructions on how to get a token, please refer to [this page](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md), or run `dotnet DiscordChatExporter.Cli.dll guide`.
|
||||
To get help with a specific command, please run:
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll command -h
|
||||
```
|
||||
|
||||
## export
|
||||
|
||||
| | Option | Description |
|
||||
| ------ | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **\*** | [-c](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#basic-usage) | [Channel ID(s)](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#how-to-get-guild-id-or-guild-channel-id) |
|
||||
| **\*** | [-t](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#basic-usage) | [Authorization token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#how-to-get-user-token). Environment variable: `DISCORD_TOKEN` |
|
||||
| | [-o](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#changing-the-output-filename) | Output file or directory path |
|
||||
| | [-f](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#changing-the-format) | [Output file format](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#file-formats). Default: HtmlDark |
|
||||
| | [--after](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-ranges) | Only include messages sent after this date |
|
||||
| | [--before](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-ranges) | Only include messages sent before this date |
|
||||
| | [-p](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#partitioning) | Split output into partitions, each limited to this number of messages (e.g. 100) or file size (e.g. 10mb) |
|
||||
| | [--filter](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Message-filters.md) | Special notation for filtering the messages that get included in the export |
|
||||
| | [--media](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#Downloading-assets) | Download assets referenced by the export (user avatars, attached files, embedded images, etc.). Default: false |
|
||||
| | [--reuse-media](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#Reuse-assets) | Reuse previously downloaded assets to avoid redundant requests. Default: false. |
|
||||
| | [--dateformat](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-formats) | Format used when writing dates. |
|
||||
| | -h | Shows help text |
|
||||
|
||||
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
|
||||
|
||||
With this command you can export Server Channels and Direct Messages.
|
||||
|
||||
### Basic usage
|
||||
|
||||
You can quickly export with DCE's default settings by using just `-t token` and `-c channelid`.
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555
|
||||
```
|
||||
|
||||
### Changing the format
|
||||
|
||||
You can change the export format to `HtmlDark`, `HtmlLight`, `PlainText` `Json` or `Csv` with `-f format`. The default format is `HtmlDark`.
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 -f Json
|
||||
```
|
||||
|
||||
### Changing the output filename
|
||||
|
||||
You can change the filename by using `-o name.ext`. e.g. for the `HTML` format:
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 -o myserver.html
|
||||
```
|
||||
|
||||
### Changing the output directory
|
||||
|
||||
You can change the export directory by using `-o` and providing a path that ends with a slash or does not have a file extension.
|
||||
If any of the folders in the path have a space in its name, escape them with quotes (").
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 -o "C:\Discord Exports"
|
||||
```
|
||||
|
||||
### Changing the filename and output directory
|
||||
|
||||
You can change both the filename and export directory by using `-o directory\name.ext`.
|
||||
Note that the filename must have an extension, otherwise it will be considered a directory name.
|
||||
If any of the folders in the path have a space in its name, escape them with quotes (").
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 -o "C:\Discord Exports\myserver.html"
|
||||
```
|
||||
|
||||
### Generating the filename and output directory dynamically
|
||||
|
||||
You can use template tokens to generate the output file path based on the guild and channel metadata.
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 -o "C:\Discord Exports\%G\%T\%C.html"
|
||||
```
|
||||
|
||||
Assuming you are exporting a channel named `"my-channel"` in the `"Text channels"` category from a server called `"My server"`, you will get the following output file path: `C:\Discord Exports\My server\Text channels\my-channel.html`
|
||||
|
||||
Here is the full list of supported template tokens:
|
||||
|
||||
- `%g` - guild ID
|
||||
- `%G` - guild name
|
||||
- `%t` - category ID
|
||||
- `%T` - category name
|
||||
- `%c` - channel ID
|
||||
- `%C` - channel name
|
||||
- `%p` - channel position
|
||||
- `%P` - category position
|
||||
- `%a` - the "after" date
|
||||
- `%b` - the "before" date
|
||||
- `%%` - escapes `%`
|
||||
|
||||
### Partitioning
|
||||
|
||||
You can use partitioning to split files after a given number of messages or file size.
|
||||
For example, a channel with 36 messages set to be partitioned every 10 messages will output 4 files.
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 -p 10
|
||||
```
|
||||
|
||||
A 45mb channel set to be partitioned every 20mb will output 3 files.
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 -p 20mb
|
||||
```
|
||||
|
||||
### Downloading assets
|
||||
|
||||
If this option is set, the export will include additional files such as user avatars, attached files, images, etc.
|
||||
Only files that are referenced by the export are downloaded, which means that, for example, user avatars will not be downloaded when using the plain text (TXT) export format.
|
||||
A folder containing the assets will be created along with the exported chat. They must be kept together.
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 --media
|
||||
```
|
||||
|
||||
### Reuse assets
|
||||
|
||||
Previously downloaded assets can be reused to skip redundant downloads as long as the chat is always exported to the same folder. Using this option can speed up future exports. This option requires the `--media` option.
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 --media --reuse-media
|
||||
```
|
||||
|
||||
### Date formats
|
||||
|
||||
This setting changes how dates are formatted in the exported files.
|
||||
|
||||
- The default one is `17-Sep-19 11:34 PM` - `dd-MMM-yy hh:mm tt`
|
||||
- To change it to `09-17-19 11:34 PM` use `MM-dd-yy hh:mm tt`
|
||||
- To change it to `17/09/2019 23:34` use `dd/MM/yyyy HH:mm`
|
||||
- To change it to `2019-09-17 23:34:05.6534` use `yyyy-MM-dd HH:mm:ss.ffff`
|
||||
- To change it to UTC `2019-09-18 04:34:05Z` use `u`
|
||||
- To display the time zone, add `K`. E.g. to change it to `17-Sep-19 11:34 PM (UTC-05:00)` use `dd-MMM-yy hh:mm tt (UTCK)`
|
||||
- To change it to Unix time `1568694845` use `unix`
|
||||
- To change it to Unix time in milliseconds `1568694845653` use `unixms`
|
||||
|
||||
More info about .NET date formats [here](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings).
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 --dateformat "yyyy-MM-dd HH:mm"
|
||||
```
|
||||
|
||||
> Special thanks to [@andrewkolos](https://github.com/andrewkolos) for adding the Unix options
|
||||
|
||||
### Date ranges
|
||||
|
||||
**Messages sent before a date**
|
||||
Use `--before` to export messages sent before the provided date. E.g. messages sent before September 18th, 2019:
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 --before 2019-09-18
|
||||
```
|
||||
|
||||
**Messages sent after a date**
|
||||
Use `--after` to export messages sent after the provided date. E.g. messages sent after September 17th, 2019 11:34 PM:
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 --after "2019-09-17 23:34"
|
||||
```
|
||||
|
||||
**Messages sent in a date range**
|
||||
Use `--before` and `--after` to export messages sent during the provided date range. E.g. messages sent between September 17th, 2019 11:34 PM and September 18th:
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 --after "2019-09-17 23:34" --before "2019-09-18"
|
||||
```
|
||||
|
||||
You can try different formats like `17-SEP-2019 11:34 PM` or even refine your ranges down to milliseconds `17-SEP-2019 23:45:30.6170`!
|
||||
Don't forget to quote (") the date if it has spaces!
|
||||
More info about .NET date formats [here](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings).
|
||||
|
||||
## exportdm
|
||||
|
||||
| | Option | Description |
|
||||
| ------ | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **\*** | [-t](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#basic-usage) | [Authorization token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#how-to-get-user-token). Environment variable: `DISCORD_TOKEN` |
|
||||
| | --parallel | Limits how many channels can be exported in parallel. Try to keep this number low so that your account doesn't get flagged. Default: 1 |
|
||||
| | [-o](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#changing-the-output-filename) | Output file or directory path |
|
||||
| | [-f](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#changing-the-format) | [Output file format](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#file-formats). Default: HtmlDark |
|
||||
| | [--after](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-ranges) | Only include messages sent after this date |
|
||||
| | [--before](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-ranges) | Only include messages sent before this date |
|
||||
| | [-p](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#partitioning) | Split output into partitions, each limited to this number of messages (e.g. 100) or file size (e.g. 10mb) |
|
||||
| | [--filter](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Message-filters.md) | Special notation for filtering the messages that get included in the export |
|
||||
| | [--media](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#Downloading-assets) | Download assets referenced by the export (user avatars, attached files, embedded images, etc.). Default: false |
|
||||
| | [--reuse-media](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#Reuse-assets) | Reuse previously downloaded assets to avoid redundant requests. Default: false. |
|
||||
| | [--dateformat](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-formats) | Date format used in output |
|
||||
| | -h | Shows help text |
|
||||
|
||||
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
|
||||
|
||||
This command exports all your Direct Messages.
|
||||
|
||||
## exportguild
|
||||
|
||||
| | Option | Description |
|
||||
| ------ | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **\*** | -g | [Server ID](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#how-to-get-guild-id-or-guild-channel-id) |
|
||||
| **\*** | [-t](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#basic-usage) | [Authorization token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#how-to-get-user-token). Environment variable: `DISCORD_TOKEN` |
|
||||
| | --parallel | Limits how many channels can be exported in parallel. Try to keep this number low so that your account doesn't get flagged. Default: 1 |
|
||||
| | [-o](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#changing-the-output-filename) | Output file or directory path |
|
||||
| | [-f](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#changing-the-format) | [Output file format](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#file-formats). Default: HtmlDark |
|
||||
| | [--after](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-ranges) | Only include messages sent after this date |
|
||||
| | [--before](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-ranges) | Only include messages sent before this date |
|
||||
| | [-p](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#partitioning) | Split output into partitions, each limited to this number of messages (e.g. 100) or file size (e.g. 10mb) |
|
||||
| | [--filter](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Message-filters.md) | Special notation for filtering the messages that get included in the export |
|
||||
| | [--media](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#Downloading-assets) | Download assets referenced by the export (user avatars, attached files, embedded images, etc.). Default: false |
|
||||
| | [--reuse-media](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#Reuse-assets) | Reuse previously downloaded assets to avoid redundant requests. Default: false. |
|
||||
| | [--dateformat](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-formats) | Date format used in output |
|
||||
| | -h | Shows help text |
|
||||
|
||||
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
|
||||
|
||||
This command exports all channels of a Server.
|
||||
|
||||
## exportall
|
||||
|
||||
| | Option | Description |
|
||||
| ------ | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **\*** | [-t](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#basic-usage) | [Authorization token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#how-to-get-user-token). Environment variable: `DISCORD_TOKEN` |
|
||||
| | --include-dm | Include direct message channels. Default: true |
|
||||
| | --parallel | Limits how many channels can be exported in parallel. Try to keep this number low so that your account doesn't get flagged. Default: 1 |
|
||||
| | [-o](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#changing-the-output-filename) | Output file or directory path |
|
||||
| | [-f](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#changing-the-format) | [Output file format](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#file-formats). Default: HtmlDark |
|
||||
| | [--after](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-ranges) | Only include messages sent after this date |
|
||||
| | [--before](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-ranges) | Only include messages sent before this date |
|
||||
| | [-p](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#partitioning) | Split output into partitions, each limited to this number of messages (e.g. 100) or file size (e.g. 10mb) |
|
||||
| | [--filter](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Message-filters.md) | Special notation for filtering the messages that get included in the export |
|
||||
| | [--media](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#Downloading-assets) | Download assets referenced by the export (user avatars, attached files, embedded images, etc.). Default: false |
|
||||
| | [--reuse-media](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#Reuse-assets) | Reuse previously downloaded assets to avoid redundant requests. Default: false. |
|
||||
| | [--dateformat](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-formats) | Date format used in output |
|
||||
| | -h | Shows help text |
|
||||
|
||||
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
|
||||
|
||||
This command exports all accessible channels, including server channels and DMs.
|
||||
|
||||
To exclude DMs, add the `--include-dm false` option:
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll exportall -t "mfa.Ifrn" --include-dm false
|
||||
```
|
||||
|
||||
## channels
|
||||
|
||||
| | Option | Description |
|
||||
| ------ | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **\*** | -g | [Server ID](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#how-to-get-guild-id-or-guild-channel-id) |
|
||||
| **\*** | [-t](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#basic-usage) | [Authorization token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#how-to-get-user-token). Environment variable: `DISCORD_TOKEN` |
|
||||
| | -h | Shows help text |
|
||||
|
||||
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
|
||||
|
||||
This command outputs the server channels in the following format:
|
||||
`Channel ID | Channel Name`
|
||||
To save the output to a file, run the command below. If the file already exists, it will be overwritten.
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll channels -t "mfa.Ifrn" -g 21814 > C:\path\to\output.txt
|
||||
```
|
||||
|
||||
## dm
|
||||
|
||||
| | Option | Description |
|
||||
| ------ | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **\*** | [-t](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#basic-usage) | [Authorization token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#how-to-get-user-token). Environment variable: `DISCORD_TOKEN` |
|
||||
| | -h | Shows help text |
|
||||
|
||||
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
|
||||
|
||||
This command outputs the list of Direct Messages.
|
||||
To save the output to a file, run the command with `> C:\path\…` like the example below. If the file already exists, it will be overwritten.
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll dm -t "mfa.Ifrn" > C:\path\to\output.txt
|
||||
```
|
||||
|
||||
## guilds
|
||||
|
||||
| | Option | Description |
|
||||
| ------ | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **\*** | [-t](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#basic-usage) | [Authorization token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#how-to-get-user-token). Environment variable: `DISCORD_TOKEN` |
|
||||
| | -h | Shows help text |
|
||||
|
||||
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
|
||||
|
||||
This command outputs a list of your Server List.
|
||||
To save the output to a file, run the command with `> C:\path\…` like the example below. If the file already exists, it will be overwritten.
|
||||
|
||||
```powershell
|
||||
dotnet DiscordChatExporter.Cli.dll guilds -t "mfa.Ifrn" > C:\path\to\output.txt
|
||||
```
|
||||
|
||||
## guide
|
||||
|
||||
This command explains [how to get your token, guild, and channel IDs](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md).
|
||||
|
||||
# File formats
|
||||
|
||||
## HTML
|
||||
|
||||

|
||||
The HTML format replicates Discord's interface, making it the most user-friendly option.
|
||||
It's the best format for attachment preview and sharing.
|
||||
You can open `.html` files with a web browser, such as Google Chrome.
|
||||
|
||||
> Please note that if a picture is deleted, or if a user changes its avatar, the respective images will no longer be displayed.
|
||||
> Export using the "Download referenced assets" (`--media`) option to avoid this.
|
||||
|
||||
## Plain Text
|
||||
|
||||
<img src="https://i.imgur.com/PbUyRXD.png" height="400"/>
|
||||
|
||||
The Plain Text format is the best option for archiving due to its small size.
|
||||
You can open `.txt` files with a text editor, such as Notepad.
|
||||
|
||||
## JSON
|
||||
|
||||
<img src="https://i.imgur.com/FAeSA4O.png" height="400"/>
|
||||
|
||||
The JSON format contains more technical information and is easily parsable.
|
||||
You can open `.json` files with a text editor, such as Notepad.
|
||||
|
||||
## CSV
|
||||
|
||||

|
||||

|
||||
|
||||
The CSV format allows for easy parsing of the chat log. Depending on your needs, the JSON format might be better.
|
||||
You can open `.csv` files with a text editor, such as Notepad, or a spreadsheet app, like Microsoft Excel and Google Sheets.
|
||||
|
||||
**([Back to top](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#getting-started))**
|
||||
|
||||
#
|
||||
|
||||
Further reading: [.NET date formats](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings)
|
||||
Special thanks to [@Yudi](https://github.com/Yudi)
|
||||
@@ -0,0 +1,20 @@
|
||||
# Linux usage instructions
|
||||
|
||||
### Step 1: Install .NET Core Runtime
|
||||
|
||||
Please follow the [instructions provided here](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Dotnet.md).
|
||||
|
||||
### Step 2: Downloading and using DiscordChatExporter.Cli
|
||||
|
||||
**1.** Download [DiscordChatExporter.CLI.zip](https://github.com/Tyrrrz/DiscordChatExporter/releases/latest) and extract it to a folder.<br/>
|
||||
**2.** Open Terminal.<br/>
|
||||
**3.** `cd` into the extracted folder. You can do this in Terminal by typing `cd`, then press the SPACE key, drag and drop the extracted folder into the Terminal window, and press the ENTER key.<br/>
|
||||
**4.** Replace `TOKEN` and `CHANNEL`, then execute this command to export:
|
||||
|
||||
```
|
||||
dotnet DiscordChatExporter.Cli.dll export -t TOKEN -c CHANNEL
|
||||
```
|
||||
|
||||
> 💡 Tip: [How to get Token and Channel IDs](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md).
|
||||
|
||||
There's much more you can do with DCE.CLI! Read the [CLI explained](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#dcecli-commands-) page to get started.
|
||||
@@ -0,0 +1,20 @@
|
||||
# macOS usage instructions
|
||||
|
||||

|
||||
|
||||
### Step 1: Install .NET Core Runtime
|
||||
|
||||
Please follow the [instructions provided here](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Dotnet.md).
|
||||
|
||||
### Step 2: Downloading and using DiscordChatExporter.Cli
|
||||
|
||||
**1.** Download [DiscordChatExporter.CLI.zip](https://github.com/Tyrrrz/DiscordChatExporter/releases/latest) and extract it to a folder.<br/>
|
||||
**2.** Search for `Terminal.app` in Spotlight (⌘+SPACE), then open it.<br/>
|
||||
**3.** In the Terminal window, type `cd` , press the SPACE key, then drag and drop the extracted folder into the window, then press the RETURN key.<br/>
|
||||
**4.** Execute the following command to export, replacing `TOKEN` and `CHANNEL` with your own values:
|
||||
|
||||
dotnet DiscordChatExporter.Cli.dll export -t TOKEN -c CHANNEL
|
||||
|
||||
> 💡 Tip: [How to get Token and Channel IDs](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md).
|
||||
|
||||
There's much more you can do with DCE.CLI! Read the [CLI explained](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#dcecli-commands-) page to get started.
|
||||
@@ -0,0 +1,115 @@
|
||||
# Message filters
|
||||
|
||||
You can use a special notation to filter messages that you want to have included in an export. The notation syntax is designed to mimic Discord's search query syntax, but with additional capabilities.
|
||||
|
||||
To configure a filter, specify it in advanced export parameters when using the GUI or by passing the `--filter` option when using the CLI.
|
||||
|
||||
## Examples
|
||||
|
||||
- Filter by user
|
||||
|
||||
```
|
||||
from:Tyrrrz
|
||||
```
|
||||
|
||||
- Filter by user (with discriminator)
|
||||
|
||||
```
|
||||
from:Tyrrrz#1234
|
||||
```
|
||||
|
||||
- Filter by message content (allowed values: `link`, `embed`, `file`, `video`, `image`, `sound`)
|
||||
|
||||
```
|
||||
has:image
|
||||
```
|
||||
|
||||
- Filter by mentioned user (same rules apply as with `from:` filter)
|
||||
|
||||
```
|
||||
mentions:Tyrrrz#1234
|
||||
```
|
||||
|
||||
- Filter by contained text (has word "hello" and word "world" somewhere in the message text):
|
||||
|
||||
```
|
||||
hello world
|
||||
```
|
||||
|
||||
- Filter by contained text (has the string "hello world" somewhere in the message text):
|
||||
|
||||
```
|
||||
"hello world"
|
||||
```
|
||||
|
||||
- Combine multiple filters ('and'):
|
||||
|
||||
```
|
||||
from:Tyrrrz has:image
|
||||
```
|
||||
|
||||
- Same thing but with an explicit operator:
|
||||
|
||||
```
|
||||
from:Tyrrrz & has:image
|
||||
```
|
||||
|
||||
- Combine multiple filters ('or'):
|
||||
|
||||
```
|
||||
from:Tyrrrz | from:"96-LB"
|
||||
```
|
||||
|
||||
- Combine multiple filters using groups:
|
||||
|
||||
```
|
||||
(from:Tyrrrz | from:"96-LB") has:image
|
||||
```
|
||||
|
||||
- Negate a filter:
|
||||
|
||||
```
|
||||
-from:Tyrrrz | -has:image
|
||||
```
|
||||
|
||||
- Negate a grouped filter:
|
||||
|
||||
```
|
||||
-(from:Tyrrrz has:image)
|
||||
```
|
||||
|
||||
- Escape special characters (`-` is escaped below so it's not parsed as negation operator):
|
||||
|
||||
```
|
||||
from:96\-LB
|
||||
```
|
||||
|
||||
## CLI Caveat
|
||||
|
||||
When using the CLI and the specified filter starts with a negation (for example `-from:Tyrrrz`), you need to quote the value and prepend it with a space (i.e. `" -from:Tyrrrz"`). This prevents the beginning of the input from being incorrectly treated as a value passed to the `-f|--format` option.
|
||||
|
||||
In other words, this breaks:
|
||||
|
||||
```
|
||||
DiscordChatExporter.Cli export [...] --filter "-from:Tyrrrz"
|
||||
```
|
||||
|
||||
This works (note the space):
|
||||
|
||||
```
|
||||
DiscordChatExporter.Cli export [...] --filter " -from:Tyrrrz"
|
||||
```
|
||||
|
||||
Additionally, when using the CLI, it's recommended to use single quotes for contingent string of characters rather than double quotes (so it doesn't collide with the double quotes used as escaping mechanism in terminals). E.g.:
|
||||
|
||||
This breaks:
|
||||
|
||||
```
|
||||
DiscordChatExporter.Cli export [...] --filter "from:"Some name with spaces""
|
||||
```
|
||||
|
||||
This works:
|
||||
|
||||
```
|
||||
DiscordChatExporter.Cli export [...] --filter "from:'Some name with spaces'"
|
||||
```
|
||||
@@ -0,0 +1,43 @@
|
||||
# Home
|
||||
|
||||
<p align="center">
|
||||
<img src="https://i.imgur.com/IkrFoA0.png" height="120" />
|
||||
<br>
|
||||
<b>DiscordChatExporter</b> can be used to export message history from a Discord channel to a file.
|
||||
</p>
|
||||
|
||||
## Installation & Usage
|
||||
|
||||
**Step 1:** [Get .NET Core Runtime](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Dotnet.md) (Required for CLI; Installed automatically for GUI; Not required in Docker)
|
||||
|
||||
**Step 2:** [Windows](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#gui-or-cli) | [macOS](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/MacOS.md) | [Linux](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Linux.md) | [Docker](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Docker.md)
|
||||
|
||||
**Step 3:** Getting Started:
|
||||
|
||||
- [Using the GUI](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#using-the-gui)
|
||||
- [Using the CLI](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#using-the-cli)
|
||||
- [File formats](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#file-formats)
|
||||
|
||||
## Guides
|
||||
|
||||
- [How to get Token and Channel IDs](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md)
|
||||
- [How to use message filters](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Message-filters.md)
|
||||
- **Export Scheduling with CLI**
|
||||
- [Windows](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-windows.md)
|
||||
- [macOS](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-MacOS.md)
|
||||
- [Linux](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-Linux.md)
|
||||
|
||||
## Video tutorial
|
||||
|
||||
- Video by [NoIntro Tutorials](https://youtube.com/channel/UCFezKSxdNKJe77-hYiuXu3Q) (using DiscordChatExporter GUI)
|
||||
|
||||
[](https://youtube.com/watch?v=jjtu0VQXV7I)
|
||||
|
||||
## FAQ & Troubleshooting
|
||||
|
||||
- [General questions](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Troubleshooting.md#general)
|
||||
- [First steps help](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Troubleshooting.md#first-steps)
|
||||
- [It's crashing/failing](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Troubleshooting.md#DCE-is-crashingfailing)
|
||||
- [.NET Core Runtime is required](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Troubleshooting.md#net-core-runtime-is-required)
|
||||
- [Errors](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Troubleshooting.md#errors)
|
||||
- [**More help**](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Troubleshooting.md)
|
||||
@@ -0,0 +1,126 @@
|
||||
# Scheduling exports with Cron
|
||||
|
||||
Make sure you already have **DiscordChatExporter.CLI** and **.NET Core** properly installed ([instructions here](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Linux.md)).
|
||||
|
||||
You can use Cron on macOS, but [this method](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-MacOS.md) is preferred.
|
||||
|
||||
#
|
||||
|
||||
**1.** Open Terminal and create a new text file with `nano /path/to/DiscordChatExporter/cron.sh`<br/>
|
||||
|
||||
> For beginners: You can't use your mouse in nano, use the arrow keys to control the cursor (caret).
|
||||
|
||||
**2.** Paste the following into the text file:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# Info: https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs
|
||||
|
||||
TOKEN=tokenhere
|
||||
CHANNELID=channelhere
|
||||
DLLFOLDER=dceFOLDERpathhere
|
||||
FILENAME=filenamehere
|
||||
EXPORTDIRECTORY=dirhere
|
||||
EXPORTFORMAT=formathere
|
||||
# Available export formats: plaintext, htmldark, htmllight, json, csv
|
||||
# /\ CaSe-SeNsItIvE /\
|
||||
# You can edit the export command on line 40 if you'd like to include more options like date ranges and date format. You can't use partitioning (-p) with this script.
|
||||
|
||||
# This will verify if EXPORTFORMAT is valid and will set the final file extension according to it. If the format is invalid, the script will display a message and exit.
|
||||
if [[ "$EXPORTFORMAT" == "plaintext" ]]; then
|
||||
FORMATEXT=.txt
|
||||
elif [[ "$EXPORTFORMAT" == "htmldark" ]] || [[ "$EXPORTFORMAT" == "htmllight" ]]; then
|
||||
FORMATEXT=.html
|
||||
elif [[ "$EXPORTFORMAT" == "json" ]]; then
|
||||
FORMATEXT=.json
|
||||
elif [[ "$EXPORTFORMAT" == "csv" ]]; then
|
||||
FORMATEXT=.csv
|
||||
else
|
||||
echo "$EXPORTFORMAT - Unknown export format"
|
||||
echo "Available export formats: plaintext, htmldark, htmllight, csv, json"
|
||||
echo "/\ CaSe-SeNsItIvE /\\"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# This will change the script's directory to DLLPATH, if unable to do so, the script will exit.
|
||||
cd $DLLFOLDER || exit 1
|
||||
|
||||
# This will export your chat
|
||||
dotnet DiscordChatExporter.Cli.dll export -t $TOKEN -c $CHANNELID -f $EXPORTFORMAT -o $FILENAME.tmp
|
||||
|
||||
# This sets the current time to a variable
|
||||
CURRENTTIME=$(date +"%Y-%m-%d-%H-%M-%S")
|
||||
|
||||
# This will move the .tmp file to the desired export location, if unable to do so, it will attempt to delete the .tmp file.
|
||||
if ! mv "$FILENAME.tmp" "${EXPORTDIRECTORY//\"}/$FILENAME-$CURRENTTIME$FORMATEXT" ; then
|
||||
echo "Unable to move $FILENAME.tmp to $EXPORTDIRECTORY/$FILENAME-$CURRENTTIME$FORMATEXT."
|
||||
echo "Cleaning up..."
|
||||
if ! rm -Rf "$FILENAME.tmp" ; then
|
||||
echo "Unable to remove $FILENAME.tmp."
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
```
|
||||
|
||||
**3.** Replace:
|
||||
|
||||
`tokenhere` with your [Token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md).
|
||||
|
||||
`channelhere` with a [Channel ID](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md).
|
||||
|
||||
`dceFOLDERpathhere` with DCE's **directory path** (e.g. `/path/to/folder`, NOT `/path/to/folder/DiscordChatExporter.dll`).
|
||||
|
||||
`filenamehere` with the exported channel's filename, without spaces.
|
||||
|
||||
`dirhere` with the export directory (e.g. /home/user/Documents/Discord\ Exports).
|
||||
|
||||
`formathere` with one of the available export formats.
|
||||
|
||||
**Remember to escape spaces** (add `\` before them) or to quote (") the paths (`"/home/my user"`)!<br/>
|
||||
|
||||
> For beginners: To save, hold down CTRL and then press O, if asked for a filename, type it and press ENTER. Hit CTRL+X to exit the text editor.<br/> > [Check out this page](https://wiki.gentoo.org/wiki/Nano/Basics_Guide) if you want to know more about nano.
|
||||
|
||||
**4.** Make your script executable with `chmod +x /path/to/DiscordChatExporter/cron.sh`
|
||||
|
||||
**5.** Let's edit the cron file. If you want to run the script with your user privileges, edit it by running `crontab -e`. If you want to run the script as root, edit it with `sudo crontab -e`.<br/>
|
||||
If this is your first time running this command, you might be asked to select a text editor. Nano is easier for beginners.
|
||||
|
||||
**6.** Add the following to the end of the file `* * * * * /path/to/DiscordChatExporter/cron.sh >/tmp/discordchatexporter.log 2>/tmp/discordchatexportererror.log`<br/>
|
||||
Don't forget to replace the `/path/to/DiscordChatExporter/cron.sh`!
|
||||
|
||||
> 💡 Tip: If you don't want logs to be created, replace both `/tmp/discordchatexporter.log` with `/dev/null`
|
||||
|
||||
Then replace the \*s according to:
|
||||
|
||||

|
||||
|
||||
#
|
||||
|
||||
**Examples**<br/>
|
||||
If you want to execute the script at minute 15 of every hour: `15 * * * *`<br/>
|
||||
Every 30 minutes `*/30 * * * *`<br/>
|
||||
Everyday at midnight `0 0 * * *`<br/>
|
||||
Everyday at noon `0 12 * * *`<br/>
|
||||
Everyday at 3, 4 and 6 PM `0 15,16,18 * * *`<br/>
|
||||
Every Wednesday at 9 AM `0 9 * * 3`
|
||||
|
||||
Verify your cron time [here](https://crontab.guru).
|
||||
|
||||
#
|
||||
|
||||
**Extra information**
|
||||
|
||||
The week starts on Sunday. 0 = SUN, 1 = MON ... 7 = SUN.
|
||||
|
||||
Be aware that if you set the day to '31', the script will only run on months that have the 31st day.
|
||||
|
||||
> 💡 Tip: [Learn more about running a cron job on the last day of the month here](https://stackoverflow.com/questions/6139189/cron-job-to-run-on-the-last-day-of-the-month) (expert).
|
||||
|
||||
The default filename for the exported channel is `YYYY-MM-DD-hh-mm-ss-yourfilename`. You can change it if you'd like.
|
||||
|
||||
Don't forget to update your token in the script after it has been reset!
|
||||
|
||||
#
|
||||
|
||||
Special thanks to [@Yudi](https://github.com/Yudi)
|
||||
@@ -0,0 +1,276 @@
|
||||
# Scheduling exports on macOS
|
||||
|
||||
Scheduling on macOS is a bit tricky, but it should work if you follow the instructions accordingly.
|
||||
|
||||
Make sure you already have **DiscordChatExporter.CLI** and **.NET Core** properly installed ([instructions here](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/macOS-usage-instructions.md)).
|
||||
|
||||
- [**1.** Creating the script](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-MacOS.md#1-creating-the-script)
|
||||
- [**2.** Creating the .plist file](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-MacOS.md#2-creating-the-plist-file)
|
||||
- [Export on System Boot/User Login](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-MacOS.md#export-on-system-bootuser-login)
|
||||
- [Export every _n_ seconds](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-MacOS.md#export-every-n-seconds)
|
||||
- [Export at a specific time and date](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-MacOS.md#export-at-a-specific-time-and-date)
|
||||
- [**3.** Loading the .plist into launchctl](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-MacOS.md#3-loading-the-plist-into-launchctl)
|
||||
|
||||
## 1. Creating the script
|
||||
|
||||
**1.** Open TextEdit.app and create a new file
|
||||
|
||||
**2.** Convert the file to a plain text one in 'Format > Make Plain Text' (⇧⌘T)
|
||||
|
||||

|
||||
|
||||
**3.** Paste the following into the text editor:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# Info: https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs
|
||||
|
||||
TOKEN=tokenhere
|
||||
CHANNELID=channelhere
|
||||
DLLFOLDER=dceFOLDERpathhere
|
||||
FILENAME=filenamehere
|
||||
EXPORTDIRECTORY=dirhere
|
||||
EXPORTFORMAT=formathere
|
||||
# Available export formats: plaintext, htmldark, htmllight, json, csv
|
||||
# /\ CaSe-SeNsItIvE /\
|
||||
# You can edit the export command on line 43 if you'd like to include more options like date ranges and date format. You can't use partitioning (-p) with this script.
|
||||
|
||||
# This variable specifies in which directories the executable programs are located. Don't change it.
|
||||
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet
|
||||
|
||||
# This will verify if EXPORTFORMAT is valid and will set the final file extension according to it. If the format is invalid, the script will display a message and exit.
|
||||
if [[ "$EXPORTFORMAT" == "plaintext" ]]; then
|
||||
FORMATEXT=.txt
|
||||
elif [[ "$EXPORTFORMAT" == "htmldark" ]] || [[ "$EXPORTFORMAT" == "htmllight" ]]; then
|
||||
FORMATEXT=.html
|
||||
elif [[ "$EXPORTFORMAT" == "json" ]]; then
|
||||
FORMATEXT=.json
|
||||
elif [[ "$EXPORTFORMAT" == "csv" ]]; then
|
||||
FORMATEXT=.csv
|
||||
else
|
||||
echo "$EXPORTFORMAT - Unknown export format"
|
||||
echo "Available export formats: plaintext, htmldark, htmllight, csv, json"
|
||||
echo "/\ CaSe-SeNsItIvE /\\"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# This will change the script's directory to DLLPATH, if unable to do so, the script will exit.
|
||||
cd $DLLFOLDER || exit 1
|
||||
|
||||
# This will export your chat
|
||||
dotnet DiscordChatExporter.Cli.dll export -t $TOKEN -c $CHANNELID -f $EXPORTFORMAT -o $FILENAME.tmp
|
||||
|
||||
# This sets the current time to a variable
|
||||
CURRENTTIME=$(date +"%Y-%m-%d-%H-%M-%S")
|
||||
|
||||
# This will move the .tmp file to the desired export location. If unable to do so, it will attempt to delete the .tmp file.
|
||||
if ! mv "$FILENAME.tmp" "${EXPORTDIRECTORY//\"}/$FILENAME-$CURRENTTIME$FORMATEXT" ; then
|
||||
echo "Unable to move $FILENAME.tmp to $EXPORTDIRECTORY/$FILENAME-$CURRENTTIME$FORMATEXT."
|
||||
echo "Cleaning up..."
|
||||
if ! rm -Rf "$FILENAME.tmp" ; then
|
||||
echo "Unable to remove $FILENAME.tmp."
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
```
|
||||
|
||||
**4.** Replace:
|
||||
`tokenhere` with your [Token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md)
|
||||
|
||||
`channelhere` with a [Channel ID](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md)
|
||||
|
||||
`dceFOLDERpathhere` with DCE's **directory's path** (e.g. `/Users/user/Desktop/DiscordChatExporterFolder`, NOT `/Users/user/Desktop/DiscordChatExporterFolder/DiscordChatExporter.DLL`)
|
||||
|
||||
`filenamehere` with the exported channel's filename, without spaces
|
||||
|
||||
`dirhere` with the directory you want the files to be saved at (e.g. `/Users/user/Documents/Discord\ Exports`)
|
||||
|
||||
`formathere` with one of the available export formats
|
||||
|
||||
To quickly get file or folder paths, select the file/folder, then hit Command+I (⌘I) and copy what's after `Where:`.
|
||||
After copying and pasting, make sure the file/folder name is not missing. If a folder has spaces in its name, add `\` before the spaces, like in the example below:
|
||||
|
||||
- `Discord\ Exports` - Wrong ✗
|
||||
- `/Users/user/Documents` - Wrong ✗
|
||||
- `/Users/user/Documents/Discord Exports` - Wrong ✗
|
||||
- `/Users/user/Documents/Discord\ Exports/DCE.Cli.dll` - Wrong ✗
|
||||
- `/Users/user/Documents/Discord \Exports` - Wrong ✗
|
||||
- `/Users/user/Documents/Discord\ Exports` - Correct ✓
|
||||
- `/Users/user/Desktop/DiscordChatExporter` - Correct ✓
|
||||
|
||||

|
||||
|
||||
**5.** Save the file as `filename.sh`, not `.txt`
|
||||
|
||||
**6.** Open Terminal.app, type `chmod +x`, press the SPACE key, then drag & drop the `filename.sh` into the Terminal window and hit RETURN. You may be prompted for your password, and you won't be able to see it as you type.
|
||||
|
||||
## 2. Creating the .plist file
|
||||
|
||||
Open TextEdit, make a Plain Text (⇧⌘T) and then paste the following into it:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>local.discordchatexporter</string>
|
||||
<key>Program</key>
|
||||
<string>/path/to/filename.sh</string>
|
||||
REPLACEME
|
||||
</dict>
|
||||
</plist>
|
||||
```
|
||||
|
||||
- The `Label` string is the name of the export job, it must be something unique. Replace the `local.discordchatexporter` between the `<string>` with another name if you'd like to run more than one script.
|
||||
|
||||
- The `Program` string is the path to the script. Replace `/path/to/filename.sh` between the `<string>` with the path of the previously created script.
|
||||
|
||||
- Replace the `REPLACEME` with the content presented in the following sections according to <u>when</u> you want to export.
|
||||
|
||||
When you're done, save the file with the same name as the `Label` and with the `.plist` extension (not `.txt`), like `local.discordchatexporter.plist`.
|
||||
|
||||
### Exporting on System Boot/User Login
|
||||
|
||||
```xml
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
```
|
||||
|
||||
### Export every _n_ seconds
|
||||
|
||||
The following example is to export every 3600 seconds (1 hour), replace the integer value with your desired time:
|
||||
|
||||
```xml
|
||||
<key>StartInterval</key>
|
||||
<integer>3600</integer>
|
||||
```
|
||||
|
||||
### Export at a specific time and date
|
||||
|
||||
```xml
|
||||
<key>StartCalendarInterval</key>
|
||||
<dict>
|
||||
<key>Weekday</key>
|
||||
<integer>0</integer>
|
||||
<key>Month</key>
|
||||
<integer>0</integer>
|
||||
<key>Day</key>
|
||||
<integer>0</integer>
|
||||
<key>Hour</key>
|
||||
<integer>0</integer>
|
||||
<key>Minute</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
```
|
||||
|
||||
| Key | Integer |
|
||||
| ----------- | ----------------- |
|
||||
| **Month** | 1-12 |
|
||||
| **Day** | 1-31 |
|
||||
| **Weekday** | 0-6 (0 is Sunday) |
|
||||
| **Hour** | 0-23 |
|
||||
| **Minute** | 0-59 |
|
||||
|
||||
**Sunday** - 0; **Monday** - 1; **Tuesday** - 2; **Wednesday** - 3; **Thursday** - 4; **Friday** - 5; **Saturday** - 6
|
||||
|
||||
Replace the template's `0`s according to the desired times.
|
||||
|
||||
You can delete the `<key>`s you don't need, don't forget to remove the `<integer>0</integer>` under it.
|
||||
Omitted keys are interpreted as wildcards, for example, if you delete the Minute key, the script will run at every minute, delete the Weekday key and it'll run at every weekday, and so on.
|
||||
|
||||
Be aware that if you set the day to '31', the script will only run on months that have the 31st day.
|
||||
|
||||
**Check the examples below ([or skip to step 3 (loading the file)](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-MacOS.md#3-loading-the-plist-into-launchctl)):**
|
||||
|
||||
Export everyday at 5:15 PM:
|
||||
|
||||
```xml
|
||||
<key>StartCalendarInterval</key>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>17</integer>
|
||||
<key>Minute</key>
|
||||
<integer>15</integer>
|
||||
</dict>
|
||||
|
||||
```
|
||||
|
||||
Every 15 minutes of an hour (xx:15):
|
||||
|
||||
```xml
|
||||
<key>StartCalendarInterval</key>
|
||||
<dict>
|
||||
<key>Minute</key>
|
||||
<integer>15</integer>
|
||||
</dict>
|
||||
|
||||
```
|
||||
|
||||
Every Sunday at midnight and every Wednesday full hour (xx:00). Notice the inclusion of `<array>` and `</array>` to allow multiple values:
|
||||
|
||||
```xml
|
||||
<key>StartCalendarInterval</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>Weekday</key>
|
||||
<integer>0</integer>
|
||||
<key>Hour</key>
|
||||
<integer>00</integer>
|
||||
<key>Minute</key>
|
||||
<integer>00</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Weekday</key>
|
||||
<integer>3</integer>
|
||||
<key>Minute</key>
|
||||
<integer>00</integer>
|
||||
</dict>
|
||||
</array>
|
||||
```
|
||||
|
||||
## 3. Loading the .plist into launchctl
|
||||
|
||||
**1.** Copy your `filename.plist` file to one of these folders according to how you want it to run:
|
||||
|
||||
- `~/Library/LaunchAgents` runs as the current logged-in user.
|
||||
|
||||
- `/Library/LaunchDaemons` runs as the system "_administrator_" (root).
|
||||
|
||||
- If macOS has a single user:
|
||||
- If you want to export only when the user is logged in, choose the first one.
|
||||
- If you want the script to always run on System Startup, choose the second one.
|
||||
- If macOS has multiple users:
|
||||
- If you want the script to run only when a certain user is logged in, choose the first one.
|
||||
- If you want the script to always run on System Startup, choose the second one.
|
||||
|
||||
To quickly go to these directories, open Finder and press Command+Shift+G (⌘⇧G), then paste the path into the text box.
|
||||
|
||||
**2.** To load the job into launchctl, in Terminal, type `launchctl load`, press SPACE, drag and drop the `.plist` into the Terminal window, then hit RETURN. It won't output anything if it was successfully loaded.
|
||||
|
||||
### Extra launchctl commands
|
||||
|
||||
**Unloading a job**
|
||||
|
||||
```
|
||||
launchctl unload /path/to/Library/LaunchAgents/local.discordchatexporter.plist
|
||||
```
|
||||
|
||||
**List every loaded job**
|
||||
|
||||
```
|
||||
launchctl list
|
||||
```
|
||||
|
||||
**Check if a specific job is enabled**
|
||||
You can also see error codes (2nd number) by running this command.
|
||||
|
||||
```
|
||||
launchctl list | grep local.discordchatexporter
|
||||
```
|
||||
|
||||
#
|
||||
|
||||
Further reading: [Script management with launchd in Terminal on Mac](https://support.apple.com/guide/terminal/script-management-with-launchd-apdc6c1077b-5d5d-4d35-9c19-60f2397b2369/mac) and [launchd.info](https://launchd.info/).
|
||||
Special thanks to [@Yudi](https://github.com/Yudi)
|
||||
@@ -0,0 +1,82 @@
|
||||
# Scheduling exports on Windows
|
||||
|
||||
We'll be using [DiscordChatExporter CLI](https://github.com/Tyrrrz/DiscordChatExporter/releases/latest), PowerShell, and Task Scheduler.
|
||||
|
||||
**1.** Open a text editor such as Notepad and paste:
|
||||
|
||||
```powershell
|
||||
# Info: https://github.com/Tyrrrz/DiscordChatExporter/wiki
|
||||
|
||||
$TOKEN = "tokenhere"
|
||||
$CHANNEL = "channelhere"
|
||||
$EXEPATH = "exefolderhere"
|
||||
$FILENAME = "filenamehere"
|
||||
$EXPORTDIRECTORY = "dirhere"
|
||||
$EXPORTFORMAT = "formathere"
|
||||
# Available export formats: PlainText, HtmlDark, HtmlLight, Json, Csv
|
||||
|
||||
cd $EXEPATH
|
||||
|
||||
.\DiscordChatExporter.Cli.exe export -t $TOKEN -c $CHANNEL -f $EXPORTFORMAT -o "$FILENAME.tmp"
|
||||
|
||||
$Date = Get-Date -Format "yyyy-MM-dd-HH-mm"
|
||||
|
||||
If($EXPORTFORMAT -match "PlainText"){mv "$FILENAME.tmp" -Destination "$EXPORTDIRECTORY\$FILENAME-$Date.txt"}
|
||||
ElseIf($EXPORTFORMAT -match "HtmlDark"){mv "$FILENAME.tmp" -Destination "$EXPORTDIRECTORY\$FILENAME-$Date.html"}
|
||||
ElseIf($EXPORTFORMAT -match "HtmlLight"){mv "$FILENAME.tmp" -Destination "$EXPORTDIRECTORY\$FILENAME-$Date.html"}
|
||||
ElseIf($EXPORTFORMAT -match "Json"){mv "$FILENAME.tmp" -Destination "$EXPORTDIRECTORY\$FILENAME-$Date.json"}
|
||||
ElseIf($EXPORTFORMAT -match "Csv"){mv "$FILENAME.tmp" -Destination "$EXPORTDIRECTORY\$FILENAME-$Date.csv"}
|
||||
exit
|
||||
```
|
||||
|
||||
**2.** Replace:
|
||||
|
||||
`tokenhere` with your [Token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md)
|
||||
|
||||
`channelhere` with a [Channel ID](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md)
|
||||
|
||||
`exefolderhere` with the .exe **directory's path** (e.g. C:\Users\User\Desktop\DiscordChatExporter)
|
||||
|
||||
`filenamehere` with a filename without spaces
|
||||
|
||||
`dirhere` with the export directory (e.g. C:\Users\User\Documents\Exports)
|
||||
|
||||
`formathere` with one of the available export formats
|
||||
|
||||
Make sure not to delete the quotes (")
|
||||
|
||||
**3.** Save the file as `filename.ps1` not `.txt`
|
||||
|
||||
## Export at Startup
|
||||
|
||||
**1.** Press Windows + R, type `shell:startup` and press ENTER
|
||||
|
||||
**2.** Paste `filename.ps1` or a shortcut into this folder
|
||||
|
||||
## Scheduling with Task Scheduler
|
||||
|
||||
Please notice your computer must be turned on so the exportation can occur.
|
||||
|
||||
**1.** Press Windows + R, type `taskschd.msc` and press ENTER
|
||||
|
||||
**2.** Select `Task Scheduler Library`, create a Basic Task, and follow the instructions on-screen
|
||||
|
||||
<img src="https://i.imgur.com/MHRVGDi.png" height="500"/>
|
||||
|
||||
[  ](https://i.imgur.com/3gHkF0t.png)
|
||||
|
||||
**3.** At 'Start a Program', write `powershell -file -ExecutionPolicy ByPass -WindowStyle Hidden "C:\path\to\filename.ps1"` in the Program/script text box
|
||||
|
||||

|
||||
|
||||
**4.** Click 'Yes'
|
||||
|
||||

|
||||
|
||||
**5.** Click 'Finish'
|
||||
|
||||

|
||||
|
||||
#
|
||||
|
||||
Special thanks to [@Yudi](https://github.com/Yudi)
|
||||
@@ -0,0 +1,261 @@
|
||||
# Obtaining Token and Channel IDs
|
||||
|
||||
> **Warning**:
|
||||
> **DO NOT SHARE YOUR TOKEN!**.
|
||||
> A token gives full access to an account. To reset a user token, change your account password. To reset a bot token, click on "[Regenerate](#how-to-get-a-bot-token)"
|
||||
|
||||
### How to get a User Token
|
||||
|
||||
**Caution:** [Automating user accounts violates Discord's terms of service](https://support.discord.com/hc/en-us/articles/115002192352-Automated-user-accounts-self-bots-) and may result in account termination. Use at your own risk.
|
||||
|
||||
#### Through your web browser
|
||||
|
||||
Prerequisite step: Navigate to [discord.com](https://discord.com) and login.
|
||||
|
||||
##### In Chrome
|
||||
|
||||
###### Using the network monitor
|
||||
|
||||
1. <img width="500" align="right" src="https://i.imgur.com/zdDwIT5.jpg" />Press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>I</kbd> (<kbd>⌥</kbd>+<kbd>⌘</kbd>+<kbd>I</kbd> on macOS). Chrome's [DevTools](https://developer.chrome.com/docs/devtools/overview) tools will display.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
2. <img width="500" align="right" src="https://i.imgur.com/BDeG0zg.png" />Click the `Network` tab. The [network panel](https://developer.chrome.com/docs/devtools/overview/#network) will open
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
3. <img width="500" align="right" src="https://i.imgur.com/0Lgj0vk.png" />Press <kbd>F5</kbd>. The page will reload, and the network log (the lower half of the network panel) will display several entries.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
4. <img width="500" align="right" src="https://i.imgur.com/rnZG8Id.png" />Click the text box labelled `Filter` and type `library`. The entries will filter down to a single entry named `library`.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
5. <img width="500" align="right" src="https://i.imgur.com/29dE3fR.png" />Click the entry named `library`. A panel will open to the right and display details about the entry. Click the `Headers` tab if it isn't already active.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
6. <img width="500" align="right" src="https://i.imgur.com/u7CxXAt.png" />Scroll through the contents of the `Headers` tab until you find an entry beginning with `authorization:`.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
7. <img width="500" align="right" src="https://i.imgur.com/dXcXzma.png" />Right-click the entry and click `copy value`.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
###### Using the storage inspector
|
||||
|
||||
1. <img width="500" align="right" src="https://i.imgur.com/zdDwIT5.jpg" />Press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>I</kbd> (<kbd>⌥</kbd>+<kbd>⌘</kbd>+<kbd>I</kbd> on macOS). Chrome's [DevTools](https://developer.chrome.com/docs/devtools/overview/) will display.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
2. <img width="500" align="right" src="https://i.imgur.com/biAUIop.png" />Press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>M</kbd> (<kbd>⌘</kbd>+<kbd>Shift</kbd>+<kbd>M</kbd>). Chrome will enter [Device Mode](https://developer.chrome.com/docs/devtools/device-mode/), and the webpage will display as if on a mobile device.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
3. <img width="500" align="right" src="https://i.imgur.com/oUDRZoy.png" />If necessary, click the `»` at the right end of the tab bar, and click `Application`. The [application panel](https://developer.chrome.com/docs/devtools/overview/#application) will display.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
4. <img width="500" align="right" src="https://i.imgur.com/sydNPia.png" />In the menu to the right, under `Storage`, expand `Local Storage` if necessary, then click `https://discord.com`. The pane to the right will display a list of key-value pairs.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
5. <img width="500" align="right" src="https://i.imgur.com/qKo0ny9.png" />In the text box marked `Filter`, type `token`. The entries will filter down to those containing the string `token`.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
6. <img width="500" align="right" src="https://i.imgur.com/caj3lQq.png" />Click the `token` entry. (Note: if the token doesn't display, try refreshing by pressing <kbd>F5</kbd> or <kbd>⌘</kbd>+<kbd>R</kbd> on macOS)
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
7. <img width="500" align="right" src="https://i.imgur.com/SwWFIH4.png" />Click the text box at the bottom, press <kbd>Ctrl</kbd>+<kbd>A</kbd> (<kbd>⌘</kbd>+<kbd>A</kbd> on macOS) then <kbd>Ctrl</kbd>+<kbd>C</kbd> (<kbd>⌘</kbd>+<kbd>C</kbd> on macOS) to copy the value to your clipboard.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
##### In Firefox
|
||||
|
||||
###### Using the network monitor
|
||||
|
||||
1. <img width="500" align="right" src="https://i.imgur.com/O34nwdG.png" />Press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>E</kbd> (<kbd>⌥</kbd>+<kbd>⌘</kbd>+<kbd>E</kbd> on macOS). Firefox’s [web developer tools](https://firefox-source-docs.mozilla.org/devtools-user/) will display at the bottom of the window, and the [network monitor](https://firefox-source-docs.mozilla.org/devtools-user/network_monitor/) will display.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
2. <img width="500" align="right" src="https://i.imgur.com/j00QzhU.png" />Press <kbd>F5</kbd>. The page will reload, and the [network request list](https://firefox-source-docs.mozilla.org/devtools-user/network_monitor/request_list/index.html) will populate with entries.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
3. <img width="500" align="right" src="https://i.imgur.com/efUCfBO.png" />Type `library` into the filter. The network request list will filter out any entries not containing the string `library`.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
4. <img width="500" align="right" src="https://i.imgur.com/cdJZ7Q1.png" />Click `library`. The [network request details pane](https://firefox-source-docs.mozilla.org/devtools-user/network_monitor/request_details/index.html) will display. The [headers tab](https://firefox-source-docs.mozilla.org/devtools-user/network_monitor/request_details/index.html#network-monitor-request-details-headers-tab) should be active by default. If it isn’t, click it.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
5. <img width="500" align="right" src="https://i.imgur.com/zBmq1JW.png" />Type `authorization` into the text box labelled `Filter Headers`.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
6. <img width="500" align="right" src="https://i.imgur.com/O3blcIS.png" />Scroll down until you see an entry labeled [authorization](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization) under `Request Headers`.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
7. <img width="500" align="right" src="https://i.imgur.com/zHYEYoZ.png" />Right-click the entry labeled `authorization` and select `copy value`.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
###### Using the storage inspector
|
||||
|
||||
1. <img width="500" align="right" src="https://i.imgur.com/A8jqpkm.png" />Press <kbd>Shift</kbd>+<kbd>F9</kbd>. Firefox’s [web developer tools](https://firefox-source-docs.mozilla.org/devtools-user/) will display at the bottom of the window, and the [storage](https://firefox-source-docs.mozilla.org/devtools-user/storage_inspector/index.html) panel will be selected.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
2. <img width="500" align="right" src="https://i.imgur.com/TGcbB7f.png" />Press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>M</kbd> (<kbd>⌥</kbd>+<kbd>⌘</kbd>+<kbd>M</kbd> on macOS). Firefox will toggle [responsive design mode](https://firefox-source-docs.mozilla.org/devtools-user/responsive_design_mode/), and the web page will display as if on a mobile device. (Note: Discord may steal focus and respond to the command by toggling mute. If this happens, return focus to Firefox’s web developer tools by clicking somewhere in it, then try the command again.)
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
3. <img width="500" align="right" src="https://i.imgur.com/2xWkep9.png" />In the [storage tree](https://firefox-source-docs.mozilla.org/devtools-user/storage_inspector/index.html#storage-inspector-storage-tree) (the list on the left side of the web developer tools panel), click [Local Storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage). The entry will expand, and the entry `https://discord.com` will display beneath it.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
4. <img width="500" align="right" src="https://i.imgur.com/tGlGuOL.png" />In the storage tree, click `https://discord.com`. The [table widget](https://firefox-source-docs.mozilla.org/devtools-user/storage_inspector/index.html#storage-inspector-table-widget) to the right of the storage tree will display several key-value pairs.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
5. <img width="500" align="right" src="https://i.imgur.com/hDNsnZ5.png" />In the text box labelled `Filter items` at the top of the table widget, enter `token`. The table will now only display entries containing the string `token`.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
6. <img width="500" align="right" src="https://i.imgur.com/8fKId1W.png" />Click the entry `token`. The [sidebar](https://firefox-source-docs.mozilla.org/devtools-user/storage_inspector/index.html#storage-inspector-sidebar) will display. (Note: If the token doesn’t display, try refreshing by pressing <kbd>F5</kbd>.)
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
7. <img width="500" align="right" src="https://i.imgur.com/yD1ZuR9.png" />Right-click the single entry in the sidebar and select `copy`.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
#### Through the desktop app / Enabling web developer tools
|
||||
|
||||
##### By editing the settings file
|
||||
|
||||
1. If Discord is running, exit the application by right-clicking the icon in your taskbar tray and clicking `Quit Discord`.
|
||||
|
||||
2. Open Discord's settings file in your preferred text editor. See the following table for help finding it:
|
||||
|
||||
| OS | Stable | Canary | Public Test Build (PTB) |
|
||||
| ------- | ----------------------------------------------------- | ----------------------------------------------------------- | -------------------------------------------------------- |
|
||||
| Windows | `%APPDATA%\discord\settings.json` | `%APPDATA%\discordcanary\settings.json` | `%APPDATA%\discordptb\settings.json` |
|
||||
| macOS | `~/Library/Application Support/discord/settings.json` | `~/Library/Application Support/discordcanary/settings.json` | `~/Library/Application Support/discordptb/settings.json` |
|
||||
| Linux | `~/.config/discord/settings.json` | `~/.config/discordcanary/settings.json` | `~/.config/discordptb/settings.json` |
|
||||
|
||||
If you use BetterDiscord, use the following table instead:
|
||||
|
||||
| OS | Stable | Canary | Public Test Build (PTB) |
|
||||
| ------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------- | -------------------------------------------------------------------- |
|
||||
| Windows | `%APPDATA%\BetterDiscord\data\stable\settings.json` | `%APPDATA%\BetterDiscord\data\canary\settings.json` | `%APPDATA%\BetterDiscord\data\ptb\settings.json` |
|
||||
| macOS | `~/Library/Application Support/BetterDiscord/data/stable/settings.json` | `~/Library/Application Support/BetterDiscord/data/canary/settings.json` | `~/Library/Application Support/BetterDiscord/data/ptb/settings.json` |
|
||||
| Linux | `~/.config/BetterDiscord/data/stable/settings.json` | `~/.config/BetterDiscord/data/canary/settings.json` | `~/.config/BetterDiscord/data/ptb/settings.json` |
|
||||
|
||||
3. Insert a blank line after the first curly bracket (`{`), add the text `"DANGEROUS_ENABLE_DEVTOOLS_ONLY_ENABLE_IF_YOU_KNOW_WHAT_YOURE_DOING": true,` to it, and save the file. Your file should resemble the following:
|
||||
|
||||
```json
|
||||
{
|
||||
"DANGEROUS_ENABLE_DEVTOOLS_ONLY_ENABLE_IF_YOU_KNOW_WHAT_YOURE_DOING": true,
|
||||
"BACKGROUND_COLOR": "#202225",
|
||||
"IS_MAXIMIZED": true
|
||||
}
|
||||
```
|
||||
|
||||
4. Launch Discord.
|
||||
|
||||
5. To find your user token, continue [here](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#in-chrome).
|
||||
|
||||
##### Via settings menu (BetterDiscord only)
|
||||
|
||||
1. <img width="500" align="right" src="https://i.imgur.com/mu1g4OF.png" />Click the User Settings button (the gear icon to the right of your username). Discord’s settings page will open.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
2. <img width="500" align="right" src="https://i.imgur.com/qFrIKON.png" />In the sidebar to the left, click `Settings` under the `BetterDiscord` group. BetterDiscord’s settings page will display.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
3. <img width="500" align="right" src="https://i.imgur.com/48Re5kj.png" />In the main panel to the right, expand the `Developer Settings` group if necessary, and toggle `DevTools` to enabled.
|
||||
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
4. Press <kbd>Esc</kbd>. The settings page will close.
|
||||
|
||||
5. To find your user token, continue [here](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#in-chrome).
|
||||
|
||||
### How to get a Bot Token
|
||||
|
||||
**1.** Go to [Discord developer portal](https://discord.com/developers/applications)
|
||||
**2.** Open your Application's settings
|
||||
**3.** Navigate to the **Bot** section on the left
|
||||
**4.** Under **Token** click **Copy**
|
||||
|
||||
**Important**: your bot needs to have **Message Content Intent** enabled for it to be able to read messages!
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
### How to get a Server ID or a Server Channel ID
|
||||
|
||||
**1.** Open Discord Settings
|
||||
**2.** Go to the **Advanced** section
|
||||
**3.** Enable **Developer Mode**
|
||||
**4.** Right click on the desired server or channel and click Copy ID
|
||||
|
||||
### How to get a Direct Message Channel ID
|
||||
|
||||
**1.** Click the three dots next to any message in the channel you want to export.
|
||||
**2.** Paste the link into a text editor.
|
||||
**3.** Copy the text in the highlighted part of the link.
|
||||
|
||||
> E.g. in https꞉//discord.com/channels/@me/**189716987098470**/0985709387059874, you should copy **189716987098470**
|
||||
|
||||
Make sure you're not copying the user's ID.
|
||||
|
||||
**Alternatively, you can also:**
|
||||
**1.** Open the desired direct message channel
|
||||
**2.** Press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>I</kbd> (<kbd>⌥</kbd>+<kbd>⌘</kbd>+<kbd>I</kbd> on macOS) on Discord to show developer tools
|
||||
**3.** Navigate to the `Console` tab
|
||||
**4.** Type `window.location.href` and press Enter
|
||||
**5.** Copy the first long sequence of numbers inside the URL
|
||||
|
||||
> E.g. in https꞉//discord.com/channels/@me/**84289740160**, you should copy **84289740160**
|
||||
@@ -0,0 +1,171 @@
|
||||
# Troubleshooting
|
||||
|
||||
Welcome to the Frequently Asked Questions (FAQ) and Troubleshooting page!
|
||||
Here you'll find the answers to most of the questions related to **DiscordChatExporter** (DCE for short) and its core features.
|
||||
|
||||
❓ If you still have unanswered questions _after_ reading this page, feel free to [create a new discussion](https://github.com/Tyrrrz/DiscordChatExporter/discussions/new).
|
||||
🐞 If you have encountered a problem that's not described here, has not [been discussed before](https://github.com/Tyrrrz/DiscordChatExporter/discussions), and is not a [known issue](https://github.com/Tyrrrz/DiscordChatExporter/issues?q=is%3Aissue), please [create a new discussion](https://github.com/Tyrrrz/DiscordChatExporter/discussions/new) or [open a bug report](https://github.com/Tyrrrz/DiscordChatExporter/issues/new).
|
||||
Don't forget to include your platform (Windows, Mac, Linux, etc.) and a detailed description of your question/problem.
|
||||
|
||||
# General
|
||||
|
||||
### Token stealer?
|
||||
|
||||
No. That's why this kind of software needs to be open-source, so the code can be audited by anyone.
|
||||
Your token is only used to connect to Discord's API, it's not sent anywhere else.
|
||||
If you're using the GUI, be aware that your token will be saved to a plain text file unless you disable it in the settings menu.
|
||||
|
||||
### Why should I be worried about the safety of my token?
|
||||
|
||||
A token can be used to log into your account, so treat it like a password and never share it.
|
||||
|
||||
### How can I reset my token?
|
||||
|
||||
Follow the [instructions here](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md).
|
||||
|
||||
### Will I get banned if I use this?
|
||||
|
||||
Automating user accounts is technically against [TOS](https://discord.com/terms), use at your discretion. [Bot accounts](https://discord.com/developers/docs/topics/oauth2#bots) don't have this restriction.
|
||||
|
||||
### Will the messages disappear from the exported file if I delete a message, delete my account or block a person?
|
||||
|
||||
Text messages will not be removed from the exported file, but if media, such as images and user avatars, is changed or deleted, it will no longer be displayed. To avoid this, export using the "Download media" (`--media`) option.
|
||||
|
||||
### Can DCE export messages that have already been deleted?
|
||||
|
||||
No, DCE cannot access them since they have been permanently deleted from Discord's servers.
|
||||
|
||||
### Can DCE export private chats?
|
||||
|
||||
Yes, if your account has access to them.
|
||||
|
||||
### Can DCE download images?
|
||||
|
||||
Yes, and other media too. Export using the "Download media" (`--media`) option.
|
||||
|
||||
### Can the exported chats be shared?
|
||||
|
||||
Yes.
|
||||
|
||||
### Can DCE recreate the exported chats in Discord?
|
||||
|
||||
No, DCE is an exporter.
|
||||
|
||||
### Can DCE reupload exported messages to another channel?
|
||||
|
||||
No, DCE is an exporter.
|
||||
|
||||
# First steps
|
||||
|
||||
### How can I find my token?
|
||||
|
||||
Check the following page: [Obtaining token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md)
|
||||
|
||||
### When I open DCE a black window pops up quickly or nothing shows up.
|
||||
|
||||
If you have [.NET Core Runtime correctly installed](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Dotnet.md), you might have downloaded DCE.CLI, try [downloading the GUI](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#gui-or-cli) instead.
|
||||
|
||||
### I can't open DCE. It sends me to a Visual Studio webpage.
|
||||
|
||||
Check the following page:
|
||||
[Installation and usage](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Readme.md#installation--usage)
|
||||
|
||||
### How do I run DCE on macOS or Linux?
|
||||
|
||||
Check the following pages:
|
||||
|
||||
- [macOS usage instructions](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/MacOS.md)
|
||||
- [Linux usage instructions](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Linux.md)
|
||||
|
||||
### How can I set DCE to export automatically at certain times?
|
||||
|
||||
Check the following pages to learn how to schedule **DiscordChatExporter.CLI** runs (advanced):
|
||||
|
||||
- [Windows scheduling](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-windows.md)
|
||||
- [macOS scheduling](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-MacOS.md)
|
||||
- [Linux scheduling](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/scheduling-Linux.md)
|
||||
|
||||
### The exported file is too large, I can't open it!
|
||||
|
||||
Try opening it with a different program, try partitioning or use a different file format, like `PlainText`.
|
||||
|
||||
### DCE is crashing/failing.
|
||||
|
||||
Check the following page: [Installing .NET Core Runtime](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Dotnet.md)
|
||||
|
||||
If you already have .NET Core installed, please check if your problem is a [known issue](https://github.com/Tyrrrz/DiscordChatExporter/issues?q=is%3Aissue) before [opening a bug report](https://github.com/Tyrrrz/DiscordChatExporter/issues/new).
|
||||
|
||||
### .NET Core Runtime is required.
|
||||
|
||||
Check the following page: [Installing .NET Core Runtime](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Dotnet.md)
|
||||
|
||||
# CLI
|
||||
|
||||
### How do I use the CLI?
|
||||
|
||||
Check the following page:
|
||||
|
||||
- [Using the CLI](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#using-the-cli)
|
||||
|
||||
If you're using **Docker**, please refer to the [Docker Usage Instructions](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Docker.md) instead.
|
||||
|
||||
### Where can I find the 'Channel IDs'?
|
||||
|
||||
Check the following page:
|
||||
|
||||
- [Obtaining Channel IDs](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md)
|
||||
|
||||
### I can't find Docker exported chats
|
||||
|
||||
Check the following page:
|
||||
|
||||
- [Docker usage instructions](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/docker)
|
||||
|
||||
### I can't export Direct Messages
|
||||
|
||||
Make sure you're [copying the DM Channel ID](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md#how-to-get-a-direct-message-channel-id), not the person's user ID.
|
||||
|
||||
### Errors
|
||||
|
||||
```
|
||||
DiscordChatExporter.Domain.Exceptions.DiscordChatExporterException: Authentication token is invalid.
|
||||
...
|
||||
```
|
||||
|
||||
↳ Make sure the provided token is correct.
|
||||
|
||||
```
|
||||
DiscordChatExporter.Domain.Exceptions.DiscordChatExporterException: Requested resource does not exist.
|
||||
```
|
||||
|
||||
↳ Check your channel ID, it might be invalid. [Read this if you need help](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md).
|
||||
|
||||
```
|
||||
DiscordChatExporter.Domain.Exceptions.DiscordChatExporterException: Access is forbidden.
|
||||
```
|
||||
|
||||
↳ This means you don't have access to the channel.
|
||||
|
||||
```
|
||||
The application to execute does not exist:
|
||||
```
|
||||
|
||||
↳ The `DiscordChatExporter.Cli.dll` file is missing. Keep the `.exe` and all the `.dll` files together. If you didn't move the files, try unzipping again.
|
||||
|
||||
```
|
||||
System.Net.WebException: Error: TrustFailure ... Invalid certificate received from server.
|
||||
...
|
||||
```
|
||||
|
||||
↳ Try running cert-sync.
|
||||
|
||||
Debian/Ubuntu: `cert-sync /etc/ssl/certs/ca-certificates.crt`
|
||||
|
||||
Red Hat: `cert-sync --user /etc/pki/tls/certs/ca-bundle.crt`
|
||||
|
||||
If it still doesn't work, try mozroots: `mozroots --import --ask-remove`
|
||||
|
||||
---
|
||||
|
||||
❓ If you still have unanswered questions, feel free to [create a new discussion](https://github.com/Tyrrrz/DiscordChatExporter/discussions/new).
|
||||
🐞 If you have encountered a problem that's not described here, has not [been discussed before](https://github.com/Tyrrrz/DiscordChatExporter/discussions), and is not a [known issue](https://github.com/Tyrrrz/DiscordChatExporter/issues?q=is%3Aissue), please [create a new discussion](https://github.com/Tyrrrz/DiscordChatExporter/discussions/new) or [open a bug report](https://github.com/Tyrrrz/DiscordChatExporter/issues/new).
|
||||
@@ -1,3 +0,0 @@
|
||||
github: Tyrrrz
|
||||
patreon: Tyrrrz
|
||||
custom: ['buymeacoffee.com/Tyrrrz', 'tyrrrz.me/donate']
|
||||
@@ -1,7 +1,13 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: 📖 Wiki
|
||||
url: https://github.com/Tyrrrz/DiscordChatExporter/wiki
|
||||
- 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
|
||||
url: https://discord.gg/2SUWKFnHSm
|
||||
about: Chat with the project community.
|
||||
- name: 📖 Documentation
|
||||
url: https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs
|
||||
about: Find usage guides and frequently asked questions.
|
||||
- name: 🗨 Discussions
|
||||
url: https://github.com/Tyrrrz/DiscordChatExporter/discussions/new
|
||||
|
||||
@@ -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,71 +0,0 @@
|
||||
name: CD
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.3.3
|
||||
|
||||
- name: Install .NET (v3.1)
|
||||
uses: actions/setup-dotnet@v1.7.2
|
||||
with:
|
||||
dotnet-version: 3.1.x
|
||||
|
||||
- name: Install .NET (v5.0)
|
||||
uses: actions/setup-dotnet@v1.7.2
|
||||
with:
|
||||
dotnet-version: 5.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
|
||||
@@ -1,39 +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 (v3.1)
|
||||
uses: actions/setup-dotnet@v1.7.2
|
||||
with:
|
||||
dotnet-version: 3.1.x
|
||||
|
||||
- name: Install .NET (v5.0)
|
||||
uses: actions/setup-dotnet@v1.7.2
|
||||
with:
|
||||
dotnet-version: 5.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: 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,129 @@
|
||||
name: main
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: windows-latest
|
||||
|
||||
env:
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
|
||||
DOTNET_NOLOGO: true
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: true
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install .NET
|
||||
uses: actions/setup-dotnet@v2
|
||||
with:
|
||||
dotnet-version: 7.0.x
|
||||
|
||||
- name: Run tests
|
||||
# Tests need access to secrets, so we can't run them against PRs because of limited trust
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
run: dotnet test --configuration Release --logger GitHubActions --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
|
||||
env:
|
||||
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
|
||||
|
||||
- name: Upload coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
||||
package:
|
||||
needs: test
|
||||
runs-on: windows-latest
|
||||
|
||||
env:
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
|
||||
DOTNET_NOLOGO: true
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: true
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install .NET
|
||||
uses: actions/setup-dotnet@v2
|
||||
with:
|
||||
dotnet-version: 7.0.x
|
||||
|
||||
- name: Publish (CLI)
|
||||
run: dotnet publish DiscordChatExporter.Cli/ -o DiscordChatExporter.Cli/bin/Publish/ --configuration Release
|
||||
|
||||
- name: Publish (GUI)
|
||||
run: dotnet publish DiscordChatExporter.Gui/ -o DiscordChatExporter.Gui/bin/Publish/ --configuration Release
|
||||
|
||||
- name: Upload artifacts (CLI)
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DiscordChatExporter.Cli
|
||||
path: DiscordChatExporter.Cli/bin/Publish/
|
||||
|
||||
- name: Upload artifacts (GUI)
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DiscordChatExporter
|
||||
path: DiscordChatExporter.Gui/bin/Publish/
|
||||
|
||||
deploy:
|
||||
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
|
||||
needs: package
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Download artifacts (CLI)
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: DiscordChatExporter.Cli
|
||||
path: DiscordChatExporter.Cli
|
||||
|
||||
- name: Download artifacts (GUI)
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: DiscordChatExporter
|
||||
path: DiscordChatExporter.Gui
|
||||
|
||||
- name: Create package (CLI)
|
||||
run: Compress-Archive -Path DiscordChatExporter.Cli/* -DestinationPath DiscordChatExporter.Cli.zip -Force
|
||||
shell: pwsh
|
||||
|
||||
- name: Create package (GUI)
|
||||
run: Compress-Archive -Path DiscordChatExporter.Gui/* -DestinationPath DiscordChatExporter.zip -Force
|
||||
shell: pwsh
|
||||
|
||||
- name: Create release
|
||||
uses: softprops/action-gh-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
files: |
|
||||
DiscordChatExporter.Cli.zip
|
||||
DiscordChatExporter.zip
|
||||
body: |
|
||||
[Changelog](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/Changelog.md)
|
||||
|
||||
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
-1
@@ -5,6 +5,7 @@
|
||||
*.sln.docstates
|
||||
.idea/
|
||||
.vs/
|
||||
.vscode/
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
@@ -19,4 +20,7 @@ bld/
|
||||
[Oo]bj/
|
||||
|
||||
# Coverage
|
||||
*.opencover.xml
|
||||
*.opencover.xml
|
||||
|
||||
# Secrets
|
||||
*.secret
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 33 KiB |
+161
-2
@@ -1,3 +1,162 @@
|
||||
### v2.37.2 (27-Jan-2023)
|
||||
|
||||
- Updated the links inside the application to point to the new documentation site. (Thanks [@CanePlayz](https://github.com/CanePlayz))
|
||||
- [CLI] Fixed an issue that there was no visual indication that an export task has failed before the whole process has completed.
|
||||
- Fixed an issue where the application sometimes crashed when it couldn't establish an HTTP connection to the target server.
|
||||
|
||||
### v2.37.1 (10-Jan-2023)
|
||||
|
||||
- [HTML] Fixed an issue where the export failed because it failed to resolve standard emoji image assets. Switched to a different CDN provider to mitigate this. (Thanks [@Lucas LaBuff](https://github.com/96-LB))
|
||||
- [GUI] Fixed an application crash that happened when the user attempted to close the same dialog multiple times in a very short time.
|
||||
|
||||
### v2.37 (08-Jan-2023)
|
||||
|
||||
- Switched from .NET 6.0 to .NET 7.0. If running on Windows, the application should update all required prerequisites automatically. Alternatively, you can download the latest version of the runtime for your system [here](https://dotnet.microsoft.com/download/dotnet/7.0).
|
||||
- Updated rate limit handling to adjust automatically based on the response headers. This may result in exports taking longer than before on bot accounts, but it makes it less likely for Discord to throttle you. Exports with user accounts shouldn't be affected too much by this change.
|
||||
- Optimized snowflake parsing by removing unnecessary checks. (Thanks [@Kuba_Z2](https://github.com/KubaZ2))
|
||||
- [Docker] Optimized the Docker image size by using the Alpine base image and publishing a self-contained distribution. (Thanks [@Velithris](https://github.com/Zireael-N))
|
||||
- Fixed an issue where exporting a channel whose name ends with a dot would fail on Windows with default output path. The dots are now trimmed in file and directory names to match the behavior of Windows Explorer.
|
||||
|
||||
### v2.36.4 (29-Oct-2022)
|
||||
|
||||
- Changed all mentions of "media" in the context of "download media" or "reuse media" to "assets". CLI options will retain their existing names for backwards compatibility.
|
||||
- [HTML] Fixed an issue which prevented emoji used inside message content from being downloaded when "download assets" option is enabled. (Thanks [@Roberto Blázquez](https://github.com/xBaank))
|
||||
|
||||
### v2.36.3 (21-Oct-2022)
|
||||
|
||||
- [GUI] Fixed an issue where opening a dialog did not prevent user interactions with background UI elements using keyboard. This sometimes caused the application to crash in weird ways.
|
||||
- [Docker] Fixed an issue where DiscordChatExporter was running as root inside the container, making the exported files inaccessible to the host. (Thanks [@Benjamin Just](https://github.com/BamButz))
|
||||
|
||||
### v2.36.2 (08-Oct-2022)
|
||||
|
||||
- Removed the message content intent check because the heuristics turned out to be not reliable enough.
|
||||
- Fixed an issue where the runtime manifest included the wrong target runtime version. This resulted in the application failing to launch for some users when upgrading from earlier versions.
|
||||
|
||||
### v2.36.1 (24-Sep-2022)
|
||||
|
||||
- Added a check which will trigger an error if the provided bot account does not have the message content intent enabled. Note, however, that this check is based on heuristics which may result in false negatives.
|
||||
- Fixed an issue where certain transient HTTP errors were not retried.
|
||||
- Fixed an issue which caused the export process to fail with the `IndexOutOfRangeException` exception on certain automated messages.
|
||||
- Fixed an issue which caused the export process to fail on unrecognized embed types.
|
||||
|
||||
### v2.36 (16-Sep-2022)
|
||||
|
||||
- [HTML] Added support for rendering GIFV embeds. They will now render as videos that automatically play when you hover your mouse over them. (Thanks [@gan-of-culture](https://github.com/gan-of-culture))
|
||||
- [HTML] Added support for rendering system notification messages, such as when a user joins a server or when a messages gets pinned. Previously, such messages were rendered as regular text messages, but now they look similar to how they're presented in the Discord client. (Thanks [@gan-of-culture](https://github.com/gan-of-culture))
|
||||
- [CLI] Improved the wording of the error message that's shown when exporting multiple channels and the provided output path is ambiguous. It now mentions that you can resolve the ambiguity by adding a slash at the end of the path.
|
||||
|
||||
### v2.35.2 (08-Sep-2022)
|
||||
|
||||
- Updated usage guide to mention the need to enable "Message Content Intent" to use a bot as a medium for exporting messages.
|
||||
- [CLI] Fixed an issue where passing an existing directory as the output path failed when exporting multiple channels (for example, when running `exportdm`). An ambiguous output path will now always be treated as a directory path if that directory already exists. If it doesn't exist, it will be treated as a file path, matching the previous behavior.
|
||||
|
||||
### v2.35.1 (26-Aug-2022)
|
||||
|
||||
- Added `~` character as an alias for `-` when negating a message filter. This should make it easier to use negated filters from CLI where the dash character already has other meanings.
|
||||
- Extended retry logic to encompass all server-side errors from Discord API, instead of only `500 Internal Server Error`.
|
||||
- [CLI] Attempt to export multiple channels will now fail if provided with an output path that is neither a directory, nor a file name template. Previously, this resulted in all channels being exported to the same file, overwriting each other.
|
||||
- Fixed an issue where a text message filter didn't work if it started with a character that's also the first character in one of the named filters (e.g. `from` or `mentions`).
|
||||
- Fixed an issue where a text message filter didn't work correctly if it was enclosed in parentheses.
|
||||
- Fixed an issue where categories were displayed alongside regular channels in the channel list, both in GUI and in CLI (when using the `guild` command).
|
||||
- [CLI] Fixed an issue where an output path starting with a tilde on Linux was not expanded properly into a full path. (Thanks [@TSRBerry](https://github.com/TSRBerry))
|
||||
|
||||
### v2.35 (02-Jul-2022)
|
||||
|
||||
- Added support for exporting text chat in voice channels. These channels are now also displayed when browsing in the GUI and in the CLI when executing the `channels` command.
|
||||
- [GUI] Direct message channels are now sorted by the timestamp of their last message, similarly to how they appear in the Discord client.
|
||||
- [GUI] Removed artificial grouping of direct message channels into "Private" and "Group".
|
||||
- [CLI] Added runtime bootstrapper capabilities to the CLI flavor of DiscordChatExporter on Windows. Now, if you attempt to run the application without the required prerequisites installed, you will be provided with an option to install them automatically.
|
||||
- [CLI] Fixed outdated information in the usage guide. (Thanks [@Clint Herron](https://github.com/HanClinto))
|
||||
- [CLI] Added whitespace padding to the output of `guilds`, `channels`, and `dm` to make the tables look more uniform.
|
||||
- [HTML] Added hyperlinks to message timestamps, which allows you to quickly copy a link to a specific message in the export. (Thanks [@Philipp C. Heckel](https://github.com/binwiederhier))
|
||||
- [HTML] Added minification. Chat exports in HTML format are now 30-35% smaller than before.
|
||||
- [HTML] Added support for rendering embeds of Twitter posts that contain multiple images. Previously, this resulted in multiple separate embeds instead of one.
|
||||
- [HTML] Added support for rendering embeds of YouTube Shorts videos.
|
||||
- [HTML] Text content is now hidden if the message only contains a link to an image and nothing else. The link itself is resolved as an image embed.
|
||||
- [HTML] Fixed an issue where some emoji that included a zero-width-joiner rune were not rendered correctly due to a wrong Twemoji URL being generated. (Thanks [@Ethan](https://github.com/ethanndickson))
|
||||
- [HTML] Fixed an issue where replies to a message that contained a quote (i.e. `>`) were not rendered correctly.
|
||||
- [HTML] Fixed an issue where code blocks with language highlighting did not have the correct background color.
|
||||
- Added file name template token that resolves to the current date (`%d`). (Thanks [@Lucas LaBuff](https://github.com/96-LB))
|
||||
- Updated the usage guide to replace the instructions for retrieving the user token with those that appear to work for more people.
|
||||
- Updated the usage guide to feature the TOS warning more prominently.
|
||||
- [Docker] Changed internal working directory from `/app/out` to `/out`. This was an unintended breaking change. Please update your volume binding configuration from `-v /path/on/machine:/app/out` to `-v /path/on/machine:/out`.
|
||||
|
||||
### v2.34.1 (01-Jun-2022)
|
||||
|
||||
- Improved retry policy to handle more transient errors. This should result in fewer errors exporting a channel due to timeout.
|
||||
- Added `has:pin` message filter. You can use it to limit exported messages to those that have been pinned. (Thanks [@Andrew Kolos](https://github.com/andrewkolos))
|
||||
- Fixed an issue which caused the export to fail when processing stickers that have no name.
|
||||
|
||||
### v2.34 (10-Apr-2022)
|
||||
|
||||
- [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)
|
||||
|
||||
- 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).
|
||||
- [HTML] Updated layout design to match Discord more closely. (Thanks [@Artem](https://github.com/Scarg))
|
||||
- [HTML] Fixed an issue where markdown inside channel topic was not rendered correctly. (Thanks [@Emily](https://github.com/emillly-b))
|
||||
- [HTML] Fixed an issue where the layout was broken for messages containing text in right-to-left languages. (Thanks [@Emily](https://github.com/emillly-b))
|
||||
- Fixed an issue where text filters weren't matching content inside of embeds.
|
||||
- [GUI] Fixed a multitude of issues related to the bootstrapper.
|
||||
|
||||
### v2.30.1 (28-Aug-2021)
|
||||
|
||||
- [HTML] Changed user avatars to render using higher resolution images. (Thanks [@Chris Helder](https://github.com/TheDude53))
|
||||
- Fixed an issue where `has:file` message filter was not recognized. (Thanks [@Lucas LaBuff](https://github.com/96-LB))
|
||||
- Fixed an issue where a unix timestamp marker with an invalid offset crashed the export process.
|
||||
|
||||
### v2.30 (08-Aug-2021)
|
||||
|
||||
- [HTML] Added special casing for Spotify track embeds to render them directly using an embedded player.
|
||||
- [HTML] Added special casing for plain image embeds to render them like image attachments.
|
||||
- [HTML] Added tooltip text for unix timestamp markers which shows the full date represented by the timestamp, regardless of configured date format.
|
||||
- [HTML] Updated the fallback text shown when the referenced message could not be loaded to make it more explicit.
|
||||
- [HTML] Updated styling of quoted text in markdown to more closely resemble how it looks in Discord.
|
||||
- [HTML] Fixed an issue where some file formats were not correctly recognized as image or video attachments, which affected how they were rendered.
|
||||
- [HTML] Fixed an issue where formatting inside named links (e.g. `[**Bold link**](https://example.com)`) was not being parsed.
|
||||
- [HTML] Fixed an issue where inline embed fields were missing horizontal spacing between columns.
|
||||
- [HTML] Fixed other minor styling issues.
|
||||
|
||||
### v2.29 (19-Jul-2021)
|
||||
|
||||
- Added support for message filtering, which is accessible as an additional export parameter in the GUI and as the `--filter` option in the CLI. Message filters use a special syntax similar to Discord's search query syntax to allow specifying which messages should be included in the export. For example, you can limit the export to only include messages that contain image attachments (`has:image`) or messages from a certain user (`from:Tyrrrz`) or messages containing certain words (`hello world`), etc. You can also combine filters together (`hi mentions:Tyrrrz`, `from:Tyrrrz | from:96-LB`, `(mentions:Tyrrrz | from:Tyrrrz) has:image`) or negate them (`-has:link`). More thorough documentation coming soon. (Thanks [@Lucas LaBuff](https://github.com/96-LB))
|
||||
@@ -17,7 +176,7 @@
|
||||
- [HTML] Added special casing for YouTube video embeds to render them directly using an embedded player. (Thanks [@quentinmay](https://github.com/quentinmay))
|
||||
- [HTML] Added support for rendering standard emoji by code. Such emoji may sometimes be found in messages sent by bots or through webhooks. (Thanks [@CanePlayz](https://github.com/CanePlayz) and [@Lucas LaBuff](https://github.com/96-LB))
|
||||
- [HTML] Changed tooltips on standard emoji to show emoji code instead of their raw string representations. (Thanks [@CanePlayz](https://github.com/CanePlayz) and [@Lucas LaBuff](https://github.com/96-LB))
|
||||
- [HTML] Added tooltips on individual messages to show when those messages were sent.
|
||||
- [HTML] Added tooltips on individual messages to show when those messages were sent.
|
||||
- [HTML] Updated colors and minor styling elements to match Discord's new style direction after rebranding.
|
||||
- [HTML] Updated Twemoji URLs to use SVG image variants for better rendering quality.
|
||||
- [HTML] Changed user avatar URLs to include predetermined size query parameter for better rendering quality.
|
||||
@@ -113,7 +272,7 @@
|
||||
- Added a new option that enables self-contained exports for all output formats. You can turn it on in the export setup dialog in GUI or using the `--media` option in CLI. When using this, the application will additionally download any media content directly referenced from the exported file instead of linking back to Discord CDN. The files which are downloaded include: guild icons, user avatars, attachments, embedded images, reaction emoji. Note that only files which are actually referenced by the export are downloaded, which means that, for example, user avatars will not be downloaded when using plain text export format. This option is not meant to enable complete offline viewing for HTML exports, but rather to make it easier to archive media content that may eventually get deleted from Discord servers. Also keep in mind that this option may make the export drastically slower and the total file size larger.
|
||||
- Changed "discordapp.com" to "discord.com" where applicable as Discord is migrating to a new domain. CDN will remain on "cdn.discordapp.com" for the foreseeable future.
|
||||
|
||||
Note that all existing and current HTML exports will likely not render accurately because Discord enabled CORS for their font resources, which prevents them from loading locally. Please refer to [issue #322](https://github.com/Tyrrrz/DiscordChatExporter/issues/322) for discussion on this topic.
|
||||
Note that all existing and current HTML exports will likely not render accurately because Discord enabled CORS for their font resources, which prevents them from loading locally. Please refer to [issue #322](https://github.com/Tyrrrz/DiscordChatExporter/issues/322) for discussion on this topic.
|
||||
|
||||
### v2.20 (27-Apr-2020)
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<Version>2.29</Version>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Version>2.37.2</Version>
|
||||
<Company>Tyrrrz</Company>
|
||||
<Copyright>Copyright (c) Alexey Golub</Copyright>
|
||||
<Copyright>Copyright (c) Oleksii Holub</Copyright>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<WarningsAsErrors>nullable</WarningsAsErrors>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
|
||||
<None Include="*.secret" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AngleSharp" Version="1.0.1" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.9.0" />
|
||||
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.1" PrivateAssets="all" />
|
||||
<PackageReference Include="JsonExtensions" Version="1.2.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
|
||||
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" PrivateAssets="all" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DiscordChatExporter.Cli\DiscordChatExporter.Cli.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
using AngleSharp.Html.Dom;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Cli.Tests.Utils;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
using JsonExtensions;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
|
||||
public class ExportWrapperFixture : IDisposable
|
||||
{
|
||||
private string DirPath { get; } = Path.Combine(
|
||||
Path.GetDirectoryName(typeof(ExportWrapperFixture).Assembly.Location) ?? Directory.GetCurrentDirectory(),
|
||||
"ExportCache",
|
||||
Guid.NewGuid().ToString()
|
||||
);
|
||||
|
||||
public ExportWrapperFixture() => DirectoryEx.Reset(DirPath);
|
||||
|
||||
private async ValueTask<string> ExportAsync(Snowflake channelId, ExportFormat format)
|
||||
{
|
||||
var fileName = channelId.ToString() + '.' + format.GetFileExtension();
|
||||
var filePath = Path.Combine(DirPath, fileName);
|
||||
|
||||
// Perform export only if it hasn't been done before
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { channelId },
|
||||
ExportFormat = format,
|
||||
OutputPath = filePath
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
}
|
||||
|
||||
return await File.ReadAllTextAsync(filePath);
|
||||
}
|
||||
|
||||
public async ValueTask<IHtmlDocument> ExportAsHtmlAsync(Snowflake channelId) => Html.Parse(
|
||||
await ExportAsync(channelId, ExportFormat.HtmlDark)
|
||||
);
|
||||
|
||||
public async ValueTask<JsonElement> ExportAsJsonAsync(Snowflake channelId) => Json.Parse(
|
||||
await ExportAsync(channelId, ExportFormat.Json)
|
||||
);
|
||||
|
||||
public async ValueTask<string> ExportAsPlainTextAsync(Snowflake channelId) =>
|
||||
await ExportAsync(channelId, ExportFormat.PlainText);
|
||||
|
||||
public async ValueTask<string> ExportAsCsvAsync(Snowflake channelId) =>
|
||||
await ExportAsync(channelId, ExportFormat.Csv);
|
||||
|
||||
public async ValueTask<IReadOnlyList<IElement>> GetMessagesAsHtmlAsync(Snowflake channelId) =>
|
||||
(await ExportAsHtmlAsync(channelId))
|
||||
.QuerySelectorAll("[data-message-id]")
|
||||
.ToArray();
|
||||
|
||||
public async ValueTask<IReadOnlyList<JsonElement>> GetMessagesAsJsonAsync(Snowflake channelId) =>
|
||||
(await ExportAsJsonAsync(channelId))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.ToArray();
|
||||
|
||||
public async ValueTask<IElement> GetMessageAsHtmlAsync(Snowflake channelId, Snowflake messageId)
|
||||
{
|
||||
var message = (await GetMessagesAsHtmlAsync(channelId))
|
||||
.SingleOrDefault(e =>
|
||||
string.Equals(
|
||||
e.GetAttribute("data-message-id"),
|
||||
messageId.ToString(),
|
||||
StringComparison.OrdinalIgnoreCase
|
||||
)
|
||||
);
|
||||
|
||||
if (message is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Message '{messageId}' does not exist in the export of channel '{channelId}'."
|
||||
);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public async ValueTask<JsonElement> GetMessageAsJsonAsync(Snowflake channelId, Snowflake messageId)
|
||||
{
|
||||
var message = (await GetMessagesAsJsonAsync(channelId))
|
||||
.SingleOrDefault(j =>
|
||||
string.Equals(
|
||||
j.GetProperty("id").GetString(),
|
||||
messageId.ToString(),
|
||||
StringComparison.OrdinalIgnoreCase
|
||||
)
|
||||
);
|
||||
|
||||
if (message.ValueKind == JsonValueKind.Undefined)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Message '{messageId}' does not exist in the export of channel '{channelId}'."
|
||||
);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public void Dispose() => DirectoryEx.DeleteIfExists(DirPath);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using DiscordChatExporter.Cli.Tests.Utils;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
|
||||
public class TempOutputFixture : IDisposable
|
||||
{
|
||||
public string DirPath { get; } = Path.Combine(
|
||||
Path.GetDirectoryName(typeof(TempOutputFixture).Assembly.Location) ?? Directory.GetCurrentDirectory(),
|
||||
"Temp",
|
||||
Guid.NewGuid().ToString()
|
||||
);
|
||||
|
||||
public TempOutputFixture() => DirectoryEx.Reset(DirPath);
|
||||
|
||||
public string GetTempFilePath(string fileName) => Path.Combine(DirPath, fileName);
|
||||
|
||||
public string GetTempFilePath() => GetTempFilePath(Guid.NewGuid() + ".tmp");
|
||||
|
||||
public void Dispose() => DirectoryEx.DeleteIfExists(DirPath);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Infra;
|
||||
|
||||
internal static class Secrets
|
||||
{
|
||||
private static readonly Lazy<string> DiscordTokenLazy = new(() =>
|
||||
{
|
||||
var fromEnvironment = Environment.GetEnvironmentVariable("DISCORD_TOKEN");
|
||||
if (!string.IsNullOrWhiteSpace(fromEnvironment))
|
||||
return fromEnvironment;
|
||||
|
||||
var secretFilePath = Path.Combine(
|
||||
Path.GetDirectoryName(typeof(Secrets).Assembly.Location) ?? Directory.GetCurrentDirectory(),
|
||||
"DiscordToken.secret"
|
||||
);
|
||||
|
||||
if (File.Exists(secretFilePath))
|
||||
return File.ReadAllText(secretFilePath);
|
||||
|
||||
throw new InvalidOperationException("Discord token not provided for tests.");
|
||||
});
|
||||
|
||||
public static string DiscordToken => DiscordTokenLazy.Value;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
# DiscordChatExporter Tests
|
||||
|
||||
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.
|
||||
|
||||
1. [Join the test server](https://discord.gg/eRV8Vap5bm)
|
||||
2. Locate your Discord authentication token
|
||||
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 an environment variable**: set `DISCORD_TOKEN` variable to your token
|
||||
4. Run the tests: `dotnet test`
|
||||
|
||||
> If you want to add a new test case, please let me know and I will give you the required permissions
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.CsvWriting;
|
||||
|
||||
public class ContentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public ContentSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
{
|
||||
// Act
|
||||
var document = await _exportWrapper.ExportAsCsvAsync(ChannelIds.DateRangeTestCases);
|
||||
|
||||
// Assert
|
||||
document.Should().ContainAll(
|
||||
"Tyrrrz#5447",
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
using FluentAssertions;
|
||||
using JsonExtensions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class DateRangeSpecs : IClassFixture<TempOutputFixture>
|
||||
{
|
||||
private readonly TempOutputFixture _tempOutput;
|
||||
|
||||
public DateRangeSpecs(TempOutputFixture tempOutput)
|
||||
{
|
||||
_tempOutput = tempOutput;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_after_specific_date_only_include_messages_sent_after_that_date()
|
||||
{
|
||||
// Arrange
|
||||
var after = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
After = Snowflake.FromDate(after)
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
var timestamps = Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
|
||||
.ToArray();
|
||||
|
||||
timestamps.All(t => t > after).Should().BeTrue();
|
||||
|
||||
timestamps.Should().BeEquivalentTo(new[]
|
||||
{
|
||||
new DateTimeOffset(2021, 07, 24, 13, 49, 13, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 38, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 39, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 40, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 09, 08, 14, 26, 35, TimeSpan.Zero)
|
||||
}, o =>
|
||||
{
|
||||
return o
|
||||
.Using<DateTimeOffset>(ctx =>
|
||||
ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromSeconds(1))
|
||||
)
|
||||
.WhenTypeIs<DateTimeOffset>();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_before_specific_date_only_include_messages_sent_before_that_date()
|
||||
{
|
||||
// Arrange
|
||||
var before = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
Before = Snowflake.FromDate(before)
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
var timestamps = Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
|
||||
.ToArray();
|
||||
|
||||
timestamps.All(t => t < before).Should().BeTrue();
|
||||
|
||||
timestamps.Should().BeEquivalentTo(new[]
|
||||
{
|
||||
new DateTimeOffset(2021, 07, 19, 13, 34, 18, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 19, 15, 58, 48, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 19, 17, 23, 58, TimeSpan.Zero)
|
||||
}, o =>
|
||||
{
|
||||
return o
|
||||
.Using<DateTimeOffset>(ctx =>
|
||||
ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromSeconds(1))
|
||||
)
|
||||
.WhenTypeIs<DateTimeOffset>();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_between_specific_dates_only_include_messages_sent_between_those_dates()
|
||||
{
|
||||
// Arrange
|
||||
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 filePath = _tempOutput.GetTempFilePath();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
Before = Snowflake.FromDate(before),
|
||||
After = Snowflake.FromDate(after)
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
var timestamps = Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
|
||||
.ToArray();
|
||||
|
||||
timestamps.All(t => t < before && t > after).Should().BeTrue();
|
||||
|
||||
timestamps.Should().BeEquivalentTo(new[]
|
||||
{
|
||||
new DateTimeOffset(2021, 07, 24, 13, 49, 13, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 38, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 39, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 40, TimeSpan.Zero)
|
||||
}, o =>
|
||||
{
|
||||
return o
|
||||
.Using<DateTimeOffset>(ctx =>
|
||||
ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromSeconds(1))
|
||||
)
|
||||
.WhenTypeIs<DateTimeOffset>();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
using DiscordChatExporter.Core.Exporting.Filtering;
|
||||
using FluentAssertions;
|
||||
using JsonExtensions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class FilterSpecs : IClassFixture<TempOutputFixture>
|
||||
{
|
||||
private readonly TempOutputFixture _tempOutput;
|
||||
|
||||
public FilterSpecs(TempOutputFixture tempOutput)
|
||||
{
|
||||
_tempOutput = tempOutput;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_text_only_include_messages_that_contain_that_text()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("some text")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
.Should()
|
||||
.ContainSingle("Some random text");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_author_only_include_messages_sent_by_that_author()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("from:Tyrrrz")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("author").GetProperty("name").GetString())
|
||||
.Should()
|
||||
.AllBe("Tyrrrz");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_content_only_include_messages_that_have_that_content()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("has:image")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
.Should()
|
||||
.ContainSingle("This has image");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_pin_only_include_messages_that_have_been_pinned()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("has:pin")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
.Should()
|
||||
.ContainSingle("This is pinned");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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 },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("mentions:Tyrrrz")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
.Should()
|
||||
.ContainSingle("This has mention");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
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 AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public AttachmentSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_generic_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885587844989612074")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().ContainAll(
|
||||
"Generic file attachment",
|
||||
"Test.txt",
|
||||
"11 bytes"
|
||||
);
|
||||
|
||||
message
|
||||
.QuerySelectorAll("a")
|
||||
.Select(e => e.GetAttribute("href"))
|
||||
.Should()
|
||||
.Contain(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_image_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885654862656843786")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Image attachment");
|
||||
|
||||
message
|
||||
.QuerySelectorAll("img")
|
||||
.Select(e => e.GetAttribute("src"))
|
||||
.Should()
|
||||
.Contain(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_video_attachment_is_rendered_correctly()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/333
|
||||
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885655761919836171")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Video attachment");
|
||||
|
||||
var videoUrl = message.QuerySelector("video source")?.GetAttribute("src");
|
||||
videoUrl.Should().Be(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_audio_attachment_is_rendered_correctly()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/333
|
||||
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885656175620808734")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Audio attachment");
|
||||
|
||||
var audioUrl = message.QuerySelector("audio source")?.GetAttribute("src");
|
||||
audioUrl.Should().Be(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||
|
||||
public class ContentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public ContentSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
{
|
||||
// Act
|
||||
var messages = await _exportWrapper.GetMessagesAsHtmlAsync(ChannelIds.DateRangeTestCases);
|
||||
|
||||
// Assert
|
||||
messages.Select(e => e.GetAttribute("data-message-id")).Should().Equal(
|
||||
"866674314627121232",
|
||||
"866710679758045195",
|
||||
"866732113319428096",
|
||||
"868490009366396958",
|
||||
"868505966528835604",
|
||||
"868505969821364245",
|
||||
"868505973294268457",
|
||||
"885169254029213696"
|
||||
);
|
||||
|
||||
messages.SelectMany(e => e.Text()).Should().ContainInOrder(
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
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 EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public EmbedSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_embed_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("866769910729146400")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().ContainAll(
|
||||
"Embed author",
|
||||
"Embed title",
|
||||
"Embed description",
|
||||
"Field 1", "Value 1",
|
||||
"Field 2", "Value 2",
|
||||
"Field 3", "Value 3",
|
||||
"Embed footer"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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
|
||||
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,
|
||||
Snowflake.Parse("867886632203976775")
|
||||
);
|
||||
|
||||
// Assert
|
||||
var iframeUrl = message.QuerySelector("iframe")?.GetAttribute("src");
|
||||
iframeUrl.Should().Be("https://open.spotify.com/embed/track/1LHZMWefF9502NPfArRfvP");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_containing_a_YouTube_video_link_is_rendered_with_a_video_embed()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/570
|
||||
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("866472508588294165")
|
||||
);
|
||||
|
||||
// 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
|
||||
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"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
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 MentionSpecs : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public MentionSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task User_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866458840245076028")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("User mention: @Tyrrrz");
|
||||
message.InnerHtml.Should().Contain("Tyrrrz#5447");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Text_channel_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459040480624680")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Text channel mention: #mention-tests");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Voice_channel_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459175462633503")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Voice channel mention: 🔊chaos-vc");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Role_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459254693429258")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Role mention: @Role 1");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
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 ReplySpecs : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public ReplySpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Reply_to_a_normal_message_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.ReplyTestCases,
|
||||
Snowflake.Parse("866460738239725598")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("reply to original");
|
||||
message.QuerySelector(".chatlog__reference-link")?.Text().Should().Contain("original");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Reply_to_a_deleted_message_is_rendered_correctly()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/645
|
||||
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.ReplyTestCases,
|
||||
Snowflake.Parse("866460975388819486")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("reply to deleted");
|
||||
message.QuerySelector(".chatlog__reference-link")?.Text().Should().Contain(
|
||||
"Original message was deleted or could not be loaded."
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Reply_to_an_empty_message_with_attachment_is_rendered_correctly()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/634
|
||||
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.ReplyTestCases,
|
||||
Snowflake.Parse("866462470335627294")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("reply to attachment");
|
||||
message.QuerySelector(".chatlog__reference-link")?.Text().Should().Contain("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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
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 AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public AttachmentSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_generic_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885587844989612074")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Generic file attachment");
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().Be(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("Test.txt");
|
||||
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(11);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_image_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885654862656843786")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Image attachment");
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().Be(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("bird-thumbnail.png");
|
||||
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(466335);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_video_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885655761919836171")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Video attachment");
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().Be(
|
||||
"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("fileSizeBytes").GetInt64().Should().Be(3114374);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_audio_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885656175620808734")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Audio attachment");
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().Be(
|
||||
"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("fileSizeBytes").GetInt64().Should().Be(1087849);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||
|
||||
public class ContentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public ContentSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
{
|
||||
// Act
|
||||
var messages = await _exportWrapper.GetMessagesAsJsonAsync(ChannelIds.DateRangeTestCases);
|
||||
|
||||
// Assert
|
||||
messages.Select(j => j.GetProperty("id").GetString()).Should().Equal(
|
||||
"866674314627121232",
|
||||
"866710679758045195",
|
||||
"866732113319428096",
|
||||
"868490009366396958",
|
||||
"868505966528835604",
|
||||
"868505969821364245",
|
||||
"868505973294268457",
|
||||
"885169254029213696"
|
||||
);
|
||||
|
||||
messages.Select(j => j.GetProperty("content").GetString()).Should().Equal(
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
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 EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public EmbedSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_embed_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("866769910729146400")
|
||||
);
|
||||
|
||||
// Assert
|
||||
var embed = message.GetProperty("embeds").EnumerateArray().Single();
|
||||
embed.GetProperty("title").GetString().Should().Be("Embed title");
|
||||
embed.GetProperty("url").GetString().Should().Be("https://example.com");
|
||||
embed.GetProperty("timestamp").GetString().Should().Be("2021-07-14T21:00:00+00:00");
|
||||
embed.GetProperty("description").GetString().Should().Be("**Embed** _description_");
|
||||
embed.GetProperty("color").GetString().Should().Be("#58B9FF");
|
||||
|
||||
var embedAuthor = embed.GetProperty("author");
|
||||
embedAuthor.GetProperty("name").GetString().Should().Be("Embed author");
|
||||
embedAuthor.GetProperty("url").GetString().Should().Be("https://example.com/author");
|
||||
embedAuthor.GetProperty("iconUrl").GetString().Should().NotBeNullOrWhiteSpace();
|
||||
|
||||
var embedThumbnail = embed.GetProperty("thumbnail");
|
||||
embedThumbnail.GetProperty("url").GetString().Should().NotBeNullOrWhiteSpace();
|
||||
embedThumbnail.GetProperty("width").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("iconUrl").GetString().Should().NotBeNullOrWhiteSpace();
|
||||
|
||||
var embedFields = embed.GetProperty("fields").EnumerateArray().ToArray();
|
||||
embedFields.Should().HaveCount(3);
|
||||
embedFields[0].GetProperty("name").GetString().Should().Be("Field 1");
|
||||
embedFields[0].GetProperty("value").GetString().Should().Be("Value 1");
|
||||
embedFields[0].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
||||
embedFields[1].GetProperty("name").GetString().Should().Be("Field 2");
|
||||
embedFields[1].GetProperty("value").GetString().Should().Be("Value 2");
|
||||
embedFields[1].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
||||
embedFields[2].GetProperty("name").GetString().Should().Be("Field 3");
|
||||
embedFields[2].GetProperty("value").GetString().Should().Be("Value 3");
|
||||
embedFields[2].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
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 MentionSpecs : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public MentionSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task User_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866458840245076028")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("User mention: @Tyrrrz");
|
||||
|
||||
message
|
||||
.GetProperty("mentions")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("id").GetString())
|
||||
.Should()
|
||||
.Contain("128178626683338752");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Text_channel_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459040480624680")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Text channel mention: #mention-tests");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Voice_channel_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459175462633503")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Voice channel mention: #chaos-vc [voice]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Role_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459254693429258")
|
||||
);
|
||||
|
||||
// Assert
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
using DiscordChatExporter.Core.Exporting.Partitioning;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class PartitioningSpecs : IClassFixture<TempOutputFixture>
|
||||
{
|
||||
private readonly TempOutputFixture _tempOutput;
|
||||
|
||||
public PartitioningSpecs(TempOutputFixture tempOutput)
|
||||
{
|
||||
_tempOutput = tempOutput;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_partitioned_by_count_are_split_into_a_corresponding_number_of_files()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
|
||||
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.HtmlDark,
|
||||
OutputPath = filePath,
|
||||
PartitionLimit = PartitionLimit.Parse("3")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
|
||||
.Should()
|
||||
.HaveCount(3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_partitioned_by_file_size_are_split_into_a_corresponding_number_of_files()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
|
||||
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.HtmlDark,
|
||||
OutputPath = filePath,
|
||||
PartitionLimit = PartitionLimit.Parse("1kb")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
|
||||
.Should()
|
||||
.HaveCount(8);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.PlainTextWriting;
|
||||
|
||||
public class ContentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public ContentSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
{
|
||||
// Act
|
||||
var document = await _exportWrapper.ExportAsPlainTextAsync(ChannelIds.DateRangeTestCases);
|
||||
|
||||
// Assert
|
||||
document.Should().ContainAll(
|
||||
"Tyrrrz#5447",
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
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;
|
||||
|
||||
public class SelfContainedSpecs : IClassFixture<TempOutputFixture>
|
||||
{
|
||||
private readonly TempOutputFixture _tempOutput;
|
||||
|
||||
public SelfContainedSpecs(TempOutputFixture tempOutput)
|
||||
{
|
||||
_tempOutput = tempOutput;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_in_self_contained_export_only_reference_local_file_resources()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.SelfContainedTestCases },
|
||||
ExportFormat = ExportFormat.HtmlDark,
|
||||
OutputPath = filePath,
|
||||
ShouldDownloadAssets = true
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Html
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.QuerySelectorAll("body [src]")
|
||||
.Select(e => e.GetAttribute("src")!)
|
||||
.Select(f => Path.GetFullPath(f, dirPath))
|
||||
.All(File.Exists)
|
||||
.Should()
|
||||
.BeTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.TestData;
|
||||
|
||||
public static class ChannelIds
|
||||
{
|
||||
public static Snowflake AttachmentTestCases { get; } = Snowflake.Parse("885587741654536192");
|
||||
|
||||
public static Snowflake DateRangeTestCases { get; } = Snowflake.Parse("866674248747319326");
|
||||
|
||||
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 MentionTestCases { get; } = Snowflake.Parse("866458801389174794");
|
||||
|
||||
public static Snowflake ReplyTestCases { get; } = Snowflake.Parse("866459871934677052");
|
||||
|
||||
public static Snowflake SelfContainedTestCases { get; } = Snowflake.Parse("887441432678379560");
|
||||
|
||||
public static Snowflake StickerTestCases { get; } = Snowflake.Parse("939668868253769729");
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.IO;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Utils;
|
||||
|
||||
internal static class DirectoryEx
|
||||
{
|
||||
public static void DeleteIfExists(string dirPath, bool recursive = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(dirPath, recursive);
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static void Reset(string dirPath)
|
||||
{
|
||||
DeleteIfExists(dirPath);
|
||||
Directory.CreateDirectory(dirPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using AngleSharp.Html.Dom;
|
||||
using AngleSharp.Html.Parser;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Utils;
|
||||
|
||||
internal static class Html
|
||||
{
|
||||
private static readonly IHtmlParser Parser = new HtmlParser();
|
||||
|
||||
public static IHtmlDocument Parse(string source) => Parser.ParseDocument(source);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
|
||||
"methodDisplayOptions": "all",
|
||||
"methodDisplay": "method"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
# -- Build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
|
||||
|
||||
WORKDIR /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 \
|
||||
--self-contained \
|
||||
--use-current-runtime \
|
||||
--configuration Release \
|
||||
--output ./publish
|
||||
|
||||
# -- Run
|
||||
FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine
|
||||
|
||||
# Alpine dotnet image doesn't include timezone data, which is needed
|
||||
# for certain date/time operations.
|
||||
RUN apk add --no-cache tzdata
|
||||
|
||||
# Create a non-root user to run the app, so that the output files
|
||||
# can be accessed by the host.
|
||||
# https://github.com/Tyrrrz/DiscordChatExporter/issues/851
|
||||
RUN adduser \
|
||||
--disabled-password \
|
||||
--no-create-home \
|
||||
dce
|
||||
|
||||
USER dce
|
||||
|
||||
COPY --from=build /build/publish /opt/dce
|
||||
|
||||
# Need to keep this as /out for backwards compatibility with documentation.
|
||||
# A lot of people have this directory mounted in their scripts files, so
|
||||
# changing it would break existing workflows.
|
||||
WORKDIR /out
|
||||
|
||||
# Add the app directory to PATH so that it's easier to debug using a shell
|
||||
ENV PATH="$PATH:/opt/dce"
|
||||
ENTRYPOINT ["DiscordChatExporter.Cli"]
|
||||
@@ -14,135 +14,248 @@ using DiscordChatExporter.Core.Exceptions;
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
using DiscordChatExporter.Core.Exporting.Filtering;
|
||||
using DiscordChatExporter.Core.Exporting.Partitioning;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using Tyrrrz.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. Directory path should end in a slash."
|
||||
)]
|
||||
public string OutputPath
|
||||
{
|
||||
[CommandOption("output", 'o', Description = "Output file or directory path.")]
|
||||
public string OutputPath { get; init; } = Directory.GetCurrentDirectory();
|
||||
get => _outputPath;
|
||||
// Handle ~/ in paths on Unix 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;
|
||||
[CommandOption(
|
||||
"format",
|
||||
'f',
|
||||
Description = "Export format."
|
||||
)]
|
||||
public ExportFormat ExportFormat { get; init; } = ExportFormat.HtmlDark;
|
||||
|
||||
[CommandOption("after", Description = "Only include messages sent after this date or message ID.")]
|
||||
public Snowflake? After { get; init; }
|
||||
[CommandOption(
|
||||
"after",
|
||||
Description = "Only include messages sent after this date or message ID."
|
||||
)]
|
||||
public Snowflake? After { get; init; }
|
||||
|
||||
[CommandOption("before", Description = "Only include messages sent before this date or message ID.")]
|
||||
public Snowflake? Before { get; init; }
|
||||
[CommandOption(
|
||||
"before",
|
||||
Description = "Only include messages sent before this date or message ID."
|
||||
)]
|
||||
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').")]
|
||||
public PartitionLimit PartitionLimit { get; init; } = PartitionLimit.Null;
|
||||
[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;
|
||||
|
||||
[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;
|
||||
[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;
|
||||
|
||||
[CommandOption("parallel", Description = "Limits how many channels can be exported in parallel.")]
|
||||
public int ParallelLimit { get; init; } = 1;
|
||||
[CommandOption(
|
||||
"parallel",
|
||||
Description = "Limits how many channels can be exported in parallel."
|
||||
)]
|
||||
public int ParallelLimit { get; init; } = 1;
|
||||
|
||||
[CommandOption("media", Description = "Download referenced media content.")]
|
||||
public bool ShouldDownloadMedia { get; init; }
|
||||
[CommandOption(
|
||||
"media",
|
||||
Description = "Download assets referenced by the export (user avatars, attached files, embedded images, etc.)."
|
||||
)]
|
||||
public bool ShouldDownloadAssets { get; init; }
|
||||
|
||||
[CommandOption("reuse-media", Description = "Reuse already existing media content to skip redundant downloads.")]
|
||||
public bool ShouldReuseMedia { get; init; }
|
||||
[CommandOption(
|
||||
"reuse-media",
|
||||
Description = "Reuse previously downloaded assets to avoid redundant requests."
|
||||
)]
|
||||
public bool ShouldReuseAssets { get; init; }
|
||||
|
||||
[CommandOption("dateformat", Description = "Format used when writing dates.")]
|
||||
public string DateFormat { get; init; } = "dd-MMM-yy hh:mm tt";
|
||||
[CommandOption(
|
||||
"dateformat",
|
||||
Description = "Format used when writing dates."
|
||||
)]
|
||||
public string DateFormat { get; init; } = "dd-MMM-yy hh:mm tt";
|
||||
|
||||
private ChannelExporter? _channelExporter;
|
||||
protected ChannelExporter Exporter => _channelExporter ??= new ChannelExporter(Discord);
|
||||
[CommandOption(
|
||||
"fuck-russia",
|
||||
Description = "Don't print the Support Ukraine message to the console."
|
||||
)]
|
||||
public bool IsUkraineSupportMessageDisabled { get; init; }
|
||||
|
||||
protected async ValueTask ExportAsync(IConsole console, IReadOnlyList<Channel> channels)
|
||||
private ChannelExporter? _channelExporter;
|
||||
protected ChannelExporter Exporter => _channelExporter ??= new ChannelExporter(Discord);
|
||||
|
||||
protected async ValueTask ExecuteAsync(IConsole console, IReadOnlyList<Channel> channels)
|
||||
{
|
||||
// Reuse assets option should only be used when the download assets option is set.
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/425
|
||||
if (ShouldReuseAssets && !ShouldDownloadAssets)
|
||||
{
|
||||
await console.Output.WriteLineAsync($"Exporting {channels.Count} channel(s)...");
|
||||
throw new CommandException(
|
||||
"Option --reuse-media cannot be used without --media."
|
||||
);
|
||||
}
|
||||
|
||||
var errors = new ConcurrentDictionary<Channel, string>();
|
||||
// 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);
|
||||
|
||||
// Wrap everything in a progress ticker
|
||||
await console.CreateProgressTicker().StartAsync(async progressContext =>
|
||||
{
|
||||
await channels.ParallelForEachAsync(async channel =>
|
||||
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>();
|
||||
|
||||
// Export
|
||||
await console.Output.WriteLineAsync($"Exporting {channels.Count} channel(s)...");
|
||||
await console.CreateProgressTicker().StartAsync(async progressContext =>
|
||||
{
|
||||
await Parallel.ForEachAsync(
|
||||
channels,
|
||||
new ParallelOptions
|
||||
{
|
||||
MaxDegreeOfParallelism = Math.Max(1, ParallelLimit),
|
||||
CancellationToken = cancellationToken
|
||||
},
|
||||
async (channel, innerCancellationToken) =>
|
||||
{
|
||||
// Export
|
||||
try
|
||||
{
|
||||
await progressContext.StartTaskAsync($"{channel.Category} / {channel.Name}", async progress =>
|
||||
{
|
||||
var guild = await Discord.GetGuildAsync(channel.GuildId);
|
||||
await progressContext.StartTaskAsync(
|
||||
$"{channel.Category.Name} / {channel.Name}",
|
||||
async progress =>
|
||||
{
|
||||
var guild = await Discord.GetGuildAsync(channel.GuildId, innerCancellationToken);
|
||||
|
||||
var request = new ExportRequest(
|
||||
guild,
|
||||
channel,
|
||||
OutputPath,
|
||||
ExportFormat,
|
||||
After,
|
||||
Before,
|
||||
PartitionLimit,
|
||||
MessageFilter,
|
||||
ShouldDownloadMedia,
|
||||
ShouldReuseMedia,
|
||||
DateFormat
|
||||
);
|
||||
var request = new ExportRequest(
|
||||
guild,
|
||||
channel,
|
||||
OutputPath,
|
||||
ExportFormat,
|
||||
After,
|
||||
Before,
|
||||
PartitionLimit,
|
||||
MessageFilter,
|
||||
ShouldDownloadAssets,
|
||||
ShouldReuseAssets,
|
||||
DateFormat
|
||||
);
|
||||
|
||||
await Exporter.ExportChannelAsync(request, progress);
|
||||
});
|
||||
await Exporter.ExportChannelAsync(
|
||||
request,
|
||||
progress.ToPercentageBased(),
|
||||
innerCancellationToken
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (DiscordChatExporterException ex) when (!ex.IsCritical)
|
||||
catch (DiscordChatExporterException ex) when (!ex.IsFatal)
|
||||
{
|
||||
errors[channel] = ex.Message;
|
||||
}
|
||||
}, ParallelLimit.ClampMin(1));
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// Print result
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
// Print result
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
{
|
||||
await console.Output.WriteLineAsync(
|
||||
$"Successfully exported {channels.Count - errors.Count} channel(s)."
|
||||
);
|
||||
}
|
||||
|
||||
// Print errors
|
||||
if (errors.Any())
|
||||
{
|
||||
await console.Output.WriteLineAsync();
|
||||
|
||||
using (console.WithForegroundColor(ConsoleColor.Red))
|
||||
{
|
||||
await console.Output.WriteLineAsync(
|
||||
$"Successfully exported {channels.Count - errors.Count} channel(s)."
|
||||
$"Failed to export {errors.Count} channel(s):"
|
||||
);
|
||||
}
|
||||
|
||||
// Print errors
|
||||
if (errors.Any())
|
||||
foreach (var (channel, error) in errors)
|
||||
{
|
||||
await console.Output.WriteLineAsync();
|
||||
await console.Output.WriteAsync($"{channel.Category.Name} / {channel.Name}: ");
|
||||
|
||||
using (console.WithForegroundColor(ConsoleColor.Red))
|
||||
{
|
||||
await console.Output.WriteLineAsync(
|
||||
$"Failed to export {errors.Count} channel(s):"
|
||||
);
|
||||
}
|
||||
|
||||
foreach (var (channel, error) in errors)
|
||||
{
|
||||
await console.Output.WriteAsync($"{channel.Category} / {channel.Name}: ");
|
||||
|
||||
using (console.WithForegroundColor(ConsoleColor.Red))
|
||||
await console.Output.WriteLineAsync(error);
|
||||
}
|
||||
|
||||
await console.Output.WriteLineAsync();
|
||||
await console.Output.WriteLineAsync(error);
|
||||
}
|
||||
|
||||
// Fail the command if ALL channels failed to export.
|
||||
// Having some of the channels fail to export is fine and expected.
|
||||
if (errors.Count >= channels.Count)
|
||||
{
|
||||
throw new CommandException("Export failed.");
|
||||
}
|
||||
await console.Output.WriteLineAsync();
|
||||
}
|
||||
|
||||
public override ValueTask ExecuteAsync(IConsole console)
|
||||
// Fail the command only if ALL channels failed to export.
|
||||
// Having some of the channels fail to export is expected.
|
||||
if (errors.Count >= channels.Count)
|
||||
{
|
||||
if (ShouldReuseMedia && !ShouldDownloadMedia)
|
||||
{
|
||||
throw new CommandException("Option --reuse-media cannot be used without --media.");
|
||||
}
|
||||
|
||||
return default;
|
||||
throw new CommandException("Export failed.");
|
||||
}
|
||||
}
|
||||
|
||||
protected async ValueTask ExecuteAsync(IConsole console, IReadOnlyList<Snowflake> channelIds)
|
||||
{
|
||||
var cancellationToken = console.RegisterCancellationHandler();
|
||||
var channels = new List<Channel>();
|
||||
|
||||
foreach (var channelId in channelIds)
|
||||
{
|
||||
var channel = await Discord.GetChannelAsync(channelId, cancellationToken);
|
||||
channels.Add(channel);
|
||||
}
|
||||
|
||||
await ExecuteAsync(console, channels);
|
||||
}
|
||||
|
||||
public override ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
// Support Ukraine callout
|
||||
if (!IsUkraineSupportMessageDisabled)
|
||||
{
|
||||
console.Output.WriteLine("┌────────────────────────────────────────────────────────────────────┐");
|
||||
console.Output.WriteLine("│ Thank you for supporting Ukraine <3 │");
|
||||
console.Output.WriteLine("│ │");
|
||||
console.Output.WriteLine("│ As Russia wages a genocidal war against my country, │");
|
||||
console.Output.WriteLine("│ I'm grateful to everyone who continues to │");
|
||||
console.Output.WriteLine("│ stand with Ukraine in our fight for freedom. │");
|
||||
console.Output.WriteLine("│ │");
|
||||
console.Output.WriteLine("│ Learn more: https://tyrrrz.me/ukraine │");
|
||||
console.Output.WriteLine("└────────────────────────────────────────────────────────────────────┘");
|
||||
console.Output.WriteLine("");
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,33 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands.Base
|
||||
namespace DiscordChatExporter.Cli.Commands.Base;
|
||||
|
||||
public abstract class TokenCommandBase : ICommand
|
||||
{
|
||||
public abstract class TokenCommandBase : ICommand
|
||||
{
|
||||
[CommandOption("token", 't', IsRequired = true, EnvironmentVariable = "DISCORD_TOKEN", Description = "Authentication token.")]
|
||||
public string TokenValue { get; init; } = "";
|
||||
[CommandOption(
|
||||
"token",
|
||||
't',
|
||||
EnvironmentVariable = "DISCORD_TOKEN",
|
||||
Description = "Authentication token."
|
||||
)]
|
||||
public required string Token { get; init; }
|
||||
|
||||
[CommandOption("bot", 'b', EnvironmentVariable = "DISCORD_TOKEN_BOT", Description = "Authenticate as a bot.")]
|
||||
public bool IsBotToken { 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; }
|
||||
|
||||
private AuthToken GetAuthToken() => new(
|
||||
IsBotToken
|
||||
? AuthTokenType.Bot
|
||||
: AuthTokenType.User,
|
||||
TokenValue
|
||||
);
|
||||
private DiscordClient? _discordClient;
|
||||
protected DiscordClient Discord => _discordClient ??= new DiscordClient(Token);
|
||||
|
||||
private DiscordClient? _discordClient;
|
||||
protected DiscordClient Discord => _discordClient ??= new DiscordClient(GetAuthToken());
|
||||
|
||||
public abstract ValueTask ExecuteAsync(IConsole console);
|
||||
}
|
||||
public abstract ValueTask ExecuteAsync(IConsole console);
|
||||
}
|
||||
@@ -5,42 +5,35 @@ using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands.Base;
|
||||
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.")]
|
||||
public class ExportAllCommand : ExportCommandBase
|
||||
[CommandOption(
|
||||
"include-dm",
|
||||
Description = "Include direct message channels."
|
||||
)]
|
||||
public bool IncludeDirectMessages { get; init; } = true;
|
||||
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
[CommandOption("include-dm", Description = "Include direct message channels.")]
|
||||
public bool IncludeDirectMessages { get; init; } = true;
|
||||
await base.ExecuteAsync(console);
|
||||
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
var cancellationToken = console.RegisterCancellationHandler();
|
||||
var channels = new List<Channel>();
|
||||
|
||||
await console.Output.WriteLineAsync("Fetching channels...");
|
||||
await foreach (var guild in Discord.GetUserGuildsAsync(cancellationToken))
|
||||
{
|
||||
await base.ExecuteAsync(console);
|
||||
// Skip DMs if instructed to
|
||||
if (!IncludeDirectMessages && guild.Id == Guild.DirectMessages.Id)
|
||||
continue;
|
||||
|
||||
// Get channel metadata
|
||||
await console.Output.WriteLineAsync("Fetching channels...");
|
||||
|
||||
var channels = new List<Channel>();
|
||||
|
||||
// Aggregate channels from all guilds
|
||||
await foreach (var guild in Discord.GetUserGuildsAsync())
|
||||
{
|
||||
// Skip DMs if instructed to
|
||||
if (!IncludeDirectMessages && guild.Id == Guild.DirectMessages.Id)
|
||||
continue;
|
||||
|
||||
await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id))
|
||||
{
|
||||
// Skip non-text channels
|
||||
if (!channel.IsTextChannel)
|
||||
continue;
|
||||
|
||||
channels.Add(channel);
|
||||
}
|
||||
}
|
||||
|
||||
// Export
|
||||
await ExportAsync(console, channels);
|
||||
await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken))
|
||||
channels.Add(channel);
|
||||
}
|
||||
|
||||
await base.ExecuteAsync(console, channels);
|
||||
}
|
||||
}
|
||||
@@ -5,34 +5,23 @@ using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands.Base;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
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)
|
||||
[CommandOption(
|
||||
"channel",
|
||||
'c',
|
||||
Description = "Channel ID(s)."
|
||||
)]
|
||||
public required IReadOnlyList<Snowflake> ChannelIds { get; init; }
|
||||
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
// TODO: change this to plural (breaking change)
|
||||
[CommandOption("channel", 'c', IsRequired = true, Description = "Channel ID(s).")]
|
||||
public IReadOnlyList<Snowflake> ChannelIds { get; init; } = Array.Empty<Snowflake>();
|
||||
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
await base.ExecuteAsync(console);
|
||||
|
||||
// Get channel metadata
|
||||
await console.Output.WriteLineAsync("Fetching channel(s)...");
|
||||
|
||||
var channels = new List<Channel>();
|
||||
|
||||
foreach (var channelId in ChannelIds)
|
||||
{
|
||||
var channel = await Discord.GetChannelAsync(channelId);
|
||||
channels.Add(channel);
|
||||
}
|
||||
|
||||
// Export
|
||||
await ExportAsync(console, channels);
|
||||
}
|
||||
await base.ExecuteAsync(console);
|
||||
await base.ExecuteAsync(console, ChannelIds);
|
||||
}
|
||||
}
|
||||
@@ -6,22 +6,23 @@ using DiscordChatExporter.Cli.Commands.Base;
|
||||
using DiscordChatExporter.Core.Discord.Data;
|
||||
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);
|
||||
await base.ExecuteAsync(console);
|
||||
|
||||
// Get channel metadata
|
||||
await console.Output.WriteLineAsync("Fetching channels...");
|
||||
var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id);
|
||||
var textChannels = channels.Where(c => c.IsTextChannel).ToArray();
|
||||
var cancellationToken = console.RegisterCancellationHandler();
|
||||
|
||||
// Export
|
||||
await ExportAsync(console, textChannels);
|
||||
}
|
||||
await console.Output.WriteLineAsync("Fetching channels...");
|
||||
|
||||
var channels = (await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken))
|
||||
.Where(c => c.Kind != ChannelKind.GuildCategory)
|
||||
.ToArray();
|
||||
|
||||
await base.ExecuteAsync(console, channels);
|
||||
}
|
||||
}
|
||||
@@ -4,27 +4,33 @@ using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands.Base;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Discord.Data;
|
||||
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.")]
|
||||
public class ExportGuildCommand : ExportCommandBase
|
||||
[CommandOption(
|
||||
"guild",
|
||||
'g',
|
||||
Description = "Guild ID."
|
||||
)]
|
||||
public required Snowflake GuildId { get; init; }
|
||||
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
[CommandOption("guild", 'g', IsRequired = true, Description = "Guild ID.")]
|
||||
public Snowflake GuildId { get; init; }
|
||||
await base.ExecuteAsync(console);
|
||||
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
await base.ExecuteAsync(console);
|
||||
var cancellationToken = console.RegisterCancellationHandler();
|
||||
|
||||
// Get channel metadata
|
||||
await console.Output.WriteLineAsync("Fetching channels...");
|
||||
var channels = await Discord.GetGuildChannelsAsync(GuildId);
|
||||
var textChannels = channels.Where(c => c.IsTextChannel).ToArray();
|
||||
await console.Output.WriteLineAsync("Fetching channels...");
|
||||
|
||||
// Export
|
||||
await ExportAsync(console, textChannels);
|
||||
}
|
||||
var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken))
|
||||
.Where(c => c.Kind != ChannelKind.GuildCategory)
|
||||
.ToArray();
|
||||
|
||||
await base.ExecuteAsync(console, channels);
|
||||
}
|
||||
}
|
||||
@@ -5,41 +5,45 @@ using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands.Base;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Discord.Data;
|
||||
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.")]
|
||||
public class GetChannelsCommand : TokenCommandBase
|
||||
[CommandOption(
|
||||
"guild",
|
||||
'g',
|
||||
Description = "Guild ID."
|
||||
)]
|
||||
public required Snowflake GuildId { get; init; }
|
||||
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
[CommandOption("guild", 'g', IsRequired = true, Description = "Guild ID.")]
|
||||
public Snowflake GuildId { get; init; }
|
||||
var cancellationToken = console.RegisterCancellationHandler();
|
||||
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken))
|
||||
.Where(c => c.Kind != ChannelKind.GuildCategory)
|
||||
.OrderBy(c => c.Category.Position)
|
||||
.ThenBy(c => c.Name)
|
||||
.ToArray();
|
||||
|
||||
foreach (var channel in channels)
|
||||
{
|
||||
var channels = await Discord.GetGuildChannelsAsync(GuildId);
|
||||
// Channel ID
|
||||
await console.Output.WriteAsync(
|
||||
channel.Id.ToString().PadRight(18, ' ')
|
||||
);
|
||||
|
||||
var textChannels = channels
|
||||
.Where(c => c.IsTextChannel)
|
||||
.OrderBy(c => c.Category.Position)
|
||||
.ThenBy(c => c.Name)
|
||||
.ToArray();
|
||||
// Separator
|
||||
using (console.WithForegroundColor(ConsoleColor.DarkGray))
|
||||
await console.Output.WriteAsync(" | ");
|
||||
|
||||
foreach (var channel in textChannels)
|
||||
{
|
||||
// Channel ID
|
||||
await console.Output.WriteAsync(channel.Id.ToString());
|
||||
|
||||
// Separator
|
||||
using (console.WithForegroundColor(ConsoleColor.DarkGray))
|
||||
await console.Output.WriteAsync(" | ");
|
||||
|
||||
// Channel category / name
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
await console.Output.WriteAsync($"{channel.Category} / {channel.Name}");
|
||||
|
||||
await console.Output.WriteLineAsync();
|
||||
}
|
||||
// Channel category / name
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
await console.Output.WriteLineAsync($"{channel.Category.Name} / {channel.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,36 +7,35 @@ using DiscordChatExporter.Cli.Commands.Base;
|
||||
using DiscordChatExporter.Core.Discord.Data;
|
||||
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 channels = (await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken))
|
||||
.Where(c => c.Kind != ChannelKind.GuildCategory)
|
||||
.OrderByDescending(c => c.LastMessageId)
|
||||
.ThenBy(c => c.Name)
|
||||
.ToArray();
|
||||
|
||||
foreach (var channel in channels)
|
||||
{
|
||||
var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id);
|
||||
// Channel ID
|
||||
await console.Output.WriteAsync(
|
||||
channel.Id.ToString().PadRight(18, ' ')
|
||||
);
|
||||
|
||||
var textChannels = channels
|
||||
.Where(c => c.IsTextChannel)
|
||||
.OrderBy(c => c.Category.Position)
|
||||
.ThenBy(c => c.Name)
|
||||
.ToArray();
|
||||
// Separator
|
||||
using (console.WithForegroundColor(ConsoleColor.DarkGray))
|
||||
await console.Output.WriteAsync(" | ");
|
||||
|
||||
foreach (var channel in textChannels)
|
||||
{
|
||||
// Channel ID
|
||||
await console.Output.WriteAsync(channel.Id.ToString());
|
||||
|
||||
// Separator
|
||||
using (console.WithForegroundColor(ConsoleColor.DarkGray))
|
||||
await console.Output.WriteAsync(" | ");
|
||||
|
||||
// Channel category / name
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
await console.Output.WriteAsync($"{channel.Category} / {channel.Name}");
|
||||
|
||||
await console.Output.WriteLineAsync();
|
||||
}
|
||||
// Channel category / name
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
await console.Output.WriteLineAsync($"{channel.Category.Name} / {channel.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,32 +4,37 @@ using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands.Base;
|
||||
using DiscordChatExporter.Core.Discord.Data;
|
||||
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 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)
|
||||
{
|
||||
var guilds = await Discord.GetUserGuildsAsync();
|
||||
// Guild ID
|
||||
await console.Output.WriteAsync(
|
||||
guild.Id.ToString().PadRight(18, ' ')
|
||||
);
|
||||
|
||||
foreach (var guild in guilds.OrderBy(g => g.Name))
|
||||
{
|
||||
// Guild ID
|
||||
await console.Output.WriteAsync(guild.Id.ToString());
|
||||
// Separator
|
||||
using (console.WithForegroundColor(ConsoleColor.DarkGray))
|
||||
await console.Output.WriteAsync(" | ");
|
||||
|
||||
// Separator
|
||||
using (console.WithForegroundColor(ConsoleColor.DarkGray))
|
||||
await console.Output.WriteAsync(" | ");
|
||||
|
||||
// Guild name
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
await console.Output.WriteAsync(guild.Name);
|
||||
|
||||
await console.Output.WriteLineAsync();
|
||||
}
|
||||
// Guild name
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
await console.Output.WriteLineAsync(guild.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,64 +4,69 @@ using CliFx;
|
||||
using CliFx.Attributes;
|
||||
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)
|
||||
{
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
console.Output.WriteLine("To get user token:");
|
||||
// User token
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
console.Output.WriteLine("To get user token:");
|
||||
|
||||
console.Output.WriteLine(" 1. Open Discord");
|
||||
console.Output.WriteLine(" 2. Press Ctrl+Shift+I to show developer tools");
|
||||
console.Output.WriteLine(" 3. Press Ctrl+Shift+M to toggle device toolbar");
|
||||
console.Output.WriteLine(" 4. Navigate to the Application tab");
|
||||
console.Output.WriteLine(" 5. On the left, expand Local Storage and select https://discord.com");
|
||||
console.Output.WriteLine(" 6. Type \"token\" into the Filter box");
|
||||
console.Output.WriteLine(" 7. If the token key does not appear, press Ctrl+R to reload");
|
||||
console.Output.WriteLine(" 8. Copy the value of the token key");
|
||||
console.Output.WriteLine(" * Automating user accounts is technically against TOS, use at your own risk.");
|
||||
console.Output.WriteLine();
|
||||
console.Output.WriteLine(" * Automating user accounts is technically against TOS — USE AT YOUR OWN RISK!");
|
||||
console.Output.WriteLine(" 1. Open Discord in your web browser and login");
|
||||
console.Output.WriteLine(" 2. Open any server or direct message channel");
|
||||
console.Output.WriteLine(" 3. Press Ctrl+Shift+I to show developer tools");
|
||||
console.Output.WriteLine(" 4. Navigate to the Network tab");
|
||||
console.Output.WriteLine(" 5. Press Ctrl+R to reload");
|
||||
console.Output.WriteLine(" 6. Search for a request containing \"messages?limit=50\" or similar");
|
||||
console.Output.WriteLine(" 7. Select the Headers tab on the right");
|
||||
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();
|
||||
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
console.Output.WriteLine("To get bot token:");
|
||||
// Bot token
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
console.Output.WriteLine("To get bot token:");
|
||||
|
||||
console.Output.WriteLine(" 1. Go to Discord developer portal");
|
||||
console.Output.WriteLine(" 2. Open your application's settings");
|
||||
console.Output.WriteLine(" 3. Navigate to the Bot section on the left");
|
||||
console.Output.WriteLine(" 4. Under Token click Copy");
|
||||
console.Output.WriteLine();
|
||||
console.Output.WriteLine(" 1. Go to Discord developer portal");
|
||||
console.Output.WriteLine(" 2. Open your application's settings");
|
||||
console.Output.WriteLine(" 3. Navigate to the Bot section on the left");
|
||||
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();
|
||||
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
console.Output.WriteLine("To get guild ID or guild channel ID:");
|
||||
// Guild or channel ID
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
console.Output.WriteLine("To get guild ID or guild channel ID:");
|
||||
|
||||
console.Output.WriteLine(" 1. Open Discord");
|
||||
console.Output.WriteLine(" 2. Open Settings");
|
||||
console.Output.WriteLine(" 3. Go to Appearance section");
|
||||
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();
|
||||
console.Output.WriteLine(" 1. Open Discord");
|
||||
console.Output.WriteLine(" 2. Open Settings");
|
||||
console.Output.WriteLine(" 3. Go to Advanced section");
|
||||
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();
|
||||
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
console.Output.WriteLine("To get direct message channel ID:");
|
||||
// Direct message channel ID
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
console.Output.WriteLine("To get direct message channel ID:");
|
||||
|
||||
console.Output.WriteLine(" 1. Open Discord");
|
||||
console.Output.WriteLine(" 2. Open the desired direct message channel");
|
||||
console.Output.WriteLine(" 3. Press Ctrl+Shift+I to show developer tools");
|
||||
console.Output.WriteLine(" 4. Navigate to the Console tab");
|
||||
console.Output.WriteLine(" 5. Type \"window.location.href\" and press Enter");
|
||||
console.Output.WriteLine(" 6. Copy the first long sequence of numbers inside the URL");
|
||||
console.Output.WriteLine();
|
||||
console.Output.WriteLine(" 1. Open Discord");
|
||||
console.Output.WriteLine(" 2. Open the desired direct message channel");
|
||||
console.Output.WriteLine(" 3. Press Ctrl+Shift+I to show developer tools");
|
||||
console.Output.WriteLine(" 4. Navigate to the Console tab");
|
||||
console.Output.WriteLine(" 5. Type \"window.location.href\" and press Enter");
|
||||
console.Output.WriteLine(" 6. Copy the first long sequence of numbers inside the URL");
|
||||
console.Output.WriteLine();
|
||||
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
console.Output.WriteLine("For more information, check out the wiki:");
|
||||
// Docs link
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
console.Output.WriteLine("If you have questions or issues, please refer to the documentation:");
|
||||
using (console.WithForegroundColor(ConsoleColor.DarkCyan))
|
||||
console.Output.WriteLine("https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs");
|
||||
|
||||
using (console.WithForegroundColor(ConsoleColor.DarkCyan))
|
||||
console.Output.WriteLine("https://github.com/Tyrrrz/DiscordChatExporter/wiki");
|
||||
|
||||
return default;
|
||||
}
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CliFx" Version="2.0.6" />
|
||||
<PackageReference Include="Spectre.Console" Version="0.41.0" />
|
||||
<PackageReference Include="Gress" Version="1.2.0" />
|
||||
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.5" />
|
||||
<PackageReference Include="CliFx" Version="2.3.1" />
|
||||
<PackageReference Include="Spectre.Console" Version="0.46.0" />
|
||||
<PackageReference Include="Gress" Version="2.0.1" />
|
||||
<PackageReference Include="DotnetRuntimeBootstrapper" Version="2.4.0" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using CliFx;
|
||||
|
||||
namespace DiscordChatExporter.Cli
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static async Task<int> Main(string[] args) =>
|
||||
await new CliApplicationBuilder()
|
||||
.AddCommandsFromThisAssembly()
|
||||
.Build()
|
||||
.RunAsync(args);
|
||||
}
|
||||
}
|
||||
return await new CliApplicationBuilder()
|
||||
.AddCommandsFromThisAssembly()
|
||||
.Build()
|
||||
.RunAsync(args);
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace DiscordChatExporter.Cli;
|
||||
|
||||
public static class Sanctions
|
||||
{
|
||||
[ModuleInitializer]
|
||||
internal static void Verify()
|
||||
{
|
||||
var isSkipped = string.Equals(
|
||||
Environment.GetEnvironmentVariable("RUSNI"),
|
||||
"PYZDA",
|
||||
StringComparison.OrdinalIgnoreCase
|
||||
);
|
||||
|
||||
if (isSkipped)
|
||||
return;
|
||||
|
||||
var locale = CultureInfo.CurrentCulture.Name;
|
||||
|
||||
var region =
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
||||
? Registry.CurrentUser
|
||||
.OpenSubKey(@"Control Panel\International\Geo", false)?
|
||||
.GetValue("Name") as string
|
||||
: null;
|
||||
|
||||
var isSanctioned =
|
||||
locale.EndsWith("-ru", StringComparison.OrdinalIgnoreCase) ||
|
||||
locale.EndsWith("-by", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(region, "ru", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(region, "by", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (!isSanctioned)
|
||||
return;
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.Error.WriteLine(
|
||||
"You cannot use this software on the territory of a terrorist state. " +
|
||||
"Set the environment variable `RUSNI=PYZDA` if you wish to override this check."
|
||||
);
|
||||
|
||||
Console.ResetColor();
|
||||
|
||||
Environment.Exit(0xFACC);
|
||||
}
|
||||
}
|
||||
@@ -3,50 +3,49 @@ using System.Threading.Tasks;
|
||||
using CliFx.Infrastructure;
|
||||
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) => AnsiConsole.Create(
|
||||
new AnsiConsoleSettings
|
||||
{
|
||||
Ansi = AnsiSupport.Detect,
|
||||
ColorSystem = ColorSystemSupport.Detect,
|
||||
Out = new AnsiConsoleOutput(console.Output)
|
||||
}
|
||||
public static IAnsiConsole CreateAnsiConsole(this IConsole console) =>
|
||||
AnsiConsole.Create(new AnsiConsoleSettings
|
||||
{
|
||||
Ansi = AnsiSupport.Detect,
|
||||
ColorSystem = ColorSystemSupport.Detect,
|
||||
Out = new AnsiConsoleOutput(console.Output)
|
||||
});
|
||||
|
||||
public static Progress CreateProgressTicker(this IConsole console) => console
|
||||
.CreateAnsiConsole()
|
||||
.Progress()
|
||||
.AutoClear(false)
|
||||
.AutoRefresh(true)
|
||||
.HideCompleted(false)
|
||||
.Columns(
|
||||
new TaskDescriptionColumn {Alignment = Justify.Left},
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn()
|
||||
);
|
||||
|
||||
public static Progress CreateProgressTicker(this IConsole console) => console
|
||||
.CreateAnsiConsole()
|
||||
.Progress()
|
||||
.AutoClear(false)
|
||||
.AutoRefresh(true)
|
||||
.HideCompleted(false)
|
||||
.Columns(
|
||||
new TaskDescriptionColumn {Alignment = Justify.Left},
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn()
|
||||
);
|
||||
public static async ValueTask StartTaskAsync(
|
||||
this ProgressContext progressContext,
|
||||
string description,
|
||||
Func<ProgressTask, ValueTask> performOperationAsync)
|
||||
{
|
||||
var progressTask = progressContext.AddTask(
|
||||
// Don't recognize random square brackets as style tags
|
||||
Markup.Escape(description),
|
||||
new ProgressTaskSettings {MaxValue = 1}
|
||||
);
|
||||
|
||||
public static async ValueTask StartTaskAsync(
|
||||
this ProgressContext progressContext,
|
||||
string description,
|
||||
Func<ProgressTask, ValueTask> performOperationAsync)
|
||||
try
|
||||
{
|
||||
var progressTask = progressContext.AddTask(
|
||||
// Don't recognize random square brackets as style tags
|
||||
Markup.Escape(description),
|
||||
new ProgressTaskSettings {MaxValue = 1}
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
await performOperationAsync(progressTask);
|
||||
}
|
||||
finally
|
||||
{
|
||||
progressTask.StopTask();
|
||||
}
|
||||
await performOperationAsync(progressTask);
|
||||
}
|
||||
finally
|
||||
{
|
||||
progressTask.Value = progressTask.MaxValue;
|
||||
progressTask.StopTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// ReSharper disable CheckNamespace
|
||||
// TODO: remove after moving to .NET 5
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
internal static class IsExternalInit
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord
|
||||
{
|
||||
public class AuthToken
|
||||
{
|
||||
public AuthTokenType Type { get; }
|
||||
|
||||
public string Value { get; }
|
||||
|
||||
public AuthToken(AuthTokenType type, string value)
|
||||
{
|
||||
Type = type;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public AuthenticationHeaderValue GetAuthenticationHeader() => Type switch
|
||||
{
|
||||
AuthTokenType.Bot => new AuthenticationHeaderValue("Bot", Value),
|
||||
_ => new AuthenticationHeaderValue(Value)
|
||||
};
|
||||
|
||||
public override string ToString() => Value;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace DiscordChatExporter.Core.Discord
|
||||
{
|
||||
public enum AuthTokenType
|
||||
{
|
||||
User,
|
||||
Bot
|
||||
}
|
||||
}
|
||||
@@ -1,78 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||
using DiscordChatExporter.Core.Utils;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data
|
||||
namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#attachment-object
|
||||
public partial record Attachment(
|
||||
Snowflake Id,
|
||||
string Url,
|
||||
string FileName,
|
||||
string? Description,
|
||||
int? Width,
|
||||
int? Height,
|
||||
FileSize FileSize) : IHasId
|
||||
{
|
||||
// https://discord.com/developers/docs/resources/channel#attachment-object
|
||||
public partial class Attachment : IHasId
|
||||
public string FileExtension => Path.GetExtension(FileName);
|
||||
|
||||
public bool IsImage => FileFormat.IsImage(FileExtension);
|
||||
|
||||
public bool IsVideo => FileFormat.IsVideo(FileExtension);
|
||||
|
||||
public bool IsAudio => FileFormat.IsAudio(FileExtension);
|
||||
|
||||
public bool IsSpoiler => FileName.StartsWith("SPOILER_", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public partial record Attachment
|
||||
{
|
||||
public static Attachment Parse(JsonElement json)
|
||||
{
|
||||
public Snowflake Id { get; }
|
||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||
var url = json.GetProperty("url").GetNonWhiteSpaceString();
|
||||
var fileName = json.GetProperty("filename").GetNonNullString();
|
||||
var description = json.GetPropertyOrNull("description")?.GetNonWhiteSpaceStringOrNull();
|
||||
var width = json.GetPropertyOrNull("width")?.GetInt32OrNull();
|
||||
var height = json.GetPropertyOrNull("height")?.GetInt32OrNull();
|
||||
var fileSize = json.GetProperty("size").GetInt64().Pipe(FileSize.FromBytes);
|
||||
|
||||
public string Url { get; }
|
||||
|
||||
public string FileName { get; }
|
||||
|
||||
public string FileExtension => Path.GetExtension(FileName);
|
||||
|
||||
public int? Width { get; }
|
||||
|
||||
public int? Height { get; }
|
||||
|
||||
public bool IsImage => ImageFileExtensions.Contains(FileExtension);
|
||||
|
||||
public bool IsVideo => VideoFileExtensions.Contains(FileExtension);
|
||||
|
||||
public bool IsAudio => AudioFileExtensions.Contains(FileExtension);
|
||||
|
||||
public bool IsSpoiler => FileName.StartsWith("SPOILER_", StringComparison.Ordinal);
|
||||
|
||||
public FileSize FileSize { get; }
|
||||
|
||||
public Attachment(
|
||||
Snowflake id,
|
||||
string url,
|
||||
string fileName,
|
||||
int? width,
|
||||
int? height,
|
||||
FileSize fileSize)
|
||||
{
|
||||
Id = id;
|
||||
Url = url;
|
||||
FileName = fileName;
|
||||
Width = width;
|
||||
Height = height;
|
||||
FileSize = fileSize;
|
||||
}
|
||||
|
||||
public override string ToString() => FileName;
|
||||
}
|
||||
|
||||
public partial class Attachment
|
||||
{
|
||||
private static readonly HashSet<string> ImageFileExtensions = new(StringComparer.OrdinalIgnoreCase)
|
||||
{".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp"};
|
||||
|
||||
private static readonly HashSet<string> VideoFileExtensions = new(StringComparer.OrdinalIgnoreCase)
|
||||
{".mp4", ".webm"};
|
||||
|
||||
private static readonly HashSet<string> AudioFileExtensions = new(StringComparer.OrdinalIgnoreCase)
|
||||
{".mp3", ".wav", ".ogg", ".flac", ".m4a"};
|
||||
|
||||
public static Attachment Parse(JsonElement json)
|
||||
{
|
||||
var id = json.GetProperty("id").GetString().Pipe(Snowflake.Parse);
|
||||
var url = json.GetProperty("url").GetString();
|
||||
var width = json.GetPropertyOrNull("width")?.GetInt32();
|
||||
var height = json.GetPropertyOrNull("height")?.GetInt32();
|
||||
var fileName = json.GetProperty("filename").GetString();
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -3,97 +3,78 @@ using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
using Tyrrrz.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data
|
||||
namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#channel-object
|
||||
public partial record Channel(
|
||||
Snowflake Id,
|
||||
ChannelKind Kind,
|
||||
Snowflake GuildId,
|
||||
ChannelCategory Category,
|
||||
string Name,
|
||||
int? Position,
|
||||
string? Topic,
|
||||
Snowflake? LastMessageId) : IHasId
|
||||
{
|
||||
// https://discord.com/developers/docs/resources/channel#channel-object
|
||||
public partial class Channel : IHasId
|
||||
{
|
||||
public Snowflake Id { get; }
|
||||
public bool SupportsVoice => Kind is ChannelKind.GuildVoiceChat or ChannelKind.GuildStageVoice;
|
||||
}
|
||||
|
||||
public ChannelType Type { get; }
|
||||
|
||||
public bool IsTextChannel => Type is
|
||||
ChannelType.GuildTextChat or
|
||||
ChannelType.DirectTextChat or
|
||||
ChannelType.DirectGroupTextChat or
|
||||
ChannelType.GuildNews or
|
||||
ChannelType.GuildStore;
|
||||
|
||||
public bool IsVoiceChannel => !IsTextChannel;
|
||||
|
||||
public Snowflake GuildId { get; }
|
||||
|
||||
public ChannelCategory Category { get; }
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public int? Position { get; }
|
||||
|
||||
public string? Topic { get; }
|
||||
|
||||
public Channel(
|
||||
Snowflake id,
|
||||
ChannelType type,
|
||||
Snowflake guildId,
|
||||
ChannelCategory category,
|
||||
string name,
|
||||
int? position,
|
||||
string? topic)
|
||||
public partial record Channel
|
||||
{
|
||||
private static ChannelCategory GetFallbackCategory(ChannelKind channelKind) => new(
|
||||
Snowflake.Zero,
|
||||
channelKind switch
|
||||
{
|
||||
Id = id;
|
||||
Type = type;
|
||||
GuildId = guildId;
|
||||
Category = category;
|
||||
Name = name;
|
||||
Position = position;
|
||||
Topic = topic;
|
||||
}
|
||||
ChannelKind.GuildTextChat => "Text",
|
||||
ChannelKind.DirectTextChat => "Private",
|
||||
ChannelKind.DirectGroupTextChat => "Group",
|
||||
ChannelKind.GuildNews => "News",
|
||||
_ => "Default"
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
public partial class Channel
|
||||
public static Channel Parse(JsonElement json, ChannelCategory? category = null, int? positionHint = null)
|
||||
{
|
||||
private static ChannelCategory GetFallbackCategory(ChannelType channelType) => new(
|
||||
Snowflake.Zero,
|
||||
channelType switch
|
||||
{
|
||||
ChannelType.GuildTextChat => "Text",
|
||||
ChannelType.DirectTextChat => "Private",
|
||||
ChannelType.DirectGroupTextChat => "Group",
|
||||
ChannelType.GuildNews => "News",
|
||||
ChannelType.GuildStore => "Store",
|
||||
_ => "Default"
|
||||
},
|
||||
null
|
||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||
var kind = (ChannelKind)json.GetProperty("type").GetInt32();
|
||||
var guildId = json.GetPropertyOrNull("guild_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
|
||||
|
||||
var name =
|
||||
// Guild channel
|
||||
json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull() ??
|
||||
|
||||
// DM channel
|
||||
json.GetPropertyOrNull("recipients")?
|
||||
.EnumerateArrayOrNull()?
|
||||
.Select(User.Parse)
|
||||
.Select(u => u.Name)
|
||||
.Pipe(s => string.Join(", ", s)) ??
|
||||
|
||||
// Fallback
|
||||
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(
|
||||
id,
|
||||
kind,
|
||||
guildId ?? Guild.DirectMessages.Id,
|
||||
category ?? GetFallbackCategory(kind),
|
||||
name,
|
||||
position,
|
||||
topic,
|
||||
lastMessageId
|
||||
);
|
||||
|
||||
public static Channel Parse(JsonElement json, ChannelCategory? category = null, int? position = null)
|
||||
{
|
||||
var id = json.GetProperty("id").GetString().Pipe(Snowflake.Parse);
|
||||
var guildId = json.GetPropertyOrNull("guild_id")?.GetString().Pipe(Snowflake.Parse);
|
||||
var topic = json.GetPropertyOrNull("topic")?.GetString();
|
||||
var type = (ChannelType) json.GetProperty("type").GetInt32();
|
||||
|
||||
var name =
|
||||
// Guild channel
|
||||
json.GetPropertyOrNull("name")?.GetString() ??
|
||||
// DM channel
|
||||
json.GetPropertyOrNull("recipients")?.EnumerateArray().Select(User.Parse).Select(u => u.Name).JoinToString(", ") ??
|
||||
// Fallback
|
||||
id.ToString();
|
||||
|
||||
return new Channel(
|
||||
id,
|
||||
type,
|
||||
guildId ?? Guild.DirectMessages.Id,
|
||||
category ?? GetFallbackCategory(type),
|
||||
name,
|
||||
position ?? json.GetPropertyOrNull("position")?.GetInt32(),
|
||||
topic
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,43 +3,24 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data
|
||||
namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
public record ChannelCategory(Snowflake Id, string Name, int? Position) : IHasId
|
||||
{
|
||||
public partial class ChannelCategory : IHasId
|
||||
public static ChannelCategory Unknown { get; } = new(Snowflake.Zero, "<unknown category>", 0);
|
||||
|
||||
public static ChannelCategory Parse(JsonElement json, int? positionHint = null)
|
||||
{
|
||||
public Snowflake Id { get; }
|
||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||
|
||||
public string Name { get; }
|
||||
var name =
|
||||
json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull() ??
|
||||
id.ToString();
|
||||
|
||||
public int? Position { get; }
|
||||
var position =
|
||||
positionHint ??
|
||||
json.GetPropertyOrNull("position")?.GetInt32OrNull();
|
||||
|
||||
public ChannelCategory(Snowflake id, string name, int? position)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
Position = position;
|
||||
}
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
public partial class ChannelCategory
|
||||
{
|
||||
public static ChannelCategory Parse(JsonElement json, int? position = null)
|
||||
{
|
||||
var id = json.GetProperty("id").GetString().Pipe(Snowflake.Parse);
|
||||
|
||||
var name =
|
||||
json.GetPropertyOrNull("name")?.GetString() ??
|
||||
id.ToString();
|
||||
|
||||
return new ChannelCategory(
|
||||
id,
|
||||
name,
|
||||
position ?? json.GetPropertyOrNull("position")?.GetInt32()
|
||||
);
|
||||
}
|
||||
|
||||
public static ChannelCategory Empty { get; } = new(Snowflake.Zero, "<unknown category>", 0);
|
||||
return new ChannelCategory(id, name, position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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
|
||||
{
|
||||
GuildTextChat = 0,
|
||||
DirectTextChat = 1,
|
||||
GuildVoiceChat = 2,
|
||||
DirectGroupTextChat = 3,
|
||||
GuildCategory = 4,
|
||||
GuildNews = 5,
|
||||
GuildNewsThread = 10,
|
||||
GuildPublicThread = 11,
|
||||
GuildPrivateThread = 12,
|
||||
GuildStageVoice = 13,
|
||||
GuildDirectory = 14,
|
||||
GuildForum = 15
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
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 ChannelType
|
||||
{
|
||||
GuildTextChat = 0,
|
||||
DirectTextChat,
|
||||
GuildVoiceChat,
|
||||
DirectGroupTextChat,
|
||||
GuildCategory,
|
||||
GuildNews,
|
||||
GuildStore
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,50 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
|
||||
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 struct FileSize
|
||||
public double TotalKiloBytes => TotalBytes / 1024.0;
|
||||
public double TotalMegaBytes => TotalKiloBytes / 1024.0;
|
||||
public double TotalGigaBytes => TotalMegaBytes / 1024.0;
|
||||
|
||||
private double GetLargestWholeNumberValue()
|
||||
{
|
||||
public long TotalBytes { get; }
|
||||
if (Math.Abs(TotalGigaBytes) >= 1)
|
||||
return TotalGigaBytes;
|
||||
|
||||
public double TotalKiloBytes => TotalBytes / 1024.0;
|
||||
public double TotalMegaBytes => TotalKiloBytes / 1024.0;
|
||||
public double TotalGigaBytes => TotalMegaBytes / 1024.0;
|
||||
if (Math.Abs(TotalMegaBytes) >= 1)
|
||||
return TotalMegaBytes;
|
||||
|
||||
public FileSize(long bytes) => TotalBytes = bytes;
|
||||
if (Math.Abs(TotalKiloBytes) >= 1)
|
||||
return TotalKiloBytes;
|
||||
|
||||
private double GetLargestWholeNumberValue()
|
||||
{
|
||||
if (Math.Abs(TotalGigaBytes) >= 1)
|
||||
return TotalGigaBytes;
|
||||
|
||||
if (Math.Abs(TotalMegaBytes) >= 1)
|
||||
return TotalMegaBytes;
|
||||
|
||||
if (Math.Abs(TotalKiloBytes) >= 1)
|
||||
return TotalKiloBytes;
|
||||
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
private string GetLargestWholeNumberSymbol()
|
||||
{
|
||||
if (Math.Abs(TotalGigaBytes) >= 1)
|
||||
return "GB";
|
||||
|
||||
if (Math.Abs(TotalMegaBytes) >= 1)
|
||||
return "MB";
|
||||
|
||||
if (Math.Abs(TotalKiloBytes) >= 1)
|
||||
return "KB";
|
||||
|
||||
return "bytes";
|
||||
}
|
||||
|
||||
public override string ToString() => $"{GetLargestWholeNumberValue():0.##} {GetLargestWholeNumberSymbol()}";
|
||||
return TotalBytes;
|
||||
}
|
||||
|
||||
public partial struct FileSize
|
||||
private string GetLargestWholeNumberSymbol()
|
||||
{
|
||||
public static FileSize FromBytes(long bytes) => new(bytes);
|
||||
if (Math.Abs(TotalGigaBytes) >= 1)
|
||||
return "GB";
|
||||
|
||||
if (Math.Abs(TotalMegaBytes) >= 1)
|
||||
return "MB";
|
||||
|
||||
if (Math.Abs(TotalKiloBytes) >= 1)
|
||||
return "KB";
|
||||
|
||||
return "bytes";
|
||||
}
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public override string ToString() =>
|
||||
string.Create(CultureInfo.InvariantCulture, $"{GetLargestWholeNumberValue():0.##} {GetLargestWholeNumberSymbol()}");
|
||||
}
|
||||
|
||||
public partial record struct FileSize
|
||||
{
|
||||
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,16 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Common
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Common;
|
||||
|
||||
public class IdBasedEqualityComparer : IEqualityComparer<IHasId>
|
||||
{
|
||||
public partial class IdBasedEqualityComparer : IEqualityComparer<IHasId>
|
||||
{
|
||||
public bool Equals(IHasId? x, IHasId? y) => x?.Id == y?.Id;
|
||||
public static IdBasedEqualityComparer Instance { get; } = new();
|
||||
|
||||
public int GetHashCode(IHasId obj) => obj.Id.GetHashCode();
|
||||
}
|
||||
public bool Equals(IHasId? x, IHasId? y) => x?.Id == y?.Id;
|
||||
|
||||
public partial class IdBasedEqualityComparer
|
||||
{
|
||||
public static IdBasedEqualityComparer Instance { get; } = new();
|
||||
}
|
||||
public int GetHashCode(IHasId obj) => obj.Id.GetHashCode();
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data
|
||||
{
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object
|
||||
public partial class Embed
|
||||
{
|
||||
public string? Title { get; }
|
||||
|
||||
public string? Url { get; }
|
||||
|
||||
public DateTimeOffset? Timestamp { get; }
|
||||
|
||||
public Color? Color { get; }
|
||||
|
||||
public EmbedAuthor? Author { get; }
|
||||
|
||||
public string? Description { get; }
|
||||
|
||||
public IReadOnlyList<EmbedField> Fields { get; }
|
||||
|
||||
public EmbedImage? Thumbnail { get; }
|
||||
|
||||
public EmbedImage? Image { get; }
|
||||
|
||||
public EmbedFooter? Footer { get; }
|
||||
|
||||
public Embed(
|
||||
string? title,
|
||||
string? url,
|
||||
DateTimeOffset? timestamp,
|
||||
Color? color,
|
||||
EmbedAuthor? author,
|
||||
string? description,
|
||||
IReadOnlyList<EmbedField> fields,
|
||||
EmbedImage? thumbnail,
|
||||
EmbedImage? image,
|
||||
EmbedFooter? footer)
|
||||
{
|
||||
Title = title;
|
||||
Url = url;
|
||||
Timestamp = timestamp;
|
||||
Color = color;
|
||||
Author = author;
|
||||
Description = description;
|
||||
Fields = fields;
|
||||
Thumbnail = thumbnail;
|
||||
Image = image;
|
||||
Footer = footer;
|
||||
}
|
||||
|
||||
public YouTubeVideoEmbedProjection? TryGetYouTubeVideo() => YouTubeVideoEmbedProjection.TryResolve(this);
|
||||
|
||||
public override string ToString() => Title ?? "<untitled embed>";
|
||||
}
|
||||
|
||||
public partial class Embed
|
||||
{
|
||||
public static Embed Parse(JsonElement json)
|
||||
{
|
||||
var title = json.GetPropertyOrNull("title")?.GetString();
|
||||
var url = json.GetPropertyOrNull("url")?.GetString();
|
||||
var timestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffset();
|
||||
var color = json.GetPropertyOrNull("color")?.GetInt32().Pipe(System.Drawing.Color.FromArgb).ResetAlpha();
|
||||
var description = json.GetPropertyOrNull("description")?.GetString();
|
||||
|
||||
var author = json.GetPropertyOrNull("author")?.Pipe(EmbedAuthor.Parse);
|
||||
var thumbnail = json.GetPropertyOrNull("thumbnail")?.Pipe(EmbedImage.Parse);
|
||||
var image = json.GetPropertyOrNull("image")?.Pipe(EmbedImage.Parse);
|
||||
var footer = json.GetPropertyOrNull("footer")?.Pipe(EmbedFooter.Parse);
|
||||
|
||||
var fields =
|
||||
json.GetPropertyOrNull("fields")?.EnumerateArray().Select(EmbedField.Parse).ToArray() ??
|
||||
Array.Empty<EmbedField>();
|
||||
|
||||
return new Embed(
|
||||
title,
|
||||
url,
|
||||
timestamp,
|
||||
color,
|
||||
author,
|
||||
description,
|
||||
fields,
|
||||
thumbnail,
|
||||
image,
|
||||
footer
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data
|
||||
{
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure
|
||||
public partial class EmbedAuthor
|
||||
{
|
||||
public string? Name { get; }
|
||||
|
||||
public string? Url { get; }
|
||||
|
||||
public string? IconUrl { get; }
|
||||
|
||||
public string? IconProxyUrl { get; }
|
||||
|
||||
public EmbedAuthor(string? name, string? url, string? iconUrl, string? iconProxyUrl)
|
||||
{
|
||||
Name = name;
|
||||
Url = url;
|
||||
IconUrl = iconUrl;
|
||||
IconProxyUrl = iconProxyUrl;
|
||||
}
|
||||
|
||||
public override string ToString() => Name ?? "<unnamed author>";
|
||||
}
|
||||
|
||||
public partial class EmbedAuthor
|
||||
{
|
||||
public static EmbedAuthor Parse(JsonElement json)
|
||||
{
|
||||
var name = json.GetPropertyOrNull("name")?.GetString();
|
||||
var url = json.GetPropertyOrNull("url")?.GetString();
|
||||
var iconUrl = json.GetPropertyOrNull("icon_url")?.GetString();
|
||||
var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetString();
|
||||
|
||||
return new EmbedAuthor(name, url, iconUrl, iconProxyUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data
|
||||
{
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
|
||||
public partial class EmbedField
|
||||
{
|
||||
public string Name { get; }
|
||||
|
||||
public string Value { get; }
|
||||
|
||||
public bool IsInline { get; }
|
||||
|
||||
public EmbedField(string name, string value, bool isInline)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
IsInline = isInline;
|
||||
}
|
||||
|
||||
public override string ToString() => $"{Name} | {Value}";
|
||||
}
|
||||
|
||||
public partial class EmbedField
|
||||
{
|
||||
public static EmbedField Parse(JsonElement json)
|
||||
{
|
||||
var name = json.GetProperty("name").GetString();
|
||||
var value = json.GetProperty("value").GetString();
|
||||
var isInline = json.GetPropertyOrNull("inline")?.GetBoolean() ?? false;
|
||||
|
||||
return new EmbedField(name, value, isInline);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data
|
||||
{
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
|
||||
public partial class EmbedFooter
|
||||
{
|
||||
public string Text { get; }
|
||||
|
||||
public string? IconUrl { get; }
|
||||
|
||||
public string? IconProxyUrl { get; }
|
||||
|
||||
public EmbedFooter(string text, string? iconUrl, string? iconProxyUrl)
|
||||
{
|
||||
Text = text;
|
||||
IconUrl = iconUrl;
|
||||
IconProxyUrl = iconProxyUrl;
|
||||
}
|
||||
|
||||
public override string ToString() => Text;
|
||||
}
|
||||
|
||||
public partial class EmbedFooter
|
||||
{
|
||||
public static EmbedFooter Parse(JsonElement json)
|
||||
{
|
||||
var text = json.GetProperty("text").GetString();
|
||||
var iconUrl = json.GetPropertyOrNull("icon_url")?.GetString();
|
||||
var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetString();
|
||||
|
||||
return new EmbedFooter(text, iconUrl, iconProxyUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data
|
||||
{
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure
|
||||
public partial class EmbedImage
|
||||
{
|
||||
public string? Url { get; }
|
||||
|
||||
public string? ProxyUrl { get; }
|
||||
|
||||
public int? Width { get; }
|
||||
|
||||
public int? Height { get; }
|
||||
|
||||
public EmbedImage(string? url, string? proxyUrl, int? width, int? height)
|
||||
{
|
||||
Url = url;
|
||||
ProxyUrl = proxyUrl;
|
||||
Height = height;
|
||||
Width = width;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class EmbedImage
|
||||
{
|
||||
public static EmbedImage Parse(JsonElement json)
|
||||
{
|
||||
var url = json.GetPropertyOrNull("url")?.GetString();
|
||||
var proxyUrl = json.GetPropertyOrNull("proxy_url")?.GetString();
|
||||
var width = json.GetPropertyOrNull("width")?.GetInt32();
|
||||
var height = json.GetPropertyOrNull("height")?.GetInt32();
|
||||
|
||||
return new EmbedImage(url, proxyUrl, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object
|
||||
public partial record Embed(
|
||||
string? Title,
|
||||
EmbedKind Kind,
|
||||
string? Url,
|
||||
DateTimeOffset? Timestamp,
|
||||
Color? Color,
|
||||
EmbedAuthor? Author,
|
||||
string? Description,
|
||||
IReadOnlyList<EmbedField> Fields,
|
||||
EmbedImage? Thumbnail,
|
||||
IReadOnlyList<EmbedImage> Images,
|
||||
EmbedVideo? Video,
|
||||
EmbedFooter? Footer)
|
||||
{
|
||||
public SpotifyTrackEmbedProjection? TryGetSpotifyTrack() =>
|
||||
SpotifyTrackEmbedProjection.TryResolve(this);
|
||||
|
||||
public YouTubeVideoEmbedProjection? TryGetYouTubeVideo() =>
|
||||
YouTubeVideoEmbedProjection.TryResolve(this);
|
||||
}
|
||||
|
||||
public partial record Embed
|
||||
{
|
||||
public static Embed Parse(JsonElement json)
|
||||
{
|
||||
var title = json.GetPropertyOrNull("title")?.GetStringOrNull();
|
||||
|
||||
var kind =
|
||||
json.GetPropertyOrNull("type")?.GetStringOrNull()?.ParseEnumOrNull<EmbedKind>() ??
|
||||
EmbedKind.Rich;
|
||||
|
||||
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
|
||||
var timestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffset();
|
||||
|
||||
var color = json
|
||||
.GetPropertyOrNull("color")?
|
||||
.GetInt32OrNull()?
|
||||
.Pipe(System.Drawing.Color.FromArgb)
|
||||
.ResetAlpha();
|
||||
|
||||
var author = json.GetPropertyOrNull("author")?.Pipe(EmbedAuthor.Parse);
|
||||
var description = json.GetPropertyOrNull("description")?.GetStringOrNull();
|
||||
|
||||
var fields =
|
||||
json.GetPropertyOrNull("fields")?.EnumerateArrayOrNull()?.Select(EmbedField.Parse).ToArray() ??
|
||||
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(
|
||||
title,
|
||||
kind,
|
||||
url,
|
||||
timestamp,
|
||||
color,
|
||||
author,
|
||||
description,
|
||||
fields,
|
||||
thumbnail,
|
||||
images,
|
||||
video,
|
||||
footer
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Text.Json;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure
|
||||
public record EmbedAuthor(
|
||||
string? Name,
|
||||
string? Url,
|
||||
string? IconUrl,
|
||||
string? IconProxyUrl)
|
||||
{
|
||||
public static EmbedAuthor Parse(JsonElement json)
|
||||
{
|
||||
var name = json.GetPropertyOrNull("name")?.GetStringOrNull();
|
||||
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
|
||||
var iconUrl = json.GetPropertyOrNull("icon_url")?.GetNonWhiteSpaceStringOrNull();
|
||||
var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetNonWhiteSpaceStringOrNull();
|
||||
|
||||
return new EmbedAuthor(name, url, iconUrl, iconProxyUrl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Text.Json;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
|
||||
public record EmbedField(
|
||||
string Name,
|
||||
string Value,
|
||||
bool IsInline)
|
||||
{
|
||||
public static EmbedField Parse(JsonElement json)
|
||||
{
|
||||
var name = json.GetProperty("name").GetNonNullString();
|
||||
var value = json.GetProperty("value").GetNonNullString();
|
||||
var isInline = json.GetPropertyOrNull("inline")?.GetBooleanOrNull() ?? false;
|
||||
|
||||
return new EmbedField(name, value, isInline);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Text.Json;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
|
||||
public record EmbedFooter(
|
||||
string Text,
|
||||
string? IconUrl,
|
||||
string? IconProxyUrl)
|
||||
{
|
||||
public static EmbedFooter Parse(JsonElement json)
|
||||
{
|
||||
var text = json.GetProperty("text").GetNonNullString();
|
||||
var iconUrl = json.GetPropertyOrNull("icon_url")?.GetNonWhiteSpaceStringOrNull();
|
||||
var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetNonWhiteSpaceStringOrNull();
|
||||
|
||||
return new EmbedFooter(text, iconUrl, iconProxyUrl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Text.Json;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure
|
||||
public record EmbedImage(
|
||||
string? Url,
|
||||
string? ProxyUrl,
|
||||
int? Width,
|
||||
int? Height)
|
||||
{
|
||||
public static EmbedImage 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 EmbedImage(url, proxyUrl, width, height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-types
|
||||
public enum EmbedKind
|
||||
{
|
||||
Rich,
|
||||
Image,
|
||||
Video,
|
||||
Gifv,
|
||||
Link
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using JsonExtensions.Reading;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-video-structure
|
||||
public record EmbedVideo(
|
||||
string? Url,
|
||||
string? ProxyUrl,
|
||||
int? Width,
|
||||
int? Height)
|
||||
{
|
||||
public static EmbedVideo Parse(JsonElement json)
|
||||
{
|
||||
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
|
||||
var proxyUrl = json.GetPropertyOrNull("proxy_url")?.GetNonWhiteSpaceStringOrNull();
|
||||
var width = json.GetPropertyOrNull("width")?.GetInt32OrNull();
|
||||
var height = json.GetPropertyOrNull("height")?.GetInt32OrNull();
|
||||
|
||||
return new EmbedVideo(url, proxyUrl, width, height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
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
|
||||
{
|
||||
private static string? TryParseTrackId(string embedUrl)
|
||||
{
|
||||
// https://open.spotify.com/track/1LHZMWefF9502NPfArRfvP?si=3efac6ce9be04f0a
|
||||
var trackId = Regex.Match(embedUrl, @"spotify\.com/track/(.*?)(?:\?|&|/|$)").Groups[1].Value;
|
||||
if (!string.IsNullOrWhiteSpace(trackId))
|
||||
return trackId;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static SpotifyTrackEmbedProjection? TryResolve(Embed embed)
|
||||
{
|
||||
if (embed.Kind != EmbedKind.Link)
|
||||
return null;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(embed.Url))
|
||||
return null;
|
||||
|
||||
var trackId = TryParseTrackId(embed.Url);
|
||||
if (string.IsNullOrWhiteSpace(trackId))
|
||||
return null;
|
||||
|
||||
return new SpotifyTrackEmbedProjection(trackId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
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
|
||||
{
|
||||
// Adapted from YoutubeExplode
|
||||
// https://github.com/Tyrrrz/YoutubeExplode/blob/bc700b631bd105d0be208a88116347034bdca88b/YoutubeExplode/Videos/VideoId.cs#L40-L62
|
||||
private static string? TryParseVideoId(string embedUrl)
|
||||
{
|
||||
// Regular URL
|
||||
// https://www.youtube.com/watch?v=yIVRs6YSbOM
|
||||
var regularMatch = Regex.Match(embedUrl, @"youtube\..+?/watch.*?v=(.*?)(?:&|/|$)").Groups[1].Value;
|
||||
if (!string.IsNullOrWhiteSpace(regularMatch))
|
||||
return regularMatch;
|
||||
|
||||
// Short URL
|
||||
// https://youtu.be/yIVRs6YSbOM
|
||||
var shortMatch = Regex.Match(embedUrl, @"youtu\.be/(.*?)(?:\?|&|/|$)").Groups[1].Value;
|
||||
if (!string.IsNullOrWhiteSpace(shortMatch))
|
||||
return shortMatch;
|
||||
|
||||
// Embed URL
|
||||
// https://www.youtube.com/embed/yIVRs6YSbOM
|
||||
var embedMatch = Regex.Match(embedUrl, @"youtube\..+?/embed/(.*?)(?:\?|&|/|$)").Groups[1].Value;
|
||||
if (!string.IsNullOrWhiteSpace(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;
|
||||
}
|
||||
|
||||
public static YouTubeVideoEmbedProjection? TryResolve(Embed embed)
|
||||
{
|
||||
if (embed.Kind != EmbedKind.Video)
|
||||
return null;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(embed.Url))
|
||||
return null;
|
||||
|
||||
var videoId = TryParseVideoId(embed.Url);
|
||||
if (string.IsNullOrWhiteSpace(videoId))
|
||||
return null;
|
||||
|
||||
return new YouTubeVideoEmbedProjection(videoId);
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,79 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Utils;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
using Tyrrrz.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data
|
||||
namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
// https://discord.com/developers/docs/resources/emoji#emoji-object
|
||||
public partial record Emoji(
|
||||
// Only present on custom emoji
|
||||
Snowflake? Id,
|
||||
// Name of a custom emoji (e.g. LUL) or actual representation of a standard emoji (e.g. 🙂)
|
||||
string Name,
|
||||
bool IsAnimated,
|
||||
string ImageUrl)
|
||||
{
|
||||
// https://discord.com/developers/docs/resources/emoji#emoji-object
|
||||
public partial class Emoji
|
||||
// Name of a custom emoji (e.g. LUL) or name of a standard emoji (e.g. slight_smile)
|
||||
public string Code => Id is not null
|
||||
? Name
|
||||
: EmojiIndex.TryGetCode(Name) ?? Name;
|
||||
}
|
||||
|
||||
public partial record Emoji
|
||||
{
|
||||
private static string GetTwemojiId(string name)
|
||||
{
|
||||
// Only present on custom emoji
|
||||
public string? Id { get; }
|
||||
var runes = name.GetRunes().ToArray();
|
||||
|
||||
// Name of custom emoji (e.g. LUL) or actual representation of standard emoji (e.g. 🙂)
|
||||
public string Name { get; }
|
||||
// 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);
|
||||
|
||||
// Name of custom emoji (e.g. LUL) or name of standard emoji (e.g. slight_smile)
|
||||
public string Code => !string.IsNullOrWhiteSpace(Id)
|
||||
? Name
|
||||
: EmojiIndex.TryGetCode(Name) ?? Name;
|
||||
|
||||
public bool IsAnimated { get; }
|
||||
|
||||
public string ImageUrl { get; }
|
||||
|
||||
public Emoji(string? id, string name, bool isAnimated, string imageUrl)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
IsAnimated = isAnimated;
|
||||
ImageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public override string ToString() => Name;
|
||||
return string.Join(
|
||||
"-",
|
||||
filteredRunes.Select(r => r.Value.ToString("x"))
|
||||
);
|
||||
}
|
||||
|
||||
public partial class Emoji
|
||||
private static string GetImageUrl(Snowflake id, bool isAnimated) => isAnimated
|
||||
? $"https://cdn.discordapp.com/emojis/{id}.gif"
|
||||
: $"https://cdn.discordapp.com/emojis/{id}.png";
|
||||
|
||||
private static string GetImageUrl(string name) =>
|
||||
$"https://cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/{GetTwemojiId(name)}.svg";
|
||||
|
||||
public static string GetImageUrl(Snowflake? id, string? name, bool isAnimated)
|
||||
{
|
||||
private static string GetTwemojiName(string name) => name
|
||||
.GetRunes()
|
||||
// Variant selector rune is skipped in Twemoji names
|
||||
.Where(r => r.Value != 0xfe0f)
|
||||
.Select(r => r.Value.ToString("x"))
|
||||
.JoinToString("-");
|
||||
// Custom emoji
|
||||
if (id is not null)
|
||||
return GetImageUrl(id.Value, isAnimated);
|
||||
|
||||
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}.png";
|
||||
}
|
||||
// Standard emoji
|
||||
if (!string.IsNullOrWhiteSpace(name))
|
||||
return GetImageUrl(name);
|
||||
|
||||
// Standard emoji
|
||||
var twemojiName = GetTwemojiName(name);
|
||||
return $"https://twemoji.maxcdn.com/2/svg/{twemojiName}.svg";
|
||||
}
|
||||
// Either ID or name should be set
|
||||
throw new ApplicationException("Emoji has neither ID nor name set.");
|
||||
}
|
||||
|
||||
public static Emoji Parse(JsonElement json)
|
||||
{
|
||||
var id = json.GetPropertyOrNull("id")?.GetString();
|
||||
var name = json.GetProperty("name").GetString();
|
||||
var isAnimated = json.GetPropertyOrNull("animated")?.GetBoolean() ?? false;
|
||||
public static Emoji Parse(JsonElement json)
|
||||
{
|
||||
var id = json.GetPropertyOrNull("id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
|
||||
var name = json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull();
|
||||
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,53 +1,42 @@
|
||||
using System.Text.Json;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
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 partial class Guild : IHasId
|
||||
public static Guild DirectMessages { get; } = new(
|
||||
Snowflake.Zero,
|
||||
"Direct Messages",
|
||||
GetDefaultIconUrl()
|
||||
);
|
||||
|
||||
private static string GetDefaultIconUrl() =>
|
||||
"https://cdn.discordapp.com/embed/avatars/0.png";
|
||||
|
||||
private static string GetIconUrl(Snowflake id, string iconHash)
|
||||
{
|
||||
public Snowflake Id { get; }
|
||||
var extension = iconHash.StartsWith("a_", StringComparison.Ordinal)
|
||||
? "gif"
|
||||
: "png";
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public string IconUrl { get; }
|
||||
|
||||
public Guild(Snowflake id, string name, string iconUrl)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
IconUrl = iconUrl;
|
||||
}
|
||||
|
||||
public override string ToString() => Name;
|
||||
return $"https://cdn.discordapp.com/icons/{id}/{iconHash}.{extension}";
|
||||
}
|
||||
|
||||
public partial class Guild
|
||||
public static Guild Parse(JsonElement json)
|
||||
{
|
||||
public static Guild DirectMessages { get; } = new(
|
||||
Snowflake.Zero,
|
||||
"Direct Messages",
|
||||
GetDefaultIconUrl()
|
||||
);
|
||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||
var name = json.GetProperty("name").GetNonNullString();
|
||||
|
||||
private static string GetDefaultIconUrl() =>
|
||||
"https://cdn.discordapp.com/embed/avatars/0.png";
|
||||
var iconHash = json.GetPropertyOrNull("icon")?.GetNonWhiteSpaceStringOrNull();
|
||||
var iconUrl = !string.IsNullOrWhiteSpace(iconHash)
|
||||
? GetIconUrl(id, iconHash)
|
||||
: GetDefaultIconUrl();
|
||||
|
||||
private static string GetIconUrl(Snowflake id, string iconHash) =>
|
||||
$"https://cdn.discordapp.com/icons/{id}/{iconHash}.png";
|
||||
|
||||
public static Guild Parse(JsonElement json)
|
||||
{
|
||||
var id = json.GetProperty("id").GetString().Pipe(Snowflake.Parse);
|
||||
var name = json.GetProperty("name").GetString();
|
||||
var iconHash = json.GetProperty("icon").GetString();
|
||||
|
||||
var iconUrl = !string.IsNullOrWhiteSpace(iconHash)
|
||||
? GetIconUrl(id, iconHash)
|
||||
: GetDefaultIconUrl();
|
||||
|
||||
return new Guild(id, name, iconUrl);
|
||||
}
|
||||
return new Guild(id, name, iconUrl);
|
||||
}
|
||||
}
|
||||
@@ -6,51 +6,41 @@ using DiscordChatExporter.Core.Discord.Data.Common;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data
|
||||
namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
// https://discord.com/developers/docs/resources/guild#guild-member-object
|
||||
public partial record Member(
|
||||
User User,
|
||||
string Nick,
|
||||
IReadOnlyList<Snowflake> RoleIds) : IHasId
|
||||
{
|
||||
// https://discord.com/developers/docs/resources/guild#guild-member-object
|
||||
public partial class Member : IHasId
|
||||
public Snowflake Id => User.Id;
|
||||
}
|
||||
|
||||
public partial record Member
|
||||
{
|
||||
public static Member CreateForUser(User user) => new(
|
||||
user,
|
||||
user.Name,
|
||||
Array.Empty<Snowflake>()
|
||||
);
|
||||
|
||||
public static Member Parse(JsonElement json)
|
||||
{
|
||||
public Snowflake Id => User.Id;
|
||||
var user = json.GetProperty("user").Pipe(User.Parse);
|
||||
var nick = json.GetPropertyOrNull("nick")?.GetNonWhiteSpaceStringOrNull();
|
||||
|
||||
public User User { get; }
|
||||
var roleIds = json
|
||||
.GetPropertyOrNull("roles")?
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetNonWhiteSpaceString())
|
||||
.Select(Snowflake.Parse)
|
||||
.ToArray() ?? Array.Empty<Snowflake>();
|
||||
|
||||
public string Nick { get; }
|
||||
|
||||
public IReadOnlyList<Snowflake> RoleIds { get; }
|
||||
|
||||
public Member(User user, string nick, IReadOnlyList<Snowflake> roleIds)
|
||||
{
|
||||
User = user;
|
||||
Nick = nick;
|
||||
RoleIds = roleIds;
|
||||
}
|
||||
|
||||
public override string ToString() => Nick;
|
||||
}
|
||||
|
||||
public partial class Member
|
||||
{
|
||||
public static Member CreateForUser(User user) => new(
|
||||
return new Member(
|
||||
user,
|
||||
user.Name,
|
||||
Array.Empty<Snowflake>()
|
||||
nick ?? user.Name,
|
||||
roleIds
|
||||
);
|
||||
|
||||
public static Member Parse(JsonElement json)
|
||||
{
|
||||
var user = json.GetProperty("user").Pipe(User.Parse);
|
||||
var nick = json.GetPropertyOrNull("nick")?.GetString();
|
||||
|
||||
var roleIds =
|
||||
json.GetPropertyOrNull("roles")?.EnumerateArray().Select(j => j.GetString()).Select(Snowflake.Parse).ToArray() ??
|
||||
Array.Empty<Snowflake>();
|
||||
|
||||
return new Member(
|
||||
user,
|
||||
nick ?? user.Name,
|
||||
roleIds
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,150 +3,155 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||
using DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data
|
||||
namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#message-object
|
||||
public record Message(
|
||||
Snowflake Id,
|
||||
MessageKind Kind,
|
||||
User Author,
|
||||
DateTimeOffset Timestamp,
|
||||
DateTimeOffset? EditedTimestamp,
|
||||
DateTimeOffset? CallEndedTimestamp,
|
||||
bool IsPinned,
|
||||
string Content,
|
||||
IReadOnlyList<Attachment> Attachments,
|
||||
IReadOnlyList<Embed> Embeds,
|
||||
IReadOnlyList<Sticker> Stickers,
|
||||
IReadOnlyList<Reaction> Reactions,
|
||||
IReadOnlyList<User> MentionedUsers,
|
||||
MessageReference? Reference,
|
||||
Message? ReferencedMessage) : IHasId
|
||||
{
|
||||
// https://discord.com/developers/docs/resources/channel#message-object-message-types
|
||||
public enum MessageType
|
||||
private static IReadOnlyList<Embed> NormalizeEmbeds(IReadOnlyList<Embed> embeds)
|
||||
{
|
||||
Default = 0,
|
||||
RecipientAdd = 1,
|
||||
RecipientRemove = 2,
|
||||
Call = 3,
|
||||
ChannelNameChange = 4,
|
||||
ChannelIconChange = 5,
|
||||
ChannelPinnedMessage = 6,
|
||||
GuildMemberJoin = 7,
|
||||
Reply = 19
|
||||
}
|
||||
if (embeds.Count <= 1)
|
||||
return embeds;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#message-object
|
||||
public partial class Message : IHasId
|
||||
{
|
||||
public Snowflake Id { get; }
|
||||
// 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
|
||||
|
||||
public MessageType Type { get; }
|
||||
var normalizedEmbeds = new List<Embed>();
|
||||
|
||||
public User Author { get; }
|
||||
|
||||
public DateTimeOffset Timestamp { get; }
|
||||
|
||||
public DateTimeOffset? EditedTimestamp { get; }
|
||||
|
||||
public DateTimeOffset? CallEndedTimestamp { get; }
|
||||
|
||||
public bool IsPinned { get; }
|
||||
|
||||
public string Content { get; }
|
||||
|
||||
public IReadOnlyList<Attachment> Attachments { get; }
|
||||
|
||||
public IReadOnlyList<Embed> Embeds { get; }
|
||||
|
||||
public IReadOnlyList<Reaction> Reactions { get; }
|
||||
|
||||
public IReadOnlyList<User> MentionedUsers { get; }
|
||||
|
||||
public MessageReference? Reference { get; }
|
||||
|
||||
public Message? ReferencedMessage { get; }
|
||||
|
||||
public Message(
|
||||
Snowflake id,
|
||||
MessageType type,
|
||||
User author,
|
||||
DateTimeOffset timestamp,
|
||||
DateTimeOffset? editedTimestamp,
|
||||
DateTimeOffset? callEndedTimestamp,
|
||||
bool isPinned,
|
||||
string content,
|
||||
IReadOnlyList<Attachment> attachments,
|
||||
IReadOnlyList<Embed> embeds,
|
||||
IReadOnlyList<Reaction> reactions,
|
||||
IReadOnlyList<User> mentionedUsers,
|
||||
MessageReference? messageReference,
|
||||
Message? referencedMessage)
|
||||
for (var i = 0; i < embeds.Count; i++)
|
||||
{
|
||||
Id = id;
|
||||
Type = type;
|
||||
Author = author;
|
||||
Timestamp = timestamp;
|
||||
EditedTimestamp = editedTimestamp;
|
||||
CallEndedTimestamp = callEndedTimestamp;
|
||||
IsPinned = isPinned;
|
||||
Content = content;
|
||||
Attachments = attachments;
|
||||
Embeds = embeds;
|
||||
Reactions = reactions;
|
||||
MentionedUsers = mentionedUsers;
|
||||
Reference = messageReference;
|
||||
ReferencedMessage = referencedMessage;
|
||||
}
|
||||
var embed = embeds[i];
|
||||
|
||||
public override string ToString() => Content;
|
||||
}
|
||||
|
||||
public partial class Message
|
||||
{
|
||||
public static Message Parse(JsonElement json)
|
||||
{
|
||||
var id = json.GetProperty("id").GetString().Pipe(Snowflake.Parse);
|
||||
var author = json.GetProperty("author").Pipe(User.Parse);
|
||||
var timestamp = json.GetProperty("timestamp").GetDateTimeOffset();
|
||||
var editedTimestamp = json.GetPropertyOrNull("edited_timestamp")?.GetDateTimeOffset();
|
||||
var callEndedTimestamp = json.GetPropertyOrNull("call")?.GetPropertyOrNull("ended_timestamp")?.GetDateTimeOffset();
|
||||
var type = (MessageType) json.GetProperty("type").GetInt32();
|
||||
var isPinned = json.GetPropertyOrNull("pinned")?.GetBoolean() ?? false;
|
||||
var messageReference = json.GetPropertyOrNull("message_reference")?.Pipe(MessageReference.Parse);
|
||||
var referencedMessage = json.GetPropertyOrNull("referenced_message")?.Pipe(Parse);
|
||||
|
||||
var content = type switch
|
||||
if (embed.Url?.Contains("://twitter.com/", StringComparison.OrdinalIgnoreCase) == true)
|
||||
{
|
||||
MessageType.RecipientAdd => "Added a recipient.",
|
||||
MessageType.RecipientRemove => "Removed a recipient.",
|
||||
MessageType.Call =>
|
||||
$"Started a call that lasted {callEndedTimestamp?.Pipe(t => t - timestamp).Pipe(t => (int) t.TotalMinutes) ?? 0} minutes.",
|
||||
MessageType.ChannelNameChange => "Changed the channel name.",
|
||||
MessageType.ChannelIconChange => "Changed the channel icon.",
|
||||
MessageType.ChannelPinnedMessage => "Pinned a message.",
|
||||
MessageType.GuildMemberJoin => "Joined the server.",
|
||||
_ => json.GetPropertyOrNull("content")?.GetString() ?? ""
|
||||
};
|
||||
// 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();
|
||||
|
||||
var attachments =
|
||||
json.GetPropertyOrNull("attachments")?.EnumerateArray().Select(Attachment.Parse).ToArray() ??
|
||||
Array.Empty<Attachment>();
|
||||
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 });
|
||||
|
||||
var embeds =
|
||||
json.GetPropertyOrNull("embeds")?.EnumerateArray().Select(Embed.Parse).ToArray() ??
|
||||
Array.Empty<Embed>();
|
||||
|
||||
var reactions =
|
||||
json.GetPropertyOrNull("reactions")?.EnumerateArray().Select(Reaction.Parse).ToArray() ??
|
||||
Array.Empty<Reaction>();
|
||||
|
||||
var mentionedUsers =
|
||||
json.GetPropertyOrNull("mentions")?.EnumerateArray().Select(User.Parse).ToArray() ??
|
||||
Array.Empty<User>();
|
||||
|
||||
return new Message(
|
||||
id,
|
||||
type,
|
||||
author,
|
||||
timestamp,
|
||||
editedTimestamp,
|
||||
callEndedTimestamp,
|
||||
isPinned,
|
||||
content,
|
||||
attachments,
|
||||
embeds,
|
||||
reactions,
|
||||
mentionedUsers,
|
||||
messageReference,
|
||||
referencedMessage
|
||||
);
|
||||
i += trailingEmbeds.Length;
|
||||
}
|
||||
else
|
||||
{
|
||||
normalizedEmbeds.Add(embed);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
normalizedEmbeds.Add(embed);
|
||||
}
|
||||
}
|
||||
|
||||
return normalizedEmbeds;
|
||||
}
|
||||
|
||||
public static Message Parse(JsonElement json)
|
||||
{
|
||||
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 timestamp = json.GetProperty("timestamp").GetDateTimeOffset();
|
||||
var editedTimestamp = json.GetPropertyOrNull("edited_timestamp")?.GetDateTimeOffset();
|
||||
var callEndedTimestamp = json
|
||||
.GetPropertyOrNull("call")?
|
||||
.GetPropertyOrNull("ended_timestamp")?
|
||||
.GetDateTimeOffset();
|
||||
|
||||
var isPinned = json.GetPropertyOrNull("pinned")?.GetBooleanOrNull() ?? false;
|
||||
|
||||
var content = kind switch
|
||||
{
|
||||
MessageKind.RecipientAdd => "Added a recipient.",
|
||||
MessageKind.RecipientRemove => "Removed a recipient.",
|
||||
MessageKind.Call =>
|
||||
$"Started a call that lasted {callEndedTimestamp?.Pipe(t => t - timestamp).Pipe(t => (int)t.TotalMinutes) ?? 0} minutes.",
|
||||
MessageKind.ChannelNameChange => "Changed the channel name.",
|
||||
MessageKind.ChannelIconChange => "Changed the channel icon.",
|
||||
MessageKind.ChannelPinnedMessage => "Pinned a message.",
|
||||
MessageKind.ThreadCreated => "Started a thread.",
|
||||
MessageKind.GuildMemberJoin => "Joined the server.",
|
||||
_ => json.GetPropertyOrNull("content")?.GetStringOrNull() ?? ""
|
||||
};
|
||||
|
||||
var attachments =
|
||||
json.GetPropertyOrNull("attachments")?.EnumerateArrayOrNull()?.Select(Attachment.Parse).ToArray() ??
|
||||
Array.Empty<Attachment>();
|
||||
|
||||
var embeds = NormalizeEmbeds(
|
||||
json.GetPropertyOrNull("embeds")?.EnumerateArrayOrNull()?.Select(Embed.Parse).ToArray() ??
|
||||
Array.Empty<Embed>()
|
||||
);
|
||||
|
||||
var stickers =
|
||||
json.GetPropertyOrNull("sticker_items")?.EnumerateArrayOrNull()?.Select(Sticker.Parse).ToArray() ??
|
||||
Array.Empty<Sticker>();
|
||||
|
||||
var reactions =
|
||||
json.GetPropertyOrNull("reactions")?.EnumerateArrayOrNull()?.Select(Reaction.Parse).ToArray() ??
|
||||
Array.Empty<Reaction>();
|
||||
|
||||
var mentionedUsers =
|
||||
json.GetPropertyOrNull("mentions")?.EnumerateArrayOrNull()?.Select(User.Parse).ToArray() ??
|
||||
Array.Empty<User>();
|
||||
|
||||
var messageReference = json.GetPropertyOrNull("message_reference")?.Pipe(MessageReference.Parse);
|
||||
var referencedMessage = json.GetPropertyOrNull("referenced_message")?.Pipe(Parse);
|
||||
|
||||
return new Message(
|
||||
id,
|
||||
kind,
|
||||
author,
|
||||
timestamp,
|
||||
editedTimestamp,
|
||||
callEndedTimestamp,
|
||||
isPinned,
|
||||
content,
|
||||
attachments,
|
||||
embeds,
|
||||
stickers,
|
||||
reactions,
|
||||
mentionedUsers,
|
||||
messageReference,
|
||||
referencedMessage
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#message-object-message-types
|
||||
public enum MessageKind
|
||||
{
|
||||
Default = 0,
|
||||
RecipientAdd = 1,
|
||||
RecipientRemove = 2,
|
||||
Call = 3,
|
||||
ChannelNameChange = 4,
|
||||
ChannelIconChange = 5,
|
||||
ChannelPinnedMessage = 6,
|
||||
GuildMemberJoin = 7,
|
||||
ThreadCreated = 18,
|
||||
Reply = 19
|
||||
}
|
||||
|
||||
public static class MessageKindExtensions
|
||||
{
|
||||
public static bool IsSystemNotification(this MessageKind c) => (int)c is >= 1 and <= 18;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user