diff --git a/package.json b/package.json index 21678cb..59b4ed7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffinbot", - "version": "4.0.0-pudding.e240922b", + "version": "4.0.0-pudding.e240924a", "main": "dist/index.js", "private": true, "dependencies": { diff --git a/src/Commands/deleteLearn.ts b/src/Commands/deleteLearn.ts index 98660b0..8e81bb3 100644 --- a/src/Commands/deleteLearn.ts +++ b/src/Commands/deleteLearn.ts @@ -23,6 +23,7 @@ import { ApplyOptions } from '@sapphire/decorators' }) class DeleteLearnCommand extends Command { public async messageRun(msg: Message, args: Args) { + const CUSTOM_ID = 'maa$deleteLearn' const command = await args.rest('string').catch(() => null) const options: SelectMenuComponentOptionData[] = [] @@ -46,7 +47,7 @@ class DeleteLearnCommand extends Command { datas.forEach(data => { options.push({ label: `${data.id}번`, - value: `maa$deleteLearn-${data.id}`, + value: `${CUSTOM_ID}-${data.id}`, description: data.result.slice(0, 100), }) }) @@ -68,7 +69,7 @@ class DeleteLearnCommand extends Command { components: [ { type: ComponentType.StringSelect, - customId: 'maa$deleteLearn', + customId: `${CUSTOM_ID}@${msg.author.id}`, placeholder: '지울 데이터를 선택해ㅈ주세요', options, }, diff --git a/src/interaction-handlers/deleteLearn.ts b/src/interaction-handlers/deleteLearn.ts index 7c44f5a..00599c1 100644 --- a/src/interaction-handlers/deleteLearn.ts +++ b/src/interaction-handlers/deleteLearn.ts @@ -10,15 +10,25 @@ import { ApplyOptions } from '@sapphire/decorators' interactionHandlerType: InteractionHandlerTypes.SelectMenu, }) class DeleteLearnHandler extends InteractionHandler { + private readonly _CUSTOM_ID = 'maa$deleteLearn' + public async parse(interaction: StringSelectMenuInteraction) { - if (interaction.customId !== 'maa$deleteLearn') return this.none() + if (!interaction.customId.startsWith(this._CUSTOM_ID)) return this.none() + const userId = interaction.customId.slice(`${this._CUSTOM_ID}@`.length) + if (interaction.user.id !== userId) { + await interaction.reply({ + ephemeral: true, + content: '당신은 이 지ㅅ식을 안 가르쳐 주셨어요.', + }) + return this.none() + } return this.some() } public async run(interaction: StringSelectMenuInteraction) { await interaction.deferUpdate() - const id = Number(interaction.values[0].slice('maa$deleteLearn-'.length)) + const id = Number(interaction.values[0].slice(`${this._CUSTOM_ID}-`.length)) const db = this.container.database await db.learn.delete({