Browse Source

Merge branch 'mongodb-compatibility'

master
benji7425 3 years ago
parent
commit
6e26ce1f3c
4 changed files with 77 additions and 25 deletions
  1. 21
      discord-bot-core/client.js
  2. 3
      discord-bot-core/internal-config.json
  3. 77
      discord-bot-core/package-lock.json
  4. 1
      discord-bot-core/package.json

21
discord-bot-core/client.js

@ -7,7 +7,7 @@ const HandleGuildMessage = require("./handle-guild-message.js");
const InternalConfig = require("./internal-config.json");
const RequireAll = require("require-all");
let neDB;
let database;
module.exports = class Client extends Discord.Client {
/**
@ -74,9 +74,16 @@ module.exports = class Client extends Discord.Client {
}
bootstrap() {
Camo.connect("nedb://guilds-data").then(db => {
neDB = db;
new CronJob(InternalConfig.dbCompactionSchedule, compactCollections, null, true);
Camo.connect(InternalConfig.dbConnectionString).then(db => {
database = db;
const dbProtocol = InternalConfig.dbConnectionString.match(/^(.+):\/\//)[1];
CoreUtil.dateLog(`Database protocol: ${dbProtocol}`);
if (dbProtocol === "nedb") {
CoreUtil.dateLog(`Seting up NeDB collection compaction cron job; schedule: ${InternalConfig.neDBCompactionSchedule}`);
new CronJob(InternalConfig.neDBCompactionSchedule, compactNeDBCollections, null, true);
}
this.emit("beforeLogin");
this.login(this._token);
@ -92,11 +99,11 @@ module.exports = class Client extends Discord.Client {
}
};
function compactCollections() {
function compactNeDBCollections() {
/*I realise it is a bit of a cheat to just access _collections in this manner, but in the absence of
camo actually having any kind of solution for this it's the easiest method I could come up with.
Maybe at some point in future I should fork camo and add this feature. The compaction function is NeDB only
and camo is designed to work with both NeDB and MongoDB, which is presumably why it doesn't alraedy exist */
for (let collectionName of Object.keys(neDB._collections))
neDB._collections[collectionName].persistence.compactDatafile();
for (let collectionName of Object.keys(database._collections))
database._collections[collectionName].persistence.compactDatafile();
}

3
discord-bot-core/internal-config.json

@ -1,5 +1,6 @@
{
"dbCompactionSchedule": "0 * * * * *",
"dbConnectionString": "nedb://guilds-data",
"neDBCompactionSchedule": "0 * * * * *",
"restartSchedule": "0 0 0 * * *",
"restartTimeout": 5000,
"website": "https://benji7425.github.io",

77
discord-bot-core/package-lock.json

@ -43,10 +43,9 @@
}
},
"bson": {
"version": "0.4.23",
"resolved": "https://registry.npmjs.org/bson/-/bson-0.4.23.tgz",
"integrity": "sha1-5louPHUH/63kEJvHV1p25Q+NqRU=",
"optional": true
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/bson/-/bson-1.0.4.tgz",
"integrity": "sha1-k8ENOeqltYQVy8QFLz5T5WKwtyw="
},
"camo": {
"version": "0.12.3",
@ -57,6 +56,35 @@
"lodash": "3.9.3",
"mongodb": "2.0.42",
"nedb": "1.8.0"
},
"dependencies": {
"bson": {
"version": "0.4.23",
"resolved": "https://registry.npmjs.org/bson/-/bson-0.4.23.tgz",
"integrity": "sha1-5louPHUH/63kEJvHV1p25Q+NqRU=",
"optional": true
},
"mongodb": {
"version": "2.0.42",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.0.42.tgz",
"integrity": "sha1-G614E9ByXOLjvVQYDzH67dJNnlM=",
"optional": true,
"requires": {
"es6-promise": "2.1.1",
"mongodb-core": "1.2.10",
"readable-stream": "1.0.31"
}
},
"mongodb-core": {
"version": "1.2.10",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-1.2.10.tgz",
"integrity": "sha1-7OFyAb05WmR/uY9Ivo+64Vvgr9k=",
"optional": true,
"requires": {
"bson": "0.4.23",
"kerberos": "0.0.23"
}
}
}
},
"core-util-is": {
@ -230,24 +258,20 @@
}
},
"mongodb": {
"version": "2.0.42",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.0.42.tgz",
"integrity": "sha1-G614E9ByXOLjvVQYDzH67dJNnlM=",
"optional": true,
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.0.1.tgz",
"integrity": "sha1-J47oAGJX7CJ5hZSmJZVGgl1t4bI=",
"requires": {
"es6-promise": "2.1.1",
"mongodb-core": "1.2.10",
"readable-stream": "1.0.31"
"mongodb-core": "3.0.1"
}
},
"mongodb-core": {
"version": "1.2.10",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-1.2.10.tgz",
"integrity": "sha1-7OFyAb05WmR/uY9Ivo+64Vvgr9k=",
"optional": true,
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.0.1.tgz",
"integrity": "sha1-/23Dbulv9ZaVPYCmhA1nMbyS7+0=",
"requires": {
"bson": "0.4.23",
"kerberos": "0.0.23"
"bson": "1.0.4",
"require_optional": "1.0.1"
}
},
"nan": {
@ -328,11 +352,30 @@
"resolved": "https://registry.npmjs.org/require-all/-/require-all-2.2.0.tgz",
"integrity": "sha1-tEIMIzrAKC0P9Jsnf7iAqLXeCJQ="
},
"require_optional": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
"integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==",
"requires": {
"resolve-from": "2.0.0",
"semver": "5.5.0"
}
},
"resolve-from": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
"integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
},
"safe-buffer": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
"integrity": "sha1-iTMSr2myEj3vcfV4iQAWce6yyFM="
},
"semver": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
"integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA=="
},
"simple-file-writer": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/simple-file-writer/-/simple-file-writer-2.0.0.tgz",

1
discord-bot-core/package.json

@ -5,6 +5,7 @@
"camo": "0.12.3",
"cron": "1.3.0",
"discord.js": "11.2.0",
"mongodb": "3.0.1",
"nedb": "1.8.0",
"parent-package-json": "2.0.1",
"require-all": "2.2.0",

Loading…
Cancel
Save