Compare commits

...

18 Commits

Author SHA1 Message Date
Tyrrrz e6f9a364e1 Update version 2023-11-23 00:25:27 +02:00
Tyrrrz 0f6841593f Simplify CLI docs 2023-11-23 00:16:36 +02:00
Tyrrrz 2262d0abfb Update readme 2023-11-21 20:09:22 +02:00
Tyrrrz ab535233dc Update readme 2023-11-21 19:38:47 +02:00
Tyrrrz dcaceaddaf Skip the whole test job on pull requests, not just one step 2023-11-21 16:33:02 +02:00
Tyrrrz 2a787d2749 Rename job for consistency 2023-11-20 16:03:02 +02:00
Tyrrrz 481ddc4cd5 Update usage guide in apps 2023-11-19 22:52:03 +02:00
Oleksii Holub c493518eaf Update token docs
Closes #1159
2023-11-19 22:50:46 +02:00
Tyrrrz 450866d1f5 Make formatting check a separate job 2023-11-19 01:53:44 +02:00
Tyrrrz 60c8703e78 Fix incorrect handling of unformatted timestamp markers 2023-11-19 00:52:19 +02:00
Tyrrrz 1c343b75f8 Update NuGet packages 2023-11-18 23:49:25 +02:00
Tyrrrz b2a22ab2a9 Ignore invalid timestamp formats
Closes #1156
2023-11-18 23:45:57 +02:00
Tyrrrz b2ac5d8b45 Fix formatting 2023-11-17 18:44:40 +02:00
Tyrrrz 008c2e64aa Clean up 2023-11-17 18:37:52 +02:00
Tyrrrz 576ee73bfc Update workflows 2023-11-16 21:45:30 +02:00
Tyrrrz db1da5545a Bypass CSharpier in tests 2023-11-16 21:17:10 +02:00
Tyrrrz 5397b0db7d Fix formatting 2023-11-16 21:12:41 +02:00
Tyrrrz e89701e3f9 Provide more context in exception messages 2023-11-16 21:10:24 +02:00
21 changed files with 178 additions and 218 deletions
+4 -4
View File
@@ -48,12 +48,12 @@ Prerequisite step: Navigate to [discord.com](https://discord.com) and login.
<br clear="right" />
<br />
4. <img width="500" align="right" src="https://i.imgur.com/rnZG8Id.png" />Click the text box labelled `Filter` and type `library`. The entries will filter down to a single entry named `library`.
4. <img width="500" align="right" src="https://i.imgur.com/rnZG8Id.png" />Click the text box labelled `Filter` and type `messages`. The entries will filter down to a single request named `messages`. If the request doesn't appear, switch to any other Discord channel to trigger it.
<br clear="right" />
<br />
5. <img width="500" align="right" src="https://i.imgur.com/29dE3fR.png" />Click the entry named `library`. A panel will open to the right and display details about the entry. Click the `Headers` tab if it isn't already active.
5. <img width="500" align="right" src="https://i.imgur.com/29dE3fR.png" />Click the entry named `messages`. A panel will open to the right and display details about the entry. Click the `Headers` tab if it isn't already active.
<br clear="right" />
<br />
@@ -136,12 +136,12 @@ Prerequisite step: Navigate to [discord.com](https://discord.com) and login.
<br clear="right" />
<br />
3. <img width="500" align="right" src="https://i.imgur.com/efUCfBO.png" />Type `library` into the filter. The network request list will filter out any entries not containing the string `library`.
3. <img width="500" align="right" src="https://i.imgur.com/efUCfBO.png" />Type `messages` into the filter. The network request list will filter out any entries not containing the string `messages`. If the request doesn't appear, switch to any other Discord channel to trigger it.
<br clear="right" />
<br />
4. <img width="500" align="right" src="https://i.imgur.com/cdJZ7Q1.png" />Click `library`. The [network request details pane](https://firefox-source-docs.mozilla.org/devtools-user/network_monitor/request_details/index.html) will display. The [headers tab](https://firefox-source-docs.mozilla.org/devtools-user/network_monitor/request_details/index.html#network-monitor-request-details-headers-tab) should be active by default. If it isnt, click it.
4. <img width="500" align="right" src="https://i.imgur.com/cdJZ7Q1.png" />Click `messages`. The [network request details pane](https://firefox-source-docs.mozilla.org/devtools-user/network_monitor/request_details/index.html) will display. The [headers tab](https://firefox-source-docs.mozilla.org/devtools-user/network_monitor/request_details/index.html#network-monitor-request-details-headers-tab) should be active by default. If it isnt, click it.
<br clear="right" />
<br />
+38 -154
View File
@@ -38,49 +38,32 @@ dotnet DiscordChatExporter.Cli.dll
## CLI commands
| Command | Description |
|-----------------------------|-----------------------------------------------------|
| [export](#export) | Exports a channel |
| [exportdm](#exportdm) | Exports all direct message channels |
| [exportguild](#exportguild) | Exports all channels within the specified server |
| [exportall](#exportall) | Exports all accessible channels |
| [channels](#channels) | Outputs the list of channels in the given server |
| [dm](#dm) | Outputs the list of direct message channels |
| [guilds](#guilds) | Outputs the list of accessible servers |
| [guide](#guide) | Explains how to obtain token, guild, and channel ID |
| Command | Description |
|-------------------------|-----------------------------------------------------|
| export | Exports a channel |
| exportdm | Exports all direct message channels |
| exportguild | Exports all channels within the specified server |
| exportall | Exports all accessible channels |
| channels | Outputs the list of channels in the given server |
| dm | Outputs the list of direct message channels |
| guilds | Outputs the list of accessible servers |
| guide | Explains how to obtain token, guild, and channel ID |
To use the commands, you'll need a token. For the instructions on how to get a token, please refer
to [this page](Token-and-IDs.md), or run `dotnet DiscordChatExporter.Cli.dll guide`.
To get help with a specific command, please run:
To use the commands, you'll need a token. For the instructions on how to get a token, please refer to [this page](Token-and-IDs.md), or run `dotnet DiscordChatExporter.Cli.dll guide`.
To get help with a specific command, run:
```console
dotnet DiscordChatExporter.Cli.dll command -h
dotnet DiscordChatExporter.Cli.dll command --help
```
### `export`
For example, to figure out how to use the `export` command, run:
With this command, you can export **server channels** and **direct messages**.
```console
dotnet DiscordChatExporter.Cli.dll export --help
```
| | Option | Description |
|--------|---------------------------------------|----------------------------------------------------------------------------------------------------------------|
| **\*** | [-c](#basic-usage) | [Channel ID(s)](Token-and-IDs.md#how-to-get-guild-id-or-guild-channel-id) |
| **\*** | [-t](#basic-usage) | [Authorization token](Token-and-IDs.md#how-to-get-user-token). Environment variable: `DISCORD_TOKEN` |
| | [-o](#changing-the-output-filename) | Output file or directory path |
| | [-f](#changing-the-format) | [Output file format](Getting-started.md#file-formats). Default: HtmlDark |
| | [--after](#date-ranges) | Only include messages sent after this date |
| | [--before](#date-ranges) | Only include messages sent before this date |
| | [-p](#partitioning) | Split output into partitions, each limited to this number of messages (e.g. 100) or file size (e.g. 10mb) |
| | [--filter](Message-filters.md) | Special notation for filtering the messages that get included in the export |
| | [--media](#downloading-assets) | Download assets referenced by the export (user avatars, attached files, embedded images, etc.). Default: false |
| | [--reuse-media](#reuse-assets) | Reuse previously downloaded assets to avoid redundant requests. Default: false |
| | [--media-dir](#downloading-assets) | Directory to store assets from all exported channels in the same place |
| | [--locale](#changing-the-date-format) | Format used when writing dates. Default: en-US |
| | -h | Shows help text |
> **Note**:
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
#### Basic usage
## Export a specific channel
You can quickly export with DCE's default settings by using just `-t token` and `-c channelid`.
@@ -234,53 +217,13 @@ 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`
### Export channels from a specific guild (server)
This command exports all your **direct messages**.
To export all channels in a specific guild, use the `exportguild` command and provide the guild ID through the `-g|--guild` option:
| | Option | Description |
|--------|---------------------------------------|----------------------------------------------------------------------------------------------------------------|
| **\*** | [-c](#basic-usage) | [Channel ID(s)](Token-and-IDs.md#how-to-get-guild-id-or-guild-channel-id) |
| **\*** | [-t](#basic-usage) | [Authorization token](Token-and-IDs.md#how-to-get-user-token). Environment variable: `DISCORD_TOKEN` |
| | [-o](#changing-the-output-filename) | Output file or directory path |
| | [-f](#changing-the-format) | [Output file format](Getting-started.md#file-formats). Default: HtmlDark |
| | [--after](#date-ranges) | Only include messages sent after this date |
| | [--before](#date-ranges) | Only include messages sent before this date |
| | [-p](#partitioning) | Split output into partitions, each limited to this number of messages (e.g. 100) or file size (e.g. 10mb) |
| | [--filter](Message-filters.md) | Special notation for filtering the messages that get included in the export |
| | [--media](#downloading-assets) | Download assets referenced by the export (user avatars, attached files, embedded images, etc.). Default: false |
| | [--reuse-media](#reuse-assets) | Reuse previously downloaded assets to avoid redundant requests. Default: false |
| | [--media-dir](#downloading-assets) | Directory to store assets from all exported channels in the same place |
| | [--locale](#changing-the-date-format) | Format used when writing dates. Default: en-US |
| | -h | Shows help text |
> **Note**:
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
### `exportguild`
This command exports all channels of a **server**.
| | Option | Description |
|--------|-------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **\*** | -g | [Server ID](Token-and-IDs.md#how-to-get-guild-id-or-guild-channel-id) |
| **\*** | [-t](#basic-usage) | [Authorization token](Token-and-IDs.md#how-to-get-user-token). Environment variable: `DISCORD_TOKEN` |
| | [-o](#changing-the-output-filename) | Output file or directory path |
| | [-f](#changing-the-format) | [Output file format](Getting-started.md#file-formats). Default: HtmlDark |
| | [--after](#date-ranges) | Only include messages sent after this date |
| | [--before](#date-ranges) | Only include messages sent before this date |
| | [-p](#partitioning) | Split output into partitions, each limited to this number of messages (e.g. 100) or file size (e.g. 10mb) |
| | [--filter](Message-filters.md) | Special notation for filtering the messages that get included in the export |
| | [--media](#downloading-assets) | Download assets referenced by the export (user avatars, attached files, embedded images, etc.). Default: false |
| | [--reuse-media](#reuse-assets) | Reuse previously downloaded assets to avoid redundant requests. Default: false |
| | [--media-dir](#downloading-assets) | Directory to store assets from all exported channels in the same place |
| | [--locale](#changing-the-date-format) | Format used when writing dates. Default: en-US |
| | [--include-threads](#including-threads) | Specify whether to include threads (and which type) in the export. By default, threads are not included. It has possible values of `none`, `active`, or `all`, indicating which threads should be included. To include both active and archived threads, use `--include-threads all`. |
| | [--include-vc](#including-voice-channels) | Include voice channels in the export. Default: true |
| | -h | Shows help text |
> **Note**:
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
```console
dotnet DiscordChatExporter.Cli.dll exportguild -t "mfa.Ifrn" -g 21814
```
#### Including threads
@@ -302,30 +245,13 @@ voice channels, use `--include-vc false`.
dotnet DiscordChatExporter.Cli.dll exportguild -t "mfa.Ifrn" -g 21814 --include-vc false
```
### `exportall`
### Export all channels
This command exports **all accessible channels**, including server channels and DMs.
To export all accessible channels, use the `exportall` command:
| | Option | Description |
|--------|-------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **\*** | [-t](#basic-usage) | [Authorization token](Token-and-IDs.md#how-to-get-user-token). Environment variable: `DISCORD_TOKEN` |
| | [-o](#changing-the-output-filename) | Output file or directory path |
| | [-f](#changing-the-format) | [Output file format](Getting-started.md#file-formats). Default: HtmlDark |
| | [--after](#date-ranges) | Only include messages sent after this date |
| | [--before](#date-ranges) | Only include messages sent before this date |
| | [-p](#partitioning) | Split output into partitions, each limited to this number of messages (e.g. 100) or file size (e.g. 10mb) |
| | [--filter](Message-filters.md) | Special notation for filtering the messages that get included in the export |
| | [--media](#downloading-assets) | Download assets referenced by the export (user avatars, attached files, embedded images, etc.). Default: false |
| | [--reuse-media](#reuse-assets) | Reuse previously downloaded assets to avoid redundant requests. Default: false |
| | [--media-dir](#downloading-assets) | Directory to store assets from all exported channels in the same place |
| | [--locale](#changing-the-date-format) | Format used when writing dates. Default: en-US |
| | [--include-threads](#including-threads) | Specify whether to include threads (and which type) in the export. By default, threads are not included. It has possible values of `none`, `active`, or `all`, indicating which threads should be included. To include both active and archived threads, use `--include-threads all`. |
| | [--include-vc](#including-voice-channels) | Include voice channels in the export. Default: true |
| | [--include-dm](#excluding-dms) | Include direct messages in the export. Default: true |
| | -h | Shows help text |
> **Note**:
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
```console
dotnet DiscordChatExporter.Cli.dll exportall -t "mfa.Ifrn"
```
#### Excluding DMs
@@ -335,68 +261,26 @@ To exclude DMs, add the `--include-dm false` option.
dotnet DiscordChatExporter.Cli.dll exportall -t "mfa.Ifrn" --include-dm false
```
### `channels`
### List channels in a guild (server)
This command outputs a **server's channels** in the following format:
`Channel ID | Channel Name`
To save the output to a file, run the command below. If the file already exists, it will be overwritten.
| | Option | Description |
|--------|-------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **\*** | -g | [Server ID](Token-and-IDs.md#how-to-get-guild-id-or-guild-channel-id) |
| **\*** | [-t](#basic-usage) | [Authorization token](Token-and-IDs.md#how-to-get-user-token). Environment variable: `DISCORD_TOKEN` |
| | [--include-threads](#including-threads) | Specify whether to include threads (and which type) in the output. By default, threads are not included. It has possible values of `none`, `active`, or `all`, indicating which threads should be included. To include both active and archived threads, use `--include-threads all`. |
| | [--include-vc](#including-voice-channels) | Include voice channels in the output. Default: true |
| | -h | Shows help text |
> **Note**:
> Options with an asterisk (**\***) are required. The order of the options doesn't matter.
To save the output to a file, run the command with `> C:\path\…` like the example below. If the file already exists, it
will be overwritten.
To list the channels available in a specific guild, use the `channels` command and provide the guild ID through the `-g|--guild` option:
```console
dotnet DiscordChatExporter.Cli.dll channels -t "mfa.Ifrn" -g 21814 > C:\path\to\output.txt
dotnet DiscordChatExporter.Cli.dll channels -t "mfa.Ifrn" -g 21814
```
### `dm`
### List direct message channels
This command outputs a list of your **direct messages**.
| | Option | Description |
|--------|--------------------|------------------------------------------------------------------------------------------------------|
| **\*** | [-t](#basic-usage) | [Authorization token](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.
To save the output to a file, run the command with `> C:\path\…` like the example below. If the file already exists, it
will be overwritten.
To list all DM channels accessible to the current account, use the `dm` command:
```console
dotnet DiscordChatExporter.Cli.dll dm -t "mfa.Ifrn" > C:\path\to\output.txt
dotnet DiscordChatExporter.Cli.dll dm -t "mfa.Ifrn"
```
### `guilds`
### List guilds (servers)
This command outputs a list of your **servers**.
| | Option | Description |
|--------|--------------------|------------------------------------------------------------------------------------------------------|
| **\*** | [-t](#basic-usage) | [Authorization token](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.
To save the output to a file, run the command with `> C:\path\…` like the example below. If the file already exists, it
will be overwritten.
To list all guilds accessible by the current account, use the `guilds` command:
```console
dotnet DiscordChatExporter.Cli.dll guilds -t "mfa.Ifrn" > C:\path\to\output.txt
```
### `guide`
This command explains [how to get your token, guild, and channel IDs](Token-and-IDs.md).
```
+3 -2
View File
@@ -1,13 +1,14 @@
name: docker
on:
workflow_dispatch:
push:
pull_request:
jobs:
# Outputs from this job aren't really used, but it's here to verify that
# the Dockerfile builds correctly on pull requests.
build:
pack:
runs-on: ubuntu-latest
permissions:
actions: write
@@ -36,7 +37,7 @@ jobs:
deploy:
# Deploy to DockerHub only on tag push or master branch push
if: ${{ github.event_name == 'push' && (github.ref_type == 'tag' || github.ref_type == 'branch' && github.ref_name == 'master') }}
if: ${{ github.ref_type == 'tag' || github.ref_type == 'branch' && github.ref_name == 'master' }}
runs-on: ubuntu-latest
permissions:
contents: read
+27 -3
View File
@@ -1,6 +1,7 @@
name: main
on:
workflow_dispatch:
push:
pull_request:
@@ -10,7 +11,29 @@ env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
format:
runs-on: windows-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # 4.1.0
- name: Install .NET
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # 3.2.0
with:
dotnet-version: 8.0.x
- name: Verify formatting
run: >
dotnet build
-t:CSharpierFormat
--configuration Release
test:
# Tests need access to secrets, so we can't run them against PRs because of limited trust
if: ${{ github.event_name != 'pull_request' }}
runs-on: windows-latest
permissions:
contents: read
@@ -25,12 +48,11 @@ jobs:
dotnet-version: 8.0.x
- name: Run tests
# Tests need access to secrets, so we can't run them against PRs because of limited trust
if: ${{ github.event_name != 'pull_request' }}
env:
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
run: >
dotnet test
-p:CSharpier_Bypass=true
--configuration Release
--logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true"
--collect:"XPlat Code Coverage"
@@ -67,6 +89,7 @@ jobs:
- name: Publish app
run: >
dotnet publish ${{ matrix.app }}
-p:CSharpier_Bypass=true
--output ${{ matrix.app }}/bin/publish/
--configuration Release
@@ -78,9 +101,10 @@ jobs:
if-no-files-found: error
release:
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
if: ${{ github.ref_type == 'tag' }}
needs:
- format
- test
- pack
+5
View File
@@ -1,5 +1,10 @@
# Changelog
## v2.42.5 (23-Nov-2023)
- General changes:
- Fixed an issue where the application crashed when trying to export a channel that contained a message with an invalid timestamp (e.g. `<t:0:x>`).
## v2.42.4 (16-Nov-2023)
- General changes:
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>2.42.4</Version>
<Version>2.42.5</Version>
<Company>Tyrrrz</Company>
<Copyright>Copyright (c) Oleksii Holub</Copyright>
<LangVersion>preview</LangVersion>
@@ -11,15 +11,15 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="AngleSharp" Version="1.0.6" />
<PackageReference Include="AngleSharp" Version="1.0.7" />
<PackageReference Include="coverlet.collector" Version="6.0.0" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.26.1" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.26.2" PrivateAssets="all" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" PrivateAssets="all" />
<PackageReference Include="JsonExtensions" Version="1.2.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.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="ReflectionMagic" Version="5.0.0" />
<PackageReference Include="xunit" Version="2.6.1" />
@@ -105,7 +105,7 @@ public static class ExportWrapper
if (message is null)
{
throw new InvalidOperationException(
$"Message '{messageId}' does not exist in the export of channel '{channelId}'."
$"Message #{messageId} not found in the export of channel #{channelId}."
);
}
@@ -129,7 +129,7 @@ public static class ExportWrapper
if (message.ValueKind == JsonValueKind.Undefined)
{
throw new InvalidOperationException(
$"Message '{messageId}' does not exist in the export of channel '{channelId}'."
$"Message #{messageId} not found in the export of channel #{channelId}."
);
}
@@ -168,7 +168,8 @@ public abstract class ExportCommandBase : DiscordCommandBase
{
throw new CommandException(
"Attempted to export multiple channels, but the output path is neither a directory nor a template. "
+ "If the provided output path is meant to be treated as a directory, make sure it ends with a slash."
+ "If the provided output path is meant to be treated as a directory, make sure it ends with a slash. "
+ $"Provided output path: '{OutputPath}'."
);
}
@@ -26,9 +26,7 @@ public class GuideCommand : ICommand
console.Output.WriteLine(" 4. Navigate to the Network tab");
console.Output.WriteLine(" 5. Press Ctrl+R to reload");
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(" 7. Search for a request that starts with \"messages\"");
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");
@@ -6,8 +6,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CliFx" Version="2.3.4" />
<PackageReference Include="CSharpier.MsBuild" Version="0.26.1" PrivateAssets="all" />
<PackageReference Include="CliFx" Version="2.3.5" />
<PackageReference Include="CSharpier.MsBuild" Version="0.26.2" PrivateAssets="all" />
<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" />
@@ -618,7 +618,7 @@ public class DiscordClient
if (!application.IsMessageContentIntentEnabled)
{
throw new DiscordChatExporterException(
"Bot account does not have the Message Content Intent enabled.",
"Provided bot account does not have the Message Content Intent enabled.",
true
);
}
@@ -22,26 +22,27 @@ public partial record struct Snowflake
public static Snowflake FromDate(DateTimeOffset instant) =>
new(((ulong)instant.ToUnixTimeMilliseconds() - 1420070400000UL) << 22);
public static Snowflake? TryParse(string? str, IFormatProvider? formatProvider = null)
public static Snowflake? TryParse(string? value, IFormatProvider? formatProvider = null)
{
if (string.IsNullOrWhiteSpace(str))
if (string.IsNullOrWhiteSpace(value))
return null;
// As number
if (ulong.TryParse(str, NumberStyles.None, formatProvider, out var value))
return new Snowflake(value);
if (ulong.TryParse(value, NumberStyles.None, formatProvider, out var number))
return new Snowflake(number);
// As date
if (DateTimeOffset.TryParse(str, formatProvider, DateTimeStyles.None, out var instant))
if (DateTimeOffset.TryParse(value, formatProvider, DateTimeStyles.None, out var instant))
return FromDate(instant);
return null;
}
public static Snowflake Parse(string str, IFormatProvider? formatProvider) =>
TryParse(str, formatProvider) ?? throw new FormatException($"Invalid snowflake '{str}'.");
public static Snowflake Parse(string value, IFormatProvider? formatProvider) =>
TryParse(value, formatProvider)
?? throw new FormatException($"Invalid snowflake '{value}'.");
public static Snowflake Parse(string str) => Parse(str, null);
public static Snowflake Parse(string value) => Parse(value, null);
}
public partial record struct Snowflake : IComparable<Snowflake>, IComparable
@@ -2,10 +2,10 @@
<ItemGroup>
<PackageReference Include="AsyncKeyedLock" Version="6.2.2" />
<PackageReference Include="CSharpier.MsBuild" Version="0.26.1" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.26.2" PrivateAssets="all" />
<PackageReference Include="Gress" Version="2.1.1" />
<PackageReference Include="JsonExtensions" Version="1.2.0" />
<PackageReference Include="Polly" Version="8.1.0" />
<PackageReference Include="Polly" Version="8.2.0" />
<PackageReference Include="RazorBlade" Version="0.4.4" />
<PackageReference Include="Superpower" Version="3.0.0" />
<PackageReference Include="WebMarkupMin.Core" Version="2.14.0" />
@@ -6,8 +6,12 @@ public class DiscordChatExporterException : Exception
{
public bool IsFatal { get; }
public DiscordChatExporterException(string message, bool isFatal = false)
: base(message)
public DiscordChatExporterException(
string message,
bool isFatal = false,
Exception? innerException = null
)
: base(message, innerException)
{
IsFatal = isFatal;
}
@@ -22,7 +22,9 @@ public class ChannelExporter(DiscordClient discord)
if (request.Channel.Kind == ChannelKind.GuildForum)
{
throw new DiscordChatExporterException(
"Channel is a forum and cannot be exported directly. "
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) "
+ $"of guild '{request.Guild.Name}' (#{request.Guild.Id}) "
+ $"is a forum and cannot be exported directly. "
+ "You need to pull its threads and export them individually."
);
}
@@ -30,14 +32,20 @@ public class ChannelExporter(DiscordClient discord)
// Check if the channel is empty
if (request.Channel.IsEmpty)
{
throw new DiscordChatExporterException("Channel does not contain any messages.");
throw new DiscordChatExporterException(
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) "
+ $"of guild '{request.Guild.Name}' (#{request.Guild.Id}) "
+ $"does not contain any messages."
);
}
// Check if the 'after' boundary is valid
if (request.After is not null && !request.Channel.MayHaveMessagesAfter(request.After.Value))
{
throw new DiscordChatExporterException(
"Channel does not contain any messages within the specified period."
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) "
+ $"of guild '{request.Guild.Name}' (#{request.Guild.Id}) "
+ $"does not contain any messages within the specified period."
);
}
@@ -48,7 +56,9 @@ public class ChannelExporter(DiscordClient discord)
)
{
throw new DiscordChatExporterException(
"Channel does not contain any messages within the specified period."
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) "
+ $"of guild '{request.Guild.Name}' (#{request.Guild.Id}) "
+ $"does not contain any messages within the specified period."
);
}
@@ -68,20 +78,36 @@ public class ChannelExporter(DiscordClient discord)
)
)
{
// Resolve members for referenced users
foreach (var user in message.GetReferencedUsers())
await context.PopulateMemberAsync(user, cancellationToken);
try
{
// Resolve members for referenced users
foreach (var user in message.GetReferencedUsers())
await context.PopulateMemberAsync(user, cancellationToken);
// Export the message
if (request.MessageFilter.IsMatch(message))
await messageExporter.ExportMessageAsync(message, cancellationToken);
// Export the message
if (request.MessageFilter.IsMatch(message))
await messageExporter.ExportMessageAsync(message, cancellationToken);
}
catch (Exception ex)
{
// Provide more context to the exception, to simplify debugging based on error messages
throw new DiscordChatExporterException(
$"Failed to export message #{message.Id} "
+ $"in channel '{request.Channel.Name}' (#{request.Channel.Id}) "
+ $"of guild '{request.Guild.Name} (#{request.Guild.Id})'.",
ex is not DiscordChatExporterException dex || dex.IsFatal,
ex
);
}
}
// Throw if no messages were exported
if (messageExporter.MessagesExported <= 0)
{
throw new DiscordChatExporterException(
"Channel does not contain any matching messages within the specified period."
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) "
+ $"of guild '{request.Guild.Name}' (#{request.Guild.Id}) "
+ $"does not contain any matching messages within the specified period."
);
}
}
@@ -340,13 +340,27 @@ internal static partial class MarkdownParser
)
);
// https://discord.com/developers/docs/reference#message-formatting-timestamp-styles
var format = m.Groups[2].Value.NullIfWhiteSpace() switch
{
// Ignore the 'relative' format because it doesn't make sense in a static export
// Known formats
"t" => "t",
"T" => "T",
"d" => "d",
"D" => "D",
"f" => "f",
"F" => "F",
// Relative format: ignore because it doesn't make sense in a static export
"r" => null,
"R" => null,
// Discord's date formats are (mostly) compatible with .NET's date formats
var f => f
// Unspecified format: will be mapped to the default format
null => null,
// Unknown format: throw an exception to consider this timestamp invalid
// https://github.com/Tyrrrz/DiscordChatExporter/issues/1156
var f
=> throw new InvalidOperationException(
$"Unknown timestamp format '{f}'."
)
};
return new TimestampNode(instant, format);
@@ -354,7 +368,12 @@ internal static partial class MarkdownParser
// https://github.com/Tyrrrz/DiscordChatExporter/issues/681
// https://github.com/Tyrrrz/DiscordChatExporter/issues/766
catch (Exception ex)
when (ex is FormatException or ArgumentOutOfRangeException or OverflowException)
when (ex
is FormatException
or ArgumentOutOfRangeException
or OverflowException
or InvalidOperationException
)
{
// For invalid timestamps, Discord renders "Invalid Date" instead of ignoring the markdown
return TimestampNode.Invalid;
@@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Cogwheel" Version="2.0.4" />
<PackageReference Include="CSharpier.MsBuild" Version="0.26.1" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.26.2" PrivateAssets="all" />
<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" />
@@ -277,9 +277,7 @@ public class DashboardViewModel : PropertyChangedBase
}
catch (DiscordChatExporterException ex) when (!ex.IsFatal)
{
_eventAggregator.Publish(
new NotificationMessage(ex.Message.TrimEnd('.') + $" ({channel.Name})")
);
_eventAggregator.Publish(new NotificationMessage(ex.Message.TrimEnd('.')));
}
finally
{
@@ -193,9 +193,8 @@
<LineBreak />
<Run Text="6. Switch between random channels to trigger network requests" />
<LineBreak />
<Run Text="7. Search for a request containing" />
<Run FontWeight="SemiBold" Text="messages?limit=50" />
<Run Text="or similar" />
<Run Text="7. Search for a request that starts with" />
<Run FontWeight="SemiBold" Text="messages" />
<LineBreak />
<Run Text="8. Select the" />
<Run FontWeight="SemiBold" Text="Headers" />
+6 -6
View File
@@ -89,11 +89,7 @@ The following table lists all available download options:
</tbody>
</table>
> **Note**:
> AUR and Nix packages linked above are maintained by the community.
> If you have any issues with them, please contact the corresponding maintainers.
> **Warning**:
> **Important**:
> To run **DiscordChatExporter** on macOS and Linux, you need to make sure that **.NET 8.0 Runtime** is installed.
> You can download it here:
>
@@ -104,6 +100,10 @@ The following table lists all available download options:
> This should not be necessary if you install **DiscordChatExporter** using a package manager, as it should take care of the dependencies for you.
> This is also not necessary if you are running **DiscordChatExporter** via Docker, because the image already contains the runtime.
> **Note**:
> AUR and Nix packages linked above are maintained by the community.
> If you have any issues with them, please contact the corresponding maintainers.
## Features
- Graphical user interface (Windows)
@@ -119,7 +119,7 @@ The following table lists all available download options:
![channel list](.assets/list.png)
![rendered output](.assets/output.png)
## Related projects
## See also
- [**Chat Analytics**](https://github.com/mlomb/chat-analytics) — solution for analyzing chat patterns of Discord users, using exports produced by **DiscordChatExporter**.
- [**DiscordChatExporter-frontend**](https://github.com/slatinsky/DiscordChatExporter-frontend) — convenient viewer for exports produced by **DiscordChatExporter**.