Added automatic process to delete stale database entries
This commit is contained in:
parent
8d9859ea72
commit
ba07757d1d
3 changed files with 140 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
const gm = require("gm");
|
||||
const cron = require("cron");
|
||||
const { promisify } = require("util");
|
||||
const client = require("../utils/client.js");
|
||||
const database = require("../utils/database.js");
|
||||
|
@ -45,6 +46,19 @@ module.exports = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
const job = new cron.CronJob("0 0 * * 0", async () => {
|
||||
logger.log("Deleting stale guild entries in database...");
|
||||
const guildDB = (await database.guilds.find({}).exec());
|
||||
for (const { id } of guildDB) {
|
||||
if (!client.guilds.get(id)) {
|
||||
await database.guilds.deleteMany({ id: id });
|
||||
logger.log(`Deleted entry for guild ID ${id}.`);
|
||||
}
|
||||
}
|
||||
logger.log("Finished deleting stale entries.");
|
||||
});
|
||||
job.start();
|
||||
|
||||
const global = (await database.global.findOne({}).exec());
|
||||
if (!global) {
|
||||
const countObject = {};
|
||||
|
|
125
package-lock.json
generated
125
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "esmbot",
|
||||
"version": "1.2.8",
|
||||
"version": "1.3.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -542,6 +542,14 @@
|
|||
"strip-eof": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"cron": {
|
||||
"version": "1.8.2",
|
||||
"resolved": "https://registry.npmjs.org/cron/-/cron-1.8.2.tgz",
|
||||
"integrity": "sha512-Gk2c4y6xKEO8FSAUTklqtfSr7oTq0CiPQeLBG5Fl0qoXpZyMcj1SG59YL+hqq04bu6/IuEA7lMkYDAplQNKkyg==",
|
||||
"requires": {
|
||||
"moment-timezone": "^0.5.x"
|
||||
}
|
||||
},
|
||||
"cross-spawn": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-4.0.2.tgz",
|
||||
|
@ -988,6 +996,56 @@
|
|||
"resolved": "https://registry.npmjs.org/fecha/-/fecha-2.3.3.tgz",
|
||||
"integrity": "sha512-lUGBnIamTAwk4znq5BcqsDaxSmZ9nDVJaij6NvRt/Tg4R69gERA+otPKbS86ROw9nxVMw2/mp1fnaiWqbs6Sdg=="
|
||||
},
|
||||
"ffi-napi": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/ffi-napi/-/ffi-napi-2.5.0.tgz",
|
||||
"integrity": "sha512-ninYS+GI4BDFOg29dEJ68uZOcWgCp05teU4Lm40vrnyh+E1fYjKYvTDMYAG+WUD75NNHPTJhNjgVqv5whSgU3w==",
|
||||
"requires": {
|
||||
"debug": "^3.1.0",
|
||||
"get-uv-event-loop-napi-h": "^1.0.5",
|
||||
"node-addon-api": "1.6.1",
|
||||
"node-gyp-build": "^4.2.1",
|
||||
"ref-napi": "^1.5.2",
|
||||
"ref-struct-di": "^1.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "3.2.6",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
|
||||
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"node-addon-api": {
|
||||
"version": "1.6.1",
|
||||
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.6.1.tgz",
|
||||
"integrity": "sha512-GcLOYrG5/enbqH4SMsqXt6GQUQGGnDnE3FLDZzXYkCgQHuZV5UDFR+EboeY8kpG0avroyOjpFQ2qLEBosFcRIA=="
|
||||
},
|
||||
"node-gyp-build": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.2.tgz",
|
||||
"integrity": "sha512-Lqh7mrByWCM8Cf9UPqpeoVBBo5Ugx+RKu885GAzmLBVYjeywScxHXPGLa4JfYNZmcNGwzR0Glu5/9GaQZMFqyA=="
|
||||
},
|
||||
"ref-napi": {
|
||||
"version": "1.5.2",
|
||||
"resolved": "https://registry.npmjs.org/ref-napi/-/ref-napi-1.5.2.tgz",
|
||||
"integrity": "sha512-hwyNmWpUkt1bDWDW4aiwCoC+SJfJO69UIdjqssNqdaS0sYJpgqzosGg/rLtk69UoQ8drZdI9yyQefM7eEMM3Gw==",
|
||||
"requires": {
|
||||
"debug": "^3.1.0",
|
||||
"node-addon-api": "^2.0.0",
|
||||
"node-gyp-build": "^4.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-addon-api": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.0.tgz",
|
||||
"integrity": "sha512-ASCL5U13as7HhOExbT6OlWJJUV/lLzL2voOSP1UVehpRD8FbSrSDjfScK/KwAvVTI5AS6r4VwbOMlIqtvRidnA=="
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"figures": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz",
|
||||
|
@ -1163,6 +1221,19 @@
|
|||
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-5.0.1.tgz",
|
||||
"integrity": "sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g="
|
||||
},
|
||||
"get-symbol-from-current-process-h": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/get-symbol-from-current-process-h/-/get-symbol-from-current-process-h-1.0.2.tgz",
|
||||
"integrity": "sha512-syloC6fsCt62ELLrr1VKBM1ggOpMdetX9hTrdW77UQdcApPHLmf7CI7OKcN1c9kYuNxKcDe4iJ4FY9sX3aw2xw=="
|
||||
},
|
||||
"get-uv-event-loop-napi-h": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/get-uv-event-loop-napi-h/-/get-uv-event-loop-napi-h-1.0.6.tgz",
|
||||
"integrity": "sha512-t5c9VNR84nRoF+eLiz6wFrEp1SE2Acg0wS+Ysa2zF0eROes+LzOfuTaVHxGy8AbS8rq7FHEJzjnCZo1BupwdJg==",
|
||||
"requires": {
|
||||
"get-symbol-from-current-process-h": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"github-from-package": {
|
||||
"version": "0.0.0",
|
||||
"resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz",
|
||||
|
@ -1475,6 +1546,14 @@
|
|||
"yallist": "^2.1.2"
|
||||
}
|
||||
},
|
||||
"magick-ffi": {
|
||||
"version": "github:Terradice/magick-ffi#8911ffad4cdad8e67991ac0f214eff5ed42215a8",
|
||||
"from": "github:Terradice/magick-ffi",
|
||||
"requires": {
|
||||
"ffi-napi": "^2.5.0",
|
||||
"ref-napi": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"memory-pager": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
|
||||
|
@ -1573,6 +1652,14 @@
|
|||
"resolved": "https://registry.npmjs.org/moment-duration-format/-/moment-duration-format-2.3.2.tgz",
|
||||
"integrity": "sha512-cBMXjSW+fjOb4tyaVHuaVE/A5TqkukDWiOfxxAjY+PEqmmBQlLwn+8OzwPiG3brouXKY5Un4pBjAeB6UToXHaQ=="
|
||||
},
|
||||
"moment-timezone": {
|
||||
"version": "0.5.31",
|
||||
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.31.tgz",
|
||||
"integrity": "sha512-+GgHNg8xRhMXfEbv81iDtrVeTcWt0kWmTEY1XQK14dICTXnWJnT0dxdlPspwqF3keKMVPXwayEsk1DI0AA/jdA==",
|
||||
"requires": {
|
||||
"moment": ">= 2.9.0"
|
||||
}
|
||||
},
|
||||
"mongodb": {
|
||||
"version": "3.5.5",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.5.tgz",
|
||||
|
@ -2050,6 +2137,42 @@
|
|||
"resolved": "https://registry.npmjs.org/readable-web-to-node-stream/-/readable-web-to-node-stream-2.0.0.tgz",
|
||||
"integrity": "sha512-+oZJurc4hXpaaqsN68GoZGQAQIA3qr09Or4fqEsargABnbe5Aau8hFn6ISVleT3cpY/0n/8drn7huyyEvTbghA=="
|
||||
},
|
||||
"ref-napi": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ref-napi/-/ref-napi-2.0.1.tgz",
|
||||
"integrity": "sha512-Uh/vcTemN/yhyW/JtuySkDb5TLxEuaZITVFJup/UeNZytNaAVV6TGU7cYMCSUR0t9MrS4TBE+olDuP6vtl0qhw==",
|
||||
"requires": {
|
||||
"debug": "^4.1.1",
|
||||
"get-symbol-from-current-process-h": "^1.0.2",
|
||||
"node-addon-api": "^2.0.0",
|
||||
"node-gyp-build": "^4.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-gyp-build": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.2.tgz",
|
||||
"integrity": "sha512-Lqh7mrByWCM8Cf9UPqpeoVBBo5Ugx+RKu885GAzmLBVYjeywScxHXPGLa4JfYNZmcNGwzR0Glu5/9GaQZMFqyA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"ref-struct-di": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/ref-struct-di/-/ref-struct-di-1.1.0.tgz",
|
||||
"integrity": "sha512-gghZITj/iQwdwFDduZ6T8kL2B2ogInlOz7AOB0ggFoEc7akAKMcDrbzh3OIPk13Kxy8U2bHPvN6nejcBh4jN7A==",
|
||||
"requires": {
|
||||
"debug": "^3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "3.2.6",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
|
||||
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"regexp-clone": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz",
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"cowsay": "^1.4.0",
|
||||
"cron": "^1.8.2",
|
||||
"dblapi.js": "^2.4.0",
|
||||
"dotenv": "^8.2.0",
|
||||
"duckduckgo-images-api": "github:benpbolton/duckduckgo-images-api",
|
||||
|
@ -26,6 +27,7 @@
|
|||
"file-type": "^13.1.2",
|
||||
"gm": "github:TheEssem/gm",
|
||||
"jsqr": "^1.2.0",
|
||||
"magick-ffi": "github:Terradice/magick-ffi",
|
||||
"moment": "^2.24.0",
|
||||
"moment-duration-format": "^2.3.2",
|
||||
"mongoose": "^5.9.9",
|
||||
|
|
Loading…
Reference in a new issue