diff --git a/README.md b/README.md index 8572ae0d..4b759121 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ See for more details. ## Development -These instructions are intended for bot development only, they are not safe to follow for self-hosting. +These instructions are intended for bot development only, they are not recommended for self-hosting. 👉 **No support is guaranteed for self-hosting the bot!** 👈 diff --git a/backend/api.env.example b/backend/api.env.example index 6a17a4e1..361519f3 100644 --- a/backend/api.env.example +++ b/backend/api.env.example @@ -13,4 +13,4 @@ DB_USER= DB_PASSWORD= DB_DATABASE= # List of user IDs -STAFF=["123"] +STAFF=106391128718245888,108552944961454080 diff --git a/backend/package.json b/backend/package.json index 75a9b6eb..cdd7c8bf 100644 --- a/backend/package.json +++ b/backend/package.json @@ -7,10 +7,10 @@ "watch": "cross-env NODE_ENV=development tsc-watch --onSuccess \"node start-dev.js\"", "watch-yaml-parse-test": "cross-env NODE_ENV=development tsc-watch --onSuccess \"node dist/backend/src/yamlParseTest.js\"", "build": "rimraf dist && tsc", - "start-bot-dev": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --inspect=0.0.0.0:9229 dist/backend/src/index.js", + "start-bot-dev": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --inspect=0.0.0.0:9229 dist/backend/src/index.js init", "start-bot-prod": "cross-env NODE_ENV=production node -r ./register-tsconfig-paths.js --unhandled-rejections=strict dist/backend/src/index.js", "watch-bot": "cross-env NODE_ENV=development tsc-watch --onSuccess \"npm run start-bot-dev\"", - "start-api-dev": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --inspect=0.0.0.0:9239 dist/backend/src/api/index.js", + "start-api-dev": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --inspect=0.0.0.0:9239 dist/backend/src/api/index.js init", "start-api-prod": "cross-env NODE_ENV=production node -r ./register-tsconfig-paths.js --unhandled-rejections=strict dist/backend/src/api/index.js", "watch-api": "cross-env NODE_ENV=development tsc-watch --onSuccess \"npm run start-api-dev\"", "typeorm": "node -r ./register-tsconfig-paths.js ./node_modules/typeorm/cli.js", diff --git a/backend/src/data/db.ts b/backend/src/data/db.ts index 9888d0b5..68395b07 100644 --- a/backend/src/data/db.ts +++ b/backend/src/data/db.ts @@ -7,16 +7,31 @@ export let connection: Connection; export function connect() { if (!connectionPromise) { - connectionPromise = createConnection().then(newConnection => { - // Verify the DB timezone is set to UTC - return newConnection.query("SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) AS tz").then(r => { - if (r[0].tz !== "00:00:00") { - throw new SimpleError(`Database timezone must be UTC (detected ${r[0].tz})`); - } + connectionPromise = createConnection().then(async (newConnection) => { + if (process.argv.includes('init')) { + const staff = (process.env.STAFF ?? "").split(','); + // Build the global config + const config = { + "prefix": "!", + "plugins": { + "utility": {} + } + }; + staff.map(id => config["owners"][id] = 100) - connection = newConnection; - return newConnection; - }); + await newConnection.query(` + INSERT IGNORE INTO configs (id, \`key\`, config, is_active, edited_by) + VALUES (1, "global", ?, true, 106391128718245888) + `, [JSON.stringify(config)]) + } + // Verify the DB timezone is set to UTC + const r = await newConnection.query("SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) AS tz") + if (r[0].tz !== "00:00:00") { + throw new SimpleError(`Database timezone must be UTC (detected ${r[0].tz})`); + } + + connection = newConnection + return newConnection }); }