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:
parent
c9fa56de2c
commit
e7c491a8d9
4 changed files with 28 additions and 13 deletions
|
@ -24,7 +24,7 @@ See <https://zeppelin.gg/> for more details.
|
||||||
|
|
||||||
## Development
|
## 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!** 👈
|
👉 **No support is guaranteed for self-hosting the bot!** 👈
|
||||||
|
|
||||||
|
|
|
@ -13,4 +13,4 @@ DB_USER=
|
||||||
DB_PASSWORD=
|
DB_PASSWORD=
|
||||||
DB_DATABASE=
|
DB_DATABASE=
|
||||||
# List of user IDs
|
# List of user IDs
|
||||||
STAFF=["123"]
|
STAFF=106391128718245888,108552944961454080
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
"watch": "cross-env NODE_ENV=development tsc-watch --onSuccess \"node start-dev.js\"",
|
"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\"",
|
"watch-yaml-parse-test": "cross-env NODE_ENV=development tsc-watch --onSuccess \"node dist/backend/src/yamlParseTest.js\"",
|
||||||
"build": "rimraf dist && tsc",
|
"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",
|
"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\"",
|
"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",
|
"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\"",
|
"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",
|
"typeorm": "node -r ./register-tsconfig-paths.js ./node_modules/typeorm/cli.js",
|
||||||
|
|
|
@ -7,16 +7,31 @@ export let connection: Connection;
|
||||||
|
|
||||||
export function connect() {
|
export function connect() {
|
||||||
if (!connectionPromise) {
|
if (!connectionPromise) {
|
||||||
connectionPromise = createConnection().then(newConnection => {
|
connectionPromise = createConnection().then(async (newConnection) => {
|
||||||
// Verify the DB timezone is set to UTC
|
if (process.argv.includes('init')) {
|
||||||
return newConnection.query("SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) AS tz").then(r => {
|
const staff = (process.env.STAFF ?? "").split(',');
|
||||||
if (r[0].tz !== "00:00:00") {
|
// Build the global config
|
||||||
throw new SimpleError(`Database timezone must be UTC (detected ${r[0].tz})`);
|
const config = {
|
||||||
}
|
"prefix": "!",
|
||||||
|
"plugins": {
|
||||||
|
"utility": {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
staff.map(id => config["owners"][id] = 100)
|
||||||
|
|
||||||
connection = newConnection;
|
await newConnection.query(`
|
||||||
return newConnection;
|
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
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue