From 0f7f1d72725fa00b83b97c1179946946f8ccd91d Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Tue, 1 Oct 2024 17:22:03 +0900 Subject: [PATCH] feat: Add using slash command preview warning message --- package.json | 2 +- src/listeners/_load.ts | 1 + src/listeners/interactionCreate.ts | 18 ++++++++++++++++++ src/listeners/messageCreate.ts | 20 +++----------------- src/modules/index.ts | 3 ++- src/modules/previewWarning.ts | 21 +++++++++++++++++++++ 6 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 src/listeners/interactionCreate.ts create mode 100644 src/modules/previewWarning.ts diff --git a/package.json b/package.json index d234f84..92302bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffinbot", - "version": "4.0.0-pudding.d241001a", + "version": "4.0.0-pudding.d241001b", "main": "dist/index.js", "private": true, "dependencies": { diff --git a/src/listeners/_load.ts b/src/listeners/_load.ts index d3aef81..d63c6fb 100644 --- a/src/listeners/_load.ts +++ b/src/listeners/_load.ts @@ -1,3 +1,4 @@ +import './interactionCreate' import './messageCreate' import './debug' import './ready' diff --git a/src/listeners/interactionCreate.ts b/src/listeners/interactionCreate.ts new file mode 100644 index 0000000..5cd22f6 --- /dev/null +++ b/src/listeners/interactionCreate.ts @@ -0,0 +1,18 @@ +import { container, Listener } from '@sapphire/framework' +import { ChatInputCommandInteraction } from 'discord.js' +import { previewWarning } from '../modules' + +class InteractionCreateListener extends Listener { + public async run(interaction: ChatInputCommandInteraction<'cached'>) { + if (interaction.isChatInputCommand()) { + if (this.container.channel !== 'RELEASE') + await previewWarning(interaction) + } + } +} + +void container.stores.loadPiece({ + piece: InteractionCreateListener, + name: 'interactionCreate', + store: 'listeners' +}) diff --git a/src/listeners/messageCreate.ts b/src/listeners/messageCreate.ts index 9106331..96e1d51 100644 --- a/src/listeners/messageCreate.ts +++ b/src/listeners/messageCreate.ts @@ -1,6 +1,6 @@ import { Listener, container } from '@sapphire/framework' import { type Message } from 'discord.js' -import { noPerm } from '../modules' +import { noPerm, previewWarning } from '../modules' import { Client } from 'dokdo' class MessageCreateListener extends Listener { @@ -14,22 +14,8 @@ class MessageCreateListener extends Listener { }) if (msg.author.bot) return if (msg.content.startsWith(prefix)) { - if (this.container.channel !== 'RELEASE') { - await msg.reply({ - embeds: [ - { - title: '정식 출시 이전 버전 사용안내', - description: - `현재 이 버전의 ${this.container.client.user?.username}은 정식출시 되기 이전이라 많이 불안정할 수 있어요.\n` + - `만약 오류가 발견되면 ${(await this.container.client.users.fetch(this.container.config.bot.owner_ID)).username}님에게 알려주세요.\n`, - color: 0xff0000, - footer: { - text: `현재 채널: ${this.container.channel.toLowerCase()} 버전: ${this.container.version}`, - }, - }, - ], - }) - } + if (this.container.channel !== 'RELEASE') await previewWarning(msg) + const args = msg.content.slice(prefix.length).trim().split(/ +/g) this.container.logger.debug(`[ChatBot] command: ${args.join(' ')}`) diff --git a/src/modules/index.ts b/src/modules/index.ts index 32d83f7..ed2989a 100644 --- a/src/modules/index.ts +++ b/src/modules/index.ts @@ -1,6 +1,7 @@ +import previewWarning from './previewWarning' import { NODE_ENV } from './env' import ChatBot from './ChatBot' import Config from './config' import noPerm from './noPerm' -export { NODE_ENV, ChatBot, noPerm, Config } +export { NODE_ENV, ChatBot, noPerm, Config, previewWarning } diff --git a/src/modules/previewWarning.ts b/src/modules/previewWarning.ts new file mode 100644 index 0000000..6aaf4c2 --- /dev/null +++ b/src/modules/previewWarning.ts @@ -0,0 +1,21 @@ +import type { ChatInputCommandInteraction, Message } from 'discord.js' +import { container } from '@sapphire/framework' + +export default async function previewWarning( + ctx: Message | ChatInputCommandInteraction<'cached'>, +) { + await ctx.channel!.send({ + embeds: [ + { + title: '정식 출시 이전 버전 사용안내', + description: + `현재 이 버전의 ${container.client.user?.username}은 정식출시 되기 이전이라 많이 불안정할 수 있어요.\n` + + `만약 오류가 발견되면 ${(await container.client.users.fetch(container.config.bot.owner_ID)).username}님에게 알려주세요.\n`, + color: 0xff0000, + footer: { + text: `현재 채널: ${container.channel.toLowerCase()} 버전: ${container.version}`, + }, + }, + ], + }) +}