From 215c73c3bcbced7b30ffda9560a19dc4d8203263 Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sun, 6 Aug 2023 13:12:15 -0400 Subject: [PATCH] Refactor and cleanup inspect.ts --- package.json | 2 +- src/components/inspect.ts | 144 +++++++++++++++++--------------------- 2 files changed, 67 insertions(+), 79 deletions(-) diff --git a/package.json b/package.json index 270acf30..1afef5cd 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "test": "tsc && mocha build/test", "format": "prettier . --write", "format-files": "prettier --write --ignore-unknown", - "ts-compile": "tsc" + "ts-check": "tsc --noEmit" }, "devDependencies": { "@types/chai": "^4.3.5", diff --git a/src/components/inspect.ts b/src/components/inspect.ts index a7c64abc..bf75677d 100644 --- a/src/components/inspect.ts +++ b/src/components/inspect.ts @@ -9,6 +9,70 @@ import { MessageContextMenuCommandBuilder, TextBasedCommand, TextBasedCommandBui import { url_re } from "./quote.js"; import { colors } from "../common.js"; +// These looks silly, but it is the best way I can think of to call all the getters and re-package +function repackage_attachment({ + contentType, + description, + ephemeral, + height, + id, + name, + proxyURL, + size, + spoiler, + url, + width, +}: Discord.Attachment) { + return { + contentType, + description, + ephemeral, + height, + id, + name, + proxyURL, + size, + spoiler, + url, + width, + }; +} +function repackage_embed({ + author, + color, + data, + description, + fields, + footer, + hexColor, + image, + length, + provider, + thumbnail, + timestamp, + title, + url, + video, +}: Discord.Embed) { + return { + author, + color, + data, + description, + fields, + footer, + hexColor, + image, + length, + provider, + thumbnail, + timestamp, + title, + url, + video, + }; +} + /** * Adds an /inspect application command for displaying the markdown used to * generate a message. @@ -52,90 +116,14 @@ export default class Inspect extends BotComponent { await command_object.followUp({ ephemeral: true, ephemeral_if_possible: true, - content: - "Attachments: " + - JSON.stringify( - message.attachments.map( - // This looks silly, but it is the best way I can think of to call all the getters and - // re-package - ({ - contentType, - description, - ephemeral, - height, - id, - name, - proxyURL, - size, - spoiler, - url, - width, - }) => ({ - contentType, - description, - ephemeral, - height, - id, - name, - proxyURL, - size, - spoiler, - url, - width, - }), - ), - null, - 4, - ), + content: "Attachments: " + JSON.stringify(message.attachments.map(repackage_attachment), null, 4), }); } if (message.embeds.length > 0) { await command_object.followUp({ ephemeral: true, ephemeral_if_possible: true, - content: - "Embeds: " + - JSON.stringify( - message.embeds.map( - // This looks silly, but it is the best way I can think of to call all the getters and - // re-package - ({ - author, - color, - data, - description, - fields, - footer, - hexColor, - image, - length, - provider, - thumbnail, - timestamp, - title, - url, - video, - }) => ({ - author, - color, - data, - description, - fields, - footer, - hexColor, - image, - length, - provider, - thumbnail, - timestamp, - title, - url, - video, - }), - ), - null, - 4, - ), + content: "Embeds: " + JSON.stringify(message.embeds.map(repackage_embed), null, 4), }); } }