Skip to content

Commit

Permalink
fix: user check and infinite timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
didinele committed Oct 11, 2023
1 parent d3f7429 commit 2b4844b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions packages/bot/src/commands/add-answer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,21 @@ export default class implements Command<ApplicationCommandType.Message> {
const imageUrl = modalInteraction.fields.getTextInputValue('image-url');
const userId = modalInteraction.fields.getTextInputValue('user-id');

const answeredBy = userId
? await interaction.client.users.fetch(userId).catch(() => interaction.user)
: interaction.user;
const answeredBy = userId ? await interaction.guild.members.fetch(userId).catch(() => null) : interaction.member;

if (!answeredBy) {
return interaction.reply({
content: 'I could not find the given user.',
ephemeral: true,
});
}

const embeds: (Embed | EmbedBuilder)[] = interaction.targetMessage.embeds;
const answerEmbed = new EmbedBuilder()
.setDescription(text)
.setImage(imageUrl.length ? imageUrl : null)
.setFooter({
text: `${answeredBy.tag} answered`,
text: `${answeredBy.nickname ?? answeredBy.user.displayName} answered`,
iconURL: answeredBy.displayAvatarURL(),
})
.setColor(Colors.Blurple);
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/commands/add-timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class implements Command<ApplicationCommandType.Message> {
const answeredAt = url.length ? `[[${text}](${url})]` : `[${text}]`;

const [toUpdate, ...rest] = interaction.targetMessage.embeds;
const updated = new EmbedBuilder(toUpdate!.toJSON()).setDescription(`${answeredAt} ${toUpdate!.description}`);
const updated = new EmbedBuilder(toUpdate!.toJSON()).setDescription(`${answeredAt} ${question.content}`);

await interaction.targetMessage.edit({
embeds: [updated, ...rest],
Expand Down

0 comments on commit 2b4844b

Please sign in to comment.