mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-23 00:03:09 +02:00
feat: upgrade script
This commit is contained in:
parent
95f76716ed
commit
dc0ac88fa7
2
.gitignore
vendored
2
.gitignore
vendored
@ -6,7 +6,7 @@ site/
|
||||
|
||||
# files
|
||||
.env
|
||||
sskey.env
|
||||
version
|
||||
user/config.js
|
||||
user/database.sqlite
|
||||
user/plugins/*/
|
@ -160,7 +160,8 @@ class Bot extends Client {
|
||||
|
||||
this.setMaxListeners(this.config.max_listeners); // set the max listeners for each event
|
||||
|
||||
require('./updater')(this); // check for updates
|
||||
require('./update/notifier')(this); // check for updates
|
||||
require('./update/upgrade')(this); // upgrade
|
||||
|
||||
const listeners = new ListenerLoader(this);
|
||||
listeners.load(); // load listeners
|
||||
|
@ -5,7 +5,7 @@ const link = require('terminal-link');
|
||||
const semver = require('semver');
|
||||
const { format } = require('leekslazylogger');
|
||||
|
||||
const { version: current } = require('../package.json');
|
||||
const { version: current } = require('../../package.json');
|
||||
|
||||
module.exports = async client => {
|
||||
if (!client.config.update_notice) return;
|
29
src/update/upgrade.js
Normal file
29
src/update/upgrade.js
Normal file
@ -0,0 +1,29 @@
|
||||
const fs = require('fs');
|
||||
const { path } = require('../utils/fs');
|
||||
const FILE = path('./version');
|
||||
const { version: current } = require('../../package.json');
|
||||
|
||||
/**
|
||||
* @param {import('../..').Bot} client
|
||||
*/
|
||||
module.exports = async client => {
|
||||
if (!fs.existsSync(FILE)) {
|
||||
return fs.writeFileSync(FILE, current);
|
||||
} else {
|
||||
const previous = fs.readFileSync(FILE, { encoding: 'utf8' });
|
||||
if (previous !== current) {
|
||||
client.log.info('Running upgrade task');
|
||||
client.log.info('Writing version');
|
||||
fs.writeFileSync(FILE, current);
|
||||
|
||||
const guilds = await client.db.models.Guild.findAll();
|
||||
guilds.forEach(async guild => {
|
||||
guild.set('blacklist', {
|
||||
members: [],
|
||||
roles: []
|
||||
});
|
||||
await guild.save();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user