Skip to content

Commit

Permalink
fix(worker): Respond with user error if notification already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
tzushimelon committed Feb 11, 2024
1 parent 1ec19e2 commit 298cb3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export function insertNotification(
user_id: userId,
keyword: cleanKeyword(keyword),
})
.onConflict((oc) =>
oc.columns(["guild_id", "user_id", "keyword"]).doNothing(),
)
.executeTakeFirst();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,16 @@ export default class NotificationCommand extends SlashCommandHandler {
keyword,
);

if (res.numInsertedOrUpdatedRows === BigInt(0)) {
if (Number(res.numInsertedOrUpdatedRows) === 0) {
const embed = new EmbedBuilder()
.setTitle("Failed to add notification")
.setDescription(
`You already have a notification set for \`${keyword}\``,
)
.setColor(Color.Error);

await interaction.reply({
content: t("notification.add.error.duplicate", {
ns: "commands",
keyword,
}),
embeds: [embed],
flags: MessageFlags.Ephemeral,
});

Expand Down

0 comments on commit 298cb3a

Please sign in to comment.