Merge branch 'mongodb-compatibility'
This commit is contained in:
commit
6e26ce1f3c
|
@ -7,7 +7,7 @@ const HandleGuildMessage = require("./handle-guild-message.js");
|
||||||
const InternalConfig = require("./internal-config.json");
|
const InternalConfig = require("./internal-config.json");
|
||||||
const RequireAll = require("require-all");
|
const RequireAll = require("require-all");
|
||||||
|
|
||||||
let neDB;
|
let database;
|
||||||
|
|
||||||
module.exports = class Client extends Discord.Client {
|
module.exports = class Client extends Discord.Client {
|
||||||
/**
|
/**
|
||||||
|
@ -74,9 +74,16 @@ module.exports = class Client extends Discord.Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap() {
|
bootstrap() {
|
||||||
Camo.connect("nedb://guilds-data").then(db => {
|
Camo.connect(InternalConfig.dbConnectionString).then(db => {
|
||||||
neDB = db;
|
database = db;
|
||||||
new CronJob(InternalConfig.dbCompactionSchedule, compactCollections, null, true);
|
|
||||||
|
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.emit("beforeLogin");
|
||||||
this.login(this._token);
|
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
|
/*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.
|
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
|
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 */
|
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))
|
for (let collectionName of Object.keys(database._collections))
|
||||||
neDB._collections[collectionName].persistence.compactDatafile();
|
database._collections[collectionName].persistence.compactDatafile();
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"dbCompactionSchedule": "0 * * * * *",
|
"dbConnectionString": "nedb://guilds-data",
|
||||||
|
"neDBCompactionSchedule": "0 * * * * *",
|
||||||
"restartSchedule": "0 0 0 * * *",
|
"restartSchedule": "0 0 0 * * *",
|
||||||
"restartTimeout": 5000,
|
"restartTimeout": 5000,
|
||||||
"website": "https://benji7425.github.io",
|
"website": "https://benji7425.github.io",
|
||||||
|
|
|
@ -43,10 +43,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bson": {
|
"bson": {
|
||||||
"version": "0.4.23",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/bson/-/bson-0.4.23.tgz",
|
"resolved": "https://registry.npmjs.org/bson/-/bson-1.0.4.tgz",
|
||||||
"integrity": "sha1-5louPHUH/63kEJvHV1p25Q+NqRU=",
|
"integrity": "sha1-k8ENOeqltYQVy8QFLz5T5WKwtyw="
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"camo": {
|
"camo": {
|
||||||
"version": "0.12.3",
|
"version": "0.12.3",
|
||||||
|
@ -57,6 +56,35 @@
|
||||||
"lodash": "3.9.3",
|
"lodash": "3.9.3",
|
||||||
"mongodb": "2.0.42",
|
"mongodb": "2.0.42",
|
||||||
"nedb": "1.8.0"
|
"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": {
|
"core-util-is": {
|
||||||
|
@ -230,24 +258,20 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mongodb": {
|
"mongodb": {
|
||||||
"version": "2.0.42",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.0.42.tgz",
|
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.0.1.tgz",
|
||||||
"integrity": "sha1-G614E9ByXOLjvVQYDzH67dJNnlM=",
|
"integrity": "sha1-J47oAGJX7CJ5hZSmJZVGgl1t4bI=",
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"es6-promise": "2.1.1",
|
"mongodb-core": "3.0.1"
|
||||||
"mongodb-core": "1.2.10",
|
|
||||||
"readable-stream": "1.0.31"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mongodb-core": {
|
"mongodb-core": {
|
||||||
"version": "1.2.10",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-1.2.10.tgz",
|
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.0.1.tgz",
|
||||||
"integrity": "sha1-7OFyAb05WmR/uY9Ivo+64Vvgr9k=",
|
"integrity": "sha1-/23Dbulv9ZaVPYCmhA1nMbyS7+0=",
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"bson": "0.4.23",
|
"bson": "1.0.4",
|
||||||
"kerberos": "0.0.23"
|
"require_optional": "1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nan": {
|
"nan": {
|
||||||
|
@ -328,11 +352,30 @@
|
||||||
"resolved": "https://registry.npmjs.org/require-all/-/require-all-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/require-all/-/require-all-2.2.0.tgz",
|
||||||
"integrity": "sha1-tEIMIzrAKC0P9Jsnf7iAqLXeCJQ="
|
"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": {
|
"safe-buffer": {
|
||||||
"version": "5.1.1",
|
"version": "5.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
|
||||||
"integrity": "sha1-iTMSr2myEj3vcfV4iQAWce6yyFM="
|
"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": {
|
"simple-file-writer": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/simple-file-writer/-/simple-file-writer-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/simple-file-writer/-/simple-file-writer-2.0.0.tgz",
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
"camo": "0.12.3",
|
"camo": "0.12.3",
|
||||||
"cron": "1.3.0",
|
"cron": "1.3.0",
|
||||||
"discord.js": "11.2.0",
|
"discord.js": "11.2.0",
|
||||||
|
"mongodb": "3.0.1",
|
||||||
"nedb": "1.8.0",
|
"nedb": "1.8.0",
|
||||||
"parent-package-json": "2.0.1",
|
"parent-package-json": "2.0.1",
|
||||||
"require-all": "2.2.0",
|
"require-all": "2.2.0",
|
||||||
|
|
Loading…
Reference in New Issue