diff --git a/package.json b/package.json index f4c7488..f88e42e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffinbot", - "version": "4.0.0-pudding.experimental_slash_test.3", + "version": "4.0.0-pudding.experimental_slash_test.4", "main": "dist/index.js", "private": true, "dependencies": { diff --git a/src/Commands/deleteLearn.ts b/src/Commands/deleteLearn.ts index f1748e1..6d893ad 100644 --- a/src/Commands/deleteLearn.ts +++ b/src/Commands/deleteLearn.ts @@ -1,16 +1,18 @@ +import { ApplyOptions } from '@sapphire/decorators' +import { + type SelectMenuComponentOptionData, + type User, + ChatInputCommandInteraction, + ComponentType, + codeBlock, + Message, +} from 'discord.js' import { Args, Command, container, DetailedDescriptionCommandObject, } from '@sapphire/framework' -import { - type SelectMenuComponentOptionData, - type Message, - ComponentType, - codeBlock, -} from 'discord.js' -import { ApplyOptions } from '@sapphire/decorators' @ApplyOptions({ name: '삭제', @@ -22,13 +24,36 @@ import { ApplyOptions } from '@sapphire/decorators' }, }) class DeleteLearnCommand extends Command { - public async messageRun(msg: Message, args: Args) { + public registerApplicationCommands(registry: Command.Registry) { + registry.registerChatInputCommand(builder => + builder + .setName(this.name) + .setDescription(this.description) + .addStringOption(option => + option + .setRequired(true) + .setName('단어') + .setDescription('삭제할 단어를 입력해주세요.'), + ), + ) + } + + private async _run(ctx: Message | ChatInputCommandInteraction, args?: Args) { + let command: string | null + let user: User + if (ctx instanceof Message) { + command = await args!.rest('string').catch(() => null) + user = ctx.author + } else { + command = ctx.options.getString('단어', true) + user = ctx.user + } + const CUSTOM_ID = 'maa$deleteLearn' - const command = await args.rest('string').catch(() => null) const options: SelectMenuComponentOptionData[] = [] const deleteDataList: string[] = [] if (!command) { - return await msg.reply( + return await ctx.reply( `사용법: \n\`\`\`${(this.detailedDescription as DetailedDescriptionCommandObject).usage}\`\`\``, ) } @@ -36,12 +61,12 @@ class DeleteLearnCommand extends Command { const deleteDatas = await this.container.database.learn.findMany({ where: { command, - user_id: msg.author.id, + user_id: user.id, }, }) if (!deleteDatas) { - return await msg.reply('해당하는 걸 찾ㅈ을 수 없어요.') + return await ctx.reply('해당하는 걸 찾ㅈ을 수 없어요.') } for (let i = 1; i <= deleteDatas.length; i++) { @@ -53,7 +78,7 @@ class DeleteLearnCommand extends Command { }) } - await msg.reply({ + await ctx.reply({ embeds: [ { title: '삭제', @@ -67,7 +92,7 @@ class DeleteLearnCommand extends Command { components: [ { type: ComponentType.StringSelect, - customId: `${CUSTOM_ID}@${msg.author.id}`, + customId: `${CUSTOM_ID}@${user.id}`, placeholder: '지울 데이터를 선택해ㅈ주세요', options, }, @@ -76,6 +101,14 @@ class DeleteLearnCommand extends Command { ], }) } + + public async messageRun(msg: Message, args: Args) { + await this._run(msg, args) + } + + public async chatInputRun(interaction: ChatInputCommandInteraction) { + await this._run(interaction) + } } void container.stores.loadPiece({ diff --git a/src/Commands/learning_data.ts b/src/Commands/learning_data.ts index bc4e8fe..cd3c5f5 100644 --- a/src/Commands/learning_data.ts +++ b/src/Commands/learning_data.ts @@ -1,6 +1,6 @@ +import { ChatInputCommandInteraction, Message } from 'discord.js' import { Command, container } from '@sapphire/framework' import { ApplyOptions } from '@sapphire/decorators' -import { type Message } from 'discord.js' @ApplyOptions({ name: '데이터학습량', @@ -11,14 +11,21 @@ import { type Message } from 'discord.js' }, }) class LearnDataCommand extends Command { - public async messageRun(msg: Message) { + public registerApplicationCommands(registry: Command.Registry) { + registry.registerChatInputCommand(builder => + builder.setName(this.name).setDescription(this.description), + ) + } + + private async _run(ctx: Message | ChatInputCommandInteraction) { + const user = ctx instanceof Message ? ctx.author : ctx.user const db = this.container.database const data = await db.statement.findMany() const nsfwData = await db.nsfw_content.findMany() const learnData = await db.learn.findMany() const userData = await db.learn.findMany({ where: { - user_id: msg.author.id, + user_id: user.id, }, }) const muffin: any[] = [] @@ -27,10 +34,18 @@ class LearnDataCommand extends Command { else return }) - await msg.reply(`머핀 데이터: ${muffin.length}개 + await ctx.reply(`머핀 데이터: ${muffin.length}개 nsfw 데이터: ${nsfwData.length}개 지금까지 배운 단어: ${learnData.length}개 -${msg.author.username}님이 가르쳐준 단어: ${userData.length}개`) +${user.username}님이 가르쳐준 단어: ${userData.length}개`) + } + + public async messageRun(msg: Message) { + await this._run(msg) + } + + public async chatInputRun(interaction: ChatInputCommandInteraction) { + await this._run(interaction) } } diff --git a/src/Commands/list.ts b/src/Commands/list.ts index 4e18417..6f0eaa3 100644 --- a/src/Commands/list.ts +++ b/src/Commands/list.ts @@ -1,5 +1,5 @@ +import { ChatInputCommandInteraction, Message, codeBlock } from 'discord.js' import { ApplyOptions } from '@sapphire/decorators' -import { Message, codeBlock } from 'discord.js' import { Command, container } from '@sapphire/framework' @ApplyOptions({ @@ -11,27 +11,34 @@ import { Command, container } from '@sapphire/framework' }, }) class ListCommand extends Command { - public async messageRun(msg: Message) { + public registerApplicationCommands(registry: Command.Registry) { + registry.registerChatInputCommand(builder => + builder.setName(this.name).setDescription(this.description), + ) + } + + private async _run(ctx: Message | ChatInputCommandInteraction) { + const user = ctx instanceof Message ? ctx.author : ctx.user const db = this.container.database const data = await db.learn.findMany({ where: { - user_id: msg.author.id, + user_id: user.id, }, }) const list: string[] = [] if (!data[0]) { - return await msg.reply('당신ㄴ은 단어를 가르쳐준 기억이 없ㅅ는데요.') + return await ctx.reply('당신ㄴ은 단어를 가르쳐준 기억이 없ㅅ는데요.') } for (const listData of data) { list.push(listData.command) } - await msg.reply({ + await ctx.reply({ embeds: [ { - title: `${msg.author.username}님의 지식`, + title: `${user.username}님의 지식`, description: `총합: ${data.length}개\n${codeBlock( 'md', list.map(item => `- ${item}`).join('\n'), @@ -42,6 +49,14 @@ class ListCommand extends Command { ], }) } + + public async messageRun(msg: Message) { + await this._run(msg) + } + + public async chatInputRun(interaction: ChatInputCommandInteraction) { + await this._run(interaction) + } } void container.stores.loadPiece({