Skip to content

Instantly share code, notes, and snippets.

@willsheppard
Created February 18, 2022 15:38
Show Gist options
  • Save willsheppard/f9b7cc9b130784ffd7bd8f144cf892f8 to your computer and use it in GitHub Desktop.
Save willsheppard/f9b7cc9b130784ffd7bd8f144cf892f8 to your computer and use it in GitHub Desktop.
Stream filter for discord chat export
if .[0][2] == "timestamp" then .[1],"\t" else empty end,
if .[0][2] == "content" then .[1],"\t" else empty end,
if .[0][2] == "author" and .[0][3] == "name" then .[1],"\t" else empty end,
if .[0][2] == "author" and .[0][3] == "nickname" then .[1],"\t" else empty end,
if .[0][2] == "attachments" and .[0][4] == "url" then .[1],"\t" else empty end,
if .[0][2] == "mentions" and (.[1] | not) then "\n" else empty end
@willsheppard
Copy link
Author

willsheppard commented Feb 18, 2022

Input

A JSON format export from DiscordChatExporter.

Because this JSON document could be so large, we have to use jq's streaming feature, which has a learning curve.

Example:

{
  "guild": {
    "id": "111111111111111111",
    "name": "something",
    "iconUrl": "https://example.com/logo.png"
  },
  "channel": {
    "id": "222222222222222222",
    "type": "GuildTextChat",
    "categoryId": "333333333333333333",
    "category": "foo",
    "name": "bar",
    "topic": "blah blah blah"
  },
  "dateRange": {
    "after": null,
    "before": null
  },
  "messages": [
    {
      "id": "444444444444444444",
      "type": "Default",
      "timestamp": "2022-01-06T22:55:19.732+00:00",
      "timestampEdited": null,
      "callEndedTimestamp": null,
      "isPinned": true,
      "content": "Hiya, welcome to the channel",
      "author": {
        "id": "555555555555555555",
        "name": "SomeGuy",
        "discriminator": "3434",
        "nickname": "HappyCat",
        "color": "#FFFFFF",
        "isBot": false,
        "avatarUrl": "https://cdn.discordapp.com/avatars/666666666666666666/cafebabecoffeebeef.png?size=128"
      },
      "attachments": [],
      "embeds": [],
      "reactions": [
        {
          "emoji": {
            "id": "777777777777777777",
            "name": "OtherGuy",
            "isAnimated": true,
            "imageUrl": "https://cdn.discordapp.com/emojis/888888888888888888.gif"
          },
          "count": 9
        },
        {
          "emoji": {
            "id": "999999999999999999",
            "name": "LastGuy",
            "isAnimated": true,
            "imageUrl": "https://cdn.discordapp.com/emojis/010101010101010101.gif"
          },
          "count": 9
        }
      ],
      "mentions": []
    },
    {
      "id": "020202020202020202",
     ....snip....

Command

cat input.json | jq -j -M --stream -f discord1.jq > output.tsv

Output

Tab Separated Values (TSV):

2022-01-06T22:55:19.732+00:00	Hiya, welcome to the channel	SomeGuy	HappyCat

@willsheppard
Copy link
Author

However, if your aim is to output HTML then just use the existing HTML export options in DiscordChatExporter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment