diff --git a/package.json b/package.json index 7e02bba..944c411 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffinbot", - "version": "3.1.0-cake.d240924a", + "version": "3.1.0-cake.d240925a", "main": "dist/index.js", "private": true, "dependencies": { diff --git a/src/Commands/deleteLearn.ts b/src/Commands/deleteLearn.ts index 6e38ba7..321a83b 100644 --- a/src/Commands/deleteLearn.ts +++ b/src/Commands/deleteLearn.ts @@ -28,7 +28,8 @@ class DeleteLearnCommand extends Command { const command = await args.rest('string').catch(() => null) const options: SelectMenuComponentOptionData[] = [] const db = this.container.database - const [datas] = await db.database.execute( + const deleteDataList: string[] = [] + const [deleteDatas] = await db.database.execute( 'SELECT * FROM learn WHERE command = ? AND user_id = ?;', [command, msg.author.id], ) @@ -39,27 +40,24 @@ class DeleteLearnCommand extends Command { ) } - if (!datas) { + if (!deleteDatas) { return await msg.channel.send('해당하는 걸 찾ㅈ을 수 없어요.') } - datas.forEach(data => { - console.log(data) + for (let i = 1; i <= deleteDatas.length; i++) { + deleteDataList.push(`${i}. ${deleteDatas[i - 1].result}`) options.push({ - label: `${data.id}번`, - value: `${CUSTOM_ID}-${data.id}`, - description: data.result.slice(0, 100), + label: `${i}번 지식`, + value: `${CUSTOM_ID}-${deleteDatas[i - 1].id}`, + description: deleteDatas[i - 1].result.slice(0, 100), }) - }) + } await msg.reply({ embeds: [ { title: '삭제', - description: `${codeBlock( - 'md', - datas.map(data => `${data.id}. ${data.result}`).join('\n'), - )}`, + description: `${codeBlock('md', deleteDataList.join('\n'))}`, timestamp: new Date().toISOString(), }, ], diff --git a/src/interaction-handlers/deleteLearn.ts b/src/interaction-handlers/deleteLearn.ts index 181661f..a0c42f8 100644 --- a/src/interaction-handlers/deleteLearn.ts +++ b/src/interaction-handlers/deleteLearn.ts @@ -30,6 +30,11 @@ class DeleteLearnHandler extends InteractionHandler { const id = interaction.values[0].slice(`${this._CUSTOM_ID}-`.length) const db = this.container.database + const decimalRegexp = /^[0-9]/g + + const itemId = interaction.component.options.map(item => + item.value.endsWith(id) ? item.label.match(decimalRegexp)![0] : null, + ) await db.learn.delete(id) @@ -37,7 +42,7 @@ class DeleteLearnHandler extends InteractionHandler { embeds: [ { title: '삭제', - description: `${id}번을 정상적으로 삭제하ㅇ였어요.`, + description: `${Number(itemId!)}번을 정상적으로 삭제하ㅇ였어요.`, timestamp: new Date().toISOString(), }, ],