mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-22 09:15: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
|
@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue