mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-07-07 14:44:39 +02:00
Compare commits
140 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c3abeadf01 | |||
| 86ee9c8d5f | |||
| c99355dec3 | |||
| 11d34109a7 | |||
| 609ca0fc0d | |||
| 6cadb19cc8 | |||
| d02649773e | |||
| 18d9c189b7 | |||
| 3d2d197904 | |||
| bf0d8ab31e | |||
| 30b447d2ae | |||
| 3d047321cf | |||
| 6d787c4071 | |||
| d779ed9bc8 | |||
| 3319b4734d | |||
| e052241713 | |||
| 2b7f1ed4ed | |||
| 03784f0d7c | |||
| e7310274ba | |||
| 4eab781450 | |||
| 6582e26cd3 | |||
| c48899e0b1 | |||
| 41b4e47d0e | |||
| 6bbde4ccdc | |||
| 469a731892 | |||
| d8315c7827 | |||
| a4111c184e | |||
| c945c98f75 | |||
| 31c7ae9312 | |||
| 03c5c1bc5e | |||
| 0ae9062a30 | |||
| 25caf04445 | |||
| 9048557b17 | |||
| faad994332 | |||
| d7537425f8 | |||
| e261edde8b | |||
| 72bb886a5e | |||
| 9428d5ed56 | |||
| b8b1fdb1d1 | |||
| 168b3c2f31 | |||
| 9575fd11b5 | |||
| a332bda07d | |||
| c3f181c9e0 | |||
| b9cd40f211 | |||
| ab933a7240 | |||
| a9fc439cc5 | |||
| d4f5fc5efc | |||
| 505330e117 | |||
| 36db99b5cf | |||
| a4110a362f | |||
| 0ab8bd67c4 | |||
| 31952a109e | |||
| 2e1636e6c9 | |||
| 20e782e6ed | |||
| ebb838bb81 | |||
| 966627f289 | |||
| 4ec00d0ec8 | |||
| 8bc1bcaf16 | |||
| 8f40acdda7 | |||
| bbe18368fa | |||
| 48eece554c | |||
| 7d7f1cc1e5 | |||
| 2a1998b81c | |||
| ac7f08ff3e | |||
| 95c5a43f6e | |||
| 91afded824 | |||
| 0981c51fb9 | |||
| 55209a0517 | |||
| c2c35cf3a3 | |||
| 404542d973 | |||
| f36852a1a2 | |||
| 0e1c3e4c76 | |||
| 83e3289ead | |||
| b51900ec6a | |||
| d1647e8286 | |||
| 95115f3e99 | |||
| 53ff8ba430 | |||
| cbab5fb71c | |||
| 9512729ec2 | |||
| 75db3e6442 | |||
| a29c517527 | |||
| c9c4ca1733 | |||
| 471c6f87db | |||
| c3d79ff0c4 | |||
| 83657962b8 | |||
| b5e0ec1c81 | |||
| d9a78d8e27 | |||
| 6620c6299c | |||
| 20a952aec5 | |||
| c405121c0b | |||
| 191294b4fe | |||
| 8e5269f0ab | |||
| 6d3adf9fde | |||
| 71751b350f | |||
| 290729158b | |||
| 2a81abb1a6 | |||
| a7f4fe0643 | |||
| 60603dfb04 | |||
| 9ad8126d60 | |||
| c8d83beb8d | |||
| f1ae0266f1 | |||
| ea4cb43479 | |||
| 2c67e502e4 | |||
| 1fc27fd5c4 | |||
| d5848bebc6 | |||
| 5cef107e98 | |||
| 2a5e09bf07 | |||
| f73d07a7c9 | |||
| d99958a9b1 | |||
| 75b942f66c | |||
| 0fdab76a74 | |||
| 53b8927fce | |||
| 3487849eba | |||
| b71af710c7 | |||
| 63124b4431 | |||
| f99f1f4641 | |||
| 3b2c308a25 | |||
| a95d2ef298 | |||
| 049338009e | |||
| 93799eb231 | |||
| 1e7b8ec83f | |||
| e7d80688aa | |||
| 60d9992c74 | |||
| c6ea04144d | |||
| b36071cddd | |||
| 90c68e3cde | |||
| 4cb8866429 | |||
| 9dc81b93da | |||
| 04f5050bbe | |||
| 6917406101 | |||
| 3436f6b060 | |||
| e00f126a5e | |||
| c7ac3229f5 | |||
| fc29735a45 | |||
| bf76f10030 | |||
| a68df7a065 | |||
| 0cf6281c19 | |||
| d1e5f418b6 | |||
| abaa31a9d1 | |||
| 374c7af48d |
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 19 KiB |
+7
-6
@@ -4,7 +4,7 @@ Docker distribution of DiscordChatExporter provides a way to run the app in a vi
|
||||
|
||||
Note that only the CLI flavor of DiscordChatExporter is available for use with Docker.
|
||||
|
||||
### Pulling
|
||||
## 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.
|
||||
|
||||
@@ -20,7 +20,7 @@ Note the `:stable` tag. DiscordChatExporter images are tagged according to the f
|
||||
|
||||
You can see all available tags [here](https://hub.docker.com/r/tyrrrz/discordchatexporter/tags?page=1&ordering=name).
|
||||
|
||||
### Usage
|
||||
## Usage
|
||||
|
||||
To run the CLI in Docker and render help text:
|
||||
|
||||
@@ -55,10 +55,11 @@ You can also use the current working directory as the output directory by specif
|
||||
- `-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>
|
||||
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/).
|
||||
|
||||
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
|
||||
## Environment variables
|
||||
|
||||
DiscordChatExpoter CLI accepts environment variables as fallbacks for the `--token` and `--bot` options.
|
||||
|
||||
@@ -70,11 +71,11 @@ 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
|
||||
## 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
|
||||
## 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.
|
||||
|
||||
|
||||
+12
-8
@@ -1,6 +1,7 @@
|
||||
# Install .NET Core runtime
|
||||
# Install .NET 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.
|
||||
|
||||
@@ -19,8 +20,11 @@ If you are using the CLI from Docker, installing the runtime on the host machine
|
||||
- [.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)
|
||||
> **Note**:
|
||||
> [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)
|
||||
|
||||
> **Note**:
|
||||
> [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).
|
||||
@@ -30,7 +34,7 @@ Look for the download link in the '**.NET Runtime**' section, under **Installers
|
||||
|
||||
## Linux
|
||||
|
||||
**You only need to install .NET Core <u>Runtime</u> v7.0**
|
||||
**You only need to install .NET Runtime v7.0**
|
||||
|
||||
Check out the instructions for your distro:
|
||||
|
||||
@@ -46,17 +50,17 @@ Installing .NET Runtime is not needed. Please refer to the [Docker usage instruc
|
||||
|
||||
## Verify installation (optional)
|
||||
|
||||
You can check which version of **.NET Core** is installed by following these instructions:
|
||||
You can check which version of **.NET Runtime** is installed by following these instructions:
|
||||
|
||||
#### Step 1
|
||||
### Step 1
|
||||
|
||||
**Windows:** Open Command Prompt (aka `cmd`)
|
||||
**macOS and Linux:** Open `Terminal`
|
||||
|
||||
#### Step 2
|
||||
### Step 2
|
||||
|
||||
Run: `dotnet --info`
|
||||
If **.NET Core Runtime** is correctly installed, the command will output the following:
|
||||
If **.NET Runtime** is correctly installed, the command will output the following:
|
||||
|
||||
```
|
||||
|
||||
|
||||
+59
-46
@@ -1,5 +1,3 @@
|
||||
# GUI, CLI and Formats explained
|
||||
|
||||
# Getting started
|
||||
|
||||
Welcome to the getting started page!
|
||||
@@ -10,22 +8,22 @@ If you still have unanswered questions after reading this page or if you have en
|
||||
|
||||
The information presented on this page is valid for **all** platforms.
|
||||
|
||||
# GUI or CLI?
|
||||
## 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.
|
||||
- **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.
|
||||
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
|
||||
## Using the GUI
|
||||
|
||||
### Video tutorial
|
||||
|
||||
@@ -35,27 +33,31 @@ If you're not comfortable with **Windows'** Command Line (cmd), please choose th
|
||||
|
||||
### Guide
|
||||
|
||||
**1.** After extracting the `.zip`, open `DiscordChatExporter.exe`
|
||||
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 (→).
|
||||
|
||||
**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.
|
||||
> **Warning**:
|
||||
> **Never share your token!**
|
||||
> A token gives full access 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.
|
||||
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.
|
||||
> **Note**:
|
||||
> 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:
|
||||
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.
|
||||
> **Note**:
|
||||
> 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.
|
||||
@@ -63,7 +65,7 @@ Click the menu button (☰) to see more options:
|
||||
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.
|
||||
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"/>
|
||||
|
||||
@@ -73,7 +75,8 @@ Click the menu button (☰) to see more options:
|
||||
Perform automatic updates on every launch.
|
||||
Default: Enabled
|
||||
|
||||
> 💡 Tip: Keep this option enabled to receive the latest features and bug fixes!
|
||||
> **Note**:
|
||||
> Keep this option enabled to receive the latest features and bug fixes!
|
||||
|
||||
**Dark mode**
|
||||
Use darker colors in the UI (User Interface).
|
||||
@@ -105,18 +108,20 @@ More info about .NET date formats [here](https://docs.microsoft.com/en-us/dotnet
|
||||
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.
|
||||
> **Note**:
|
||||
> 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
|
||||
## Using the CLI
|
||||
|
||||
> **Note**:
|
||||
> 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**).
|
||||
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.
|
||||
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.
|
||||

|
||||
@@ -125,7 +130,7 @@ Default: 1
|
||||
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.
|
||||
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:
|
||||
|
||||
@@ -137,7 +142,7 @@ 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
|
||||
### DCE.CLI commands
|
||||
|
||||
| Command | Description |
|
||||
| ------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
|
||||
@@ -157,7 +162,7 @@ To get help with a specific command, please run:
|
||||
dotnet DiscordChatExporter.Cli.dll command -h
|
||||
```
|
||||
|
||||
## export
|
||||
#### `export`
|
||||
|
||||
| | Option | Description |
|
||||
| ------ | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
@@ -174,11 +179,12 @@ dotnet DiscordChatExporter.Cli.dll command -h
|
||||
| | [--dateformat](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-formats) | Format used when writing dates. |
|
||||
| | -h | Shows help text |
|
||||
|
||||
> **Note**:
|
||||
> 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
|
||||
##### Basic usage
|
||||
|
||||
You can quickly export with DCE's default settings by using just `-t token` and `-c channelid`.
|
||||
|
||||
@@ -186,7 +192,7 @@ You can quickly export with DCE's default settings by using just `-t token` and
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555
|
||||
```
|
||||
|
||||
### Changing the format
|
||||
##### Changing the format
|
||||
|
||||
You can change the export format to `HtmlDark`, `HtmlLight`, `PlainText` `Json` or `Csv` with `-f format`. The default format is `HtmlDark`.
|
||||
|
||||
@@ -194,7 +200,7 @@ You can change the export format to `HtmlDark`, `HtmlLight`, `PlainText` `Json`
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 -f Json
|
||||
```
|
||||
|
||||
### Changing the output filename
|
||||
##### Changing the output filename
|
||||
|
||||
You can change the filename by using `-o name.ext`. e.g. for the `HTML` format:
|
||||
|
||||
@@ -202,7 +208,7 @@ You can change the filename by using `-o name.ext`. e.g. for the `HTML` format:
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 -o myserver.html
|
||||
```
|
||||
|
||||
### Changing the output directory
|
||||
##### 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 (").
|
||||
@@ -211,7 +217,7 @@ If any of the folders in the path have a space in its name, escape them with quo
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 -o "C:\Discord Exports"
|
||||
```
|
||||
|
||||
### Changing the filename and output directory
|
||||
##### 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.
|
||||
@@ -221,7 +227,7 @@ If any of the folders in the path have a space in its name, escape them with quo
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 -o "C:\Discord Exports\myserver.html"
|
||||
```
|
||||
|
||||
### Generating the filename and output directory dynamically
|
||||
##### 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.
|
||||
|
||||
@@ -245,7 +251,7 @@ Here is the full list of supported template tokens:
|
||||
- `%b` - the "before" date
|
||||
- `%%` - escapes `%`
|
||||
|
||||
### Partitioning
|
||||
##### 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.
|
||||
@@ -260,7 +266,7 @@ A 45mb channel set to be partitioned every 20mb will output 3 files.
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 -p 20mb
|
||||
```
|
||||
|
||||
### Downloading assets
|
||||
##### 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.
|
||||
@@ -270,7 +276,7 @@ A folder containing the assets will be created along with the exported chat. The
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 --media
|
||||
```
|
||||
|
||||
### Reuse assets
|
||||
##### 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.
|
||||
|
||||
@@ -278,7 +284,7 @@ Previously downloaded assets can be reused to skip redundant downloads as long a
|
||||
dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 --media --reuse-media
|
||||
```
|
||||
|
||||
### Date formats
|
||||
##### Date formats
|
||||
|
||||
This setting changes how dates are formatted in the exported files.
|
||||
|
||||
@@ -299,7 +305,7 @@ dotnet DiscordChatExporter.Cli.dll export -t "mfa.Ifrn" -c 53555 --dateformat "y
|
||||
|
||||
> Special thanks to [@andrewkolos](https://github.com/andrewkolos) for adding the Unix options
|
||||
|
||||
### Date ranges
|
||||
##### 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:
|
||||
@@ -326,7 +332,7 @@ You can try different formats like `17-SEP-2019 11:34 PM` or even refine your ra
|
||||
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
|
||||
#### `exportdm`
|
||||
|
||||
| | Option | Description |
|
||||
| ------ | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
@@ -343,11 +349,12 @@ More info about .NET date formats [here](https://docs.microsoft.com/en-us/dotnet
|
||||
| | [--dateformat](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-formats) | Date format used in output |
|
||||
| | -h | Shows help text |
|
||||
|
||||
> **Note**:
|
||||
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
|
||||
|
||||
This command exports all your Direct Messages.
|
||||
|
||||
## exportguild
|
||||
#### `exportguild`
|
||||
|
||||
| | Option | Description |
|
||||
| ------ | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
@@ -365,11 +372,12 @@ This command exports all your Direct Messages.
|
||||
| | [--dateformat](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-formats) | Date format used in output |
|
||||
| | -h | Shows help text |
|
||||
|
||||
> **Note**:
|
||||
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
|
||||
|
||||
This command exports all channels of a Server.
|
||||
|
||||
## exportall
|
||||
#### `exportall`
|
||||
|
||||
| | Option | Description |
|
||||
| ------ | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
@@ -387,6 +395,7 @@ This command exports all channels of a Server.
|
||||
| | [--dateformat](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Getting-started.md#date-formats) | Date format used in output |
|
||||
| | -h | Shows help text |
|
||||
|
||||
> **Note**:
|
||||
> 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.
|
||||
@@ -397,7 +406,7 @@ To exclude DMs, add the `--include-dm false` option:
|
||||
dotnet DiscordChatExporter.Cli.dll exportall -t "mfa.Ifrn" --include-dm false
|
||||
```
|
||||
|
||||
## channels
|
||||
#### `channels`
|
||||
|
||||
| | Option | Description |
|
||||
| ------ | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
@@ -405,6 +414,7 @@ dotnet DiscordChatExporter.Cli.dll exportall -t "mfa.Ifrn" --include-dm false
|
||||
| **\*** | [-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 |
|
||||
|
||||
> **Note**:
|
||||
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
|
||||
|
||||
This command outputs the server channels in the following format:
|
||||
@@ -415,13 +425,14 @@ To save the output to a file, run the command below. If the file already exists,
|
||||
dotnet DiscordChatExporter.Cli.dll channels -t "mfa.Ifrn" -g 21814 > C:\path\to\output.txt
|
||||
```
|
||||
|
||||
## dm
|
||||
#### `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 |
|
||||
|
||||
> **Note**:
|
||||
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
|
||||
|
||||
This command outputs the list of Direct Messages.
|
||||
@@ -431,13 +442,14 @@ To save the output to a file, run the command with `> C:\path\…` like the exam
|
||||
dotnet DiscordChatExporter.Cli.dll dm -t "mfa.Ifrn" > C:\path\to\output.txt
|
||||
```
|
||||
|
||||
## guilds
|
||||
#### `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 |
|
||||
|
||||
> **Note**:
|
||||
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
|
||||
|
||||
This command outputs a list of your Server List.
|
||||
@@ -447,37 +459,38 @@ To save the output to a file, run the command with `> C:\path\…` like the exam
|
||||
dotnet DiscordChatExporter.Cli.dll guilds -t "mfa.Ifrn" > C:\path\to\output.txt
|
||||
```
|
||||
|
||||
## guide
|
||||
#### `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
|
||||
## File formats
|
||||
|
||||
## HTML
|
||||
### 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.
|
||||
> **Warning**:
|
||||
> If a picture is deleted, or if a user changes its avatar, the respective images will no longer be displayed.
|
||||
> Export using the "Download referenced assets" (`--media`) option to avoid this.
|
||||
|
||||
## Plain Text
|
||||
### 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
|
||||
### 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
|
||||
### CSV
|
||||
|
||||

|
||||

|
||||
@@ -487,7 +500,7 @@ You can open `.csv` files with a text editor, such as Notepad, or a spreadsheet
|
||||
|
||||
**([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)
|
||||
|
||||
+7
-7
@@ -1,20 +1,20 @@
|
||||
# Linux usage instructions
|
||||
|
||||
### Step 1: Install .NET Core Runtime
|
||||
## Installing .NET Runtime
|
||||
|
||||
Please follow the [instructions provided here](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Dotnet.md).
|
||||
|
||||
### Step 2: Downloading and using DiscordChatExporter.Cli
|
||||
## 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:
|
||||
1. Download [DiscordChatExporter.CLI.zip](https://github.com/Tyrrrz/DiscordChatExporter/releases/latest) and extract it to a folder.
|
||||
2. Open Terminal.
|
||||
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.
|
||||
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).
|
||||
> [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.
|
||||
|
||||
+10
-8
@@ -2,19 +2,21 @@
|
||||
|
||||

|
||||
|
||||
### Step 1: Install .NET Core Runtime
|
||||
## Installing .NET Runtime
|
||||
|
||||
Please follow the [instructions provided here](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Dotnet.md).
|
||||
|
||||
### Step 2: Downloading and using DiscordChatExporter.Cli
|
||||
## 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:
|
||||
1. Download [DiscordChatExporter.CLI.zip](https://github.com/Tyrrrz/DiscordChatExporter/releases/latest) and extract it to a folder.
|
||||
2. Search for `Terminal.app` in Spotlight (⌘+SPACE), then open it.
|
||||
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.
|
||||
4. Execute the following command to export, replacing `TOKEN` and `CHANNEL` with your own values:
|
||||
|
||||
dotnet DiscordChatExporter.Cli.dll export -t TOKEN -c CHANNEL
|
||||
```
|
||||
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).
|
||||
> [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.
|
||||
|
||||
+10
-20
@@ -2,7 +2,7 @@
|
||||
|
||||
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.
|
||||
To configure a filter, specify it in advanced export parameters when using the GUI or by passing the `--filter` option when using the CLI. For the CLI version, see also [caveats](#cli-caveats).
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -78,38 +78,28 @@ from:Tyrrrz | from:"96-LB"
|
||||
-(from:Tyrrrz has:image)
|
||||
```
|
||||
|
||||
- Escape special characters (`-` is escaped below so it's not parsed as negation operator):
|
||||
- Escape special characters (`-` is escaped below, so it's not parsed as negation operator):
|
||||
|
||||
```
|
||||
from:96\-LB
|
||||
```
|
||||
|
||||
## CLI Caveat
|
||||
## CLI Caveats
|
||||
|
||||
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:
|
||||
In most cases, you will need to enclose your filter in quotes (`"`) to escape characters that may have special meaning in your shell:
|
||||
|
||||
```
|
||||
DiscordChatExporter.Cli export [...] --filter "-from:Tyrrrz"
|
||||
DiscordChatExporter.Cli export [...] --filter "from:Tyrrrz has:image"
|
||||
```
|
||||
|
||||
This works (note the space):
|
||||
If you need to include quotes inside the filter itself as well, use single quotes (`'`) for those instead:
|
||||
|
||||
```
|
||||
DiscordChatExporter.Cli export [...] --filter " -from:Tyrrrz"
|
||||
DiscordChatExporter.Cli export [...] --filter "from:Tyrrrz 'hello world'"
|
||||
```
|
||||
|
||||
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:
|
||||
Additionally, negated filters (those that start with `-`) may cause parsing issues even when enclosed in quotes. To avoid this, use the tilde (`~`) character instead of the dash (`-`):
|
||||
|
||||
```
|
||||
DiscordChatExporter.Cli export [...] --filter "from:"Some name with spaces""
|
||||
```
|
||||
|
||||
This works:
|
||||
|
||||
```
|
||||
DiscordChatExporter.Cli export [...] --filter "from:'Some name with spaces'"
|
||||
```
|
||||
DiscordChatExporter.Cli export [...] --filter ~from:Tyrrrz
|
||||
```
|
||||
+10
-19
@@ -1,31 +1,22 @@
|
||||
# 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)
|
||||
- [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)
|
||||
- [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)
|
||||
- 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)
|
||||
- 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
|
||||
|
||||
|
||||
+34
-35
@@ -4,13 +4,14 @@ Make sure you already have **DiscordChatExporter.CLI** and **.NET Core** properl
|
||||
|
||||
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/>
|
||||
1. Open Terminal and create a new text file with `nano /path/to/DiscordChatExporter/cron.sh`
|
||||
|
||||
> For beginners: You can't use your mouse in nano, use the arrow keys to control the cursor (caret).
|
||||
> **Note**:
|
||||
> 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:
|
||||
2. Paste the following into the text file:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
@@ -63,51 +64,49 @@ fi
|
||||
exit 0
|
||||
```
|
||||
|
||||
**3.** Replace:
|
||||
3. Replace:
|
||||
|
||||
`tokenhere` with your [Token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md).
|
||||
- `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.
|
||||
|
||||
`channelhere` with a [Channel ID](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md).
|
||||
> **Note**:
|
||||
> Remember to escape spaces (add `\` before them) or to quote (") the paths (`"/home/my user"`)!
|
||||
|
||||
`dceFOLDERpathhere` with DCE's **directory path** (e.g. `/path/to/folder`, NOT `/path/to/folder/DiscordChatExporter.dll`).
|
||||
> **Note**:
|
||||
> 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.
|
||||
> [Check out this page](https://wiki.gentoo.org/wiki/Nano/Basics_Guide) if you want to know more about nano.
|
||||
|
||||
`filenamehere` with the exported channel's filename, without spaces.
|
||||
4. Make your script executable with `chmod +x /path/to/DiscordChatExporter/cron.sh`
|
||||
|
||||
`dirhere` with the export directory (e.g. /home/user/Documents/Discord\ Exports).
|
||||
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`. If this is your first time running this command, you might be asked to select a text editor. Nano is easier for beginners.
|
||||
|
||||
`formathere` with one of the available export formats.
|
||||
6. Add the following to the end of the file `* * * * * /path/to/DiscordChatExporter/cron.sh >/tmp/discordchatexporter.log 2>/tmp/discordchatexportererror.log`. Don't forget to replace the `/path/to/DiscordChatExporter/cron.sh`!
|
||||
|
||||
**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`
|
||||
> **Note**:
|
||||
> 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`
|
||||
**Examples**:
|
||||
|
||||
- If you want to execute the script at minute 15 of every hour: `15 * * * *`
|
||||
- Every 30 minutes `*/30 * * * *`
|
||||
- Every day at midnight `0 0 * * *`
|
||||
- Every day at noon `0 12 * * *`
|
||||
- Every day at 3, 4 and 6 PM `0 15,16,18 * * *`
|
||||
- Every Wednesday at 9 AM `0 9 * * 3`
|
||||
|
||||
Verify your cron time [here](https://crontab.guru).
|
||||
|
||||
#
|
||||
---
|
||||
|
||||
**Extra information**
|
||||
|
||||
@@ -115,12 +114,12 @@ 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).
|
||||
> [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)
|
||||
|
||||
+18
-32
@@ -4,22 +4,15 @@ Scheduling on macOS is a bit tricky, but it should work if you follow the instru
|
||||
|
||||
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)
|
||||
## Creating the script
|
||||
|
||||
## 1. Creating the script
|
||||
1. Open TextEdit.app and create a new file
|
||||
|
||||
**1.** Open TextEdit.app and create a new file
|
||||
|
||||
**2.** Convert the file to a plain text one in 'Format > Make Plain Text' (⇧⌘T)
|
||||
2. Convert the file to a plain text one in 'Format > Make Plain Text' (⇧⌘T)
|
||||
|
||||

|
||||
|
||||
**3.** Paste the following into the text editor:
|
||||
3. Paste the following into the text editor:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
@@ -75,18 +68,14 @@ fi
|
||||
exit 0
|
||||
```
|
||||
|
||||
**4.** Replace:
|
||||
`tokenhere` with your [Token](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md)
|
||||
4. Replace:
|
||||
|
||||
`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
|
||||
- `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:
|
||||
@@ -101,11 +90,10 @@ After copying and pasting, make sure the file/folder name is not missing. If a f
|
||||
|
||||

|
||||
|
||||
**5.** Save the file as `filename.sh`, not `.txt`
|
||||
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.
|
||||
|
||||
**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
|
||||
## Creating the .plist file
|
||||
|
||||
Open TextEdit, make a Plain Text (⇧⌘T) and then paste the following into it:
|
||||
|
||||
@@ -124,9 +112,7 @@ Open TextEdit, make a Plain Text (⇧⌘T) and then paste the following into it:
|
||||
```
|
||||
|
||||
- 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`.
|
||||
@@ -230,9 +216,9 @@ Every Sunday at midnight and every Wednesday full hour (xx:00). Notice the inclu
|
||||
</array>
|
||||
```
|
||||
|
||||
## 3. Loading the .plist into launchctl
|
||||
## Loading the .plist into launchctl
|
||||
|
||||
**1.** Copy your `filename.plist` file to one of these folders according to how you want it to run:
|
||||
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.
|
||||
|
||||
@@ -247,7 +233,7 @@ Every Sunday at midnight and every Wednesday full hour (xx:00). Notice the inclu
|
||||
|
||||
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.
|
||||
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
|
||||
|
||||
@@ -270,7 +256,7 @@ 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)
|
||||
|
||||
+17
-24
@@ -2,7 +2,7 @@
|
||||
|
||||
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:
|
||||
1. Open a text editor such as Notepad and paste:
|
||||
|
||||
```powershell
|
||||
# Info: https://github.com/Tyrrrz/DiscordChatExporter/wiki
|
||||
@@ -29,54 +29,47 @@ ElseIf($EXPORTFORMAT -match "Csv"){mv "$FILENAME.tmp" -Destination "$EXPORTDIREC
|
||||
exit
|
||||
```
|
||||
|
||||
**2.** Replace:
|
||||
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
|
||||
- `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`
|
||||
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
|
||||
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
|
||||
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
|
||||
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'
|
||||
4. Click 'Yes'
|
||||
|
||||

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

|
||||
|
||||
#
|
||||
---
|
||||
|
||||
Special thanks to [@Yudi](https://github.com/Yudi)
|
||||
|
||||
+25
-44
@@ -1,20 +1,20 @@
|
||||
# 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)"
|
||||
> **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) in the bot settings.
|
||||
|
||||
### How to get a User 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
|
||||
### Through your web browser
|
||||
|
||||
Prerequisite step: Navigate to [discord.com](https://discord.com) and login.
|
||||
|
||||
##### In Chrome
|
||||
#### In Chrome
|
||||
|
||||
###### Using the network monitor
|
||||
##### 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.
|
||||
|
||||
@@ -51,7 +51,7 @@ Prerequisite step: Navigate to [discord.com](https://discord.com) and login.
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
###### Using the storage inspector
|
||||
##### 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.
|
||||
|
||||
@@ -88,9 +88,9 @@ Prerequisite step: Navigate to [discord.com](https://discord.com) and login.
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
##### In Firefox
|
||||
#### In Firefox
|
||||
|
||||
###### Using the network monitor
|
||||
##### 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.
|
||||
|
||||
@@ -127,7 +127,7 @@ Prerequisite step: Navigate to [discord.com](https://discord.com) and login.
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
###### Using the storage inspector
|
||||
##### 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.
|
||||
|
||||
@@ -164,9 +164,9 @@ Prerequisite step: Navigate to [discord.com](https://discord.com) and login.
|
||||
<br clear="right" />
|
||||
<br />
|
||||
|
||||
#### Through the desktop app / Enabling web developer tools
|
||||
### Through the desktop app / Enabling web developer tools
|
||||
|
||||
##### By editing the settings file
|
||||
#### 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`.
|
||||
|
||||
@@ -200,7 +200,7 @@ Prerequisite step: Navigate to [discord.com](https://discord.com) and login.
|
||||
|
||||
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)
|
||||
#### 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.
|
||||
|
||||
@@ -218,44 +218,25 @@ Prerequisite step: Navigate to [discord.com](https://discord.com) and login.
|
||||
<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
|
||||
## 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**
|
||||
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!
|
||||
> **Warning**:
|
||||
> 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
|
||||
## How to get a Server ID or a 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**
|
||||
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 Server ID or Copy Channel ID
|
||||
@@ -3,11 +3,10 @@
|
||||
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.
|
||||
- ❓ 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
|
||||
## General
|
||||
|
||||
### Token stealer?
|
||||
|
||||
@@ -55,7 +54,7 @@ No, DCE is an exporter.
|
||||
|
||||
No, DCE is an exporter.
|
||||
|
||||
# First steps
|
||||
## First steps
|
||||
|
||||
### How can I find my token?
|
||||
|
||||
@@ -99,7 +98,7 @@ If you already have .NET Core installed, please check if your problem is a [know
|
||||
|
||||
Check the following page: [Installing .NET Core Runtime](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Dotnet.md)
|
||||
|
||||
# CLI
|
||||
## CLI
|
||||
|
||||
### How do I use the CLI?
|
||||
|
||||
@@ -125,7 +124,7 @@ Check the following page:
|
||||
|
||||
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
|
||||
## Errors
|
||||
|
||||
```
|
||||
DiscordChatExporter.Domain.Exceptions.DiscordChatExporterException: Authentication token is invalid.
|
||||
@@ -167,5 +166,6 @@ 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).
|
||||
> ❓ 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).
|
||||
|
||||
@@ -3,62 +3,62 @@ description: Report broken functionality.
|
||||
labels: [bug]
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
🧐 **Guidelines:**
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
🧐 **Guidelines:**
|
||||
|
||||
- Search through [existing issues](https://github.com/Tyrrrz/DiscordChatExporter/issues?q=is%3Aissue) first to ensure that this bug has not been reported before.
|
||||
- Write a descriptive title for your issue. Avoid generic or vague titles such as "Something's not working" or "A couple of problems".
|
||||
- Keep your issue focused on one single problem. If you have multiple bug reports, 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 reporting a bug, please use [discussions](https://github.com/Tyrrrz/DiscordChatExporter/discussions/new) instead.
|
||||
- Search through [existing issues](https://github.com/Tyrrrz/DiscordChatExporter/issues?q=is%3Aissue) first to ensure that this bug has not been reported before.
|
||||
- Write a descriptive title for your issue. Avoid generic or vague titles such as "Something's not working" or "A couple of problems".
|
||||
- Keep your issue focused on one single problem. If you have multiple bug reports, 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 reporting a bug, please use [discussions](https://github.com/Tyrrrz/DiscordChatExporter/discussions/new) instead.
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: Version
|
||||
description: Which version of DiscordChatExporter does this bug affect?
|
||||
placeholder: ver X.Y.Z
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
attributes:
|
||||
label: Version
|
||||
description: Which version of DiscordChatExporter does this bug affect?
|
||||
placeholder: ver X.Y.Z
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: Flavor
|
||||
description: Does this bug affect the GUI version, the CLI version, or both?
|
||||
multiple: true
|
||||
options:
|
||||
- GUI (Graphical User Interface)
|
||||
- CLI (Command Line Interface)
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: Flavor
|
||||
description: Does this bug affect the GUI version, the CLI version, or both?
|
||||
multiple: true
|
||||
options:
|
||||
- GUI (Graphical User Interface)
|
||||
- CLI (Command-Line Interface)
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: Export format
|
||||
description: Does this bug affect specific export format(s)? If not applicable, leave this field blank.
|
||||
multiple: true
|
||||
options:
|
||||
- HTML
|
||||
- TXT
|
||||
- JSON
|
||||
- CSV
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: Export format
|
||||
description: Does this bug affect 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 bug.
|
||||
placeholder: I was doing X expecting Y to happen, but Z happened instead.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Details
|
||||
description: Clear and thorough explanation of the bug.
|
||||
placeholder: I was doing X expecting Y to happen, but Z happened instead.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Steps to reproduce
|
||||
description: Minimum steps required to reproduce the bug.
|
||||
placeholder: |
|
||||
- Step 1
|
||||
- Step 2
|
||||
- Step 3
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Steps to reproduce
|
||||
description: Minimum steps required to reproduce the bug.
|
||||
placeholder: |
|
||||
- Step 1
|
||||
- Step 2
|
||||
- Step 3
|
||||
validations:
|
||||
required: true
|
||||
|
||||
@@ -5,51 +5,82 @@ on: [push, pull_request]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: write
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Build container
|
||||
run: docker build -f DiscordChatExporter.Cli.dockerfile .
|
||||
- name: Install Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Build image
|
||||
run: >
|
||||
docker buildx build
|
||||
--file DiscordChatExporter.Cli.dockerfile
|
||||
--platform linux/amd64,linux/arm64
|
||||
--output type=tar,dest=DiscordChatExporter.Cli.Docker.tar
|
||||
.
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DiscordChatExporter.Cli.Docker
|
||||
path: DiscordChatExporter.Cli.Docker.tar
|
||||
|
||||
deploy-latest:
|
||||
if: ${{ github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'master' }}
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to DockerHub
|
||||
run: docker login -u tyrrrz -p ${{ secrets.DOCKER_TOKEN }}
|
||||
run: >
|
||||
echo ${{ secrets.DOCKER_TOKEN }} |
|
||||
docker login --username tyrrrz --password-stdin
|
||||
|
||||
- name: Build container
|
||||
run: docker build -f DiscordChatExporter.Cli.dockerfile -t tyrrrz/discordchatexporter:latest .
|
||||
|
||||
- name: Push container
|
||||
run: docker push tyrrrz/discordchatexporter:latest
|
||||
- name: Build & push image
|
||||
run: >
|
||||
docker buildx build
|
||||
--file DiscordChatExporter.Cli.dockerfile
|
||||
--platform linux/amd64,linux/arm64
|
||||
--push
|
||||
--tag tyrrrz/discordchatexporter:latest
|
||||
.
|
||||
|
||||
deploy-stable:
|
||||
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Get release version
|
||||
id: get_version
|
||||
uses: dawidd6/action-get-tag@v1
|
||||
- name: Install Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to DockerHub
|
||||
run: docker login -u tyrrrz -p ${{ secrets.DOCKER_TOKEN }}
|
||||
run: >
|
||||
echo ${{ secrets.DOCKER_TOKEN }} |
|
||||
docker login --username tyrrrz --password-stdin
|
||||
|
||||
- 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 }}
|
||||
- name: Build & push image
|
||||
run: >
|
||||
docker buildx build
|
||||
--file DiscordChatExporter.Cli.dockerfile
|
||||
--platform linux/amd64,linux/arm64
|
||||
--push
|
||||
--tag tyrrrz/discordchatexporter:stable
|
||||
--tag tyrrrz/discordchatexporter:${{ github.ref_name }}
|
||||
.
|
||||
+52
-26
@@ -5,6 +5,8 @@ on: [push, pull_request]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: windows-latest
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
|
||||
@@ -23,7 +25,14 @@ jobs:
|
||||
- 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
|
||||
run: >
|
||||
dotnet test
|
||||
--configuration Release
|
||||
--logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true"
|
||||
--collect:"XPlat Code Coverage"
|
||||
--
|
||||
RunConfiguration.CollectSourceInformation=true
|
||||
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
|
||||
env:
|
||||
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
|
||||
|
||||
@@ -32,9 +41,12 @@ jobs:
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
||||
package:
|
||||
pack:
|
||||
needs: test
|
||||
runs-on: windows-latest
|
||||
permissions:
|
||||
actions: write
|
||||
contents: read
|
||||
|
||||
env:
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
|
||||
@@ -51,27 +63,36 @@ jobs:
|
||||
dotnet-version: 7.0.x
|
||||
|
||||
- name: Publish (CLI)
|
||||
run: dotnet publish DiscordChatExporter.Cli/ -o DiscordChatExporter.Cli/bin/Publish/ --configuration Release
|
||||
run: >
|
||||
dotnet publish DiscordChatExporter.Cli
|
||||
--output DiscordChatExporter.Cli/publish/
|
||||
--configuration Release
|
||||
|
||||
- name: Publish (GUI)
|
||||
run: dotnet publish DiscordChatExporter.Gui/ -o DiscordChatExporter.Gui/bin/Publish/ --configuration Release
|
||||
run: >
|
||||
dotnet publish DiscordChatExporter.Gui
|
||||
--output DiscordChatExporter.Gui/publish/
|
||||
--configuration Release
|
||||
|
||||
- name: Upload artifacts (CLI)
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DiscordChatExporter.Cli
|
||||
path: DiscordChatExporter.Cli/bin/Publish/
|
||||
path: DiscordChatExporter.Cli/publish/
|
||||
|
||||
- name: Upload artifacts (GUI)
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DiscordChatExporter
|
||||
path: DiscordChatExporter.Gui/bin/Publish/
|
||||
path: DiscordChatExporter.Gui/publish/
|
||||
|
||||
deploy:
|
||||
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
|
||||
needs: package
|
||||
needs: pack
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Download artifacts (CLI)
|
||||
@@ -87,43 +108,48 @@ jobs:
|
||||
path: DiscordChatExporter.Gui
|
||||
|
||||
- name: Create package (CLI)
|
||||
run: Compress-Archive -Path DiscordChatExporter.Cli/* -DestinationPath DiscordChatExporter.Cli.zip -Force
|
||||
shell: pwsh
|
||||
run: >
|
||||
Compress-Archive
|
||||
-Path DiscordChatExporter.Cli/*
|
||||
-DestinationPath DiscordChatExporter.Cli.zip
|
||||
-Force
|
||||
|
||||
- name: Create package (GUI)
|
||||
run: Compress-Archive -Path DiscordChatExporter.Gui/* -DestinationPath DiscordChatExporter.zip -Force
|
||||
shell: pwsh
|
||||
run: >
|
||||
Compress-Archive
|
||||
-Path DiscordChatExporter.Gui/*
|
||||
-DestinationPath DiscordChatExporter.zip
|
||||
-Force
|
||||
|
||||
- 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)
|
||||
run: >
|
||||
gh release create "${{ github.ref_name }}"
|
||||
"DiscordChatExporter.Cli.zip"
|
||||
"DiscordChatExporter.zip"
|
||||
--repo "${{ github.event.repository.full_name }}"
|
||||
--title "${{ github.ref_name }}"
|
||||
--notes "[Changelog](${{ github.event.repository.html_url }}/blob/${{ github.ref_name }}/Changelog.md)"
|
||||
--verify-tag
|
||||
|
||||
notify:
|
||||
needs: deploy
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Get release version
|
||||
id: get_version
|
||||
uses: dawidd6/action-get-tag@v1
|
||||
|
||||
- name: Notify Discord
|
||||
uses: satak/webrequest-action@v1.2.4
|
||||
uses: tyrrrz/action-http-request@v1
|
||||
with:
|
||||
url: ${{ secrets.DISCORD_WEBHOOK }}
|
||||
method: POST
|
||||
headers: |
|
||||
Content-Type: application/json; charset=UTF-8
|
||||
body: |
|
||||
{
|
||||
"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>"
|
||||
"content": "**${{ github.event.repository.name }}** new version released!\nVersion: `${{ github.ref_name }}`\nChangelog: <${{ github.event.repository.html_url }}/blob/${{ github.ref_name }}/Changelog.md>"
|
||||
}
|
||||
+1
-4
@@ -20,7 +20,4 @@ bld/
|
||||
[Oo]bj/
|
||||
|
||||
# Coverage
|
||||
*.opencover.xml
|
||||
|
||||
# Secrets
|
||||
*.secret
|
||||
*.opencover.xml
|
||||
+122
-60
@@ -1,15 +1,77 @@
|
||||
### v2.37.2 (27-Jan-2023)
|
||||
# Changelog
|
||||
|
||||
## v2.40 (08-Jun-2023)
|
||||
|
||||
- General changes:
|
||||
- Added support for users that don't have discriminators.
|
||||
- Added a precondition check that verifies whether the requested channel contains any messages for the specified period, before starting the export process. This check works by comparing the export bounds against the ID of the last message in the channel, which is provided by the Discord API as part of the channel metadata. When exporting many channels in batches (e.g. using the `exportall` command), this check may eliminate a significant number of unnecessary API calls and speed up the export process.
|
||||
- CLI changes:
|
||||
- Extended the `channels` command with the `--include-threads` option. When this option is provided, the command will include channel threads in the output. (Thanks [@WAUthethird](https://github.com/WAUthethird))
|
||||
- Simplified the information in the `guide` command related to the extraction of DM channel IDs. Discord now provides a native way of copying IDs of DM channels, so the previous devtools-based workaround is no longer necessary.
|
||||
- GUI changes:
|
||||
- Added a blur effect to the token text box, which activates when the control loses focus. This is done to reduce the risk of accidentally exposing the token when taking screenshots.
|
||||
- HTML format changes:
|
||||
- Added support for the header markdown syntax.
|
||||
- Added support for the list markdown syntax.
|
||||
|
||||
## v2.39.1 (10-Mar-2023)
|
||||
|
||||
- Fixed an issue where messages containing mentions of users that left the server (but haven't deleted their account) were incorrectly rendered as `@Unknown`.
|
||||
- Fixed an issue where messages containing video links were not rendered correctly in the HTML export. Now, they are rendered using a video player and the referenced assets are pulled if the "download assets" option is enabled.
|
||||
|
||||
## v2.39 (25-Feb-2023)
|
||||
|
||||
- Added an option to specify the directory path for downloaded assets. This can be used, in combination with the "reuse assets" option, to have a shared asset directory for multiple exports. In GUI, this option can be found in the advanced section of the export dialog. In CLI, it's available as `--media-dir <path>`. (Thanks [@96-LB](https://github.com/96-LB))
|
||||
- Added support for server-level user avatars. If a user has a custom avatar set on the server, it will be rendered instead of their main avatar.
|
||||
- CLI changes:
|
||||
- Extended the `exportall` command with the `--data-package` option. You can use this option to provide the path to your personal data package (`package.zip` file), requested from Discord. When provided, the command will pull channels listed in the package instead of using the Discord API to query them. This can be particularly useful if you want to export DM channels that have been closed, as the personal data package should still contain their IDs.
|
||||
- HTML format changes:
|
||||
- Added support for rendering group DM channel invites.
|
||||
- Changed the primary font from `Whitney` to `gg sans` to match the new Discord design.
|
||||
- Fixed an issue where the external font sometimes failed to load if the export was created with the "download assets" option enabled.
|
||||
- Fixed an issue where `gifv` attachments were incorrectly treated as images instead of video files.
|
||||
|
||||
## v2.38 (16-Feb-2023)
|
||||
|
||||
- General changes:
|
||||
- Added an option to disable markdown processing when exporting. You can use this to produce JSON or plain text exports without unwrapping mentions, custom emoji, and certain other special tokens. In GUI, this option can be found in the export dialog. In CLI, it's available as the `--markdown <true|false>` flag.
|
||||
- Added support for different formatting options when rendering timestamps (i.e. the `f` in `<t:1234567890:f>`). As an exception, relative timestamps are formatted as regular timestamps since that makes more sense in a static export. Currently, all formatting options are rendered based on the `English (US)` locale, with the intent to make that more configurable in the future.
|
||||
- Changed the default date format from `dd-MMM-yy hh:mm tt` to `MM/dd/yyyy h:mm tt` to match the date format used by Discord for message timestamps when the `English (US)` language is selected. This should make the default date format more consistent with other non-configurable date formats used by DiscordChatExporter. In the future, this setting will most likely be removed entirely in favor of a more flexible approach.
|
||||
- Updated the usage guide with additional steps required to retrieve the user token.
|
||||
- Fixed an issue where certain user mentions were incorrectly rendered as `@Unknown`.
|
||||
- Fixed an issue where some embed images were rendered using their actual URLs instead of Discord proxy URLs.
|
||||
- GUI changes:
|
||||
- Added a text box for specifying the output path when exporting channels. It can be used to set an output path that uses template tokens, which previously required hacky workarounds. This text box can be left empty, in which case clicking on the "Export" button will open the file or folder picker dialog, matching the previous behavior.
|
||||
- Added a notification when the application is updated to a new version, containing the changelog link.
|
||||
- Moved the "reuse assets" option from the settings dialog to the export dialog.
|
||||
- Replaced the lock icon in the token text box with a key icon, to better reflect the purpose of the input.
|
||||
- Minor cosmetic improvements.
|
||||
- CLI changes:
|
||||
- Changed the behavior of the `export` command when providing IDs of category channels. Now, instead of displaying an error, the command will export all channels contained within the corresponding categories.
|
||||
- HTML format changes:
|
||||
- Added proper support for more system notification messages.
|
||||
- Added support for rendering server invites. Now, if the message contains an invite link, the export will show the server icon and include additional information, such as the name of the server and the target channel.
|
||||
- Changed the preamble part of the export to show the channel icon when available, instead of the default Discord logo. This is only available for group DM channels. (Thanks [@CanePlayz](https://github.com/CanePlayz))
|
||||
- Fixed an issue where some miscellaneous characters were incorrectly treated as emoji, which resulted in them being rendered as broken images. (Thanks [@CanePlayz](https://github.com/CanePlayz))
|
||||
- Fixed an issue where messages triggered by app interactions were not rendered as replies.
|
||||
- Fixed an issue where server cross-posts were not rendered correctly.
|
||||
- JSON format changes:
|
||||
- Added an `iconUrl` field for the top-level `channel` object, which specifies the URL of the channel icon. This is only available for group DM channels.
|
||||
- Added a `code` field for reactions, which specifies the code of the associated emoji. For standard Unicode emoji, this is equal to the emoji alias (e.g. `slightly_smiling_face`). For custom Discord emoji, this is equal to the emoji name (same as the already existing `name` field).
|
||||
- Added an `interaction` field for messages, which contains information about the app interaction that triggered that response, if applicable.
|
||||
|
||||
## 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)
|
||||
## 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)
|
||||
## 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.
|
||||
@@ -17,40 +79,40 @@
|
||||
- [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)
|
||||
## 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)
|
||||
## 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)
|
||||
## 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)
|
||||
## 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)
|
||||
## 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)
|
||||
## 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)
|
||||
## 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`.
|
||||
@@ -60,7 +122,7 @@
|
||||
- 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)
|
||||
## 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.
|
||||
@@ -81,13 +143,13 @@
|
||||
- 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)
|
||||
## v2.34.1 (01-Jun-2022)
|
||||
|
||||
- Improved retry policy to handle more transient errors. This should result in fewer errors exporting a channel due to timeout.
|
||||
- Added `has:pin` message filter. You can use it to limit exported messages to those that have been pinned. (Thanks [@Andrew Kolos](https://github.com/andrewkolos))
|
||||
- Fixed an issue which caused the export to fail when processing stickers that have no name.
|
||||
|
||||
### v2.34 (10-Apr-2022)
|
||||
## v2.34 (10-Apr-2022)
|
||||
|
||||
- [HTML] Reworked layout to be more consistent with Discord.
|
||||
- [HTML] Changed user profile picture dimensions from `128x128` to `512x512`. (Thanks [@Chris Helder](https://github.com/TheDude53))
|
||||
@@ -98,15 +160,15 @@
|
||||
- [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)
|
||||
## v2.33.2 (07-Mar-2022)
|
||||
|
||||
- Actually fixed it this time.
|
||||
|
||||
### v2.33.1 (07-Mar-2022)
|
||||
## 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)
|
||||
## 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)).
|
||||
@@ -116,7 +178,7 @@
|
||||
- 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)
|
||||
## 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))
|
||||
@@ -125,12 +187,12 @@
|
||||
- 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)
|
||||
## v2.31.1 (15-Dec-2021)
|
||||
|
||||
- Fixed an issue which caused an error when parsing certain custom emoji reactions.
|
||||
- [GUI] Improved user interface.
|
||||
|
||||
### v2.31 (06-Dec-2021)
|
||||
## v2.31 (06-Dec-2021)
|
||||
|
||||
- Changed target runtime of the application (both GUI and CLI) from .NET 3.1 to .NET 6. Those using the GUI version will not need to take any action as the application should install the necessary prerequisites automatically. Those using the CLI version will need to download and install .NET 6 runtime manually [from here](https://dotnet.microsoft.com/download/dotnet/6.0) (look for ".NET Runtime 6.0.x" section on the right and choose the distribution appropriate for your system).
|
||||
- [HTML] Updated layout design to match Discord more closely. (Thanks [@Artem](https://github.com/Scarg))
|
||||
@@ -139,13 +201,13 @@
|
||||
- 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)
|
||||
## 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)
|
||||
## 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.
|
||||
@@ -157,7 +219,7 @@
|
||||
- [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)
|
||||
## 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))
|
||||
- Added support for rendering mentions of voice channels, in addition to text channels.
|
||||
@@ -171,7 +233,7 @@
|
||||
- [CLI] Fixed an issue where providing an incorrectly formatted partition limit via `-p|--partition` option resulted in a non-descriptive and unhelpful error.
|
||||
- Improved "Requested resource does not exist" error message by including the ID of the requested resource.
|
||||
|
||||
### v2.28 (19-Jun-2021)
|
||||
## v2.28 (19-Jun-2021)
|
||||
|
||||
- [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))
|
||||
@@ -189,12 +251,12 @@
|
||||
- [GUI] Fixed an issue where the list of missing components, reported by the prerequisite check at application startup, included Windows updates that were not applicable to the user's system due to the fact that other superseding updates have already been installed. This issue only affected users running DiscordChatExporter on Windows 7.
|
||||
- [GUI] Fixed a few other minor issues related to the prerequisite installation window.
|
||||
|
||||
### v2.27.1 (08-Jun-2021)
|
||||
## v2.27.1 (08-Jun-2021)
|
||||
|
||||
- [GUI] Application will now detect if the required .NET Runtime or any of its prerequisites are missing and prompt the user to download and install them automatically. **Experimental feature, please test it out and report any issues you may find!**
|
||||
- [CLI] Fixed an issue where the application crashed when exporting a channel that had square brackets as part of its name or category name. (Thanks [@Lucas LaBuff](https://github.com/96-LB))
|
||||
|
||||
### v2.27 (24-Apr-2021)
|
||||
## v2.27 (24-Apr-2021)
|
||||
|
||||
- Added partitioning by file size. You can now use values such as `10mb` to indicate a size-based cut off point, in addition to values like `10` to indicate a number of messages. (Thanks [@Andrew Kolos](https://github.com/andrewkolos))
|
||||
- [CLI] Improved formatting and progress reporting.
|
||||
@@ -205,12 +267,12 @@
|
||||
- [JSON] Fixed an issue where the application sometimes crashed with an error saying `']' invalid without a matching open`, which was just a validation message that masked the actual error behind the failure. (Thanks [@Lucas LaBuff](https://github.com/96-LB))
|
||||
- Fixed an issue where progress was not reported correctly if the channel didn't have any messages in the specified time range.
|
||||
|
||||
### v2.26.1 (06-Feb-2021)
|
||||
## v2.26.1 (06-Feb-2021)
|
||||
|
||||
- [CLI] Added support for file name templates, which allow you to dynamically generate output file names based on channel and guild metadata. (Thanks [@Lucas LaBuff](https://github.com/96-LB))
|
||||
- Fixed an issue where the application sometimes crashed with `Invalid snowflake` message when exporting chat logs that contained invalid or outdated mentions. (Thanks [@Lucas LaBuff](https://github.com/96-LB))
|
||||
|
||||
### v2.26 (29-Dec-2020)
|
||||
## v2.26 (29-Dec-2020)
|
||||
|
||||
- [HTML] Added support for replies. (Thanks [@Sanqui](https://github.com/Sanqui))
|
||||
- [HTML] Improved styling of non-media attachments (regular files, i.e. not video, audio, or image). (Thanks [@Lucas LaBuff](https://github.com/96-LB))
|
||||
@@ -223,14 +285,14 @@
|
||||
- Fixed an issue where the application sometimes crashed with `NullReferenceException` when retrying a failed HTTP request.
|
||||
- Migrated to Discord API v8.
|
||||
|
||||
### v2.25 (23-Nov-2020)
|
||||
## v2.25 (23-Nov-2020)
|
||||
|
||||
- [JSON] Added `mentions` property to the output. This contains users referenced inside the message text, but doesn't include mentions in embeds. (Thanks [@Andrew Kolos](https://github.com/andrewkolos))
|
||||
- [HTML] Added better previews for attached video and audio. They are now rendered using a browser native player element. The actual file path can still be retrieved by right clicking and selecting "Copy file path". (Thanks [@sas41](https://github.com/sas41))
|
||||
- [CLI] Fixed an issue where using `--media` option without providing a rooted path via `--output` option triggered an error.
|
||||
- [CLI] Fixed an issue where using `--reuse-media` option without also providing `--media` option was accepted, but didn't actually do anything. Now this produces an error instead. (Thanks [@Andrew Kolos](https://github.com/andrewkolos))
|
||||
|
||||
### v2.24 (24-Oct-2020)
|
||||
## v2.24 (24-Oct-2020)
|
||||
|
||||
- [CLI] Updated to [CliFx v1.5](https://github.com/Tyrrrz/CliFx), which brings some UX improvements.
|
||||
- [GUI] Added dark mode, which can be enabled in settings. (Thanks [@Andrew Kolos](https://github.com/andrewkolos))
|
||||
@@ -240,20 +302,20 @@
|
||||
- Added retry policy for downloading media content. This is mostly a workaround for transient failures that sometimes may occur when downloading assets referenced from embeds. (Thanks [@Andrew Kolos](https://github.com/andrewkolos))
|
||||
- Added an option to reuse already downloaded media to avoid redundant network requests. It can be enabled in settings in GUI, or by passing `--reuse-media` in CLI. To facilitate this feature, the file name strategy has been changed as well -- now instead of relying on the original file name and adding `(n)` to the end in case of duplicates, a URL hash is injected in every file name. This also means that when the "reuse media" option is disabled, existing files inside the media directory may be overwritten. (Thanks [@Andrew Kolos](https://github.com/andrewkolos))
|
||||
|
||||
### v2.23 (14-Sep-2020)
|
||||
## v2.23 (14-Sep-2020)
|
||||
|
||||
- [CLI] Added a command to export all channels across all servers. Use `exportall` to do it. (Thanks [@wyattscarpenter](https://github.com/wyattscarpenter))
|
||||
- [HTML] Fixed an issue where Whitney fonts were not being loaded properly, causing the browser to fall back to Helvetica.
|
||||
- Fixed an issue where self-contained export crashed occasionally. This usually happened when the server hosting the file did not serve the stream properly. Such files are now ignored after the first failed attempt.
|
||||
|
||||
### v2.22 (12-Aug-2020)
|
||||
## v2.22 (12-Aug-2020)
|
||||
|
||||
- [GUI] Improved the channel list by adding collapsible category groups. (Thanks [@CarJem Generations](https://github.com/CarJem))
|
||||
- [GUI] Improved exporting options by adding a set of controls that can be used to limit the date range of the export down to minutes. Previously it was only possible to configure the date range without the time component. (Thanks [@CarJem Generations](https://github.com/CarJem))
|
||||
- [HTML] Fixed an issue where the export didn't reflect changes in nicknames between messages sent by bots. This affected chat logs that contained interactions with the Tupperbox bot. (Thanks [@CarJem Generations](https://github.com/CarJem))
|
||||
- [CLI] Fixed an issue where the application crashed if there were two environment variables defined that had the same name but in different case.
|
||||
|
||||
### v2.21.2 (30-Jul-2020)
|
||||
## v2.21.2 (30-Jul-2020)
|
||||
|
||||
- [GUI] When copy-pasting token, any surrounding spaces are now discarded, in addition to double quotes.
|
||||
- [HTML] Changed underlying templating engine to provide higher performance and better error messages. New templating engine adds a small cold start, but any export after the first should be faster.
|
||||
@@ -262,19 +324,19 @@
|
||||
- Fixed an issue where the application crashed when trying to download media with a file name that exceeds system's maximum allowed length.
|
||||
- Fixed an issue where the application crashed when trying to download media with illegal characters in the file name.
|
||||
|
||||
### v2.21.1 (19-Jul-2020)
|
||||
## v2.21.1 (19-Jul-2020)
|
||||
|
||||
- Fixed an issue where the export crashed if an embedded image has been deleted. Such media files are now ignored.
|
||||
- Changed the naming convention for downloaded media files so that the original file names are used when possible.
|
||||
|
||||
### v2.21 (18-Jul-2020)
|
||||
## v2.21 (18-Jul-2020)
|
||||
|
||||
- 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.
|
||||
|
||||
### v2.20 (27-Apr-2020)
|
||||
## v2.20 (27-Apr-2020)
|
||||
|
||||
- [CLI] Added environment variables as fallback for `--token` and `--bot` options. They are `DISCORD_TOKEN` and `DISCORD_TOKEN_BOT` respectively.
|
||||
- [GUI] Fixed a crash that occurred if the application was closed in the middle of an auto-update.
|
||||
@@ -291,27 +353,27 @@ Note that all existing and current HTML exports will likely not render accuratel
|
||||
- [CLI] Updated commands to also show channel category as well as channel name wherever relevant.
|
||||
- Starting with this release, Docker images will have new tags: `stable` for latest stable release and `2.20` for a specific version.
|
||||
|
||||
### v2.19 (26-Mar-2020)
|
||||
## v2.19 (26-Mar-2020)
|
||||
|
||||
- Added parallel exporting. This option allows you to export multiple channels faster by doing it in parallel. You can configure the parallel limit in settings (GUI) or with the `--parallel` option (CLI). Default value is `1`, which means there is no parallelization. Warning: be careful when using this option, as this will result in higher volume of concurrent HTTP requests sent to Discord, which might get you flagged. Use at your own risk.
|
||||
- [HTML] Added support for user colors. User names are now appropriately colored according to the assigned guild roles.
|
||||
- [HTML] Added support for nicknames. User names are replaced with nicknames where it's applicable. It's still possible to see the full user name by hovering your mouse over the nickname.
|
||||
- [HTML] Improved styling for mentions to bring it more in line with how it looks in Discord.
|
||||
|
||||
### v2.18 (04-Feb-2020)
|
||||
## v2.18 (04-Feb-2020)
|
||||
|
||||
- Added JSON export format. It's a structured data format which is easy to parse. If you're using DiscordChatExporter to export chat logs for further ingestion by another tool, this is most likely the format you will want to use.
|
||||
- [GUI] You can now quickly jump to a specific channel in a list. For example, if you want to jump to a channel named "General", you can simply press the 'g' key in the channel list view. You can also press 'g', 'e' and 'n' in quick succession which will jump to the next channel that starts with "gen". This mechanic is consistent with other Windows applications.
|
||||
- [CLI] Improved help text screen.
|
||||
|
||||
### v2.17 (12-Jan-2020)
|
||||
## v2.17 (12-Jan-2020)
|
||||
|
||||
- Fixed an issue where an empty file was produced when exporting a channel with no messages (for specified period). With the new behavior, no file will be created and instead a message will be shown to the user informing of the failure.
|
||||
- [HTML/TXT] Added message count to the bottom of the file. This number shows how many messages were exported as part of the current file. Prior to 2.16 this number was present along with the rest of the metadata at the top, then removed due to changes in the exporter, and now brought back at the end of the file instead.
|
||||
- [HTML] Fixed an issue where some emoji were not properly rendered.
|
||||
- [GUI] Added a setting that lets you configure whether to remember the last used token. Previously it was the default behavior, but now you can disable it if you don't want the token persisted on your system.
|
||||
|
||||
### v2.16 (08-Dec-2019)
|
||||
## v2.16 (08-Dec-2019)
|
||||
|
||||
- Migrated from .NET Framework to .NET Core. To run this and future versions of DiscordChatExporter you will need [.NET Core runtime for desktop apps](https://dotnet.microsoft.com/download/dotnet-core/3.1/runtime) (for GUI/CLI version on Windows) or [.NET Core base runtime](https://dotnet.microsoft.com/download/dotnet-core/3.1) (for CLI version on Windows, Linux or macOS).
|
||||
- Reworked the exporter engine to render output using streaming data source. This means that only a very small portion of messages are cached in memory when exporting. In other words, you are only limited by storage space and not how much RAM you have, so you can now export terabytes of chat logs without hitting out of memory exceptions. I still recommend using partitions if you're exporting very large chat logs (250k+ messages) to HTML, unless you want your computer to catch fire when you try to open the export in browser.
|
||||
@@ -327,7 +389,7 @@ Note that all existing and current HTML exports will likely not render accuratel
|
||||
|
||||
Please note that CSV export is most likely not going to receive future updates and will remain only as an option for those who wish to use it for text analysis. In other words, it won't contain any of the rich media features like embeds. If you're currently using CSV as a structured output to feed into your program, JSON output will replace that in the future.
|
||||
|
||||
### v2.15 (15-Sep-2019)
|
||||
## v2.15 (15-Sep-2019)
|
||||
|
||||
- Improved markdown parser and made it even faster for non-HTML formats.
|
||||
- [HTML] Added support for block quotes.
|
||||
@@ -340,56 +402,56 @@ Please note that CSV export is most likely not going to receive future updates a
|
||||
- [GUI] Streamlined auto-update process a bit.
|
||||
- [GUI] Added some tooltips.
|
||||
|
||||
### v2.14 (15-Jun-2019)
|
||||
## v2.14 (15-Jun-2019)
|
||||
|
||||
- [TXT] Added support for embeds.
|
||||
- [TXT] Added support for reactions.
|
||||
- [CSV] Added support for reactions.
|
||||
- [TXT] Changed how attachments are rendered.
|
||||
|
||||
### v2.13.1 (06-Jun-2019)
|
||||
## v2.13.1 (06-Jun-2019)
|
||||
|
||||
- Fixed an issue where the app sometimes crashed when exporting due to `System.InvalidCastException`.
|
||||
- [HTML] Added `data-user-id` attribute to `span.chatlog__author-name`. The value of this attribute is author's Discord user ID.
|
||||
|
||||
### v2.13 (15-May-2019)
|
||||
## v2.13 (15-May-2019)
|
||||
|
||||
- Updated usage instructions.
|
||||
- [HTML] Added BOT tags to messages posted by bots.
|
||||
- [GUI] UI will now be disabled when exporting.
|
||||
- [GUI] Notification informing that the export has completed will now appear after all exports have completed, instead of each of them separately.
|
||||
|
||||
### v2.12.1 (12-Apr-2019)
|
||||
## v2.12.1 (12-Apr-2019)
|
||||
|
||||
- [GUI] Fixed an issue where the app crashed when trying to export multiple channels.
|
||||
- [HTML] Fixed an issue where some of the emoji were rendered via Twemoji while Discord renders them as plain text.
|
||||
- [HTML] Fixed an issue where emoji weren't jumbo if there were more than one of them.
|
||||
|
||||
### v2.12 (11-Apr-2019)
|
||||
## v2.12 (11-Apr-2019)
|
||||
|
||||
- Improved markdown parsing performance which speeds up the final stage of exporting by around 4.5 times.
|
||||
- Improved performance when exporting as PlainText or CSV.
|
||||
- [GUI] Fixed an issue where the app would freeze up and report as "not responding" during the final stage of exporting.
|
||||
- [CLI] Fixed an issue where it would say "Completed" after exporting a chat log, even if the process failed.
|
||||
|
||||
### v2.11 (14-Mar-2019)
|
||||
## v2.11 (14-Mar-2019)
|
||||
|
||||
- [HTML] Added syntax highlighting for multiline code blocks via Highlight.js.
|
||||
- Added retry policy for all 5xx status codes to prevent random crashes.
|
||||
|
||||
### v2.10.2 (10-Mar-2019)
|
||||
## v2.10.2 (10-Mar-2019)
|
||||
|
||||
- [HTML] Updated message grouping algorithm to make it the same as in Discord. Removed "message group limit" setting and parameter.
|
||||
- [HTML] Added small margin at the end of the chatlog so it doesn't look like it was truncated.
|
||||
- [CLI] Fixed an issue where the app would crash if stdout was redirected. Progress will not be reported in such cases.
|
||||
|
||||
### v2.10.1 (06-Mar-2019)
|
||||
## v2.10.1 (06-Mar-2019)
|
||||
|
||||
- [HTML] Fixed an issue where multiple emoji on a single line would get rendered as one emoji.
|
||||
- [HTML] Fixed an issue where an open square bracket character would incorrectly render as an emoji.
|
||||
- [HTML] Added alt text to emoji images so that they will be rendered using default font when Twemoji images are not available.
|
||||
|
||||
### v2.10 (03-Mar-2019)
|
||||
## v2.10 (03-Mar-2019)
|
||||
|
||||
- [HTML] Reworked the entire markdown parsing engine which fixes numerous rendering inconsistencies (over 15 issues fixed).
|
||||
- [HTML] Added support for animated emoji.
|
||||
@@ -400,11 +462,11 @@ Please note that CSV export is most likely not going to receive future updates a
|
||||
- [GUI] Checkmarks are now displayed next to channels that are selected.
|
||||
- [CLI] Added progress reporting when exporting chat logs.
|
||||
|
||||
### v2.9.1 (10-Feb-2019)
|
||||
## v2.9.1 (10-Feb-2019)
|
||||
|
||||
- Fixed an issue where some of the last messages in a channel would sometimes not get exported.
|
||||
|
||||
### v2.9 (09-Feb-2019)
|
||||
## v2.9 (09-Feb-2019)
|
||||
|
||||
- Added categories to channel list in GUI. Channels are now also grouped by category.
|
||||
- Added ability to export multiple channels at once in GUI by selecting them with shift or ctrl keys.
|
||||
@@ -419,7 +481,7 @@ Please note that CSV export is most likely not going to receive future updates a
|
||||
- Fixed an issue where dialogs would sometimes appear over other windows.
|
||||
- Fixed an issue where launching DiscordChatExporter from Windows Start Menu would make it crash.
|
||||
|
||||
### v2.8 (03-Nov-2018)
|
||||
## v2.8 (03-Nov-2018)
|
||||
|
||||
- Added support for partitioning which lets you split the output into multiple files by setting the partition message limit (`-p` parameter for CLI).
|
||||
- Exported file will no longer open automatically on completion.
|
||||
@@ -428,25 +490,25 @@ Please note that CSV export is most likely not going to receive future updates a
|
||||
- Improved encoding of newlines in CSV export.
|
||||
- Improved error messages in the GUI app during crashes.
|
||||
|
||||
### v2.7 (14-Sep-2018)
|
||||
## v2.7 (14-Sep-2018)
|
||||
|
||||
- Updated instructions on how to obtain the user token.
|
||||
- Expanded CLI with new commands: `channels` (get a list of channels in a guild), `dm` (get a list of DM channels), `guilds` (get a list of guilds), on top of `export` (export chatlog).
|
||||
- Improved help text and error messages in CLI.
|
||||
- In CLI, the file name will be automatically generated if the provided output file path is a directory.
|
||||
|
||||
### v2.6 (25-Jul-2018)
|
||||
## v2.6 (25-Jul-2018)
|
||||
|
||||
- Added support for bot tokens as an alternative to user tokens. For GUI, use the button in the top-left to switch between user and bot token. For CLI, pass the `--bot` switch to indicate that the given token is a bot token.
|
||||
- Added support for animated avatars.
|
||||
|
||||
### v2.5.1 (01-Jul-2018)
|
||||
## v2.5.1 (01-Jul-2018)
|
||||
|
||||
- Fixed a bug that would prevent timestamps from rendering properly in CSV and PlainText exports.
|
||||
- Fixed incorrect layout in CSV export.
|
||||
- Improved readability of PlainText export.
|
||||
|
||||
### v2.5 (28-Jun-2018)
|
||||
## v2.5 (28-Jun-2018)
|
||||
|
||||
- Added support for embeds and webhooks (HTML only).
|
||||
- Implemented progress reporting when downloading messages.
|
||||
@@ -458,22 +520,22 @@ Please note that CSV export is most likely not going to receive future updates a
|
||||
- Added validation for from/to dates in the UI which prevents choosing invalid date ranges.
|
||||
- Added an error message when trying to export a deleted channel.
|
||||
|
||||
### v2.4.1 (15-Apr-2018)
|
||||
## v2.4.1 (15-Apr-2018)
|
||||
|
||||
- Added CSV export format.
|
||||
- Channels are now ordered by name in the UI.
|
||||
- Exported file is now always opened upon completion.
|
||||
|
||||
### v2.4 (08-Apr-2018)
|
||||
## v2.4 (08-Apr-2018)
|
||||
|
||||
- Added channel topic to output.
|
||||
- Added a command line interface alternative to the current graphical user interface.
|
||||
- Added a command-line interface alternative to the current graphical user interface.
|
||||
- Implemented application auto-update (can be disabled in settings).
|
||||
- Improved some GUI elements and replaced some dialogs with notifications.
|
||||
- Fixed a lot of issues with the markdown processor.
|
||||
- Fixed DM group chats that have a custom name being shown as blank in the list.
|
||||
|
||||
### v2.3 (27-Oct-2017)
|
||||
## v2.3 (27-Oct-2017)
|
||||
|
||||
- Improved message date filtering, it's now marginally faster.
|
||||
- Fixed underscores not recognized as italics in markdown.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Version>2.37.2</Version>
|
||||
<Version>2.40</Version>
|
||||
<Company>Tyrrrz</Company>
|
||||
<Copyright>Copyright (c) Oleksii Holub</Copyright>
|
||||
<LangVersion>preview</LangVersion>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<UserSecretsId>d1fe5ae2-2a19-404d-a36e-81ba9eada1c1</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -11,15 +12,18 @@
|
||||
</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="AngleSharp" Version="1.0.3" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0" />
|
||||
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.2" 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="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
|
||||
<PackageReference Include="ReflectionMagic" Version="4.1.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" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
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);
|
||||
}
|
||||
+3
-1
@@ -1,6 +1,6 @@
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.TestData;
|
||||
namespace DiscordChatExporter.Cli.Tests.Infra;
|
||||
|
||||
public static class ChannelIds
|
||||
{
|
||||
@@ -14,6 +14,8 @@ public static class ChannelIds
|
||||
|
||||
public static Snowflake FilterTestCases { get; } = Snowflake.Parse("866744075033641020");
|
||||
|
||||
public static Snowflake MarkdownTestCases { get; } = Snowflake.Parse("866459526819348521");
|
||||
|
||||
public static Snowflake MentionTestCases { get; } = Snowflake.Parse("866458801389174794");
|
||||
|
||||
public static Snowflake ReplyTestCases { get; } = Snowflake.Parse("866459871934677052");
|
||||
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
using AngleSharp.Html.Dom;
|
||||
using AsyncKeyedLock;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands;
|
||||
using DiscordChatExporter.Cli.Tests.Utils;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
using JsonExtensions;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Infra;
|
||||
|
||||
public static class ExportWrapper
|
||||
{
|
||||
private static readonly AsyncKeyedLocker<string> Locker = new(o =>
|
||||
{
|
||||
o.PoolSize = 20;
|
||||
o.PoolInitialFill = 1;
|
||||
});
|
||||
|
||||
private static readonly string DirPath = Path.Combine(
|
||||
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? Directory.GetCurrentDirectory(),
|
||||
"ExportCache"
|
||||
);
|
||||
|
||||
static ExportWrapper()
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(DirPath, true);
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(DirPath);
|
||||
}
|
||||
|
||||
private static async ValueTask<string> ExportAsync(Snowflake channelId, ExportFormat format)
|
||||
{
|
||||
var fileName = channelId.ToString() + '.' + format.GetFileExtension();
|
||||
var filePath = Path.Combine(DirPath, fileName);
|
||||
|
||||
// Lock separately for each channel and format
|
||||
using (await Locker.LockAsync(filePath))
|
||||
{
|
||||
// Perform the 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 static async ValueTask<IHtmlDocument> ExportAsHtmlAsync(Snowflake channelId) => Html.Parse(
|
||||
await ExportAsync(channelId, ExportFormat.HtmlDark)
|
||||
);
|
||||
|
||||
public static async ValueTask<JsonElement> ExportAsJsonAsync(Snowflake channelId) => Json.Parse(
|
||||
await ExportAsync(channelId, ExportFormat.Json)
|
||||
);
|
||||
|
||||
public static async ValueTask<string> ExportAsPlainTextAsync(Snowflake channelId) =>
|
||||
await ExportAsync(channelId, ExportFormat.PlainText);
|
||||
|
||||
public static async ValueTask<string> ExportAsCsvAsync(Snowflake channelId) =>
|
||||
await ExportAsync(channelId, ExportFormat.Csv);
|
||||
|
||||
public static async ValueTask<IReadOnlyList<IElement>> GetMessagesAsHtmlAsync(Snowflake channelId) =>
|
||||
(await ExportAsHtmlAsync(channelId))
|
||||
.QuerySelectorAll("[data-message-id]")
|
||||
.ToArray();
|
||||
|
||||
public static async ValueTask<IReadOnlyList<JsonElement>> GetMessagesAsJsonAsync(Snowflake channelId) =>
|
||||
(await ExportAsJsonAsync(channelId))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.ToArray();
|
||||
|
||||
public static 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 static 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;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,17 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
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);
|
||||
private static readonly IConfigurationRoot Configuration = new ConfigurationBuilder()
|
||||
.AddUserSecrets(Assembly.GetExecutingAssembly())
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
public static string DiscordToken =>
|
||||
Configuration["DISCORD_TOKEN"] ??
|
||||
throw new InvalidOperationException("Discord token not provided for tests.");
|
||||
});
|
||||
|
||||
public static string DiscordToken => DiscordTokenLazy.Value;
|
||||
}
|
||||
@@ -5,9 +5,8 @@ In order to run these tests locally, you need to join the test server and config
|
||||
|
||||
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
|
||||
3. Add your token to user secrets: `dotnet user-secrets set DISCORD_TOKEN <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
|
||||
> **Note**:
|
||||
> If you want to add a new test case, please let me know and I will give you the required permissions on the server.
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class CsvContentSpecs
|
||||
{
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_in_the_CSV_format()
|
||||
{
|
||||
// Act
|
||||
var document = await ExportWrapper.ExportAsCsvAsync(ChannelIds.DateRangeTestCases);
|
||||
|
||||
// Assert
|
||||
document.Should().ContainAll(
|
||||
"tyrrrz",
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
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"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,8 @@ 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.Discord;
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
using FluentAssertions;
|
||||
@@ -15,21 +14,14 @@ using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class DateRangeSpecs : IClassFixture<TempOutputFixture>
|
||||
public class DateRangeSpecs
|
||||
{
|
||||
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()
|
||||
public async Task I_can_filter_the_export_to_only_include_messages_sent_after_the_specified_date()
|
||||
{
|
||||
// Arrange
|
||||
var after = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
using var file = TempFile.Create();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
@@ -37,13 +29,13 @@ public class DateRangeSpecs : IClassFixture<TempOutputFixture>
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
OutputPath = file.Path,
|
||||
After = Snowflake.FromDate(after)
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
var timestamps = Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.Parse(await File.ReadAllTextAsync(file.Path))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
|
||||
@@ -69,11 +61,11 @@ public class DateRangeSpecs : IClassFixture<TempOutputFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_before_specific_date_only_include_messages_sent_before_that_date()
|
||||
public async Task I_can_filter_the_export_to_only_include_messages_sent_before_the_specified_date()
|
||||
{
|
||||
// Arrange
|
||||
var before = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
using var file = TempFile.Create();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
@@ -81,13 +73,13 @@ public class DateRangeSpecs : IClassFixture<TempOutputFixture>
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
OutputPath = file.Path,
|
||||
Before = Snowflake.FromDate(before)
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
var timestamps = Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.Parse(await File.ReadAllTextAsync(file.Path))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
|
||||
@@ -111,12 +103,12 @@ public class DateRangeSpecs : IClassFixture<TempOutputFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_between_specific_dates_only_include_messages_sent_between_those_dates()
|
||||
public async Task I_can_filter_the_export_to_only_include_messages_sent_between_the_specified_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();
|
||||
using var file = TempFile.Create();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
@@ -124,14 +116,14 @@ public class DateRangeSpecs : IClassFixture<TempOutputFixture>
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
OutputPath = file.Path,
|
||||
Before = Snowflake.FromDate(before),
|
||||
After = Snowflake.FromDate(after)
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
var timestamps = Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.Parse(await File.ReadAllTextAsync(file.Path))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
|
||||
|
||||
@@ -3,9 +3,8 @@ 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 DiscordChatExporter.Core.Exporting.Filtering;
|
||||
using FluentAssertions;
|
||||
@@ -14,20 +13,13 @@ using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class FilterSpecs : IClassFixture<TempOutputFixture>
|
||||
public class FilterSpecs
|
||||
{
|
||||
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()
|
||||
public async Task I_can_filter_the_export_to_only_include_messages_that_contain_the_specified_text()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
using var file = TempFile.Create();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
@@ -35,13 +27,13 @@ public class FilterSpecs : IClassFixture<TempOutputFixture>
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
OutputPath = file.Path,
|
||||
MessageFilter = MessageFilter.Parse("some text")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.Parse(await File.ReadAllTextAsync(file.Path))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
@@ -50,10 +42,10 @@ public class FilterSpecs : IClassFixture<TempOutputFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_author_only_include_messages_sent_by_that_author()
|
||||
public async Task I_can_filter_the_export_to_only_include_messages_that_were_sent_by_the_specified_author()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
using var file = TempFile.Create();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
@@ -61,25 +53,25 @@ public class FilterSpecs : IClassFixture<TempOutputFixture>
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
OutputPath = file.Path,
|
||||
MessageFilter = MessageFilter.Parse("from:Tyrrrz")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.Parse(await File.ReadAllTextAsync(file.Path))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("author").GetProperty("name").GetString())
|
||||
.Should()
|
||||
.AllBe("Tyrrrz");
|
||||
.AllBe("tyrrrz");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_content_only_include_messages_that_have_that_content()
|
||||
public async Task I_can_filter_the_export_to_only_include_messages_that_contain_the_specified_content()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
using var file = TempFile.Create();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
@@ -87,13 +79,13 @@ public class FilterSpecs : IClassFixture<TempOutputFixture>
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
OutputPath = file.Path,
|
||||
MessageFilter = MessageFilter.Parse("has:image")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.Parse(await File.ReadAllTextAsync(file.Path))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
@@ -102,10 +94,10 @@ public class FilterSpecs : IClassFixture<TempOutputFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_pin_only_include_messages_that_have_been_pinned()
|
||||
public async Task I_can_filter_the_export_to_only_include_messages_that_have_been_pinned()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
using var file = TempFile.Create();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
@@ -113,13 +105,13 @@ public class FilterSpecs : IClassFixture<TempOutputFixture>
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
OutputPath = file.Path,
|
||||
MessageFilter = MessageFilter.Parse("has:pin")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.Parse(await File.ReadAllTextAsync(file.Path))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
@@ -128,10 +120,10 @@ public class FilterSpecs : IClassFixture<TempOutputFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_mention_only_include_messages_that_have_that_mention()
|
||||
public async Task I_can_filter_the_export_to_only_include_messages_that_contain_the_specified_mention()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
using var file = TempFile.Create();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
@@ -139,13 +131,13 @@ public class FilterSpecs : IClassFixture<TempOutputFixture>
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
OutputPath = file.Path,
|
||||
MessageFilter = MessageFilter.Parse("mentions:Tyrrrz")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Json
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.Parse(await File.ReadAllTextAsync(file.Path))
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
|
||||
+11
-19
@@ -1,28 +1,20 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
public class HtmlAttachmentSpecs
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public AttachmentSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_generic_attachment_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_generic_attachment()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885587844989612074")
|
||||
);
|
||||
@@ -44,10 +36,10 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_image_attachment_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_an_image_attachment()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885654862656843786")
|
||||
);
|
||||
@@ -65,12 +57,12 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_video_attachment_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_video_attachment()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/333
|
||||
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885655761919836171")
|
||||
);
|
||||
@@ -85,12 +77,12 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_audio_attachment_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_an_audio_attachment()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/333
|
||||
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885656175620808734")
|
||||
);
|
||||
+5
-13
@@ -1,27 +1,19 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class ContentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
public class HtmlContentSpecs
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public ContentSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
public async Task I_can_export_a_channel_in_the_HTML_format()
|
||||
{
|
||||
// Act
|
||||
var messages = await _exportWrapper.GetMessagesAsHtmlAsync(ChannelIds.DateRangeTestCases);
|
||||
var messages = await ExportWrapper.GetMessagesAsHtmlAsync(ChannelIds.DateRangeTestCases);
|
||||
|
||||
// Assert
|
||||
messages.Select(e => e.GetAttribute("data-message-id")).Should().Equal(
|
||||
+58
-29
@@ -1,28 +1,21 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||
public class HtmlEmbedSpecs
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public EmbedSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_embed_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_rich_embed()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("866769910729146400")
|
||||
);
|
||||
@@ -40,12 +33,12 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_containing_an_image_link_is_rendered_with_an_image_embed()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_an_image_embed()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/537
|
||||
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("991768701126852638")
|
||||
);
|
||||
@@ -54,18 +47,19 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||
message
|
||||
.QuerySelectorAll("img")
|
||||
.Select(e => e.GetAttribute("src"))
|
||||
.Where(s => s?.EndsWith("i.redd.it/f8w05ja8s4e61.png") ?? false)
|
||||
.WhereNotNull()
|
||||
.Where(s => s.EndsWith("f8w05ja8s4e61.png"))
|
||||
.Should()
|
||||
.ContainSingle();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_containing_an_image_link_and_nothing_else_is_rendered_without_text_content()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_an_image_embed_and_the_text_is_hidden_if_it_only_contains_the_image_link()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/682
|
||||
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("991768701126852638")
|
||||
);
|
||||
@@ -76,10 +70,29 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_containing_a_gifv_link_is_rendered_with_a_video_embed()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_video_embed()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("1083751036596002856")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message
|
||||
.QuerySelectorAll("source")
|
||||
.Select(e => e.GetAttribute("src"))
|
||||
.WhereNotNull()
|
||||
.Where(s => s.EndsWith("i_am_currently_feeling_slight_displeasure_of_what_you_have_just_sent_lqrem.mp4"))
|
||||
.Should()
|
||||
.ContainSingle();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_GIFV_embed()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("1019234520349814794")
|
||||
);
|
||||
@@ -88,16 +101,17 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||
message
|
||||
.QuerySelectorAll("source")
|
||||
.Select(e => e.GetAttribute("src"))
|
||||
.Where(s => s?.EndsWith("media.tenor.com/DDAJeW6BQKkAAAPo/tooncasm-test-copy.mp4") ?? false)
|
||||
.WhereNotNull()
|
||||
.Where(s => s.EndsWith("tooncasm-test-copy.mp4"))
|
||||
.Should()
|
||||
.ContainSingle();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_containing_a_gifv_link_and_nothing_else_is_rendered_without_text_content()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_GIFV_embed_and_the_text_is_hidden_if_it_only_contains_the_video_link()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("1019234520349814794")
|
||||
);
|
||||
@@ -108,12 +122,12 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_containing_a_Spotify_track_link_is_rendered_with_a_track_embed()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_Spotify_track_embed()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/657
|
||||
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("867886632203976775")
|
||||
);
|
||||
@@ -124,12 +138,12 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_containing_a_YouTube_video_link_is_rendered_with_a_video_embed()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_YouTube_video_embed()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/570
|
||||
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("866472508588294165")
|
||||
);
|
||||
@@ -140,12 +154,12 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_containing_a_Twitter_post_link_with_multiple_images_is_rendered_as_a_single_embed()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_Twitter_post_embed_that_includes_multiple_images()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/695
|
||||
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("991757444017557665")
|
||||
);
|
||||
@@ -164,4 +178,19 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||
|
||||
message.QuerySelectorAll(".chatlog__embed").Should().ContainSingle();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_guild_invite()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/649
|
||||
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("1075116548966064128")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("DiscordChatExporter TestServer");
|
||||
}
|
||||
}
|
||||
+6
-15
@@ -4,32 +4,23 @@ 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;
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class GroupingSpecs : IClassFixture<TempOutputFixture>
|
||||
public class HtmlGroupingSpecs
|
||||
{
|
||||
private readonly TempOutputFixture _tempOutput;
|
||||
|
||||
public GroupingSpecs(TempOutputFixture tempOutput)
|
||||
{
|
||||
_tempOutput = tempOutput;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_are_grouped_correctly()
|
||||
public async Task I_can_export_a_channel_and_the_messages_are_grouped_according_to_their_author_and_timestamps()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/152
|
||||
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
using var file = TempFile.Create();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
@@ -37,12 +28,12 @@ public class GroupingSpecs : IClassFixture<TempOutputFixture>
|
||||
Token = Secrets.DiscordToken,
|
||||
ChannelIds = new[] { ChannelIds.GroupingTestCases },
|
||||
ExportFormat = ExportFormat.HtmlDark,
|
||||
OutputPath = filePath
|
||||
OutputPath = file.Path
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
var messageGroups = Html
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.Parse(await File.ReadAllTextAsync(file.Path))
|
||||
.QuerySelectorAll(".chatlog__message-group");
|
||||
|
||||
messageGroups.Should().HaveCount(2);
|
||||
@@ -0,0 +1,228 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Cli.Tests.Utils;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class HtmlMarkdownSpecs
|
||||
{
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestamp_marker()
|
||||
{
|
||||
// Date formatting code relies on the local time zone, so we need to set it to a fixed value
|
||||
TimeZoneInfoEx.SetLocal(TimeSpan.FromHours(+2));
|
||||
|
||||
try
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MarkdownTestCases,
|
||||
Snowflake.Parse("1074323136411078787")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Default timestamp: 02/12/2023 3:36 PM");
|
||||
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 3:36 PM");
|
||||
}
|
||||
finally
|
||||
{
|
||||
TimeZoneInfo.ClearCachedData();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestamp_marker_in_the_short_format()
|
||||
{
|
||||
// Date formatting code relies on the local time zone, so we need to set it to a fixed value
|
||||
TimeZoneInfoEx.SetLocal(TimeSpan.FromHours(+2));
|
||||
|
||||
try
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MarkdownTestCases,
|
||||
Snowflake.Parse("1074323205268967596")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Short time timestamp: 3:36 PM");
|
||||
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 3:36 PM");
|
||||
}
|
||||
finally
|
||||
{
|
||||
TimeZoneInfo.ClearCachedData();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestamp_marker_in_the_long_format()
|
||||
{
|
||||
// Date formatting code relies on the local time zone, so we need to set it to a fixed value
|
||||
TimeZoneInfoEx.SetLocal(TimeSpan.FromHours(+2));
|
||||
|
||||
try
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MarkdownTestCases,
|
||||
Snowflake.Parse("1074323235342139483")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Long time timestamp: 3:36:12 PM");
|
||||
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 3:36 PM");
|
||||
}
|
||||
finally
|
||||
{
|
||||
TimeZoneInfo.ClearCachedData();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestamp_marker_in_the_short_date_format()
|
||||
{
|
||||
// Date formatting code relies on the local time zone, so we need to set it to a fixed value
|
||||
TimeZoneInfoEx.SetLocal(TimeSpan.FromHours(+2));
|
||||
|
||||
try
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MarkdownTestCases,
|
||||
Snowflake.Parse("1074323326727634984")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Short date timestamp: 02/12/2023");
|
||||
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 3:36 PM");
|
||||
}
|
||||
finally
|
||||
{
|
||||
TimeZoneInfo.ClearCachedData();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestamp_marker_in_the_long_date_format()
|
||||
{
|
||||
// Date formatting code relies on the local time zone, so we need to set it to a fixed value
|
||||
TimeZoneInfoEx.SetLocal(TimeSpan.FromHours(+2));
|
||||
|
||||
try
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MarkdownTestCases,
|
||||
Snowflake.Parse("1074323350731640863")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Long date timestamp: February 12, 2023");
|
||||
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 3:36 PM");
|
||||
}
|
||||
finally
|
||||
{
|
||||
TimeZoneInfo.ClearCachedData();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestamp_marker_in_the_full_format()
|
||||
{
|
||||
// Date formatting code relies on the local time zone, so we need to set it to a fixed value
|
||||
TimeZoneInfoEx.SetLocal(TimeSpan.FromHours(+2));
|
||||
|
||||
try
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MarkdownTestCases,
|
||||
Snowflake.Parse("1074323374379118593")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Full timestamp: February 12, 2023 3:36 PM");
|
||||
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 3:36 PM");
|
||||
}
|
||||
finally
|
||||
{
|
||||
TimeZoneInfo.ClearCachedData();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestamp_marker_in_the_full_long_format()
|
||||
{
|
||||
// Date formatting code relies on the local time zone, so we need to set it to a fixed value
|
||||
TimeZoneInfoEx.SetLocal(TimeSpan.FromHours(+2));
|
||||
|
||||
try
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MarkdownTestCases,
|
||||
Snowflake.Parse("1074323409095376947")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Full long timestamp: Sunday, February 12, 2023 3:36 PM");
|
||||
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 3:36 PM");
|
||||
}
|
||||
finally
|
||||
{
|
||||
TimeZoneInfo.ClearCachedData();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestamp_marker_in_the_relative_format()
|
||||
{
|
||||
// Date formatting code relies on the local time zone, so we need to set it to a fixed value
|
||||
TimeZoneInfoEx.SetLocal(TimeSpan.FromHours(+2));
|
||||
|
||||
try
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MarkdownTestCases,
|
||||
Snowflake.Parse("1074323436853285004")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Relative timestamp: 02/12/2023 3:36 PM");
|
||||
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 3:36 PM");
|
||||
}
|
||||
finally
|
||||
{
|
||||
TimeZoneInfo.ClearCachedData();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_an_invalid_timestamp_marker()
|
||||
{
|
||||
// Date formatting code relies on the local time zone, so we need to set it to a fixed value
|
||||
TimeZoneInfoEx.SetLocal(TimeSpan.FromHours(+2));
|
||||
|
||||
try
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MarkdownTestCases,
|
||||
Snowflake.Parse("1074328534409019563")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Invalid timestamp: Invalid date");
|
||||
}
|
||||
finally
|
||||
{
|
||||
TimeZoneInfo.ClearCachedData();
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-21
@@ -1,41 +1,33 @@
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class MentionSpecs : IClassFixture<ExportWrapperFixture>
|
||||
public class HtmlMentionSpecs
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public MentionSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task User_mention_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_user_mention()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866458840245076028")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("User mention: @Tyrrrz");
|
||||
message.InnerHtml.Should().Contain("Tyrrrz#5447");
|
||||
message.InnerHtml.Should().Contain("tyrrrz");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Text_channel_mention_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_text_channel_mention()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459040480624680")
|
||||
);
|
||||
@@ -45,23 +37,23 @@ public class MentionSpecs : IClassFixture<ExportWrapperFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Voice_channel_mention_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_voice_channel_mention()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459175462633503")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Voice channel mention: 🔊chaos-vc");
|
||||
message.Text().Should().Contain("Voice channel mention: 🔊general");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Role_mention_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_role_mention()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsHtmlAsync(
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459254693429258")
|
||||
);
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class HtmlReplySpecs
|
||||
{
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_that_replies_to_another_message()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.ReplyTestCases,
|
||||
Snowflake.Parse("866460738239725598")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("reply to original");
|
||||
message.QuerySelector(".chatlog__reply-link")?.Text().Should().Contain("original");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_that_replies_to_a_deleted_message()
|
||||
{
|
||||
// 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__reply-link")?.Text().Should().Contain(
|
||||
"Original message was deleted or could not be loaded."
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_that_replies_to_an_empty_message_with_an_attachment()
|
||||
{
|
||||
// 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__reply-link")?.Text().Should().Contain("Click to see attachment");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_that_replies_to_an_interaction()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/569
|
||||
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.ReplyTestCases,
|
||||
Snowflake.Parse("1075152916417085492")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("used /poll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_cross_posted_from_another_guild()
|
||||
{
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/633
|
||||
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.ReplyTestCases,
|
||||
Snowflake.Parse("1072165330853576876")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("This is a test message from an announcement channel on another server");
|
||||
message.Text().Should().Contain("SERVER");
|
||||
message.QuerySelector(".chatlog__reply-link").Should().BeNull();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class HtmlStickerSpecs
|
||||
{
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_PNG_sticker()
|
||||
{
|
||||
// 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://cdn.discordapp.com/stickers/904215665597120572.png");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_Lottie_sticker()
|
||||
{
|
||||
// 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://cdn.discordapp.com/stickers/816087132447178774.json");
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
+27
-31
@@ -1,27 +1,19 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
public class JsonAttachmentSpecs
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public AttachmentSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_generic_attachment_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_generic_attachment()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885587844989612074")
|
||||
);
|
||||
@@ -31,18 +23,19 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().Be(
|
||||
|
||||
attachments[0].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);
|
||||
attachments[0].GetProperty("fileName").GetString().Should().Be("Test.txt");
|
||||
attachments[0].GetProperty("fileSizeBytes").GetInt64().Should().Be(11);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_image_attachment_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_an_image_attachment()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885654862656843786")
|
||||
);
|
||||
@@ -52,18 +45,19 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().Be(
|
||||
|
||||
attachments[0].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);
|
||||
attachments[0].GetProperty("fileName").GetString().Should().Be("bird-thumbnail.png");
|
||||
attachments[0].GetProperty("fileSizeBytes").GetInt64().Should().Be(466335);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_video_attachment_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_video_attachment()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885655761919836171")
|
||||
);
|
||||
@@ -73,18 +67,19 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().Be(
|
||||
|
||||
attachments[0].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);
|
||||
attachments[0].GetProperty("fileName").GetString().Should().Be("file_example_MP4_640_3MG.mp4");
|
||||
attachments[0].GetProperty("fileSizeBytes").GetInt64().Should().Be(3114374);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_audio_attachment_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_an_audio_attachment()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885656175620808734")
|
||||
);
|
||||
@@ -94,10 +89,11 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().Be(
|
||||
|
||||
attachments[0].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);
|
||||
attachments[0].GetProperty("fileName").GetString().Should().Be("file_example_MP3_1MG.mp3");
|
||||
attachments[0].GetProperty("fileSizeBytes").GetInt64().Should().Be(1087849);
|
||||
}
|
||||
}
|
||||
+5
-13
@@ -1,26 +1,18 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class ContentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
public class JsonContentSpecs
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public ContentSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
public async Task I_can_export_a_channel_in_the_JSON_format()
|
||||
{
|
||||
// Act
|
||||
var messages = await _exportWrapper.GetMessagesAsJsonAsync(ChannelIds.DateRangeTestCases);
|
||||
var messages = await ExportWrapper.GetMessagesAsJsonAsync(ChannelIds.DateRangeTestCases);
|
||||
|
||||
// Assert
|
||||
messages.Select(j => j.GetProperty("id").GetString()).Should().Equal(
|
||||
+5
-13
@@ -1,27 +1,19 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
|
||||
public class JsonEmbedSpecs
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public EmbedSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_embed_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_rich_embed()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("866769910729146400")
|
||||
);
|
||||
+12
-20
@@ -1,27 +1,19 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class MentionSpecs : IClassFixture<ExportWrapperFixture>
|
||||
public class JsonMentionSpecs
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public MentionSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task User_mention_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_user_mention()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866458840245076028")
|
||||
);
|
||||
@@ -38,10 +30,10 @@ public class MentionSpecs : IClassFixture<ExportWrapperFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Text_channel_mention_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_text_channel_mention()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459040480624680")
|
||||
);
|
||||
@@ -51,23 +43,23 @@ public class MentionSpecs : IClassFixture<ExportWrapperFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Voice_channel_mention_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_voice_channel_mention()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459175462633503")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Voice channel mention: #chaos-vc [voice]");
|
||||
message.GetProperty("content").GetString().Should().Be("Voice channel mention: #general [voice]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Role_mention_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_role_mention()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459254693429258")
|
||||
);
|
||||
+10
-18
@@ -1,27 +1,19 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||
using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class StickerSpecs : IClassFixture<ExportWrapperFixture>
|
||||
public class JsonStickerSpecs
|
||||
{
|
||||
private readonly ExportWrapperFixture _exportWrapper;
|
||||
|
||||
public StickerSpecs(ExportWrapperFixture exportWrapper)
|
||||
{
|
||||
_exportWrapper = exportWrapper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_PNG_based_sticker_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_PNG_sticker()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.StickerTestCases,
|
||||
Snowflake.Parse("939670623158943754")
|
||||
);
|
||||
@@ -34,15 +26,15 @@ public class StickerSpecs : IClassFixture<ExportWrapperFixture>
|
||||
|
||||
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");
|
||||
sticker.GetProperty("format").GetString().Should().Be("Apng");
|
||||
sticker.GetProperty("sourceUrl").GetString().Should().Be("https://cdn.discordapp.com/stickers/904215665597120572.png");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_Lottie_based_sticker_is_rendered_correctly()
|
||||
public async Task I_can_export_a_channel_that_contains_a_message_with_a_Lottie_sticker()
|
||||
{
|
||||
// Act
|
||||
var message = await _exportWrapper.GetMessageAsJsonAsync(
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.StickerTestCases,
|
||||
Snowflake.Parse("939670526517997590")
|
||||
);
|
||||
@@ -56,6 +48,6 @@ public class StickerSpecs : IClassFixture<ExportWrapperFixture>
|
||||
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");
|
||||
sticker.GetProperty("sourceUrl").GetString().Should().Be("https://cdn.discordapp.com/stickers/816087132447178774.json");
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,8 @@
|
||||
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 DiscordChatExporter.Core.Exporting.Partitioning;
|
||||
using FluentAssertions;
|
||||
@@ -12,22 +11,14 @@ using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class PartitioningSpecs : IClassFixture<TempOutputFixture>
|
||||
public class PartitioningSpecs
|
||||
{
|
||||
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()
|
||||
public async Task I_can_export_a_channel_with_partitioning_based_on_message_count()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
|
||||
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
|
||||
using var dir = TempDir.Create();
|
||||
var filePath = Path.Combine(dir.Path, "output.html");
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
@@ -40,18 +31,17 @@ public class PartitioningSpecs : IClassFixture<TempOutputFixture>
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
|
||||
Directory.EnumerateFiles(dir.Path, "output*")
|
||||
.Should()
|
||||
.HaveCount(3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_partitioned_by_file_size_are_split_into_a_corresponding_number_of_files()
|
||||
public async Task I_can_export_a_channel_with_partitioning_based_on_file_size()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
|
||||
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
|
||||
using var dir = TempDir.Create();
|
||||
var filePath = Path.Combine(dir.Path, "output.html");
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
@@ -64,7 +54,7 @@ public class PartitioningSpecs : IClassFixture<TempOutputFixture>
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
|
||||
Directory.EnumerateFiles(dir.Path, "output*")
|
||||
.Should()
|
||||
.HaveCount(8);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Cli.Tests.Infra;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class PlainTextContentSpecs
|
||||
{
|
||||
[Fact]
|
||||
public async Task I_can_export_a_channel_in_the_TXT_format()
|
||||
{
|
||||
// Act
|
||||
var document = await ExportWrapper.ExportAsPlainTextAsync(ChannelIds.DateRangeTestCases);
|
||||
|
||||
// Assert
|
||||
document.Should().ContainAll(
|
||||
"tyrrrz",
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
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"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,7 @@ 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;
|
||||
@@ -13,21 +11,14 @@ using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public class SelfContainedSpecs : IClassFixture<TempOutputFixture>
|
||||
public class SelfContainedSpecs
|
||||
{
|
||||
private readonly TempOutputFixture _tempOutput;
|
||||
|
||||
public SelfContainedSpecs(TempOutputFixture tempOutput)
|
||||
{
|
||||
_tempOutput = tempOutput;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_in_self_contained_export_only_reference_local_file_resources()
|
||||
public async Task I_can_export_a_channel_and_download_all_referenced_assets()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
|
||||
using var dir = TempDir.Create();
|
||||
var filePath = Path.Combine(dir.Path, "output.html");
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
@@ -44,7 +35,7 @@ public class SelfContainedSpecs : IClassFixture<TempOutputFixture>
|
||||
.Parse(await File.ReadAllTextAsync(filePath))
|
||||
.QuerySelectorAll("body [src]")
|
||||
.Select(e => e.GetAttribute("src")!)
|
||||
.Select(f => Path.GetFullPath(f, dirPath))
|
||||
.Select(f => Path.GetFullPath(f, dir.Path))
|
||||
.All(File.Exists)
|
||||
.Should()
|
||||
.BeTrue();
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
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,41 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using PathEx = System.IO.Path;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Utils;
|
||||
|
||||
internal partial class TempDir : IDisposable
|
||||
{
|
||||
public string Path { get; }
|
||||
|
||||
public TempDir(string path) =>
|
||||
Path = path;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(Path, true);
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal partial class TempDir
|
||||
{
|
||||
public static TempDir Create()
|
||||
{
|
||||
var dirPath = PathEx.Combine(
|
||||
PathEx.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? Directory.GetCurrentDirectory(),
|
||||
"Temp",
|
||||
Guid.NewGuid().ToString()
|
||||
);
|
||||
|
||||
Directory.CreateDirectory(dirPath);
|
||||
|
||||
return new TempDir(dirPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using PathEx = System.IO.Path;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Utils;
|
||||
|
||||
internal partial class TempFile : IDisposable
|
||||
{
|
||||
public string Path { get; }
|
||||
|
||||
public TempFile(string path) =>
|
||||
Path = path;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(Path);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal partial class TempFile
|
||||
{
|
||||
public static TempFile Create()
|
||||
{
|
||||
var dirPath = PathEx.Combine(
|
||||
PathEx.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? Directory.GetCurrentDirectory(),
|
||||
"Temp"
|
||||
);
|
||||
|
||||
Directory.CreateDirectory(dirPath);
|
||||
|
||||
var filePath = PathEx.Combine(
|
||||
dirPath,
|
||||
Guid.NewGuid() + ".tmp"
|
||||
);
|
||||
|
||||
return new TempFile(filePath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using ReflectionMagic;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Utils;
|
||||
|
||||
internal static class TimeZoneInfoEx
|
||||
{
|
||||
// https://stackoverflow.com/a/63700512/2205454
|
||||
public static void SetLocal(TimeZoneInfo timeZone) =>
|
||||
typeof(TimeZoneInfo).AsDynamicType().s_cachedData._localTimeZone = timeZone;
|
||||
|
||||
public static void SetLocal(TimeSpan offset) =>
|
||||
SetLocal(TimeZoneInfo.CreateCustomTimeZone("test-tz", offset, "test-tz", "test-tz"));
|
||||
}
|
||||
@@ -1,44 +1,45 @@
|
||||
# -- Build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
|
||||
# Specify the platform here so that we pull the SDK image matching the host platform,
|
||||
# instead of the target platform specified during build by the `--platform` option.
|
||||
# Use the .NET 8.0 preview because the `--arch` option is only available in that version.
|
||||
# https://github.com/dotnet/dotnet-docker/issues/4388#issuecomment-1459038566
|
||||
# TODO: switch images to Alpine once .NET 8.0 is released.
|
||||
# Currently, the correct preview version is only available on Debian.
|
||||
# https://github.com/dotnet/dotnet-docker/blob/main/samples/selecting-tags.md
|
||||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview AS build
|
||||
|
||||
# Expose the target architecture set by the `docker build --platform` option, so that
|
||||
# we can build the assembly for the correct platform.
|
||||
ARG TARGETARCH
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
COPY favicon.ico ./
|
||||
COPY NuGet.config ./
|
||||
COPY Directory.Build.props ./
|
||||
COPY DiscordChatExporter.Core ./DiscordChatExporter.Core
|
||||
COPY DiscordChatExporter.Cli ./DiscordChatExporter.Cli
|
||||
COPY favicon.ico .
|
||||
COPY NuGet.config .
|
||||
COPY Directory.Build.props .
|
||||
COPY DiscordChatExporter.Core DiscordChatExporter.Core
|
||||
COPY DiscordChatExporter.Cli DiscordChatExporter.Cli
|
||||
|
||||
# Publish a self-contained assembly so we can use a slimmer runtime image
|
||||
RUN dotnet publish DiscordChatExporter.Cli \
|
||||
--configuration Release \
|
||||
--self-contained \
|
||||
--use-current-runtime \
|
||||
--configuration Release \
|
||||
--output ./publish
|
||||
--arch $TARGETARCH \
|
||||
--output publish/
|
||||
|
||||
# -- Run
|
||||
FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine
|
||||
# Use `runtime-deps` instead of `runtime` because we have a self-contained assembly
|
||||
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/runtime-deps:7.0 AS run
|
||||
|
||||
# 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.
|
||||
# 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
|
||||
|
||||
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.
|
||||
# This directory is exposed to the user for mounting purposes, so it's important that it always
|
||||
# stays the same for backwards compatibility.
|
||||
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"]
|
||||
COPY --from=build /build/publish /opt/dce
|
||||
ENTRYPOINT ["/opt/dce/DiscordChatExporter.Cli"]
|
||||
+1
-1
@@ -7,7 +7,7 @@ using DiscordChatExporter.Core.Discord;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands.Base;
|
||||
|
||||
public abstract class TokenCommandBase : ICommand
|
||||
public abstract class DiscordCommandBase : ICommand
|
||||
{
|
||||
[CommandOption(
|
||||
"token",
|
||||
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Exceptions;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands.Converters;
|
||||
using DiscordChatExporter.Cli.Utils.Extensions;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Discord.Data;
|
||||
@@ -15,18 +16,23 @@ using DiscordChatExporter.Core.Exporting;
|
||||
using DiscordChatExporter.Core.Exporting.Filtering;
|
||||
using DiscordChatExporter.Core.Exporting.Partitioning;
|
||||
using DiscordChatExporter.Core.Utils;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using Gress;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands.Base;
|
||||
|
||||
public abstract class ExportCommandBase : TokenCommandBase
|
||||
public abstract class ExportCommandBase : DiscordCommandBase
|
||||
{
|
||||
private readonly string _outputPath = Directory.GetCurrentDirectory();
|
||||
|
||||
[CommandOption(
|
||||
"output",
|
||||
'o',
|
||||
Description = "Output file or directory path. Directory path should end in a slash."
|
||||
Description =
|
||||
"Output file or directory path. " +
|
||||
"Directory path must end with a slash to avoid ambiguity. " +
|
||||
"If a directory is specified, file names will be generated automatically. " +
|
||||
"Supports template tokens, see the documentation for more info."
|
||||
)]
|
||||
public string OutputPath
|
||||
{
|
||||
@@ -58,13 +64,17 @@ public abstract class ExportCommandBase : TokenCommandBase
|
||||
[CommandOption(
|
||||
"partition",
|
||||
'p',
|
||||
Description = "Split output into partitions, each limited to this number of messages (e.g. '100') or file size (e.g. '10mb')."
|
||||
Description =
|
||||
"Split the output into partitions, each limited to the specified " +
|
||||
"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')."
|
||||
Description =
|
||||
"Only include messages that satisfy this filter. " +
|
||||
"See the documentation for more info."
|
||||
)]
|
||||
public MessageFilter MessageFilter { get; init; } = MessageFilter.Null;
|
||||
|
||||
@@ -74,6 +84,12 @@ public abstract class ExportCommandBase : TokenCommandBase
|
||||
)]
|
||||
public int ParallelLimit { get; init; } = 1;
|
||||
|
||||
[CommandOption(
|
||||
"markdown",
|
||||
Description = "Process markdown, mentions, and other special tokens."
|
||||
)]
|
||||
public bool ShouldFormatMarkdown { get; init; } = true;
|
||||
|
||||
[CommandOption(
|
||||
"media",
|
||||
Description = "Download assets referenced by the export (user avatars, attached files, embedded images, etc.)."
|
||||
@@ -86,15 +102,34 @@ public abstract class ExportCommandBase : TokenCommandBase
|
||||
)]
|
||||
public bool ShouldReuseAssets { get; init; }
|
||||
|
||||
private readonly string? _assetsDirPath;
|
||||
|
||||
[CommandOption(
|
||||
"media-dir",
|
||||
Description =
|
||||
"Download assets to this directory. " +
|
||||
"If not specified, the asset directory path will be derived from the output path."
|
||||
)]
|
||||
public string? AssetsDirPath
|
||||
{
|
||||
get => _assetsDirPath;
|
||||
// Handle ~/ in paths on Unix systems
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/pull/903
|
||||
init => _assetsDirPath = value is not null ? Path.GetFullPath(value) : null;
|
||||
}
|
||||
|
||||
[CommandOption(
|
||||
"dateformat",
|
||||
Description = "Format used when writing dates."
|
||||
)]
|
||||
public string DateFormat { get; init; } = "dd-MMM-yy hh:mm tt";
|
||||
public string DateFormat { get; init; } = "MM/dd/yyyy h:mm tt";
|
||||
|
||||
[CommandOption(
|
||||
"fuck-russia",
|
||||
Description = "Don't print the Support Ukraine message to the console."
|
||||
EnvironmentVariable = "FUCK_RUSSIA",
|
||||
Description = "Don't print the Support Ukraine message to the console.",
|
||||
// Use a converter to accept '1' as 'true' to reuse the existing environment variable
|
||||
Converter = typeof(TruthyBooleanBindingConverter)
|
||||
)]
|
||||
public bool IsUkraineSupportMessageDisabled { get; init; }
|
||||
|
||||
@@ -103,7 +138,7 @@ public abstract class ExportCommandBase : TokenCommandBase
|
||||
|
||||
protected async ValueTask ExecuteAsync(IConsole console, IReadOnlyList<Channel> channels)
|
||||
{
|
||||
// Reuse assets option should only be used when the download assets option is set.
|
||||
// Asset reuse can only be enabled if the download assets option is set
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/425
|
||||
if (ShouldReuseAssets && !ShouldDownloadAssets)
|
||||
{
|
||||
@@ -112,8 +147,16 @@ public abstract class ExportCommandBase : TokenCommandBase
|
||||
);
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Assets directory can only be specified if the download assets option is set
|
||||
if (!string.IsNullOrWhiteSpace(AssetsDirPath) && !ShouldDownloadAssets)
|
||||
{
|
||||
throw new CommandException(
|
||||
"Option --media-dir cannot be used without --media."
|
||||
);
|
||||
}
|
||||
|
||||
// Make sure the user does not try to export multiple channels into one file.
|
||||
// Output path must either be a directory or contain template tokens for this to work.
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/799
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/917
|
||||
var isValidOutputPath =
|
||||
@@ -132,10 +175,10 @@ public abstract class ExportCommandBase : TokenCommandBase
|
||||
);
|
||||
}
|
||||
|
||||
// Export
|
||||
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 =>
|
||||
{
|
||||
@@ -160,11 +203,13 @@ public abstract class ExportCommandBase : TokenCommandBase
|
||||
guild,
|
||||
channel,
|
||||
OutputPath,
|
||||
AssetsDirPath,
|
||||
ExportFormat,
|
||||
After,
|
||||
Before,
|
||||
PartitionLimit,
|
||||
MessageFilter,
|
||||
ShouldFormatMarkdown,
|
||||
ShouldDownloadAssets,
|
||||
ShouldReuseAssets,
|
||||
DateFormat
|
||||
@@ -186,7 +231,7 @@ public abstract class ExportCommandBase : TokenCommandBase
|
||||
);
|
||||
});
|
||||
|
||||
// Print result
|
||||
// Print the result
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
{
|
||||
await console.Output.WriteLineAsync(
|
||||
@@ -201,39 +246,61 @@ public abstract class ExportCommandBase : TokenCommandBase
|
||||
|
||||
using (console.WithForegroundColor(ConsoleColor.Red))
|
||||
{
|
||||
await console.Output.WriteLineAsync(
|
||||
await console.Error.WriteLineAsync(
|
||||
$"Failed to export {errors.Count} channel(s):"
|
||||
);
|
||||
}
|
||||
|
||||
foreach (var (channel, error) in errors)
|
||||
{
|
||||
await console.Output.WriteAsync($"{channel.Category.Name} / {channel.Name}: ");
|
||||
await console.Error.WriteAsync($"{channel.Category.Name} / {channel.Name}: ");
|
||||
|
||||
using (console.WithForegroundColor(ConsoleColor.Red))
|
||||
await console.Output.WriteLineAsync(error);
|
||||
await console.Error.WriteLineAsync(error);
|
||||
}
|
||||
|
||||
await console.Output.WriteLineAsync();
|
||||
await console.Error.WriteLineAsync();
|
||||
}
|
||||
|
||||
// Fail the command only if ALL channels failed to export.
|
||||
// Having some of the channels fail to export is expected.
|
||||
// If only some channels failed to export, it's okay.
|
||||
if (errors.Count >= channels.Count)
|
||||
{
|
||||
throw new CommandException("Export failed.");
|
||||
}
|
||||
}
|
||||
|
||||
protected async ValueTask ExecuteAsync(IConsole console, IReadOnlyList<Snowflake> channelIds)
|
||||
{
|
||||
var cancellationToken = console.RegisterCancellationHandler();
|
||||
|
||||
await console.Output.WriteLineAsync("Resolving channel(s)...");
|
||||
|
||||
var channels = new List<Channel>();
|
||||
var channelsByGuild = new Dictionary<Snowflake, IReadOnlyList<Channel>>();
|
||||
|
||||
foreach (var channelId in channelIds)
|
||||
{
|
||||
var channel = await Discord.GetChannelAsync(channelId, cancellationToken);
|
||||
channels.Add(channel);
|
||||
|
||||
// Unwrap categories
|
||||
if (channel.Kind == ChannelKind.GuildCategory)
|
||||
{
|
||||
var guildChannels =
|
||||
channelsByGuild.GetValueOrDefault(channel.GuildId) ??
|
||||
await Discord.GetGuildChannelsAsync(channel.GuildId, cancellationToken);
|
||||
|
||||
foreach (var guildChannel in guildChannels)
|
||||
{
|
||||
if (guildChannel.Category.Id == channel.Id)
|
||||
channels.Add(guildChannel);
|
||||
}
|
||||
|
||||
// Cache the guild channels to avoid redundant work
|
||||
channelsByGuild[channel.GuildId] = guildChannels;
|
||||
}
|
||||
else
|
||||
{
|
||||
channels.Add(channel);
|
||||
}
|
||||
}
|
||||
|
||||
await ExecuteAsync(console, channels);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using CliFx.Extensibility;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands.Converters;
|
||||
|
||||
internal class TruthyBooleanBindingConverter : BindingConverter<bool>
|
||||
{
|
||||
public override bool Convert(string? rawValue)
|
||||
{
|
||||
// Null is still considered true, to match the base behavior
|
||||
if (rawValue is null)
|
||||
return true;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(rawValue))
|
||||
return false;
|
||||
|
||||
if (bool.TryParse(rawValue, out var boolValue))
|
||||
return boolValue;
|
||||
|
||||
if (int.TryParse(rawValue, CultureInfo.InvariantCulture, out var intValue) && intValue == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Compression;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Exceptions;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands.Base;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Discord.Data;
|
||||
using DiscordChatExporter.Core.Exceptions;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands;
|
||||
|
||||
[Command("exportall", Description = "Export all accessible channels.")]
|
||||
[Command("exportall", Description = "Exports all accessible channels.")]
|
||||
public class ExportAllCommand : ExportCommandBase
|
||||
{
|
||||
[CommandOption(
|
||||
"include-dm",
|
||||
Description = "Include direct message channels."
|
||||
)]
|
||||
public bool IncludeDirectMessages { get; init; } = true;
|
||||
public bool IncludeDirectChannels { get; init; } = true;
|
||||
|
||||
[CommandOption(
|
||||
"include-guilds",
|
||||
Description = "Include guild channels."
|
||||
)]
|
||||
public bool IncludeGuildChannels { get; init; } = true;
|
||||
|
||||
[CommandOption(
|
||||
"data-package",
|
||||
Description =
|
||||
"Path to the personal data package (ZIP file) requested from Discord. " +
|
||||
"If provided, only channels referenced in the dump will be exported."
|
||||
)]
|
||||
public string? DataPackageFilePath { get; init; }
|
||||
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
@@ -23,16 +43,60 @@ public class ExportAllCommand : ExportCommandBase
|
||||
var cancellationToken = console.RegisterCancellationHandler();
|
||||
var channels = new List<Channel>();
|
||||
|
||||
await console.Output.WriteLineAsync("Fetching channels...");
|
||||
await foreach (var guild in Discord.GetUserGuildsAsync(cancellationToken))
|
||||
// Pull from the API
|
||||
if (string.IsNullOrWhiteSpace(DataPackageFilePath))
|
||||
{
|
||||
// Skip DMs if instructed to
|
||||
if (!IncludeDirectMessages && guild.Id == Guild.DirectMessages.Id)
|
||||
continue;
|
||||
await console.Output.WriteLineAsync("Fetching channels...");
|
||||
|
||||
await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken))
|
||||
channels.Add(channel);
|
||||
await foreach (var guild in Discord.GetUserGuildsAsync(cancellationToken))
|
||||
{
|
||||
await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken))
|
||||
{
|
||||
channels.Add(channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Pull from the data package
|
||||
else
|
||||
{
|
||||
await console.Output.WriteLineAsync("Extracting channels...");
|
||||
using var archive = ZipFile.OpenRead(DataPackageFilePath);
|
||||
|
||||
var entry = archive.GetEntry("messages/index.json");
|
||||
if (entry is null)
|
||||
throw new CommandException("Could not find channel index inside the data package.");
|
||||
|
||||
await using var stream = entry.Open();
|
||||
using var document = await JsonDocument.ParseAsync(stream, default, cancellationToken);
|
||||
|
||||
foreach (var property in document.RootElement.EnumerateObjectOrEmpty())
|
||||
{
|
||||
var channelId = Snowflake.Parse(property.Name);
|
||||
var channelName = property.Value.GetString();
|
||||
|
||||
// Null items refer to deleted channels
|
||||
if (channelName is null)
|
||||
continue;
|
||||
|
||||
await console.Output.WriteLineAsync($"Fetching channel '{channelName}' ({channelId})...");
|
||||
|
||||
try
|
||||
{
|
||||
var channel = await Discord.GetChannelAsync(channelId, cancellationToken);
|
||||
channels.Add(channel);
|
||||
}
|
||||
catch (DiscordChatExporterException)
|
||||
{
|
||||
await console.Error.WriteLineAsync($"Channel '{channelName}' ({channelId}) is inaccessible.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out unwanted channels
|
||||
if (!IncludeDirectChannels)
|
||||
channels.RemoveAll(c => c.Kind.IsDirect());
|
||||
if (!IncludeGuildChannels)
|
||||
channels.RemoveAll(c => c.Kind.IsGuild());
|
||||
|
||||
await base.ExecuteAsync(console, channels);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
@@ -8,14 +7,16 @@ using DiscordChatExporter.Core.Discord;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands;
|
||||
|
||||
[Command("export", Description = "Export one or multiple channels.")]
|
||||
[Command("export", Description = "Exports one or multiple channels.")]
|
||||
public class ExportChannelsCommand : ExportCommandBase
|
||||
{
|
||||
// TODO: change this to plural (breaking change)
|
||||
[CommandOption(
|
||||
"channel",
|
||||
'c',
|
||||
Description = "Channel ID(s)."
|
||||
Description =
|
||||
"Channel ID(s). " +
|
||||
"If provided with category ID(s), all channels inside those categories will be exported."
|
||||
)]
|
||||
public required IReadOnlyList<Snowflake> ChannelIds { get; init; }
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands.Base;
|
||||
@@ -8,7 +7,7 @@ using DiscordChatExporter.Core.Utils.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands;
|
||||
|
||||
[Command("exportdm", Description = "Export all direct message channels.")]
|
||||
[Command("exportdm", Description = "Exports all direct message channels.")]
|
||||
public class ExportDirectMessagesCommand : ExportCommandBase
|
||||
{
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
@@ -18,10 +17,7 @@ public class ExportDirectMessagesCommand : ExportCommandBase
|
||||
var cancellationToken = console.RegisterCancellationHandler();
|
||||
|
||||
await console.Output.WriteLineAsync("Fetching channels...");
|
||||
|
||||
var channels = (await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken))
|
||||
.Where(c => c.Kind != ChannelKind.GuildCategory)
|
||||
.ToArray();
|
||||
var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken);
|
||||
|
||||
await base.ExecuteAsync(console, channels);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ using DiscordChatExporter.Core.Utils.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands;
|
||||
|
||||
[Command("exportguild", Description = "Export all channels within specified guild.")]
|
||||
[Command("exportguild", Description = "Exports all channels within the specified guild.")]
|
||||
public class ExportGuildCommand : ExportCommandBase
|
||||
{
|
||||
[CommandOption(
|
||||
|
||||
@@ -11,7 +11,7 @@ using DiscordChatExporter.Core.Utils.Extensions;
|
||||
namespace DiscordChatExporter.Cli.Commands;
|
||||
|
||||
[Command("channels", Description = "Get the list of channels in a guild.")]
|
||||
public class GetChannelsCommand : TokenCommandBase
|
||||
public class GetChannelsCommand : DiscordCommandBase
|
||||
{
|
||||
[CommandOption(
|
||||
"guild",
|
||||
@@ -20,6 +20,12 @@ public class GetChannelsCommand : TokenCommandBase
|
||||
)]
|
||||
public required Snowflake GuildId { get; init; }
|
||||
|
||||
[CommandOption(
|
||||
"include-threads",
|
||||
Description = "Include threads in the output."
|
||||
)]
|
||||
public bool IncludeThreads { get; init; }
|
||||
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
var cancellationToken = console.RegisterCancellationHandler();
|
||||
@@ -30,11 +36,20 @@ public class GetChannelsCommand : TokenCommandBase
|
||||
.ThenBy(c => c.Name)
|
||||
.ToArray();
|
||||
|
||||
var channelIdMaxLength = channels
|
||||
.Select(c => c.Id.ToString().Length)
|
||||
.OrderDescending()
|
||||
.FirstOrDefault();
|
||||
|
||||
var threads = IncludeThreads
|
||||
? (await Discord.GetGuildThreadsAsync(GuildId, cancellationToken)).OrderBy(c => c.Name).ToArray()
|
||||
: Array.Empty<ChannelThread>();
|
||||
|
||||
foreach (var channel in channels)
|
||||
{
|
||||
// Channel ID
|
||||
await console.Output.WriteAsync(
|
||||
channel.Id.ToString().PadRight(18, ' ')
|
||||
channel.Id.ToString().PadRight(channelIdMaxLength, ' ')
|
||||
);
|
||||
|
||||
// Separator
|
||||
@@ -44,6 +59,39 @@ public class GetChannelsCommand : TokenCommandBase
|
||||
// Channel category / name
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
await console.Output.WriteLineAsync($"{channel.Category.Name} / {channel.Name}");
|
||||
|
||||
var channelThreads = threads.Where(t => t.ParentId == channel.Id).ToArray();
|
||||
var channelThreadIdMaxLength = channelThreads
|
||||
.Select(t => t.Id.ToString().Length)
|
||||
.OrderDescending()
|
||||
.FirstOrDefault();
|
||||
|
||||
foreach (var thread in channelThreads)
|
||||
{
|
||||
// Indent
|
||||
await console.Output.WriteAsync(" * ");
|
||||
|
||||
// Thread ID
|
||||
await console.Output.WriteAsync(
|
||||
thread.Id.ToString().PadRight(channelThreadIdMaxLength, ' ')
|
||||
);
|
||||
|
||||
// Separator
|
||||
using (console.WithForegroundColor(ConsoleColor.DarkGray))
|
||||
await console.Output.WriteAsync(" | ");
|
||||
|
||||
// Thread name
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
await console.Output.WriteAsync($"Thread / {thread.Name}");
|
||||
|
||||
// Separator
|
||||
using (console.WithForegroundColor(ConsoleColor.DarkGray))
|
||||
await console.Output.WriteAsync(" | ");
|
||||
|
||||
// Thread status
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
await console.Output.WriteLineAsync(thread.IsActive ? "Active" : "Archived");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-3
@@ -9,8 +9,8 @@ using DiscordChatExporter.Core.Utils.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands;
|
||||
|
||||
[Command("dm", Description = "Get the list of direct message channels.")]
|
||||
public class GetDirectMessageChannelsCommand : TokenCommandBase
|
||||
[Command("dm", Description = "Gets the list of all direct message channels.")]
|
||||
public class GetDirectChannelsCommand : DiscordCommandBase
|
||||
{
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
@@ -22,11 +22,16 @@ public class GetDirectMessageChannelsCommand : TokenCommandBase
|
||||
.ThenBy(c => c.Name)
|
||||
.ToArray();
|
||||
|
||||
var channelIdMaxLength = channels
|
||||
.Select(c => c.Id.ToString().Length)
|
||||
.OrderDescending()
|
||||
.FirstOrDefault();
|
||||
|
||||
foreach (var channel in channels)
|
||||
{
|
||||
// Channel ID
|
||||
await console.Output.WriteAsync(
|
||||
channel.Id.ToString().PadRight(18, ' ')
|
||||
channel.Id.ToString().PadRight(channelIdMaxLength, ' ')
|
||||
);
|
||||
|
||||
// Separator
|
||||
@@ -9,8 +9,8 @@ using DiscordChatExporter.Core.Utils.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands;
|
||||
|
||||
[Command("guilds", Description = "Get the list of accessible guilds.")]
|
||||
public class GetGuildsCommand : TokenCommandBase
|
||||
[Command("guilds", Description = "Gets the list of accessible guilds.")]
|
||||
public class GetGuildsCommand : DiscordCommandBase
|
||||
{
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
@@ -19,13 +19,19 @@ public class GetGuildsCommand : TokenCommandBase
|
||||
var guilds = (await Discord.GetUserGuildsAsync(cancellationToken))
|
||||
// Show direct messages first
|
||||
.OrderByDescending(g => g.Id == Guild.DirectMessages.Id)
|
||||
.ThenBy(g => g.Name);
|
||||
.ThenBy(g => g.Name)
|
||||
.ToArray();
|
||||
|
||||
var guildIdMaxLength = guilds
|
||||
.Select(g => g.Id.ToString().Length)
|
||||
.OrderDescending()
|
||||
.FirstOrDefault();
|
||||
|
||||
foreach (var guild in guilds)
|
||||
{
|
||||
// Guild ID
|
||||
await console.Output.WriteAsync(
|
||||
guild.Id.ToString().PadRight(18, ' ')
|
||||
guild.Id.ToString().PadRight(guildIdMaxLength, ' ')
|
||||
);
|
||||
|
||||
// Separator
|
||||
|
||||
@@ -6,7 +6,7 @@ using CliFx.Infrastructure;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands;
|
||||
|
||||
[Command("guide", Description = "Explains how to obtain token, guild or channel ID.")]
|
||||
[Command("guide", Description = "Explains how to obtain the token, guild or channel ID.")]
|
||||
public class GuideCommand : ICommand
|
||||
{
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
@@ -21,10 +21,11 @@ public class GuideCommand : ICommand
|
||||
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(" 6. Switch between random channels to trigger network requests");
|
||||
console.Output.WriteLine(" 7. Search for a request containing \"messages?limit=50\" or similar");
|
||||
console.Output.WriteLine(" 8. Select the Headers tab on the right");
|
||||
console.Output.WriteLine(" 9. Scroll down to the Request Headers section");
|
||||
console.Output.WriteLine(" 10. Copy the value of the \"authorization\" header");
|
||||
console.Output.WriteLine();
|
||||
|
||||
// Bot token
|
||||
@@ -40,25 +41,13 @@ public class GuideCommand : ICommand
|
||||
|
||||
// Guild or channel ID
|
||||
using (console.WithForegroundColor(ConsoleColor.White))
|
||||
console.Output.WriteLine("To get guild ID or guild channel ID:");
|
||||
console.Output.WriteLine("To get guild ID or channel ID:");
|
||||
|
||||
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();
|
||||
|
||||
// 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(" 5. Right-click on the desired guild or channel and click Copy Server ID or Copy Channel ID");
|
||||
console.Output.WriteLine();
|
||||
|
||||
// Docs link
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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" />
|
||||
<PackageReference Include="CliFx" Version="2.3.4" />
|
||||
<PackageReference Include="Deorcify" Version="1.0.2" PrivateAssets="all" />
|
||||
<PackageReference Include="DotnetRuntimeBootstrapper" Version="2.5.1" PrivateAssets="all" />
|
||||
<PackageReference Include="Gress" Version="2.1.1" />
|
||||
<PackageReference Include="Spectre.Console" Version="0.47.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
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;
|
||||
|
||||
@@ -20,11 +19,26 @@ public partial record Attachment(
|
||||
{
|
||||
public string FileExtension => Path.GetExtension(FileName);
|
||||
|
||||
public bool IsImage => FileFormat.IsImage(FileExtension);
|
||||
public bool IsImage =>
|
||||
string.Equals(FileExtension, ".jpg", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(FileExtension, ".jpeg", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(FileExtension, ".png", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(FileExtension, ".gif", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(FileExtension, ".bmp", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(FileExtension, ".webp", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public bool IsVideo => FileFormat.IsVideo(FileExtension);
|
||||
public bool IsVideo =>
|
||||
string.Equals(FileExtension, ".gifv", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(FileExtension, ".mp4", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(FileExtension, ".webm", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(FileExtension, ".mov", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public bool IsAudio => FileFormat.IsAudio(FileExtension);
|
||||
public bool IsAudio =>
|
||||
string.Equals(FileExtension, ".mp3", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(FileExtension, ".wav", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(FileExtension, ".ogg", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(FileExtension, ".flac", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(FileExtension, ".m4a", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public bool IsSpoiler => FileName.StartsWith("SPOILER_", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
@@ -14,32 +14,25 @@ public partial record Channel(
|
||||
ChannelCategory Category,
|
||||
string Name,
|
||||
int? Position,
|
||||
string? IconUrl,
|
||||
string? Topic,
|
||||
Snowflake? LastMessageId) : IHasId
|
||||
{
|
||||
public bool SupportsVoice => Kind is ChannelKind.GuildVoiceChat or ChannelKind.GuildStageVoice;
|
||||
public bool IsVoice => Kind is ChannelKind.GuildVoiceChat or ChannelKind.GuildStageVoice;
|
||||
}
|
||||
|
||||
public partial record Channel
|
||||
{
|
||||
private static ChannelCategory GetFallbackCategory(ChannelKind channelKind) => new(
|
||||
Snowflake.Zero,
|
||||
channelKind switch
|
||||
{
|
||||
ChannelKind.GuildTextChat => "Text",
|
||||
ChannelKind.DirectTextChat => "Private",
|
||||
ChannelKind.DirectGroupTextChat => "Group",
|
||||
ChannelKind.GuildNews => "News",
|
||||
_ => "Default"
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
public static Channel Parse(JsonElement json, ChannelCategory? category = null, int? positionHint = null)
|
||||
public static Channel Parse(JsonElement json, ChannelCategory? categoryHint = null, int? positionHint = 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 guildId =
|
||||
json.GetPropertyOrNull("guild_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse) ??
|
||||
Guild.DirectMessages.Id;
|
||||
|
||||
var category = categoryHint ?? ChannelCategory.CreateDefault(kind);
|
||||
|
||||
var name =
|
||||
// Guild channel
|
||||
@@ -49,7 +42,7 @@ public partial record Channel
|
||||
json.GetPropertyOrNull("recipients")?
|
||||
.EnumerateArrayOrNull()?
|
||||
.Select(User.Parse)
|
||||
.Select(u => u.Name)
|
||||
.Select(u => u.DisplayName)
|
||||
.Pipe(s => string.Join(", ", s)) ??
|
||||
|
||||
// Fallback
|
||||
@@ -59,6 +52,12 @@ public partial record Channel
|
||||
positionHint ??
|
||||
json.GetPropertyOrNull("position")?.GetInt32OrNull();
|
||||
|
||||
// Icons can only be set for group DM channels
|
||||
var iconUrl = json
|
||||
.GetPropertyOrNull("icon")?
|
||||
.GetNonWhiteSpaceStringOrNull()?
|
||||
.Pipe(h => ImageCdn.GetChannelIconUrl(id, h));
|
||||
|
||||
var topic = json.GetPropertyOrNull("topic")?.GetStringOrNull();
|
||||
|
||||
var lastMessageId = json
|
||||
@@ -69,10 +68,11 @@ public partial record Channel
|
||||
return new Channel(
|
||||
id,
|
||||
kind,
|
||||
guildId ?? Guild.DirectMessages.Id,
|
||||
category ?? GetFallbackCategory(kind),
|
||||
guildId,
|
||||
category,
|
||||
name,
|
||||
position,
|
||||
iconUrl,
|
||||
topic,
|
||||
lastMessageId
|
||||
);
|
||||
|
||||
@@ -7,7 +7,18 @@ namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
public record ChannelCategory(Snowflake Id, string Name, int? Position) : IHasId
|
||||
{
|
||||
public static ChannelCategory Unknown { get; } = new(Snowflake.Zero, "<unknown category>", 0);
|
||||
public static ChannelCategory CreateDefault(ChannelKind channelKind) => new(
|
||||
Snowflake.Zero,
|
||||
channelKind switch
|
||||
{
|
||||
ChannelKind.GuildTextChat => "Text",
|
||||
ChannelKind.DirectTextChat => "Private",
|
||||
ChannelKind.DirectGroupTextChat => "Group",
|
||||
ChannelKind.GuildNews => "News",
|
||||
_ => "Default"
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
public static ChannelCategory Parse(JsonElement json, int? positionHint = null)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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,
|
||||
@@ -16,4 +15,13 @@ public enum ChannelKind
|
||||
GuildStageVoice = 13,
|
||||
GuildDirectory = 14,
|
||||
GuildForum = 15
|
||||
}
|
||||
|
||||
public static class ChannelKindExtensions
|
||||
{
|
||||
public static bool IsDirect(this ChannelKind kind) =>
|
||||
kind is ChannelKind.DirectTextChat or ChannelKind.DirectGroupTextChat;
|
||||
|
||||
public static bool IsGuild(this ChannelKind kind) =>
|
||||
!kind.IsDirect();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#channel-object-example-thread-channel
|
||||
public record ChannelThread(
|
||||
Snowflake Id,
|
||||
ChannelKind Kind,
|
||||
Snowflake GuildId,
|
||||
Snowflake ParentId,
|
||||
string Name,
|
||||
bool IsActive,
|
||||
Snowflake? LastMessageId) : IHasId
|
||||
{
|
||||
public static ChannelThread Parse(JsonElement json)
|
||||
{
|
||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||
var kind = (ChannelKind)json.GetProperty("type").GetInt32();
|
||||
var guildId = json.GetProperty("guild_id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||
var parentId = json.GetProperty("parent_id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||
var name = json.GetProperty("name").GetNonWhiteSpaceString();
|
||||
|
||||
var isActive = !json
|
||||
.GetPropertyOrNull("thread_metadata")?
|
||||
.GetPropertyOrNull("archived")?
|
||||
.GetBooleanOrNull() ?? true;
|
||||
|
||||
var lastMessageId = json
|
||||
.GetPropertyOrNull("last_message_id")?
|
||||
.GetNonWhiteSpaceStringOrNull()?
|
||||
.Pipe(Snowflake.Parse);
|
||||
|
||||
return new ChannelThread(
|
||||
id,
|
||||
kind,
|
||||
guildId,
|
||||
parentId,
|
||||
name,
|
||||
isActive,
|
||||
lastMessageId
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Common;
|
||||
|
||||
public class IdBasedEqualityComparer : IEqualityComparer<IHasId>
|
||||
{
|
||||
public static IdBasedEqualityComparer Instance { get; } = new();
|
||||
|
||||
public bool Equals(IHasId? x, IHasId? y) => x?.Id == y?.Id;
|
||||
|
||||
public int GetHashCode(IHasId obj) => obj.Id.GetHashCode();
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Common;
|
||||
|
||||
// https://discord.com/developers/docs/reference#image-formatting
|
||||
public static class ImageCdn
|
||||
{
|
||||
// Standard emoji are rendered through Twemoji
|
||||
public static string GetStandardEmojiUrl(string emojiName)
|
||||
{
|
||||
var runes = emojiName.GetRunes().ToArray();
|
||||
|
||||
// Variant selector rune is skipped in Twemoji IDs,
|
||||
// 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);
|
||||
|
||||
var twemojiId = string.Join(
|
||||
"-",
|
||||
filteredRunes.Select(r => r.Value.ToString("x"))
|
||||
);
|
||||
|
||||
return $"https://cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/{twemojiId}.svg";
|
||||
}
|
||||
|
||||
public static string GetCustomEmojiUrl(Snowflake emojiId, bool isAnimated = false) =>
|
||||
isAnimated
|
||||
? $"https://cdn.discordapp.com/emojis/{emojiId}.gif"
|
||||
: $"https://cdn.discordapp.com/emojis/{emojiId}.png";
|
||||
|
||||
public static string GetGuildIconUrl(Snowflake guildId, string iconHash, int size = 512) =>
|
||||
iconHash.StartsWith("a_", StringComparison.Ordinal)
|
||||
? $"https://cdn.discordapp.com/icons/{guildId}/{iconHash}.gif?size={size}"
|
||||
: $"https://cdn.discordapp.com/icons/{guildId}/{iconHash}.png?size={size}";
|
||||
|
||||
public static string GetChannelIconUrl(Snowflake channelId, string iconHash, int size = 512) =>
|
||||
iconHash.StartsWith("a_", StringComparison.Ordinal)
|
||||
? $"https://cdn.discordapp.com/channel-icons/{channelId}/{iconHash}.gif?size={size}"
|
||||
: $"https://cdn.discordapp.com/channel-icons/{channelId}/{iconHash}.png?size={size}";
|
||||
|
||||
public static string GetUserAvatarUrl(Snowflake userId, string avatarHash, int size = 512) =>
|
||||
avatarHash.StartsWith("a_", StringComparison.Ordinal)
|
||||
? $"https://cdn.discordapp.com/avatars/{userId}/{avatarHash}.gif?size={size}"
|
||||
: $"https://cdn.discordapp.com/avatars/{userId}/{avatarHash}.png?size={size}";
|
||||
|
||||
public static string GetFallbackUserAvatarUrl(int discriminator) =>
|
||||
$"https://cdn.discordapp.com/embed/avatars/{discriminator % 5}.png";
|
||||
|
||||
public static string GetMemberAvatarUrl(Snowflake guildId, Snowflake userId, string avatarHash, int size = 512) =>
|
||||
avatarHash.StartsWith("a_", StringComparison.Ordinal)
|
||||
? $"https://cdn.discordapp.com/guilds/{guildId}/users/{userId}/avatars/{avatarHash}.gif?size={size}"
|
||||
: $"https://cdn.discordapp.com/guilds/{guildId}/users/{userId}/avatars/{avatarHash}.png?size={size}";
|
||||
|
||||
public static string GetStickerUrl(Snowflake stickerId, string format = "png") =>
|
||||
$"https://cdn.discordapp.com/stickers/{stickerId}.{format}";
|
||||
}
|
||||
@@ -23,6 +23,10 @@ public partial record Embed(
|
||||
EmbedVideo? Video,
|
||||
EmbedFooter? Footer)
|
||||
{
|
||||
// Embeds can only have one image according to the API model,
|
||||
// but the client can render multiple images in some cases.
|
||||
public EmbedImage? Image => Images.FirstOrDefault();
|
||||
|
||||
public SpotifyTrackEmbedProjection? TryGetSpotifyTrack() =>
|
||||
SpotifyTrackEmbedProjection.TryResolve(this);
|
||||
|
||||
@@ -41,7 +45,7 @@ public partial record Embed
|
||||
EmbedKind.Rich;
|
||||
|
||||
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
|
||||
var timestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffset();
|
||||
var timestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffsetOrNull();
|
||||
|
||||
var color = json
|
||||
.GetPropertyOrNull("color")?
|
||||
@@ -66,7 +70,7 @@ public partial record Embed
|
||||
// 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() ??
|
||||
json.GetPropertyOrNull("image")?.Pipe(EmbedImage.Parse).ToSingletonEnumerable().ToArray() ??
|
||||
Array.Empty<EmbedImage>();
|
||||
|
||||
var video = json.GetPropertyOrNull("video")?.Pipe(EmbedVideo.Parse);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
|
||||
public partial record YouTubeVideoEmbedProjection(string VideoId)
|
||||
{
|
||||
@@ -9,37 +7,6 @@ public partial record YouTubeVideoEmbedProjection(string 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)
|
||||
@@ -48,8 +15,8 @@ public partial record YouTubeVideoEmbedProjection
|
||||
if (string.IsNullOrWhiteSpace(embed.Url))
|
||||
return null;
|
||||
|
||||
var videoId = TryParseVideoId(embed.Url);
|
||||
if (string.IsNullOrWhiteSpace(videoId))
|
||||
var videoId = YoutubeExplode.Videos.VideoId.TryParse(embed.Url);
|
||||
if (videoId is null)
|
||||
return null;
|
||||
|
||||
return new YouTubeVideoEmbedProjection(videoId);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||
using DiscordChatExporter.Core.Utils;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
@@ -24,54 +24,32 @@ public partial record Emoji(
|
||||
|
||||
public partial record Emoji
|
||||
{
|
||||
private static string GetTwemojiId(string name)
|
||||
{
|
||||
var runes = name.GetRunes().ToArray();
|
||||
|
||||
// Variant selector rune is skipped in Twemoji names, except when the emoji also contains a zero-width joiner.
|
||||
// VS = 0xfe0f; ZWJ = 0x200d.
|
||||
var filteredRunes = runes.Any(r => r.Value == 0x200d)
|
||||
? runes
|
||||
: runes.Where(r => r.Value != 0xfe0f);
|
||||
|
||||
return string.Join(
|
||||
"-",
|
||||
filteredRunes.Select(r => r.Value.ToString("x"))
|
||||
);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// Custom emoji
|
||||
if (id is not null)
|
||||
return GetImageUrl(id.Value, isAnimated);
|
||||
return ImageCdn.GetCustomEmojiUrl(id.Value, isAnimated);
|
||||
|
||||
// Standard emoji
|
||||
if (!string.IsNullOrWhiteSpace(name))
|
||||
return GetImageUrl(name);
|
||||
return ImageCdn.GetStandardEmojiUrl(name);
|
||||
|
||||
// Either ID or name should be set
|
||||
throw new ApplicationException("Emoji has neither ID nor name set.");
|
||||
throw new InvalidOperationException("Either the emoji ID or name should be provided.");
|
||||
}
|
||||
|
||||
public static Emoji Parse(JsonElement json)
|
||||
{
|
||||
var id = json.GetPropertyOrNull("id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
|
||||
var name = json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull();
|
||||
|
||||
// Names may be missing on custom emoji within reactions
|
||||
var name = json.GetPropertyOrNull("name")?.GetNonWhiteSpaceStringOrNull() ?? "Unknown Emoji";
|
||||
|
||||
var isAnimated = json.GetPropertyOrNull("animated")?.GetBooleanOrNull() ?? false;
|
||||
var imageUrl = GetImageUrl(id, name, isAnimated);
|
||||
|
||||
return new Emoji(
|
||||
id,
|
||||
// Name may be missing if it's an emoji inside a reaction
|
||||
name ?? "<unknown emoji>",
|
||||
name,
|
||||
isAnimated,
|
||||
imageUrl
|
||||
);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
@@ -9,33 +8,24 @@ namespace DiscordChatExporter.Core.Discord.Data;
|
||||
// https://discord.com/developers/docs/resources/guild#guild-object
|
||||
public record Guild(Snowflake Id, string Name, string IconUrl) : IHasId
|
||||
{
|
||||
// Direct messages are encapsulated within a special pseudo-guild for consistency
|
||||
public static Guild DirectMessages { get; } = new(
|
||||
Snowflake.Zero,
|
||||
"Direct Messages",
|
||||
GetDefaultIconUrl()
|
||||
ImageCdn.GetFallbackUserAvatarUrl(0)
|
||||
);
|
||||
|
||||
private static string GetDefaultIconUrl() =>
|
||||
"https://cdn.discordapp.com/embed/avatars/0.png";
|
||||
|
||||
private static string GetIconUrl(Snowflake id, string iconHash)
|
||||
{
|
||||
var extension = iconHash.StartsWith("a_", StringComparison.Ordinal)
|
||||
? "gif"
|
||||
: "png";
|
||||
|
||||
return $"https://cdn.discordapp.com/icons/{id}/{iconHash}.{extension}";
|
||||
}
|
||||
|
||||
public static Guild Parse(JsonElement json)
|
||||
{
|
||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||
var name = json.GetProperty("name").GetNonNullString();
|
||||
|
||||
var iconHash = json.GetPropertyOrNull("icon")?.GetNonWhiteSpaceStringOrNull();
|
||||
var iconUrl = !string.IsNullOrWhiteSpace(iconHash)
|
||||
? GetIconUrl(id, iconHash)
|
||||
: GetDefaultIconUrl();
|
||||
var iconUrl =
|
||||
json
|
||||
.GetPropertyOrNull("icon")?
|
||||
.GetNonWhiteSpaceStringOrNull()?
|
||||
.Pipe(h => ImageCdn.GetGuildIconUrl(id, h)) ??
|
||||
ImageCdn.GetFallbackUserAvatarUrl(0);
|
||||
|
||||
return new Guild(id, name, iconUrl);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
// https://discord.com/developers/docs/interactions/receiving-and-responding#message-interaction-object
|
||||
public record Interaction(Snowflake Id, string Name, User User)
|
||||
{
|
||||
public static Interaction Parse(JsonElement json)
|
||||
{
|
||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||
var name = json.GetProperty("name").GetNonWhiteSpaceString();
|
||||
var user = json.GetProperty("user").Pipe(User.Parse);
|
||||
|
||||
return new Interaction(id, name, user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
// https://discord.com/developers/docs/resources/invite#invite-object
|
||||
public record Invite(
|
||||
string Code,
|
||||
Guild Guild,
|
||||
Channel? Channel)
|
||||
{
|
||||
public static string? TryGetCodeFromUrl(string url) =>
|
||||
Regex.Match(url, @"^https?://discord\.gg/(\w+)/?$").Groups[1].Value.NullIfWhiteSpace();
|
||||
|
||||
public static Invite Parse(JsonElement json)
|
||||
{
|
||||
var code = json.GetProperty("code").GetNonWhiteSpaceString();
|
||||
var guild = json.GetPropertyOrNull("guild")?.Pipe(Guild.Parse) ?? Guild.DirectMessages;
|
||||
var channel = json.GetPropertyOrNull("channel")?.Pipe(c => Channel.Parse(c));
|
||||
|
||||
return new Invite(code, guild, channel);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,8 @@ namespace DiscordChatExporter.Core.Discord.Data;
|
||||
// https://discord.com/developers/docs/resources/guild#guild-member-object
|
||||
public partial record Member(
|
||||
User User,
|
||||
string Nick,
|
||||
string? DisplayName,
|
||||
string? AvatarUrl,
|
||||
IReadOnlyList<Snowflake> RoleIds) : IHasId
|
||||
{
|
||||
public Snowflake Id => User.Id;
|
||||
@@ -19,16 +20,12 @@ public partial record Member(
|
||||
|
||||
public partial record Member
|
||||
{
|
||||
public static Member CreateForUser(User user) => new(
|
||||
user,
|
||||
user.Name,
|
||||
Array.Empty<Snowflake>()
|
||||
);
|
||||
public static Member CreateDefault(User user) => new(user, null, null, Array.Empty<Snowflake>());
|
||||
|
||||
public static Member Parse(JsonElement json)
|
||||
public static Member Parse(JsonElement json, Snowflake? guildId = null)
|
||||
{
|
||||
var user = json.GetProperty("user").Pipe(User.Parse);
|
||||
var nick = json.GetPropertyOrNull("nick")?.GetNonWhiteSpaceStringOrNull();
|
||||
var displayName = json.GetPropertyOrNull("nick")?.GetNonWhiteSpaceStringOrNull();
|
||||
|
||||
var roleIds = json
|
||||
.GetPropertyOrNull("roles")?
|
||||
@@ -37,9 +34,17 @@ public partial record Member
|
||||
.Select(Snowflake.Parse)
|
||||
.ToArray() ?? Array.Empty<Snowflake>();
|
||||
|
||||
var avatarUrl = guildId is not null
|
||||
? json
|
||||
.GetPropertyOrNull("avatar")?
|
||||
.GetNonWhiteSpaceStringOrNull()?
|
||||
.Pipe(h => ImageCdn.GetMemberAvatarUrl(guildId.Value, user.Id, h))
|
||||
: null;
|
||||
|
||||
return new Member(
|
||||
user,
|
||||
nick ?? user.Name,
|
||||
displayName,
|
||||
avatarUrl,
|
||||
roleIds
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,10 @@ using JsonExtensions.Reading;
|
||||
namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#message-object
|
||||
public record Message(
|
||||
public partial record Message(
|
||||
Snowflake Id,
|
||||
MessageKind Kind,
|
||||
MessageFlags Flags,
|
||||
User Author,
|
||||
DateTimeOffset Timestamp,
|
||||
DateTimeOffset? EditedTimestamp,
|
||||
@@ -25,14 +26,34 @@ public record Message(
|
||||
IReadOnlyList<Reaction> Reactions,
|
||||
IReadOnlyList<User> MentionedUsers,
|
||||
MessageReference? Reference,
|
||||
Message? ReferencedMessage) : IHasId
|
||||
Message? ReferencedMessage,
|
||||
Interaction? Interaction) : IHasId
|
||||
{
|
||||
public bool IsReplyLike => Kind == MessageKind.Reply || Interaction is not null;
|
||||
|
||||
public IEnumerable<User> GetReferencedUsers()
|
||||
{
|
||||
yield return Author;
|
||||
|
||||
foreach (var user in MentionedUsers)
|
||||
yield return user;
|
||||
|
||||
if (ReferencedMessage is not null)
|
||||
yield return ReferencedMessage.Author;
|
||||
|
||||
if (Interaction is not null)
|
||||
yield return Interaction.User;
|
||||
}
|
||||
}
|
||||
|
||||
public partial record Message
|
||||
{
|
||||
private static IReadOnlyList<Embed> NormalizeEmbeds(IReadOnlyList<Embed> embeds)
|
||||
{
|
||||
if (embeds.Count <= 1)
|
||||
return embeds;
|
||||
|
||||
// Discord API doesn't support embeds with multiple images, even though the Discord client does.
|
||||
// Discord API doesn't support embeds with multiple images, even though 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.
|
||||
@@ -87,30 +108,19 @@ public record Message(
|
||||
{
|
||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||
var kind = (MessageKind)json.GetProperty("type").GetInt32();
|
||||
var flags = (MessageFlags?)json.GetPropertyOrNull("flags")?.GetInt32OrNull() ?? MessageFlags.None;
|
||||
var author = json.GetProperty("author").Pipe(User.Parse);
|
||||
|
||||
var timestamp = json.GetProperty("timestamp").GetDateTimeOffset();
|
||||
var editedTimestamp = json.GetPropertyOrNull("edited_timestamp")?.GetDateTimeOffset();
|
||||
var editedTimestamp = json.GetPropertyOrNull("edited_timestamp")?.GetDateTimeOffsetOrNull();
|
||||
|
||||
var callEndedTimestamp = json
|
||||
.GetPropertyOrNull("call")?
|
||||
.GetPropertyOrNull("ended_timestamp")?
|
||||
.GetDateTimeOffset();
|
||||
.GetDateTimeOffsetOrNull();
|
||||
|
||||
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 content = json.GetPropertyOrNull("content")?.GetStringOrNull() ?? "";
|
||||
|
||||
var attachments =
|
||||
json.GetPropertyOrNull("attachments")?.EnumerateArrayOrNull()?.Select(Attachment.Parse).ToArray() ??
|
||||
@@ -135,10 +145,12 @@ public record Message(
|
||||
|
||||
var messageReference = json.GetPropertyOrNull("message_reference")?.Pipe(MessageReference.Parse);
|
||||
var referencedMessage = json.GetPropertyOrNull("referenced_message")?.Pipe(Parse);
|
||||
var interaction = json.GetPropertyOrNull("interaction")?.Pipe(Interaction.Parse);
|
||||
|
||||
return new Message(
|
||||
id,
|
||||
kind,
|
||||
flags,
|
||||
author,
|
||||
timestamp,
|
||||
editedTimestamp,
|
||||
@@ -151,7 +163,8 @@ public record Message(
|
||||
reactions,
|
||||
mentionedUsers,
|
||||
messageReference,
|
||||
referencedMessage
|
||||
referencedMessage,
|
||||
interaction
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#message-object-message-flags
|
||||
[Flags]
|
||||
public enum MessageFlags
|
||||
{
|
||||
None = 0,
|
||||
CrossPosted = 1,
|
||||
CrossPost = 2,
|
||||
SuppressEmbeds = 4,
|
||||
SourceMessageDeleted = 8,
|
||||
Urgent = 16,
|
||||
HasThread = 32,
|
||||
Ephemeral = 64,
|
||||
Loading = 128
|
||||
}
|
||||
@@ -17,5 +17,5 @@ public enum MessageKind
|
||||
|
||||
public static class MessageKindExtensions
|
||||
{
|
||||
public static bool IsSystemNotification(this MessageKind c) => (int)c is >= 1 and <= 18;
|
||||
public static bool IsSystemNotification(this MessageKind kind) => (int)kind is >= 1 and <= 18;
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public record Role(Snowflake Id, string Name, int Position, Color? Color) : IHas
|
||||
|
||||
var color = json
|
||||
.GetPropertyOrNull("color")?
|
||||
.GetInt32()
|
||||
.GetInt32OrNull()?
|
||||
.Pipe(System.Drawing.Color.FromArgb)
|
||||
.ResetAlpha()
|
||||
.NullIf(c => c.ToRgb() <= 0);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Text.Json;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
|
||||
@@ -7,18 +9,19 @@ namespace DiscordChatExporter.Core.Discord.Data;
|
||||
// https://discord.com/developers/docs/resources/sticker#sticker-resource
|
||||
public record Sticker(Snowflake Id, string Name, StickerFormat Format, string SourceUrl)
|
||||
{
|
||||
private static string GetSourceUrl(Snowflake id, StickerFormat format)
|
||||
{
|
||||
var extension = format == StickerFormat.Lottie ? "json" : "png";
|
||||
return $"https://discord.com/stickers/{id}.{extension}";
|
||||
}
|
||||
|
||||
public static Sticker Parse(JsonElement json)
|
||||
{
|
||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||
var name = json.GetProperty("name").GetNonNullString();
|
||||
var format = (StickerFormat)json.GetProperty("format_type").GetInt32();
|
||||
var sourceUrl = GetSourceUrl(id, format);
|
||||
|
||||
var sourceUrl = ImageCdn.GetStickerUrl(id, format switch
|
||||
{
|
||||
StickerFormat.Png => "png",
|
||||
StickerFormat.Apng => "png",
|
||||
StickerFormat.Lottie => "json",
|
||||
_ => throw new InvalidOperationException($"Unknown sticker format '{format}'.")
|
||||
});
|
||||
|
||||
return new Sticker(id, name, format, sourceUrl);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
public enum StickerFormat
|
||||
{
|
||||
Png = 1,
|
||||
PngAnimated = 2,
|
||||
Apng = 2,
|
||||
Lottie = 3
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using JsonExtensions.Reading;
|
||||
@@ -10,41 +9,49 @@ namespace DiscordChatExporter.Core.Discord.Data;
|
||||
public partial record User(
|
||||
Snowflake Id,
|
||||
bool IsBot,
|
||||
int Discriminator,
|
||||
// Remove after Discord migrates all accounts to the new system.
|
||||
// With that, also remove the DiscriminatorFormatted and FullName properties.
|
||||
// Replace existing calls to FullName with Name (not DisplayName).
|
||||
int? Discriminator,
|
||||
string Name,
|
||||
string DisplayName,
|
||||
string AvatarUrl) : IHasId
|
||||
{
|
||||
public string DiscriminatorFormatted => $"{Discriminator:0000}";
|
||||
public string DiscriminatorFormatted => Discriminator is not null
|
||||
? $"{Discriminator:0000}"
|
||||
: "0000";
|
||||
|
||||
public string FullName => $"{Name}#{DiscriminatorFormatted}";
|
||||
// This effectively represents the user's true identity.
|
||||
// In the old system, this is formed from the username and discriminator.
|
||||
// In the new system, the username is already the user's unique identifier.
|
||||
public string FullName => Discriminator is not null
|
||||
? $"{Name}#{DiscriminatorFormatted}"
|
||||
: Name;
|
||||
}
|
||||
|
||||
public partial record User
|
||||
{
|
||||
private static string GetDefaultAvatarUrl(int discriminator) =>
|
||||
$"https://cdn.discordapp.com/embed/avatars/{discriminator % 5}.png";
|
||||
|
||||
private static string GetAvatarUrl(Snowflake id, string avatarHash)
|
||||
{
|
||||
var extension = avatarHash.StartsWith("a_", StringComparison.Ordinal)
|
||||
? "gif"
|
||||
: "png";
|
||||
|
||||
return $"https://cdn.discordapp.com/avatars/{id}/{avatarHash}.{extension}?size=512";
|
||||
}
|
||||
|
||||
public static User Parse(JsonElement json)
|
||||
{
|
||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||
var isBot = json.GetPropertyOrNull("bot")?.GetBooleanOrNull() ?? false;
|
||||
var discriminator = json.GetProperty("discriminator").GetNonWhiteSpaceString().Pipe(int.Parse);
|
||||
|
||||
var discriminator = json
|
||||
.GetPropertyOrNull("discriminator")?
|
||||
.GetNonWhiteSpaceStringOrNull()?
|
||||
.Pipe(int.Parse)
|
||||
.NullIfDefault();
|
||||
|
||||
var name = json.GetProperty("username").GetNonNullString();
|
||||
var displayName = json.GetPropertyOrNull("global_name")?.GetNonWhiteSpaceStringOrNull() ?? name;
|
||||
|
||||
var avatarHash = json.GetPropertyOrNull("avatar")?.GetNonWhiteSpaceStringOrNull();
|
||||
var avatarUrl = !string.IsNullOrWhiteSpace(avatarHash)
|
||||
? GetAvatarUrl(id, avatarHash)
|
||||
: GetDefaultAvatarUrl(discriminator);
|
||||
var avatarUrl =
|
||||
json
|
||||
.GetPropertyOrNull("avatar")?
|
||||
.GetNonWhiteSpaceStringOrNull()?
|
||||
.Pipe(h => ImageCdn.GetUserAvatarUrl(id, h)) ??
|
||||
ImageCdn.GetFallbackUserAvatarUrl(discriminator ?? 0);
|
||||
|
||||
return new User(id, isBot, discriminator, name, avatarUrl);
|
||||
return new User(id, isBot, discriminator, name, displayName, avatarUrl);
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ namespace DiscordChatExporter.Core.Discord;
|
||||
public class DiscordClient
|
||||
{
|
||||
private readonly string _token;
|
||||
private readonly Uri _baseUri = new("https://discord.com/api/v9/", UriKind.Absolute);
|
||||
private readonly Uri _baseUri = new("https://discord.com/api/v10/", UriKind.Absolute);
|
||||
|
||||
private TokenKind? _resolvedTokenKind;
|
||||
|
||||
@@ -66,7 +66,8 @@ public class DiscordClient
|
||||
var resetAfterDelay = response
|
||||
.Headers
|
||||
.TryGetValue("X-RateLimit-Reset-After")?
|
||||
.Pipe(s => TimeSpan.FromSeconds(double.Parse(s, CultureInfo.InvariantCulture)));
|
||||
.Pipe(s => double.Parse(s, CultureInfo.InvariantCulture))
|
||||
.Pipe(TimeSpan.FromSeconds);
|
||||
|
||||
if (remainingRequestCount <= 0 && resetAfterDelay is not null)
|
||||
{
|
||||
@@ -143,19 +144,25 @@ public class DiscordClient
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var response = await GetResponseAsync(url, cancellationToken);
|
||||
|
||||
return response.IsSuccessStatusCode
|
||||
? await response.Content.ReadAsJsonAsync(cancellationToken)
|
||||
: null;
|
||||
}
|
||||
|
||||
public async ValueTask<User?> TryGetUserAsync(
|
||||
Snowflake userId,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var response = await TryGetJsonResponseAsync($"users/{userId}", cancellationToken);
|
||||
return response?.Pipe(User.Parse);
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<Guild> GetUserGuildsAsync(
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
{
|
||||
yield return Guild.DirectMessages;
|
||||
|
||||
var currentAfter = Snowflake.Zero;
|
||||
|
||||
while (true)
|
||||
{
|
||||
var url = new UrlBuilder()
|
||||
@@ -167,8 +174,9 @@ public class DiscordClient
|
||||
var response = await GetJsonResponseAsync(url, cancellationToken);
|
||||
|
||||
var isEmpty = true;
|
||||
foreach (var guild in response.EnumerateArray().Select(Guild.Parse))
|
||||
foreach (var guildJson in response.EnumerateArray())
|
||||
{
|
||||
var guild = Guild.Parse(guildJson);
|
||||
yield return guild;
|
||||
|
||||
currentAfter = guild.Id;
|
||||
@@ -205,34 +213,105 @@ public class DiscordClient
|
||||
{
|
||||
var response = await GetJsonResponseAsync($"guilds/{guildId}/channels", cancellationToken);
|
||||
|
||||
var responseOrdered = response
|
||||
var channelsJson = response
|
||||
.EnumerateArray()
|
||||
.OrderBy(j => j.GetProperty("position").GetInt32())
|
||||
.ThenBy(j => j.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse))
|
||||
.ToArray();
|
||||
|
||||
var categories = responseOrdered
|
||||
.Where(j => j.GetProperty("type").GetInt32() == (int) ChannelKind.GuildCategory)
|
||||
var categories = channelsJson
|
||||
.Where(j => j.GetProperty("type").GetInt32() == (int)ChannelKind.GuildCategory)
|
||||
.Select((j, index) => ChannelCategory.Parse(j, index + 1))
|
||||
.ToDictionary(j => j.Id.ToString(), StringComparer.Ordinal);
|
||||
|
||||
// Discord positions are not deterministic, so we need to normalize them
|
||||
// because the user may refer to the channel position via file name template.
|
||||
// Discord channel positions are relative, so we need to normalize them
|
||||
// so that the user may refer to them more easily in file name templates.
|
||||
var position = 0;
|
||||
|
||||
foreach (var channelJson in responseOrdered)
|
||||
foreach (var channelJson in channelsJson)
|
||||
{
|
||||
var parentId = channelJson.GetPropertyOrNull("parent_id")?.GetNonWhiteSpaceStringOrNull();
|
||||
var parentId = channelJson
|
||||
.GetPropertyOrNull("parent_id")?
|
||||
.GetNonWhiteSpaceStringOrNull();
|
||||
|
||||
var category = !string.IsNullOrWhiteSpace(parentId)
|
||||
? categories.GetValueOrDefault(parentId)
|
||||
: null;
|
||||
|
||||
var channel = Channel.Parse(channelJson, category, position);
|
||||
|
||||
yield return Channel.Parse(channelJson, category, position);
|
||||
position++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
yield return channel;
|
||||
public async IAsyncEnumerable<ChannelThread> GetGuildThreadsAsync(
|
||||
Snowflake guildId,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
{
|
||||
var tokenKind = _resolvedTokenKind ??= await GetTokenKindAsync(cancellationToken);
|
||||
var channels = await GetGuildChannelsAsync(guildId, cancellationToken);
|
||||
|
||||
// User accounts can only fetch threads using the search endpoint
|
||||
if (tokenKind == TokenKind.User)
|
||||
{
|
||||
foreach (var channel in channels)
|
||||
{
|
||||
var currentOffset = 0;
|
||||
while (true)
|
||||
{
|
||||
var url = new UrlBuilder()
|
||||
.SetPath($"channels/{channel.Id}/threads/search")
|
||||
.SetQueryParameter("offset", currentOffset.ToString())
|
||||
.Build();
|
||||
|
||||
var response = await TryGetJsonResponseAsync(url, cancellationToken);
|
||||
if (response is null)
|
||||
break;
|
||||
|
||||
foreach (var threadJson in response.Value.GetProperty("threads").EnumerateArray())
|
||||
{
|
||||
yield return ChannelThread.Parse(threadJson);
|
||||
currentOffset++;
|
||||
}
|
||||
|
||||
if (!response.Value.GetProperty("has_more").GetBoolean())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Bot accounts can only fetch threads using the threads endpoint
|
||||
else
|
||||
{
|
||||
// Active threads
|
||||
{
|
||||
var response = await GetJsonResponseAsync($"guilds/{guildId}/threads/active", cancellationToken);
|
||||
foreach (var threadJson in response.GetProperty("threads").EnumerateArray())
|
||||
yield return ChannelThread.Parse(threadJson);
|
||||
}
|
||||
|
||||
foreach (var channel in channels)
|
||||
{
|
||||
// Public archived threads
|
||||
{
|
||||
var response = await GetJsonResponseAsync(
|
||||
$"channels/{channel.Id}/threads/archived/public",
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
foreach (var threadJson in response.GetProperty("threads").EnumerateArray())
|
||||
yield return ChannelThread.Parse(threadJson);
|
||||
}
|
||||
|
||||
// Private archived threads
|
||||
{
|
||||
var response = await GetJsonResponseAsync(
|
||||
$"channels/{channel.Id}/threads/archived/private",
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
foreach (var threadJson in response.GetProperty("threads").EnumerateArray())
|
||||
yield return ChannelThread.Parse(threadJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,21 +324,28 @@ public class DiscordClient
|
||||
yield break;
|
||||
|
||||
var response = await GetJsonResponseAsync($"guilds/{guildId}/roles", cancellationToken);
|
||||
|
||||
foreach (var roleJson in response.EnumerateArray())
|
||||
yield return Role.Parse(roleJson);
|
||||
}
|
||||
|
||||
public async ValueTask<Member> GetGuildMemberAsync(
|
||||
public async ValueTask<Member?> TryGetGuildMemberAsync(
|
||||
Snowflake guildId,
|
||||
User user,
|
||||
Snowflake memberId,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (guildId == Guild.DirectMessages.Id)
|
||||
return Member.CreateForUser(user);
|
||||
return null;
|
||||
|
||||
var response = await TryGetJsonResponseAsync($"guilds/{guildId}/members/{user.Id}", cancellationToken);
|
||||
return response?.Pipe(Member.Parse) ?? Member.CreateForUser(user);
|
||||
var response = await TryGetJsonResponseAsync($"guilds/{guildId}/members/{memberId}", cancellationToken);
|
||||
return response?.Pipe(j => Member.Parse(j, guildId));
|
||||
}
|
||||
|
||||
public async ValueTask<Invite?> TryGetGuildInviteAsync(
|
||||
string code,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var response = await TryGetJsonResponseAsync($"invites/{code}", cancellationToken);
|
||||
return response?.Pipe(Invite.Parse);
|
||||
}
|
||||
|
||||
public async ValueTask<ChannelCategory> GetChannelCategoryAsync(
|
||||
@@ -271,11 +357,11 @@ public class DiscordClient
|
||||
var response = await GetJsonResponseAsync($"channels/{channelId}", cancellationToken);
|
||||
return ChannelCategory.Parse(response);
|
||||
}
|
||||
// In some cases, the Discord API returns an empty body when requesting channel category.
|
||||
// Instead, we use an empty channel category as a fallback.
|
||||
// In some cases, Discord API returns an empty body when requesting a channel.
|
||||
// Use an empty channel category as fallback for these cases.
|
||||
catch (DiscordChatExporterException)
|
||||
{
|
||||
return ChannelCategory.Unknown;
|
||||
return new ChannelCategory(channelId, "Unknown Category", 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +371,10 @@ public class DiscordClient
|
||||
{
|
||||
var response = await GetJsonResponseAsync($"channels/{channelId}", cancellationToken);
|
||||
|
||||
var parentId = response.GetPropertyOrNull("parent_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse);
|
||||
var parentId = response
|
||||
.GetPropertyOrNull("parent_id")?
|
||||
.GetNonWhiteSpaceStringOrNull()?
|
||||
.Pipe(Snowflake.Parse);
|
||||
|
||||
var category = parentId is not null
|
||||
? await GetChannelCategoryAsync(parentId.Value, cancellationToken)
|
||||
@@ -316,18 +405,18 @@ public class DiscordClient
|
||||
IProgress<Percentage>? progress = null,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
{
|
||||
// Get the last message in the specified range.
|
||||
// This snapshots the boundaries, which means that messages posted after the export started
|
||||
// will not appear in the output.
|
||||
// Additionally, it provides the date of the last message, which is used to calculate progress.
|
||||
// Get the last message in the specified range, so we can later calculate the
|
||||
// progress based on the difference between message timestamps.
|
||||
// This also snapshots the boundaries, which means that messages posted after
|
||||
// the export started will not appear in the output.
|
||||
var lastMessage = await TryGetLastMessageAsync(channelId, before, cancellationToken);
|
||||
if (lastMessage is null || lastMessage.Timestamp < after?.ToDate())
|
||||
yield break;
|
||||
|
||||
// Keep track of first message in range in order to calculate progress
|
||||
// Keep track of the first message in range in order to calculate the progress
|
||||
var firstMessage = default(Message);
|
||||
var currentAfter = after ?? Snowflake.Zero;
|
||||
|
||||
var currentAfter = after ?? Snowflake.Zero;
|
||||
while (true)
|
||||
{
|
||||
var url = new UrlBuilder()
|
||||
@@ -341,7 +430,8 @@ public class DiscordClient
|
||||
var messages = response
|
||||
.EnumerateArray()
|
||||
.Select(Message.Parse)
|
||||
.Reverse() // reverse because messages appear newest first
|
||||
// Messages are returned from newest to oldest, so we need to reverse them
|
||||
.Reverse()
|
||||
.ToArray();
|
||||
|
||||
// Break if there are no messages (can happen if messages are deleted during execution)
|
||||
@@ -352,11 +442,11 @@ public class DiscordClient
|
||||
{
|
||||
firstMessage ??= message;
|
||||
|
||||
// Ensure messages are in range (take into account that last message could have been deleted)
|
||||
// Ensure that the messages are in range
|
||||
if (message.Timestamp > lastMessage.Timestamp)
|
||||
yield break;
|
||||
|
||||
// Report progress based on the duration of exported messages divided by total
|
||||
// Report progress based on timestamps
|
||||
if (progress is not null)
|
||||
{
|
||||
var exportedDuration = (message.Timestamp - firstMessage.Timestamp).Duration();
|
||||
@@ -364,7 +454,7 @@ public class DiscordClient
|
||||
|
||||
progress.Report(Percentage.FromFraction(
|
||||
// Avoid division by zero if all messages have the exact same timestamp
|
||||
// (which may be the case if there's only one message in the channel)
|
||||
// (which happens when there's only one message in the channel)
|
||||
totalDuration > TimeSpan.Zero
|
||||
? exportedDuration / totalDuration
|
||||
: 1
|
||||
|
||||
@@ -18,8 +18,8 @@ public partial record struct Snowflake
|
||||
{
|
||||
public static Snowflake Zero { get; } = new(0);
|
||||
|
||||
public static Snowflake FromDate(DateTimeOffset date) => new(
|
||||
((ulong)date.ToUnixTimeMilliseconds() - 1420070400000UL) << 22
|
||||
public static Snowflake FromDate(DateTimeOffset instant) => new(
|
||||
((ulong)instant.ToUnixTimeMilliseconds() - 1420070400000UL) << 22
|
||||
);
|
||||
|
||||
public static Snowflake? TryParse(string? str, IFormatProvider? formatProvider = null)
|
||||
@@ -29,15 +29,11 @@ public partial record struct Snowflake
|
||||
|
||||
// As number
|
||||
if (ulong.TryParse(str, NumberStyles.None, formatProvider, out var value))
|
||||
{
|
||||
return new Snowflake(value);
|
||||
}
|
||||
|
||||
// As date
|
||||
if (DateTimeOffset.TryParse(str, formatProvider, DateTimeStyles.None, out var date))
|
||||
{
|
||||
return FromDate(date);
|
||||
}
|
||||
if (DateTimeOffset.TryParse(str, formatProvider, DateTimeStyles.None, out var instant))
|
||||
return FromDate(instant);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -59,4 +55,8 @@ public partial record struct Snowflake : IComparable<Snowflake>, IComparable
|
||||
|
||||
return Value.CompareTo(other.Value);
|
||||
}
|
||||
|
||||
public static bool operator >(Snowflake left, Snowflake right) => left.CompareTo(right) > 0;
|
||||
|
||||
public static bool operator <(Snowflake left, Snowflake right) => left.CompareTo(right) < 0;
|
||||
}
|
||||
@@ -1,20 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Gress" Version="2.0.1" />
|
||||
<PackageReference Include="AsyncKeyedLock" Version="6.2.1" />
|
||||
<PackageReference Include="Gress" Version="2.1.1" />
|
||||
<PackageReference Include="JsonExtensions" Version="1.2.0" />
|
||||
<PackageReference Include="Polly" Version="7.2.3" />
|
||||
<PackageReference Include="RazorBlade" Version="0.4.2" />
|
||||
<PackageReference Include="RazorBlade" Version="0.4.3" />
|
||||
<PackageReference Include="Superpower" Version="3.0.0" />
|
||||
<PackageReference Include="WebMarkupMin.Core" Version="2.13.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<RazorBlade Include="Exporting\Writers\Html\*.cshtml" />
|
||||
<PackageReference Include="WebMarkupMin.Core" Version="2.14.0" />
|
||||
<PackageReference Include="YoutubeExplode" Version="6.2.15" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -40,5 +40,5 @@ Failed to perform an HTTP request.
|
||||
new($"Requested resource ({resourceId}) does not exist.");
|
||||
|
||||
internal static DiscordChatExporterException ChannelIsEmpty() =>
|
||||
new("No messages found for the specified period.");
|
||||
new("Channel is empty or contains no messages for the specified period.");
|
||||
}
|
||||
@@ -1,13 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Discord.Data;
|
||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||
using DiscordChatExporter.Core.Exceptions;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using Gress;
|
||||
|
||||
namespace DiscordChatExporter.Core.Exporting;
|
||||
@@ -23,24 +18,20 @@ public class ChannelExporter
|
||||
IProgress<Percentage>? progress = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
// Build context
|
||||
var contextMembers = new HashSet<Member>(IdBasedEqualityComparer.Instance);
|
||||
var contextChannels = await _discord.GetGuildChannelsAsync(request.Guild.Id, cancellationToken);
|
||||
var contextRoles = await _discord.GetGuildRolesAsync(request.Guild.Id, cancellationToken);
|
||||
// Check if the channel is empty
|
||||
if (request.Channel.LastMessageId is null)
|
||||
throw DiscordChatExporterException.ChannelIsEmpty();
|
||||
|
||||
var context = new ExportContext(
|
||||
request,
|
||||
contextMembers,
|
||||
contextChannels,
|
||||
contextRoles
|
||||
);
|
||||
// Check if the 'after' boundary is valid
|
||||
if (request.After is not null && request.Channel.LastMessageId < request.After)
|
||||
throw DiscordChatExporterException.ChannelIsEmpty();
|
||||
|
||||
// Build context
|
||||
var context = new ExportContext(_discord, request);
|
||||
await context.PopulateChannelsAndRolesAsync(cancellationToken);
|
||||
|
||||
// Export messages
|
||||
await using var messageExporter = new MessageExporter(context);
|
||||
|
||||
var exportedAnything = false;
|
||||
var encounteredUsers = new HashSet<User>(IdBasedEqualityComparer.Instance);
|
||||
|
||||
await foreach (var message in _discord.GetMessagesAsync(
|
||||
request.Channel.Id,
|
||||
request.After,
|
||||
@@ -48,34 +39,17 @@ public class ChannelExporter
|
||||
progress,
|
||||
cancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// Skips any messages that fail to pass the supplied filter
|
||||
if (!request.MessageFilter.IsMatch(message))
|
||||
continue;
|
||||
|
||||
// Resolve members for referenced users
|
||||
foreach (var referencedUser in message.MentionedUsers.Prepend(message.Author))
|
||||
{
|
||||
if (!encounteredUsers.Add(referencedUser))
|
||||
continue;
|
||||
foreach (var user in message.GetReferencedUsers())
|
||||
await context.PopulateMemberAsync(user, cancellationToken);
|
||||
|
||||
var member = await _discord.GetGuildMemberAsync(
|
||||
request.Guild.Id,
|
||||
referencedUser,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
contextMembers.Add(member);
|
||||
}
|
||||
|
||||
// Export message
|
||||
await messageExporter.ExportMessageAsync(message, cancellationToken);
|
||||
exportedAnything = true;
|
||||
// Export the message
|
||||
if (request.MessageFilter.IsMatch(message))
|
||||
await messageExporter.ExportMessageAsync(message, cancellationToken);
|
||||
}
|
||||
|
||||
// Throw if no messages were exported
|
||||
if (!exportedAnything)
|
||||
if (messageExporter.MessagesExported <= 0)
|
||||
throw DiscordChatExporterException.ChannelIsEmpty();
|
||||
}
|
||||
}
|
||||
+18
-5
@@ -4,10 +4,9 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Discord.Data;
|
||||
using DiscordChatExporter.Core.Exporting.Writers.MarkdownVisitors;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Core.Exporting.Writers;
|
||||
namespace DiscordChatExporter.Core.Exporting;
|
||||
|
||||
internal partial class CsvMessageWriter : MessageWriter
|
||||
{
|
||||
@@ -19,10 +18,12 @@ internal partial class CsvMessageWriter : MessageWriter
|
||||
_writer = new StreamWriter(stream);
|
||||
}
|
||||
|
||||
private ValueTask<string> FormatMarkdownAsync(
|
||||
private async ValueTask<string> FormatMarkdownAsync(
|
||||
string markdown,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
PlainTextMarkdownVisitor.FormatAsync(Context, markdown, cancellationToken);
|
||||
Context.Request.ShouldFormatMarkdown
|
||||
? await PlainTextMarkdownVisitor.FormatAsync(Context, markdown, cancellationToken)
|
||||
: markdown;
|
||||
|
||||
public override async ValueTask WritePreambleAsync(CancellationToken cancellationToken = default) =>
|
||||
await _writer.WriteLineAsync("AuthorID,Author,Date,Content,Attachments,Reactions");
|
||||
@@ -86,7 +87,19 @@ internal partial class CsvMessageWriter : MessageWriter
|
||||
await _writer.WriteAsync(',');
|
||||
|
||||
// Message content
|
||||
await _writer.WriteAsync(CsvEncode(await FormatMarkdownAsync(message.Content, cancellationToken)));
|
||||
if (message.Kind.IsSystemNotification())
|
||||
{
|
||||
await _writer.WriteAsync(CsvEncode(
|
||||
message.GetFallbackContent()
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
await _writer.WriteAsync(CsvEncode(
|
||||
await FormatMarkdownAsync(message.Content, cancellationToken)
|
||||
));
|
||||
}
|
||||
|
||||
await _writer.WriteAsync(',');
|
||||
|
||||
// Attachments
|
||||
@@ -7,6 +7,7 @@ using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsyncKeyedLock;
|
||||
using DiscordChatExporter.Core.Utils;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
|
||||
@@ -14,6 +15,12 @@ namespace DiscordChatExporter.Core.Exporting;
|
||||
|
||||
internal partial class ExportAssetDownloader
|
||||
{
|
||||
private static readonly AsyncKeyedLocker<string> Locker = new(o =>
|
||||
{
|
||||
o.PoolSize = 20;
|
||||
o.PoolInitialFill = 1;
|
||||
});
|
||||
|
||||
private readonly string _workingDirPath;
|
||||
private readonly bool _reuse;
|
||||
|
||||
@@ -28,15 +35,18 @@ internal partial class ExportAssetDownloader
|
||||
|
||||
public async ValueTask<string> DownloadAsync(string url, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_pathCache.TryGetValue(url, out var cachedFilePath))
|
||||
return cachedFilePath;
|
||||
|
||||
var fileName = GetFileNameFromUrl(url);
|
||||
var filePath = Path.Combine(_workingDirPath, fileName);
|
||||
|
||||
// Reuse existing files if we're allowed to
|
||||
if (!_reuse || !File.Exists(filePath))
|
||||
using (await Locker.LockAsync(filePath, cancellationToken))
|
||||
{
|
||||
if (_pathCache.TryGetValue(url, out var cachedFilePath))
|
||||
return cachedFilePath;
|
||||
|
||||
// Reuse existing files if we're allowed to
|
||||
if (_reuse && File.Exists(filePath))
|
||||
return _pathCache[url] = filePath;
|
||||
|
||||
Directory.CreateDirectory(_workingDirPath);
|
||||
|
||||
await Http.ResiliencePolicy.ExecuteAsync(async () =>
|
||||
@@ -50,9 +60,9 @@ internal partial class ExportAssetDownloader
|
||||
try
|
||||
{
|
||||
var lastModified = response.Content.Headers.TryGetValue("Last-Modified")?.Pipe(s =>
|
||||
DateTimeOffset.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None, out var date)
|
||||
? date
|
||||
: (DateTimeOffset?) null
|
||||
DateTimeOffset.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None, out var instant)
|
||||
? instant
|
||||
: (DateTimeOffset?)null
|
||||
);
|
||||
|
||||
if (lastModified is not null)
|
||||
@@ -65,32 +75,29 @@ internal partial class ExportAssetDownloader
|
||||
catch
|
||||
{
|
||||
// This can apparently fail for some reason.
|
||||
// Updating the file date is not a critical task, so we'll just ignore exceptions thrown here.
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/585
|
||||
// Updating file dates is not a critical task, so we'll just
|
||||
// ignore exceptions thrown here.
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return _pathCache[url] = filePath;
|
||||
return _pathCache[url] = filePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal partial class ExportAssetDownloader
|
||||
{
|
||||
private static string GetUrlHash(string url)
|
||||
{
|
||||
using var hash = SHA256.Create();
|
||||
|
||||
var data = hash.ComputeHash(Encoding.UTF8.GetBytes(url));
|
||||
return data.ToHex().Truncate(5); // 5 chars ought to be enough for anybody
|
||||
}
|
||||
private static string GetUrlHash(string url) => SHA256
|
||||
.HashData(Encoding.UTF8.GetBytes(url))
|
||||
.ToHex()
|
||||
// 5 chars ought to be enough for anybody
|
||||
.Truncate(5);
|
||||
|
||||
private static string GetFileNameFromUrl(string url)
|
||||
{
|
||||
var urlHash = GetUrlHash(url);
|
||||
|
||||
// Try to extract file name from URL
|
||||
// Try to extract the file name from URL
|
||||
var fileName = Regex.Match(url, @".+/([^?]*)").Groups[1].Value;
|
||||
|
||||
// If it's not there, just use the URL hash as the file name
|
||||
@@ -102,7 +109,7 @@ internal partial class ExportAssetDownloader
|
||||
var fileExtension = Path.GetExtension(fileName);
|
||||
|
||||
// Probably not a file extension, just a dot in a long file name
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/708
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/pull/812
|
||||
if (fileExtension.Length > 41)
|
||||
{
|
||||
fileNameWithoutExtension = fileName;
|
||||
|
||||
@@ -14,49 +14,92 @@ namespace DiscordChatExporter.Core.Exporting;
|
||||
|
||||
internal class ExportContext
|
||||
{
|
||||
private readonly Dictionary<Snowflake, Member?> _members = new();
|
||||
private readonly Dictionary<Snowflake, Channel> _channels = new();
|
||||
private readonly Dictionary<Snowflake, Role> _roles = new();
|
||||
private readonly ExportAssetDownloader _assetDownloader;
|
||||
|
||||
public DiscordClient Discord { get; }
|
||||
|
||||
public ExportRequest Request { get; }
|
||||
|
||||
public IReadOnlyCollection<Member> Members { get; }
|
||||
|
||||
public IReadOnlyCollection<Channel> Channels { get; }
|
||||
|
||||
public IReadOnlyCollection<Role> Roles { get; }
|
||||
|
||||
public ExportContext(
|
||||
ExportRequest request,
|
||||
IReadOnlyCollection<Member> members,
|
||||
IReadOnlyCollection<Channel> channels,
|
||||
IReadOnlyCollection<Role> roles)
|
||||
public ExportContext(DiscordClient discord,
|
||||
ExportRequest request)
|
||||
{
|
||||
Discord = discord;
|
||||
Request = request;
|
||||
Members = members;
|
||||
Channels = channels;
|
||||
Roles = roles;
|
||||
|
||||
_assetDownloader = new ExportAssetDownloader(request.OutputAssetsDirPath, request.ShouldReuseAssets);
|
||||
_assetDownloader = new ExportAssetDownloader(
|
||||
request.AssetsDirPath,
|
||||
request.ShouldReuseAssets
|
||||
);
|
||||
}
|
||||
|
||||
public string FormatDate(DateTimeOffset date) => Request.DateFormat switch
|
||||
public async ValueTask PopulateChannelsAndRolesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
"unix" => date.ToUnixTimeSeconds().ToString(),
|
||||
"unixms" => date.ToUnixTimeMilliseconds().ToString(),
|
||||
var format => date.ToLocalString(format)
|
||||
await foreach (var channel in Discord.GetGuildChannelsAsync(Request.Guild.Id, cancellationToken))
|
||||
_channels[channel.Id] = channel;
|
||||
|
||||
await foreach (var role in Discord.GetGuildRolesAsync(Request.Guild.Id, cancellationToken))
|
||||
_roles[role.Id] = role;
|
||||
}
|
||||
|
||||
// Because members cannot be pulled in bulk, we need to populate them on demand
|
||||
private async ValueTask PopulateMemberAsync(
|
||||
Snowflake id,
|
||||
User? fallbackUser,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_members.ContainsKey(id))
|
||||
return;
|
||||
|
||||
var member = await Discord.TryGetGuildMemberAsync(Request.Guild.Id, id, cancellationToken);
|
||||
|
||||
// User may have left the guild since they were mentioned.
|
||||
// Create a dummy member object based on the user info.
|
||||
if (member is null)
|
||||
{
|
||||
var user = fallbackUser ?? await Discord.TryGetUserAsync(id, cancellationToken);
|
||||
|
||||
// User may have been deleted since they were mentioned
|
||||
if (user is not null)
|
||||
member = Member.CreateDefault(user);
|
||||
}
|
||||
|
||||
// Store the result even if it's null, to avoid re-fetching non-existing members
|
||||
_members[id] = member;
|
||||
}
|
||||
|
||||
public async ValueTask PopulateMemberAsync(Snowflake id, CancellationToken cancellationToken = default) =>
|
||||
await PopulateMemberAsync(id, null, cancellationToken);
|
||||
|
||||
public async ValueTask PopulateMemberAsync(User user, CancellationToken cancellationToken = default) =>
|
||||
await PopulateMemberAsync(user.Id, user, cancellationToken);
|
||||
|
||||
public string FormatDate(DateTimeOffset instant) => Request.DateFormat switch
|
||||
{
|
||||
"unix" => instant.ToUnixTimeSeconds().ToString(),
|
||||
"unixms" => instant.ToUnixTimeMilliseconds().ToString(),
|
||||
var format => instant.ToLocalString(format)
|
||||
};
|
||||
|
||||
public Member? TryGetMember(Snowflake id) => Members.FirstOrDefault(m => m.Id == id);
|
||||
public Member? TryGetMember(Snowflake id) => _members.GetValueOrDefault(id);
|
||||
|
||||
public Channel? TryGetChannel(Snowflake id) => Channels.FirstOrDefault(c => c.Id == id);
|
||||
public Channel? TryGetChannel(Snowflake id) => _channels.GetValueOrDefault(id);
|
||||
|
||||
public Role? TryGetRole(Snowflake id) => Roles.FirstOrDefault(r => r.Id == id);
|
||||
public Role? TryGetRole(Snowflake id) => _roles.GetValueOrDefault(id);
|
||||
|
||||
public Color? TryGetUserColor(Snowflake id)
|
||||
{
|
||||
var member = TryGetMember(id);
|
||||
var roles = member?.RoleIds.Join(Roles, i => i, r => r.Id, (_, role) => role);
|
||||
|
||||
return roles?
|
||||
var memberRoles = member?
|
||||
.RoleIds
|
||||
.Select(TryGetRole)
|
||||
.WhereNotNull()
|
||||
.ToArray();
|
||||
|
||||
return memberRoles?
|
||||
.Where(r => r.Color is not null)
|
||||
.OrderByDescending(r => r.Position)
|
||||
.Select(r => r.Color)
|
||||
@@ -71,34 +114,32 @@ internal class ExportContext
|
||||
try
|
||||
{
|
||||
var filePath = await _assetDownloader.DownloadAsync(url, cancellationToken);
|
||||
var relativeFilePath = Path.GetRelativePath(Request.OutputDirPath, filePath);
|
||||
|
||||
// We want relative path so that the output files can be copied around without breaking.
|
||||
// Base directory path may be null if the file is stored at the root or relative to working directory.
|
||||
var relativeFilePath = !string.IsNullOrWhiteSpace(Request.OutputBaseDirPath)
|
||||
? Path.GetRelativePath(Request.OutputBaseDirPath, filePath)
|
||||
: filePath;
|
||||
// Prefer relative paths so that the output files can be copied around without breaking references.
|
||||
// If the assets path is outside of the export directory, use an absolute path instead.
|
||||
var optimalFilePath =
|
||||
relativeFilePath.StartsWith(".." + Path.DirectorySeparatorChar, StringComparison.Ordinal) ||
|
||||
relativeFilePath.StartsWith(".." + Path.AltDirectorySeparatorChar, StringComparison.Ordinal)
|
||||
? filePath
|
||||
: relativeFilePath;
|
||||
|
||||
// HACK: for HTML, we need to format the URL properly
|
||||
// For HTML, the path needs to be properly formatted
|
||||
if (Request.Format is ExportFormat.HtmlDark or ExportFormat.HtmlLight)
|
||||
{
|
||||
// Need to escape each path segment while keeping the directory separators intact
|
||||
return string.Join(
|
||||
Path.AltDirectorySeparatorChar,
|
||||
relativeFilePath
|
||||
.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)
|
||||
.Select(Uri.EscapeDataString)
|
||||
);
|
||||
// Create a 'file:///' URI and then strip the 'file:///' prefix to allow for relative paths
|
||||
return new Uri(new Uri("file:///"), optimalFilePath).ToString()[8..];
|
||||
}
|
||||
|
||||
return relativeFilePath;
|
||||
return optimalFilePath;
|
||||
}
|
||||
// Try to catch only exceptions related to failed HTTP requests
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/332
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/372
|
||||
catch (Exception ex) when (ex is HttpRequestException or OperationCanceledException)
|
||||
{
|
||||
// TODO: add logging so we can be more liberal with catching exceptions
|
||||
// We don't want this to crash the exporting process in case of failure
|
||||
// We don't want this to crash the exporting process in case of failure.
|
||||
// TODO: add logging so we can be more liberal with catching exceptions.
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,35 +10,87 @@ using DiscordChatExporter.Core.Utils;
|
||||
|
||||
namespace DiscordChatExporter.Core.Exporting;
|
||||
|
||||
public partial record ExportRequest(
|
||||
Guild Guild,
|
||||
Channel Channel,
|
||||
string OutputPath,
|
||||
ExportFormat Format,
|
||||
Snowflake? After,
|
||||
Snowflake? Before,
|
||||
PartitionLimit PartitionLimit,
|
||||
MessageFilter MessageFilter,
|
||||
bool ShouldDownloadAssets,
|
||||
bool ShouldReuseAssets,
|
||||
string DateFormat)
|
||||
public partial class ExportRequest
|
||||
{
|
||||
private string? _outputBaseFilePath;
|
||||
public string OutputBaseFilePath => _outputBaseFilePath ??= GetOutputBaseFilePath(
|
||||
Guild,
|
||||
Channel,
|
||||
OutputPath,
|
||||
Format,
|
||||
After,
|
||||
Before
|
||||
);
|
||||
public Guild Guild { get; }
|
||||
|
||||
public string OutputBaseDirPath => Path.GetDirectoryName(OutputBaseFilePath) ?? OutputPath;
|
||||
public Channel Channel { get; }
|
||||
|
||||
public string OutputAssetsDirPath => $"{OutputBaseFilePath}_Files{Path.DirectorySeparatorChar}";
|
||||
public string OutputFilePath { get; }
|
||||
|
||||
public string OutputDirPath { get; }
|
||||
|
||||
public string AssetsDirPath { get; }
|
||||
|
||||
public ExportFormat Format { get; }
|
||||
|
||||
public Snowflake? After { get; }
|
||||
|
||||
public Snowflake? Before { get; }
|
||||
|
||||
public PartitionLimit PartitionLimit { get; }
|
||||
|
||||
public MessageFilter MessageFilter { get; }
|
||||
|
||||
public bool ShouldFormatMarkdown { get; }
|
||||
|
||||
public bool ShouldDownloadAssets { get; }
|
||||
|
||||
public bool ShouldReuseAssets { get; }
|
||||
|
||||
public string DateFormat { get; }
|
||||
|
||||
public ExportRequest(
|
||||
Guild guild,
|
||||
Channel channel,
|
||||
string outputPath,
|
||||
string? assetsDirPath,
|
||||
ExportFormat format,
|
||||
Snowflake? after,
|
||||
Snowflake? before,
|
||||
PartitionLimit partitionLimit,
|
||||
MessageFilter messageFilter,
|
||||
bool shouldFormatMarkdown,
|
||||
bool shouldDownloadAssets,
|
||||
bool shouldReuseAssets,
|
||||
string dateFormat)
|
||||
{
|
||||
Guild = guild;
|
||||
Channel = channel;
|
||||
Format = format;
|
||||
After = after;
|
||||
Before = before;
|
||||
PartitionLimit = partitionLimit;
|
||||
MessageFilter = messageFilter;
|
||||
ShouldFormatMarkdown = shouldFormatMarkdown;
|
||||
ShouldDownloadAssets = shouldDownloadAssets;
|
||||
ShouldReuseAssets = shouldReuseAssets;
|
||||
DateFormat = dateFormat;
|
||||
|
||||
OutputFilePath = GetOutputBaseFilePath(
|
||||
Guild,
|
||||
Channel,
|
||||
outputPath,
|
||||
Format,
|
||||
After,
|
||||
Before
|
||||
);
|
||||
|
||||
OutputDirPath = Path.GetDirectoryName(OutputFilePath)!;
|
||||
|
||||
AssetsDirPath = !string.IsNullOrWhiteSpace(assetsDirPath)
|
||||
? FormatPath(
|
||||
assetsDirPath,
|
||||
Guild,
|
||||
Channel,
|
||||
After,
|
||||
Before
|
||||
)
|
||||
: $"{OutputFilePath}_Files{Path.DirectorySeparatorChar}";
|
||||
}
|
||||
}
|
||||
|
||||
public partial record ExportRequest
|
||||
public partial class ExportRequest
|
||||
{
|
||||
public static string GetDefaultOutputFileName(
|
||||
Guild guild,
|
||||
@@ -82,17 +134,15 @@ public partial record ExportRequest
|
||||
return PathEx.EscapeFileName(buffer.ToString());
|
||||
}
|
||||
|
||||
private static string GetOutputBaseFilePath(
|
||||
private static string FormatPath(
|
||||
string path,
|
||||
Guild guild,
|
||||
Channel channel,
|
||||
string outputPath,
|
||||
ExportFormat format,
|
||||
Snowflake? after = null,
|
||||
Snowflake? before = null)
|
||||
Snowflake? after,
|
||||
Snowflake? before)
|
||||
{
|
||||
// Format path
|
||||
var actualOutputPath = Regex.Replace(
|
||||
outputPath,
|
||||
return Regex.Replace(
|
||||
path,
|
||||
"%.",
|
||||
m => PathEx.EscapeFileName(m.Value switch
|
||||
{
|
||||
@@ -111,6 +161,17 @@ public partial record ExportRequest
|
||||
_ => m.Value
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private static string GetOutputBaseFilePath(
|
||||
Guild guild,
|
||||
Channel channel,
|
||||
string outputPath,
|
||||
ExportFormat format,
|
||||
Snowflake? after = null,
|
||||
Snowflake? before = null)
|
||||
{
|
||||
var actualOutputPath = FormatPath(outputPath, guild, channel, after, before);
|
||||
|
||||
// Output is a directory
|
||||
if (Directory.Exists(actualOutputPath) || string.IsNullOrWhiteSpace(Path.GetExtension(actualOutputPath)))
|
||||
|
||||
@@ -11,6 +11,7 @@ internal class FromMessageFilter : MessageFilter
|
||||
|
||||
public override bool IsMatch(Message message) =>
|
||||
string.Equals(_value, message.Author.Name, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(_value, message.Author.DisplayName, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(_value, message.Author.FullName, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(_value, message.Author.Id.ToString(), StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ internal class MentionsMessageFilter : MessageFilter
|
||||
|
||||
public override bool IsMatch(Message message) => message.MentionedUsers.Any(user =>
|
||||
string.Equals(_value, user.Name, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(_value, user.DisplayName, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(_value, user.FullName, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(_value, user.Id.ToString(), StringComparison.OrdinalIgnoreCase)
|
||||
);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user