diff --git a/.gitignore b/.gitignore index 8165879..68b9a93 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,7 @@ web_modules/ .env.test.local .env.production.local .env.local +docker.env # parcel-bundler cache (https://parceljs.org/) .cache diff --git a/Dockerfile b/Dockerfile index d500741..0d21de5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18.20.3 +FROM node:18.20.4 ENV DOCKERIZE_VERSION v0.2.0 RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ diff --git a/config.example.json b/config.example.json deleted file mode 100644 index 1e1a924..0000000 --- a/config.example.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "bot": { - "owner_ID": "", - "token": "", - "prefix": "" - }, - "train": { - "user_ID": "" - }, - "mysql": { - "user": "", - "host": "", - "password": "", - "database": "", - "port": 3306 - } -} diff --git a/docker-compose.yml b/docker-compose.yml index 36aaa6c..02b5aae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: ports: - "1502:3306" env_file: - - "./.env" + - "./docker.env" networks: - muffin_ai discord_bot: @@ -19,6 +19,8 @@ services: - muffin_ai depends_on: - database + env_file: + - "./.env" networks: muffin_ai: diff --git a/example-docker.env b/example-docker.env new file mode 100644 index 0000000..c374e75 --- /dev/null +++ b/example-docker.env @@ -0,0 +1,5 @@ +# Docker configs +MYSQL_USER= +MYSQL_PASSWORD= +MYSQL_DATABASE= +MYSQL_ROOT_PASSWORD= diff --git a/example.env b/example.env index 83da920..228d83f 100644 --- a/example.env +++ b/example.env @@ -1,8 +1,13 @@ -# docker (option) -MYSQL_USER= -MYSQL_PASSWORD= -MYSQL_DATABASE= -MYSQL_ROOT_PASSWORD= +# Prisma configs +# Environment variables declared in this file are automatically made available to Prisma. +# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema -# prisma (require) -DATABASE_URL= \ No newline at end of file +# 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= + +# Bot configs +BOT_TOKEN= +BOT_OWNER_ID= +BOT_PREFIX= +TRAIN_USER_ID= diff --git a/package.json b/package.json index 38fb064..21678cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffinbot", - "version": "4.0.0-pudding.e240922a", + "version": "4.0.0-pudding.e240922b", "main": "dist/index.js", "private": true, "dependencies": { @@ -13,6 +13,7 @@ "discord-api-types": "^0.37.100", "discord.js": "^14.16.2", "dokdo": "^0.6.2", + "dotenv": "^16.4.5", "mysql2": "^3.11.3", "semver": "^7.6.3", "undici": "^6.19.8" diff --git a/src/Client.ts b/src/Client.ts index 2f96ca6..9e52d82 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1,11 +1,12 @@ import { SapphireClient, container, LogLevel } from '@sapphire/framework' -import { GatewayIntentBits, Partials, type Snowflake } from 'discord.js' -import { ChatBot, NODE_ENV } from './modules' +import { GatewayIntentBits, Partials } from 'discord.js' +import { ChatBot, Config, NODE_ENV } from './modules' import { version } from '../package.json' import { PrismaClient } from '../prisma' -import config from '../config.json' import semver from 'semver' +const config = new Config() + // Load pieces import './interaction-handlers/_load' import './listeners/_load' @@ -68,15 +69,7 @@ declare module '@sapphire/framework' { prefix: string version: string dokdoAliases: string[] - config: { - bot: { - owner_ID: Snowflake - token: string - } - train: { - user_ID: Snowflake - } - } + config: Config release: 'EXPERIMENTAL' | 'DEV' | 'PREVIEW' | 'RELEASE' } } diff --git a/src/modules/config.ts b/src/modules/config.ts new file mode 100644 index 0000000..9d08998 --- /dev/null +++ b/src/modules/config.ts @@ -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!, + } +} diff --git a/src/modules/index.ts b/src/modules/index.ts index 42df732..32d83f7 100644 --- a/src/modules/index.ts +++ b/src/modules/index.ts @@ -1,5 +1,6 @@ import { NODE_ENV } from './env' import ChatBot from './ChatBot' +import Config from './config' import noPerm from './noPerm' -export { NODE_ENV, ChatBot, noPerm } +export { NODE_ENV, ChatBot, noPerm, Config } diff --git a/yarn.lock b/yarn.lock index be97664..aca5a74 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1823,7 +1823,7 @@ __metadata: languageName: node linkType: hard -"dotenv@npm:^16.3.1": +"dotenv@npm:^16.3.1, dotenv@npm:^16.4.5": version: 16.4.5 resolution: "dotenv@npm:16.4.5" checksum: 10c0/48d92870076832af0418b13acd6e5a5a3e83bb00df690d9812e94b24aff62b88ade955ac99a05501305b8dc8f1b0ee7638b18493deb6fe93d680e5220936292f @@ -3014,6 +3014,7 @@ __metadata: discord-api-types: "npm:^0.37.100" discord.js: "npm:^14.16.2" dokdo: "npm:^0.6.2" + dotenv: "npm:^16.4.5" eslint: "npm:^9.11.0" eslint-config-prettier: "npm:^9.1.0" eslint-plugin-prettier: "npm:^5.2.1"