Skip to content

Commit

Permalink
Refactor and cleanup inspect.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Aug 6, 2023
1 parent 7af50b8 commit 215c73c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 79 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
144 changes: 66 additions & 78 deletions src/components/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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),
});
}
}
Expand Down

0 comments on commit 215c73c

Please sign in to comment.