3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-21 16:55:03 +00:00

Automatically create global on first run

This commit is contained in:
Bluenix 2021-07-05 22:52:35 +02:00
parent c9fa56de2c
commit e7c491a8d9
No known key found for this signature in database
GPG key ID: 1C1ED07E6FC8AA48
4 changed files with 28 additions and 13 deletions

View file

@ -24,7 +24,7 @@ See <https://zeppelin.gg/> 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!** 👈

View file

@ -13,4 +13,4 @@ DB_USER=
DB_PASSWORD=
DB_DATABASE=
# List of user IDs
STAFF=["123"]
STAFF=106391128718245888,108552944961454080

View file

@ -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",

View file

@ -7,16 +7,31 @@ export let connection: Connection;
export function connect() {
if (!connectionPromise) {
connectionPromise = createConnection().then(newConnection => {
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)
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
return newConnection.query("SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) AS tz").then(r => {
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;
});
connection = newConnection
return newConnection
});
}