Fix: deleteLearn's item id
This commit is contained in:
parent
bbf0b0cd08
commit
1af47ed911
3 changed files with 17 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "muffinbot",
|
"name": "muffinbot",
|
||||||
"version": "3.1.0-cake.d240924a",
|
"version": "3.1.0-cake.d240925a",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -28,7 +28,8 @@ class DeleteLearnCommand extends Command {
|
||||||
const command = await args.rest('string').catch(() => null)
|
const command = await args.rest('string').catch(() => null)
|
||||||
const options: SelectMenuComponentOptionData[] = []
|
const options: SelectMenuComponentOptionData[] = []
|
||||||
const db = this.container.database
|
const db = this.container.database
|
||||||
const [datas] = await db.database.execute<LearnData[]>(
|
const deleteDataList: string[] = []
|
||||||
|
const [deleteDatas] = await db.database.execute<LearnData[]>(
|
||||||
'SELECT * FROM learn WHERE command = ? AND user_id = ?;',
|
'SELECT * FROM learn WHERE command = ? AND user_id = ?;',
|
||||||
[command, msg.author.id],
|
[command, msg.author.id],
|
||||||
)
|
)
|
||||||
|
@ -39,27 +40,24 @@ class DeleteLearnCommand extends Command {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!datas) {
|
if (!deleteDatas) {
|
||||||
return await msg.channel.send('해당하는 걸 찾ㅈ을 수 없어요.')
|
return await msg.channel.send('해당하는 걸 찾ㅈ을 수 없어요.')
|
||||||
}
|
}
|
||||||
|
|
||||||
datas.forEach(data => {
|
for (let i = 1; i <= deleteDatas.length; i++) {
|
||||||
console.log(data)
|
deleteDataList.push(`${i}. ${deleteDatas[i - 1].result}`)
|
||||||
options.push({
|
options.push({
|
||||||
label: `${data.id}번`,
|
label: `${i}번 지식`,
|
||||||
value: `${CUSTOM_ID}-${data.id}`,
|
value: `${CUSTOM_ID}-${deleteDatas[i - 1].id}`,
|
||||||
description: data.result.slice(0, 100),
|
description: deleteDatas[i - 1].result.slice(0, 100),
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
await msg.reply({
|
await msg.reply({
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
title: '삭제',
|
title: '삭제',
|
||||||
description: `${codeBlock(
|
description: `${codeBlock('md', deleteDataList.join('\n'))}`,
|
||||||
'md',
|
|
||||||
datas.map(data => `${data.id}. ${data.result}`).join('\n'),
|
|
||||||
)}`,
|
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -30,6 +30,11 @@ class DeleteLearnHandler extends InteractionHandler {
|
||||||
|
|
||||||
const id = interaction.values[0].slice(`${this._CUSTOM_ID}-`.length)
|
const id = interaction.values[0].slice(`${this._CUSTOM_ID}-`.length)
|
||||||
const db = this.container.database
|
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)
|
await db.learn.delete(id)
|
||||||
|
|
||||||
|
@ -37,7 +42,7 @@ class DeleteLearnHandler extends InteractionHandler {
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
title: '삭제',
|
title: '삭제',
|
||||||
description: `${id}번을 정상적으로 삭제하ㅇ였어요.`,
|
description: `${Number(itemId!)}번을 정상적으로 삭제하ㅇ였어요.`,
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue