Skip to content

Commit e42bde7

Browse files
committed
feat: Use option for raw whois data instead of button
1 parent fa69cdc commit e42bde7

1 file changed

Lines changed: 24 additions & 34 deletions

File tree

src/commands/chatInput/whois.ts

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,11 @@ import {
55
UserFlags,
66
type APIEmbedField,
77
ApplicationIntegrationType,
8-
ButtonStyle
98
} from "@discordjs/core/http-only";
10-
import {
11-
ActionRowBuilder,
12-
ButtonBuilder,
13-
codeBlock,
14-
EmbedBuilder,
15-
roleMention,
16-
time
17-
} from "@discordjs/builders";
9+
import { codeBlock, EmbedBuilder, roleMention, time } from "@discordjs/builders";
1810
import { formatWithOptions } from "node:util";
1911
import { ChatInputCommand } from "#structures";
20-
import { Collector, formatUser, getFlags, timeFromSnowflake } from "#util";
12+
import { formatUser, getFlags, timeFromSnowflake } from "#util";
2113
import type { ApplicationRPC } from "#typings";
2214

2315
export default new ChatInputCommand({
@@ -61,12 +53,28 @@ export default new ChatInputCommand({
6153
}
6254

6355
const member = options.getMember("user");
56+
const raw = Boolean(options.getBoolean("raw", false));
6457
const user = await app.api.users.get(options.getUser("user", true).id);
6558
const titlePrefix = user.bot
6659
? "Bot"
6760
: member
6861
? "Member"
6962
: "User";
63+
64+
if (raw) {
65+
const rawMemberData = member && {
66+
...member,
67+
user
68+
};
69+
70+
await app.api.interactions.reply(interaction.id, interaction.token, {
71+
content: codeBlock("js", formatWithOptions({ depth: 5 }, "%O", rawMemberData ?? user).slice(0, 1990)),
72+
flags: app.ephemeral
73+
});
74+
75+
return;
76+
}
77+
7078
const embed = new EmbedBuilder()
7179
.setThumbnail(user.avatar ? app.api.rest.cdn.avatar(user.id, user.avatar, { extension: "png", size: 1024 }) : null)
7280
.setTitle(`${titlePrefix} info: ${user.username}`)
@@ -117,32 +125,8 @@ export default new ChatInputCommand({
117125

118126
await app.api.interactions.reply(interaction.id, interaction.token, {
119127
embeds: [embed.toJSON()],
120-
components: [new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder()
121-
.setCustomId("raw")
122-
.setStyle(ButtonStyle.Primary)
123-
.setLabel("Raw")
124-
).toJSON()],
125128
flags: app.ephemeral
126129
});
127-
128-
new Collector(app, {
129-
filter: int => (int.member ?? int).user!.id === (interaction.member ?? interaction).user!.id,
130-
max: 1,
131-
timeout: 20_000
132-
}).on("collect", async int => {
133-
const rawMemberData = member && {
134-
...member,
135-
user
136-
};
137-
138-
await app.api.interactions.updateMessage(int.id, int.token, {
139-
content: codeBlock("js", formatWithOptions({ depth: 5 }, "%O", rawMemberData ?? user).slice(0, 1990)),
140-
components: [],
141-
embeds: []
142-
});
143-
}).on("end", async (ints) => {
144-
if (!ints.length) await app.api.interactions.editReply(process.env.CLIENT_ID!, interaction.token, { components: [] });
145-
});
146130
},
147131
data: {
148132
name: "whois",
@@ -153,6 +137,12 @@ export default new ChatInputCommand({
153137
name: "user",
154138
description: "The user to get info on",
155139
required: true
140+
},
141+
{
142+
type: ApplicationCommandOptionType.Boolean,
143+
name: "raw",
144+
description: "Whether to show the raw data or not",
145+
required: false
156146
}
157147
]
158148
}

0 commit comments

Comments
 (0)