BREAKING CHANGE: Config file is now .env file.

This commit is contained in:
Siwoo Jeon 2024-09-22 21:31:34 +09:00
parent 63864b073f
commit 0f664e97fb
Signed by: migan
GPG key ID: 036E9A8C5E8E48DA
11 changed files with 46 additions and 41 deletions

1
.gitignore vendored
View file

@ -79,6 +79,7 @@ web_modules/
.env.test.local .env.test.local
.env.production.local .env.production.local
.env.local .env.local
docker.env
# parcel-bundler cache (https://parceljs.org/) # parcel-bundler cache (https://parceljs.org/)
.cache .cache

View file

@ -1,4 +1,4 @@
FROM node:18.20.3 FROM node:18.20.4
ENV DOCKERIZE_VERSION v0.2.0 ENV DOCKERIZE_VERSION v0.2.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \

View file

@ -1,17 +0,0 @@
{
"bot": {
"owner_ID": "",
"token": "",
"prefix": ""
},
"train": {
"user_ID": ""
},
"mysql": {
"user": "",
"host": "",
"password": "",
"database": "",
"port": 3306
}
}

View file

@ -9,7 +9,7 @@ services:
ports: ports:
- "1502:3306" - "1502:3306"
env_file: env_file:
- "./.env" - "./docker.env"
networks: networks:
- muffin_ai - muffin_ai
discord_bot: discord_bot:
@ -19,6 +19,8 @@ services:
- muffin_ai - muffin_ai
depends_on: depends_on:
- database - database
env_file:
- "./.env"
networks: networks:
muffin_ai: muffin_ai:

5
example-docker.env Normal file
View file

@ -0,0 +1,5 @@
# Docker configs
MYSQL_USER=
MYSQL_PASSWORD=
MYSQL_DATABASE=
MYSQL_ROOT_PASSWORD=

View file

@ -1,8 +1,13 @@
# docker (option) # Prisma configs
MYSQL_USER= # Environment variables declared in this file are automatically made available to Prisma.
MYSQL_PASSWORD= # See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
MYSQL_DATABASE=
MYSQL_ROOT_PASSWORD=
# prisma (require) # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL= DATABASE_URL=
# Bot configs
BOT_TOKEN=
BOT_OWNER_ID=
BOT_PREFIX=
TRAIN_USER_ID=

View file

@ -1,6 +1,6 @@
{ {
"name": "muffinbot", "name": "muffinbot",
"version": "4.0.0-pudding.e240922a", "version": "4.0.0-pudding.e240922b",
"main": "dist/index.js", "main": "dist/index.js",
"private": true, "private": true,
"dependencies": { "dependencies": {
@ -13,6 +13,7 @@
"discord-api-types": "^0.37.100", "discord-api-types": "^0.37.100",
"discord.js": "^14.16.2", "discord.js": "^14.16.2",
"dokdo": "^0.6.2", "dokdo": "^0.6.2",
"dotenv": "^16.4.5",
"mysql2": "^3.11.3", "mysql2": "^3.11.3",
"semver": "^7.6.3", "semver": "^7.6.3",
"undici": "^6.19.8" "undici": "^6.19.8"

View file

@ -1,11 +1,12 @@
import { SapphireClient, container, LogLevel } from '@sapphire/framework' import { SapphireClient, container, LogLevel } from '@sapphire/framework'
import { GatewayIntentBits, Partials, type Snowflake } from 'discord.js' import { GatewayIntentBits, Partials } from 'discord.js'
import { ChatBot, NODE_ENV } from './modules' import { ChatBot, Config, NODE_ENV } from './modules'
import { version } from '../package.json' import { version } from '../package.json'
import { PrismaClient } from '../prisma' import { PrismaClient } from '../prisma'
import config from '../config.json'
import semver from 'semver' import semver from 'semver'
const config = new Config()
// Load pieces // Load pieces
import './interaction-handlers/_load' import './interaction-handlers/_load'
import './listeners/_load' import './listeners/_load'
@ -68,15 +69,7 @@ declare module '@sapphire/framework' {
prefix: string prefix: string
version: string version: string
dokdoAliases: string[] dokdoAliases: string[]
config: { config: Config
bot: {
owner_ID: Snowflake
token: string
}
train: {
user_ID: Snowflake
}
}
release: 'EXPERIMENTAL' | 'DEV' | 'PREVIEW' | 'RELEASE' release: 'EXPERIMENTAL' | 'DEV' | 'PREVIEW' | 'RELEASE'
} }
} }

13
src/modules/config.ts Normal file
View file

@ -0,0 +1,13 @@
import 'dotenv/config'
export default class MAAConfig {
public readonly bot = {
token: process.env.BOT_TOKEN!,
owner_ID: process.env.BOT_OWNER_ID!,
prefix: process.env.BOT_PREFIX!,
}
public readonly train = {
user_id: process.env.TRAIN_USER_ID!,
}
}

View file

@ -1,5 +1,6 @@
import { NODE_ENV } from './env' import { NODE_ENV } from './env'
import ChatBot from './ChatBot' import ChatBot from './ChatBot'
import Config from './config'
import noPerm from './noPerm' import noPerm from './noPerm'
export { NODE_ENV, ChatBot, noPerm } export { NODE_ENV, ChatBot, noPerm, Config }

View file

@ -1823,7 +1823,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"dotenv@npm:^16.3.1": "dotenv@npm:^16.3.1, dotenv@npm:^16.4.5":
version: 16.4.5 version: 16.4.5
resolution: "dotenv@npm:16.4.5" resolution: "dotenv@npm:16.4.5"
checksum: 10c0/48d92870076832af0418b13acd6e5a5a3e83bb00df690d9812e94b24aff62b88ade955ac99a05501305b8dc8f1b0ee7638b18493deb6fe93d680e5220936292f checksum: 10c0/48d92870076832af0418b13acd6e5a5a3e83bb00df690d9812e94b24aff62b88ade955ac99a05501305b8dc8f1b0ee7638b18493deb6fe93d680e5220936292f
@ -3014,6 +3014,7 @@ __metadata:
discord-api-types: "npm:^0.37.100" discord-api-types: "npm:^0.37.100"
discord.js: "npm:^14.16.2" discord.js: "npm:^14.16.2"
dokdo: "npm:^0.6.2" dokdo: "npm:^0.6.2"
dotenv: "npm:^16.4.5"
eslint: "npm:^9.11.0" eslint: "npm:^9.11.0"
eslint-config-prettier: "npm:^9.1.0" eslint-config-prettier: "npm:^9.1.0"
eslint-plugin-prettier: "npm:^5.2.1" eslint-plugin-prettier: "npm:^5.2.1"