diff --git a/package.json b/package.json index cf66f8f..5a4a603 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffinbot", - "version": "4.0.0-pudding.p241018a", + "version": "4.0.0-pudding.p241027a", "main": "dist/src/index.js", "private": true, "dependencies": { diff --git a/src/client.ts b/src/client.ts index c5a6c82..69e216d 100644 --- a/src/client.ts +++ b/src/client.ts @@ -65,8 +65,13 @@ export default class MuffinBot extends SapphireClient { } public override async login(): Promise { - if (container.channel === 'RELEASE') await container.chatBot.train(this) - else { + if (container.channel === 'RELEASE') { + if (!config.train.user_ID) + container.logger.info( + '[MuffinBot] .env파일에 TRAIN_USER_ID값이 없어서 학습 기능이 꺼졌어요.', + ) + else await container.chatBot.train(this) + } else { container.logger.info( '[MuffinBot] 해당 채널은 RELEASE 채널이 아니라서 학습 기능이 꺼졌습니다.', ) diff --git a/src/modules/config.ts b/src/modules/config.ts index c6f3ace..bcadae6 100644 --- a/src/modules/config.ts +++ b/src/modules/config.ts @@ -1,13 +1,22 @@ import 'dotenv/config' +function getConfigValue( + value: 'BOT_TOKEN' | 'BOT_OWNER_ID' | 'BOT_PREFIX', +) { + const configValue = process.env[value] + if (!configValue) + throw new Error(`.env 파일에서 ${value}값을 찾을 수 없어요.`) + return configValue +} + export default class MAAConfig { public readonly bot = { - token: process.env.BOT_TOKEN!, - owner_ID: process.env.BOT_OWNER_ID!, - prefix: process.env.BOT_PREFIX!, + token: getConfigValue('BOT_TOKEN'), + owner_ID: getConfigValue('BOT_OWNER_ID'), + prefix: getConfigValue('BOT_PREFIX'), } public readonly train = { - user_ID: process.env.TRAIN_USER_ID!, + user_ID: process.env.TRAIN_USER_ID, } }