From c4980da8b7f0be8fce4b1c7ca4531ea006fd4fa7 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Tue, 21 Nov 2023 23:31:00 +0300 Subject: [PATCH] item deletion + linked counter interaction fix. idk if it works but i don't wanna bother testing --- src/commands/item.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/commands/item.ts b/src/commands/item.ts index 1994962..89d0dcf 100644 --- a/src/commands/item.ts +++ b/src/commands/item.ts @@ -1,5 +1,5 @@ import { AutocompleteInteraction, CommandInteraction, SlashCommandBuilder } from 'discord.js'; -import { CustomCraftingRecipeItem, CustomItem, db } from '../lib/db'; +import { Counter, CustomCraftingRecipeItem, CustomItem, db } from '../lib/db'; import { customItemAutocomplete, formatItem, formatItems, getItem, giveItem, itemAutocomplete } from '../lib/rpg/items'; import { behaviors } from '../lib/rpg/behaviors'; import { Command } from '../types/index'; @@ -236,6 +236,13 @@ export default { return interaction.followUp(`⚠️ This item is used in the following recipes:\n${recipes.map(r => `- ${formatRecipe(r!)}`).join('\n')}`); } + const linkedWith = await db('counters') + .where('linkedItem', item.id); + + if (linkedWith.length > 0) { + return interaction.followUp(`⚠️ This item is used in the following counters:\n${linkedWith.map(c => `- ${c.key} ${c.value} in <#${c.channel}>`).join('\n')}`); + } + await db('customItems') .where('id', item.id) .delete();