From 8263ad06b96ef34b131b3f29f9f332bc0cb8e39a Mon Sep 17 00:00:00 2001 From: Migan178 Date: Sun, 23 Jun 2024 15:16:54 +0900 Subject: [PATCH] feat: Feture add help command --- package.json | 2 +- src/Client.ts | 10 ++++ src/Commands/deleteLearn.ts | 6 ++- src/Commands/help.ts | 90 +++++++++++++++++++++++++++-------- src/Commands/learn.ts | 8 ++++ src/Commands/learning_data.ts | 3 ++ src/Commands/list.ts | 3 ++ 7 files changed, 100 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 4b79ef5..7cd6efc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffinbot", - "version": "3.0.0-cake.d240622b", + "version": "3.0.0-cake.d240623a", "main": "dist/index.js", "private": true, "dependencies": { diff --git a/src/Client.ts b/src/Client.ts index 887e72a..84e263a 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1,10 +1,12 @@ import { SapphireClient, container, LogLevel } from '@sapphire/framework' import { GatewayIntentBits, type Snowflake } from 'discord.js' import { ChatBot, NODE_ENV, MaaDatabase } from './modules' +import { version } from '../package.json' import config from '../config.json' container.config = config container.prefix = '머핀아 ' +container.version = version container.database = new MaaDatabase() container.chatBot = new ChatBot(container.database) @@ -35,6 +37,7 @@ declare module '@sapphire/pieces' { database: MaaDatabase chatBot: ChatBot prefix: string + version: string config: { bot: { owner_ID: Snowflake @@ -53,3 +56,10 @@ declare module '@sapphire/pieces' { } } } + +declare module '@sapphire/framework' { + interface DetailedDescriptionCommandObject { + usage: string + examples?: string[] + } +} diff --git a/src/Commands/deleteLearn.ts b/src/Commands/deleteLearn.ts index bb868b5..a400bee 100644 --- a/src/Commands/deleteLearn.ts +++ b/src/Commands/deleteLearn.ts @@ -6,7 +6,11 @@ import { type Message } from 'discord.js' @ApplyOptions({ name: '삭제', aliases: ['지워', '잊어'], - description: '배운 단어를 삭ㅈ제해요.' + description: '배운 단어를 삭ㅈ제해요.', + detailedDescription: { + usage: '머핀아 삭제 (삭제할 단어)', + examples: ['머핀아 삭제 머핀'], + }, }) export default class extends Command { public async messageRun(msg: Message, args: Args) { diff --git a/src/Commands/help.ts b/src/Commands/help.ts index e6a52f4..4a2867b 100644 --- a/src/Commands/help.ts +++ b/src/Commands/help.ts @@ -1,34 +1,84 @@ import { codeBlock, type Message } from 'discord.js' import { ApplyOptions } from '@sapphire/decorators' -import { Command } from '@sapphire/framework' -import { version } from '../../package.json' +import { Args, Command } from '@sapphire/framework' @ApplyOptions({ name: '도움말', aliases: ['명령어', '도움', 'help'], description: '기본적인 사용ㅂ법이에요.', + detailedDescription: { + usage: '머핀아 도움말 [명령어]', + examples: ['머핀아 도움말', '머핀아 도움말 배워'], + }, }) export default class extends Command { - public async messageRun(msg: Message) { - const commandList: string[] = [] + public async messageRun(msg: Message, args: Args) { + const commandName = await args.pick('string').catch(() => null) + if ( + !commandName || + !this.container.stores.get('commands').get(commandName) + ) { + const commandList: string[] = [] - this.container.stores.get('commands').forEach(module => { - commandList.push(module.name) - }) + this.container.stores.get('commands').forEach(module => { + commandList.push(module.name) + }) - await msg.reply({ - embeds: [ - { - title: '머핀봇의 도움말', - description: codeBlock( - 'md', - commandList.map(item => `- ${item}`).join('\n'), - ), - footer: { - text: `머핀봇 버전: ${version}`, + await msg.reply({ + embeds: [ + { + title: '머핀봇의 도움말', + description: codeBlock( + 'md', + commandList.map(item => `- ${item}`).join('\n'), + ), + footer: { + text: `머핀봇 버전: ${this.container.version}`, + }, }, - }, - ], - }) + ], + }) + } else { + const { name, aliases, description, detailedDescription } = + this.container.stores.get('commands').get(commandName)! + if (typeof detailedDescription === 'string') return + + await msg.reply({ + embeds: [ + { + title: '머핀봇의 도움말', + description: `명령어: ${name}`, + fields: [ + { + name: '설명', + value: description, + inline: true, + }, + { + name: '별칭', + value: aliases.map(item => `\`${item}\``).join(', '), + inline: true, + }, + { + name: '사용법', + value: `\`${detailedDescription.usage}\``, + inline: true, + }, + detailedDescription.examples + ? { + name: '예시', + value: `\`\`\`${detailedDescription.examples.map(item => item).join('\n')}\`\`\``, + inline: false, + } + : { + name: '예시', + value: '없음', + inline: false, + }, + ], + }, + ], + }) + } } } diff --git a/src/Commands/learn.ts b/src/Commands/learn.ts index 6b9f52d..cde1760 100644 --- a/src/Commands/learn.ts +++ b/src/Commands/learn.ts @@ -6,6 +6,14 @@ import { type Message } from 'discord.js' name: '배워', aliases: ['공부'], description: '단어를 가르치는 명령ㅇ어에요.', + detailedDescription: { + usage: '머핀아 배워 (등록할 단어) (대답)', + examples: [ + '머핀아 배워 안녕 안녕!', + '머핀아 배워 "야 죽을래?" "아니요 ㅠㅠㅠ"', + '머핀아 배워 미간은_누구야? 이봇의_개발자요', + ], + }, }) export default class extends Command { public async messageRun(msg: Message, args: Args) { diff --git a/src/Commands/learning_data.ts b/src/Commands/learning_data.ts index 4e31790..ac732c4 100644 --- a/src/Commands/learning_data.ts +++ b/src/Commands/learning_data.ts @@ -7,6 +7,9 @@ import { type Message } from 'discord.js' name: '데이터학습량', aliases: ['학습데이터량', '데이터량'], description: '봇이 학습한 데ㅇ이터량을 보여줘요.', + detailedDescription: { + usage: '머핀아 학습데이터량', + }, }) export default class extends Command { public async messageRun(msg: Message) { diff --git a/src/Commands/list.ts b/src/Commands/list.ts index d78b68b..5940118 100644 --- a/src/Commands/list.ts +++ b/src/Commands/list.ts @@ -6,6 +6,9 @@ import { Command } from '@sapphire/framework' name: '리스트', aliases: ['list', '목록'], description: '당신이 가ㄹ르쳐준 단어를 나열해요.', + detailedDescription: { + usage: '머핀아 리스트' + } }) export default class extends Command { public async messageRun(msg: Message) {