From 2517d50bec70d538f79a2610a2766116325d8aa5 Mon Sep 17 00:00:00 2001 From: Migan178 Date: Wed, 26 Jun 2024 20:14:22 +0900 Subject: [PATCH] fix: hard coding --- config.example.json | 3 ++- package.json | 2 +- src/Client.ts | 4 +++- src/Commands/deleteLearn.ts | 10 ++++++++-- src/Commands/help.ts | 10 +++++++--- src/Commands/learn.ts | 22 +++++++++++----------- src/Commands/list.ts | 6 +++--- src/listeners/debug.ts | 2 +- src/listeners/messageCreate.ts | 13 ++++++------- src/listeners/ready.ts | 2 +- src/modules/ChatBot.ts | 2 +- src/modules/wordRelay.ts | 12 ++++++++++++ 12 files changed, 56 insertions(+), 32 deletions(-) create mode 100644 src/modules/wordRelay.ts diff --git a/config.example.json b/config.example.json index 2f2fe89..1e1a924 100644 --- a/config.example.json +++ b/config.example.json @@ -1,7 +1,8 @@ { "bot": { "owner_ID": "", - "token": "" + "token": "", + "prefix": "" }, "train": { "user_ID": "" diff --git a/package.json b/package.json index 696e779..5c59a51 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffinbot", - "version": "3.0.0-cake.d240625a", + "version": "3.0.0-cake.d240626a", "main": "dist/index.js", "private": true, "dependencies": { diff --git a/src/Client.ts b/src/Client.ts index 84e263a..741fe8e 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -5,10 +5,11 @@ import { version } from '../package.json' import config from '../config.json' container.config = config -container.prefix = '머핀아 ' +container.prefix = config.bot.prefix container.version = version container.database = new MaaDatabase() container.chatBot = new ChatBot(container.database) +container.dokdoAliases = ['dokdo', 'dok', 'Dokdo', 'Dok', '테스트'] export default class MuffinBot extends SapphireClient { public constructor() { @@ -38,6 +39,7 @@ declare module '@sapphire/pieces' { chatBot: ChatBot prefix: string version: string + dokdoAliases: string[] config: { bot: { owner_ID: Snowflake diff --git a/src/Commands/deleteLearn.ts b/src/Commands/deleteLearn.ts index 3a79400..2eb7894 100644 --- a/src/Commands/deleteLearn.ts +++ b/src/Commands/deleteLearn.ts @@ -5,7 +5,11 @@ import { codeBlock, } from 'discord.js' import { ApplyOptions } from '@sapphire/decorators' -import { Args, Command } from '@sapphire/framework' +import { + Args, + Command, + DetailedDescriptionCommandObject, +} from '@sapphire/framework' import { type LearnData } from '../modules' @ApplyOptions({ @@ -28,7 +32,9 @@ export default class extends Command { ) if (!command) { - return await msg.channel.send('사용법: \n```머핀아 삭제 (지울 단어)```') + return await msg.channel.send( + `사용법: \n\`\`\`${(this.detailedDescription as DetailedDescriptionCommandObject).usage}\`\`\``, + ) } if (!datas) { diff --git a/src/Commands/help.ts b/src/Commands/help.ts index e50d4ba..3107516 100644 --- a/src/Commands/help.ts +++ b/src/Commands/help.ts @@ -21,13 +21,13 @@ export default class extends Command { const commandList: string[] = [] this.container.stores.get('commands').forEach(module => { - commandList.push(module.name) + commandList.push(`${module.name} - ${module.description}`) }) await msg.reply({ embeds: [ { - title: '머핀봇의 도움말', + title: `${this.container.client.user?.username}의 도움말`, description: codeBlock( 'md', commandList.map(item => `- ${item}`).join('\n'), @@ -35,6 +35,7 @@ export default class extends Command { footer: { text: `머핀봇 버전: ${this.container.version}`, }, + timestamp: new Date().toISOString(), }, ], }) @@ -46,7 +47,7 @@ export default class extends Command { await msg.reply({ embeds: [ { - title: '머핀봇의 도움말', + title: `${this.container.client.user?.username}의 도움말`, description: `명령어: ${name}`, fields: [ { @@ -76,6 +77,9 @@ export default class extends Command { inline: false, }, ], + footer: { + text: `머핀봇 버전: ${this.container.version}`, + }, timestamp: new Date().toISOString(), }, ], diff --git a/src/Commands/learn.ts b/src/Commands/learn.ts index 0a1c603..c39f983 100644 --- a/src/Commands/learn.ts +++ b/src/Commands/learn.ts @@ -1,6 +1,6 @@ -import { Args, Command } from '@sapphire/framework' +import { type Args, Command } from '@sapphire/framework' +import { codeBlock, type Message } from 'discord.js' import { ApplyOptions } from '@sapphire/decorators' -import { type Message } from 'discord.js' @ApplyOptions({ name: '배워', @@ -17,6 +17,7 @@ import { type Message } from 'discord.js' }) export default class extends Command { public async messageRun(msg: Message, args: Args) { + if (typeof this.detailedDescription === 'string') return const config = this.container.config const command = (await args.pick('string').catch(() => null))?.replaceAll( '_', @@ -28,28 +29,27 @@ export default class extends Command { ) if (!command || !result) { return await msg.reply( - '```\n사용법: 머핀아 배워 (등록할 단어) (대답)\n예시:\n머핀아 배워 안녕 안녕!\n머핀아 배워 "야 죽을래?" "아니요 ㅠㅠㅠ"\n머핀아 배워 미간은_누구야? 이봇의_개발자요\n```', + codeBlock( + 'md', + `사용법: ${this.detailedDescription} + 예시: ${this.detailedDescription.examples?.map(example => example).join('\n')}`, + ), ) } const commands: string[] = [] const aliases: string[] = [] this.container.stores.get('commands').forEach(module => { commands.push(module.name) - module.aliases.forEach(alias => { - aliases.push(alias) - }) + module.aliases.forEach(alias => aliases.push(alias)) }) const ignore = [ ...commands, ...aliases, + ...this.container.dokdoAliases, '미간', 'Migan', 'migan', '간미', - 'dokdo', - 'dok', - 'Dokdo', - 'Dok', ] const disallowed = ['@everyone', '@here', `<@${config.bot.owner_ID}>`] const db = this.container.database @@ -67,9 +67,9 @@ export default class extends Command { } await db.learn.insert({ + user_id: msg.author.id, command, result, - user_id: msg.author.id, }) await msg.reply(`${command}을/를 배웠ㅇ어요.`) } diff --git a/src/Commands/list.ts b/src/Commands/list.ts index 5940118..7b7a3b5 100644 --- a/src/Commands/list.ts +++ b/src/Commands/list.ts @@ -7,8 +7,8 @@ import { Command } from '@sapphire/framework' aliases: ['list', '목록'], description: '당신이 가ㄹ르쳐준 단어를 나열해요.', detailedDescription: { - usage: '머핀아 리스트' - } + usage: '머핀아 리스트', + }, }) export default class extends Command { public async messageRun(msg: Message) { @@ -29,7 +29,7 @@ export default class extends Command { await msg.reply({ embeds: [ { - title: '지식', + title: `${msg.author.username}님의 지식`, description: `총합: ${data.length}개\n${codeBlock( 'md', list.map(item => `- ${item}`).join('\n'), diff --git a/src/listeners/debug.ts b/src/listeners/debug.ts index 4f73e61..e1a36dd 100644 --- a/src/listeners/debug.ts +++ b/src/listeners/debug.ts @@ -2,6 +2,6 @@ import { Listener } from '@sapphire/framework' export default class extends Listener { public async run(debug: string) { - this.container.logger.debug(debug) + this.container.logger.debug(`[MuffinBot] ${debug}`) } } diff --git a/src/listeners/messageCreate.ts b/src/listeners/messageCreate.ts index 6a59d93..be91cda 100644 --- a/src/listeners/messageCreate.ts +++ b/src/listeners/messageCreate.ts @@ -5,21 +5,20 @@ import Dokdo from 'dokdo' export default class extends Listener { public async run(msg: Message) { + const prefix = this.container.prefix const dokdo = new Dokdo(this.container.client, { aliases: ['dokdo', 'dok'], owners: [this.container.config.bot.owner_ID], + prefix: prefix, noPerm, - prefix: this.container.prefix, }) if (msg.author.bot) return - if (msg.content.startsWith(this.container.prefix)) { - const args = msg.content - .slice(this.container.prefix.length) - .trim() - .split(/ +/g) + if (msg.content.startsWith(prefix)) { + const args = msg.content.slice(prefix.length).trim().split(/ +/g) this.container.logger.debug(`[ChatBot] command: ${args.join(' ')}`) - if (args[0].startsWith('dokdo') || args[0].startsWith('dok')) { + + if (dokdo.options.aliases?.includes(args[0])) { await dokdo.run(msg) } else { if (!this.container.stores.get('commands').get(args[0])) { diff --git a/src/listeners/ready.ts b/src/listeners/ready.ts index 1d39733..f4be793 100644 --- a/src/listeners/ready.ts +++ b/src/listeners/ready.ts @@ -15,6 +15,6 @@ export default class extends Listener { setStatus() setInterval(() => setStatus(), 600000) - this.container.logger.info(`[MuffinBotClient] 먹힐 준ㅂ비 완료`) + this.container.logger.info(`[MuffinBot] 먹힐 준ㅂ비 완료`) } } diff --git a/src/modules/ChatBot.ts b/src/modules/ChatBot.ts index 0219c58..a425696 100644 --- a/src/modules/ChatBot.ts +++ b/src/modules/ChatBot.ts @@ -59,7 +59,7 @@ export default class ChatBot { if (!(msg.channel as TextChannel).nsfw) return if (!msg.content.startsWith(prefix)) return const persona = `user:${msg.author.username.slice(0, 50).toLowerCase()}` - const text = msg.content.replace('머핀아 ', '') + const text = msg.content.replace(prefix, '') await this.db.nsfwContent.insert({ text, persona, diff --git a/src/modules/wordRelay.ts b/src/modules/wordRelay.ts new file mode 100644 index 0000000..bea4b91 --- /dev/null +++ b/src/modules/wordRelay.ts @@ -0,0 +1,12 @@ +import { type Message, PermissionFlagsBits } from 'discord.js' + +export class WordRelay { + public async startGame(msg: Message) { + if ( + msg.guild.members.me?.permissions.has( + PermissionFlagsBits.CreatePublicThreads, + ) + ) + return msg.reply('제게 공개 스레드 만들기 권한ㅇ이 없어요.') + } +}