From 13762b85f608871e674dd417f2fae8cfc814fe54 Mon Sep 17 00:00:00 2001 From: Migan178 Date: Sat, 3 Aug 2024 19:21:06 +0900 Subject: [PATCH] feat: Manually load pieces reason: Some environment can't load pieces. --- src/Client.ts | 5 +++++ src/Commands/_load.ts | 5 +++++ src/Commands/deleteLearn.ts | 19 +++++++++++++------ src/Commands/help.ts | 10 ++++++++-- src/Commands/learn.ts | 10 ++++++++-- src/Commands/learning_data.ts | 10 ++++++++-- src/Commands/list.ts | 10 ++++++++-- src/interaction-handlers/_load.ts | 1 + src/interaction-handlers/deleteLearn.ts | 9 ++++++++- src/listeners/_load.ts | 3 +++ src/listeners/debug.ts | 10 ++++++++-- src/listeners/messageCreate.ts | 10 ++++++++-- src/listeners/ready.ts | 10 ++++++++-- tsup.config.ts | 7 +------ 14 files changed, 92 insertions(+), 27 deletions(-) create mode 100644 src/Commands/_load.ts create mode 100644 src/interaction-handlers/_load.ts create mode 100644 src/listeners/_load.ts diff --git a/src/Client.ts b/src/Client.ts index 5ecbe8d..4287b0b 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -5,6 +5,10 @@ import { version } from '../package.json' import config from '../config.json' import semver from 'semver' +import './interaction-handlers/_load' +import './listeners/_load' +import './Commands/_load' + container.config = config container.prefix = config.bot.prefix container.version = version @@ -43,6 +47,7 @@ export default class MuffinBot extends SapphireClient { repliedUser: true, }, partials: [Partials.Message, Partials.ThreadMember], + baseUserDirectory: null, }) } diff --git a/src/Commands/_load.ts b/src/Commands/_load.ts new file mode 100644 index 0000000..b8bf690 --- /dev/null +++ b/src/Commands/_load.ts @@ -0,0 +1,5 @@ +import './learning_data' +import './deleteLearn' +import './learn' +import './help' +import './list' diff --git a/src/Commands/deleteLearn.ts b/src/Commands/deleteLearn.ts index 2eb7894..b463d4f 100644 --- a/src/Commands/deleteLearn.ts +++ b/src/Commands/deleteLearn.ts @@ -1,3 +1,9 @@ +import { + Args, + Command, + container, + DetailedDescriptionCommandObject, +} from '@sapphire/framework' import { type SelectMenuComponentOptionData, type Message, @@ -5,11 +11,6 @@ import { codeBlock, } from 'discord.js' import { ApplyOptions } from '@sapphire/decorators' -import { - Args, - Command, - DetailedDescriptionCommandObject, -} from '@sapphire/framework' import { type LearnData } from '../modules' @ApplyOptions({ @@ -21,7 +22,7 @@ import { type LearnData } from '../modules' examples: ['머핀아 삭제 머핀'], }, }) -export default class extends Command { +class DeleteLearnCommand extends Command { public async messageRun(msg: Message, args: Args) { const command = await args.rest('string').catch(() => null) const options: SelectMenuComponentOptionData[] = [] @@ -77,3 +78,9 @@ export default class extends Command { }) } } + +void container.stores.loadPiece({ + piece: DeleteLearnCommand, + name: 'delete', + store: 'commands', +}) diff --git a/src/Commands/help.ts b/src/Commands/help.ts index 3107516..ea228a6 100644 --- a/src/Commands/help.ts +++ b/src/Commands/help.ts @@ -1,6 +1,6 @@ +import { Args, Command, container } from '@sapphire/framework' import { codeBlock, type Message } from 'discord.js' import { ApplyOptions } from '@sapphire/decorators' -import { Args, Command } from '@sapphire/framework' @ApplyOptions({ name: '도움말', @@ -11,7 +11,7 @@ import { Args, Command } from '@sapphire/framework' examples: ['머핀아 도움말', '머핀아 도움말 배워'], }, }) -export default class extends Command { +class HelpCommand extends Command { public async messageRun(msg: Message, args: Args) { const commandName = await args.pick('string').catch(() => null) if ( @@ -87,3 +87,9 @@ export default class extends Command { } } } + +void container.stores.loadPiece({ + piece: HelpCommand, + name: 'help', + store: 'commands', +}) diff --git a/src/Commands/learn.ts b/src/Commands/learn.ts index c39f983..ecf6445 100644 --- a/src/Commands/learn.ts +++ b/src/Commands/learn.ts @@ -1,4 +1,4 @@ -import { type Args, Command } from '@sapphire/framework' +import { type Args, Command, container } from '@sapphire/framework' import { codeBlock, type Message } from 'discord.js' import { ApplyOptions } from '@sapphire/decorators' @@ -15,7 +15,7 @@ import { ApplyOptions } from '@sapphire/decorators' ], }, }) -export default class extends Command { +class LearnCommand extends Command { public async messageRun(msg: Message, args: Args) { if (typeof this.detailedDescription === 'string') return const config = this.container.config @@ -74,3 +74,9 @@ export default class extends Command { await msg.reply(`${command}을/를 배웠ㅇ어요.`) } } + +void container.stores.loadPiece({ + piece: LearnCommand, + name: 'learn', + store: 'commands', +}) diff --git a/src/Commands/learning_data.ts b/src/Commands/learning_data.ts index ac732c4..76b6ba0 100644 --- a/src/Commands/learning_data.ts +++ b/src/Commands/learning_data.ts @@ -1,6 +1,6 @@ import { ApplyOptions } from '@sapphire/decorators' import { type ResponseData } from '../modules' -import { Command } from '@sapphire/framework' +import { Command, container } from '@sapphire/framework' import { type Message } from 'discord.js' @ApplyOptions({ @@ -11,7 +11,7 @@ import { type Message } from 'discord.js' usage: '머핀아 학습데이터량', }, }) -export default class extends Command { +class LearnDataCommand extends Command { public async messageRun(msg: Message) { const db = this.container.database const data = await db.statement.all() @@ -30,3 +30,9 @@ nsfw 데이터: ${nsfwData.length}개 ${msg.author.username}님이 가르쳐준 단어: ${userData.length}개`) } } + +void container.stores.loadPiece({ + piece: LearnDataCommand, + name: 'learn_data', + store: 'commands', +}) diff --git a/src/Commands/list.ts b/src/Commands/list.ts index 7b7a3b5..562e521 100644 --- a/src/Commands/list.ts +++ b/src/Commands/list.ts @@ -1,6 +1,6 @@ import { ApplyOptions } from '@sapphire/decorators' import { Message, codeBlock } from 'discord.js' -import { Command } from '@sapphire/framework' +import { Command, container } from '@sapphire/framework' @ApplyOptions({ name: '리스트', @@ -10,7 +10,7 @@ import { Command } from '@sapphire/framework' usage: '머핀아 리스트', }, }) -export default class extends Command { +class ListCommand extends Command { public async messageRun(msg: Message) { const db = this.container.database const data = await db.learn.findOneAnotherKey('user_id', msg.author.id) @@ -41,3 +41,9 @@ export default class extends Command { }) } } + +void container.stores.loadPiece({ + piece: ListCommand, + name: 'list', + store: 'commands', +}) diff --git a/src/interaction-handlers/_load.ts b/src/interaction-handlers/_load.ts new file mode 100644 index 0000000..338146d --- /dev/null +++ b/src/interaction-handlers/_load.ts @@ -0,0 +1 @@ +import './deleteLearn' diff --git a/src/interaction-handlers/deleteLearn.ts b/src/interaction-handlers/deleteLearn.ts index abbc485..9ed06e4 100644 --- a/src/interaction-handlers/deleteLearn.ts +++ b/src/interaction-handlers/deleteLearn.ts @@ -1,4 +1,5 @@ import { + container, InteractionHandler, InteractionHandlerTypes, } from '@sapphire/framework' @@ -8,7 +9,7 @@ import { ApplyOptions } from '@sapphire/decorators' @ApplyOptions({ interactionHandlerType: InteractionHandlerTypes.SelectMenu, }) -export default class extends InteractionHandler { +class DeleteLearnHandler extends InteractionHandler { public async parse(interaction: StringSelectMenuInteraction) { if (interaction.customId !== 'maa$deleteLearn') return this.none() return this.some() @@ -34,3 +35,9 @@ export default class extends InteractionHandler { }) } } + +void container.stores.loadPiece({ + piece: DeleteLearnHandler, + name: 'deleteLearn', + store: 'interaction-handlers', +}) diff --git a/src/listeners/_load.ts b/src/listeners/_load.ts new file mode 100644 index 0000000..d3aef81 --- /dev/null +++ b/src/listeners/_load.ts @@ -0,0 +1,3 @@ +import './messageCreate' +import './debug' +import './ready' diff --git a/src/listeners/debug.ts b/src/listeners/debug.ts index e1a36dd..fcea723 100644 --- a/src/listeners/debug.ts +++ b/src/listeners/debug.ts @@ -1,7 +1,13 @@ -import { Listener } from '@sapphire/framework' +import { Listener, container } from '@sapphire/framework' -export default class extends Listener { +class DebugListener extends Listener { public async run(debug: string) { this.container.logger.debug(`[MuffinBot] ${debug}`) } } + +void container.stores.loadPiece({ + piece: DebugListener, + name: 'debug', + store: 'listeners', +}) diff --git a/src/listeners/messageCreate.ts b/src/listeners/messageCreate.ts index 60b839f..b6cd727 100644 --- a/src/listeners/messageCreate.ts +++ b/src/listeners/messageCreate.ts @@ -1,9 +1,9 @@ -import { Listener } from '@sapphire/framework' +import { Listener, container } from '@sapphire/framework' import { type Message } from 'discord.js' import { noPerm } from '../modules' import Dokdo from 'dokdo' -export default class extends Listener { +class MessageCreateListener extends Listener { public async run(msg: Message) { const prefix = this.container.prefix const dokdo = new Dokdo(this.container.client, { @@ -46,3 +46,9 @@ export default class extends Listener { } } } + +void container.stores.loadPiece({ + piece: MessageCreateListener, + name: 'messageCreate', + store: 'listeners', +}) diff --git a/src/listeners/ready.ts b/src/listeners/ready.ts index f4be793..64bf632 100644 --- a/src/listeners/ready.ts +++ b/src/listeners/ready.ts @@ -1,9 +1,9 @@ +import { container, Listener } from '@sapphire/framework' import { ApplyOptions } from '@sapphire/decorators' -import { Listener } from '@sapphire/framework' import { ActivityType, Client } from 'discord.js' @ApplyOptions({ once: true }) -export default class extends Listener { +class ClientReadyListener extends Listener { public async run(client: Client) { function setStatus() { client.user.setActivity({ @@ -18,3 +18,9 @@ export default class extends Listener { this.container.logger.info(`[MuffinBot] 먹힐 준ㅂ비 완료`) } } + +void container.stores.loadPiece({ + piece: ClientReadyListener, + name: 'ready', + store: 'listeners', +}) diff --git a/tsup.config.ts b/tsup.config.ts index 5c59f20..a92db36 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -5,12 +5,7 @@ const sourcemap = process.env.NODE_ENV === 'development' ? true : false export default defineConfig({ clean: true, format: ['cjs'], - entry: [ - 'src/index.ts', - 'src/Commands/*.ts', - 'src/listeners/*.ts', - 'src/interaction-handlers/*.ts', - ], + entry: ['src/index.ts'], minify: true, sourcemap, })