From 02aa698352d7a57be1b64b579c05a1b6650358a1 Mon Sep 17 00:00:00 2001 From: Evelyne Lachance Date: Wed, 12 Jun 2019 08:03:14 -0400 Subject: [PATCH] Update enmap 5, fix setup, ensure defaultsettings --- index.js | 4 ++-- modules/functions.js | 28 +++++++++++++++------------- package.json | 4 ++-- setup.js | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 420d2333..aaaa9962 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ const Discord = require("discord.js"); // We also load the rest of the things we need in this file: const { promisify } = require("util"); const readdir = promisify(require("fs").readdir); -const Enmap = require("enmap"); +const Enmap = require("../enmap"); // This is your client. Some people call it `bot`, some people call it `self`, // some might call it `cootchie`. Either way, when you see `client.something`, @@ -32,7 +32,7 @@ require("./modules/functions.js")(client); client.commands = new Enmap(); client.aliases = new Enmap(); -// Now we integrate the use of Evie's awesome Enhanced Map module, which +// Now we integrate the use of Evie's awesome EnMap module, which // essentially saves a collection to disk. This is great for per-server configs, // and makes things extremely easy for this purpose. client.settings = new Enmap({name: "settings"}); diff --git a/modules/functions.js b/modules/functions.js index b47f0634..0105bf9a 100644 --- a/modules/functions.js +++ b/modules/functions.js @@ -33,28 +33,30 @@ module.exports = (client) => { the default settings are used. */ + + // THIS IS HERE BECAUSE SOME PEOPLE DELETE ALL THE GUILD SETTINGS + // And then they're stuck because the default settings are also gone. + // So if you do that, you're resetting your defaults. Congrats. + const defaultSettings = { + "prefix": "~", + "modLogChannel": "mod-log", + "modRole": "Moderator", + "adminRole": "Administrator", + "systemNotice": "true", + "welcomeChannel": "welcome", + "welcomeMessage": "Say hello to {{user}}, everyone! We all need a warm welcome sometimes :D", + "welcomeEnabled": "false" + }; // getSettings merges the client defaults with the guild settings. guild settings in // enmap should only have *unique* overrides that are different from defaults. client.getSettings = (guild) => { + client.settings.ensure("default", defaultSettings); if(!guild) return client.settings.get("default"); const guildConf = client.settings.get(guild.id) || {}; // This "..." thing is the "Spread Operator". It's awesome! // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax return ({...client.settings.get("default"), ...guildConf}); - } - - // writeSettings overrides, or adds, any configuration item that is different - // than the defaults. This ensures less storage wasted and to detect overrides. - client.writeSettings = (id, newSettings) => { - const defaults = client.settings.get("default"); - let settings = client.settings.get(id) || {}; - // Using the spread operator again, and lodash's "pickby" function to remove any key - // from the settings that aren't in the defaults (meaning, they don't belong there) - client.settings.set(id, { - ..._.pickBy(settings, (v, k) => !_.isNil(defaults[k])), - ..._.pickBy(newSettings, (v, k) => !_.isNil(defaults[k])) - }); }; /* diff --git a/package.json b/package.json index e7676d18..94f94e03 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,10 @@ }, "homepage": "https://github.com/An-Idiots-Guide/guidebot#readme", "dependencies": { - "better-sqlite-pool": "^0.2.2", + "better-sqlite3": "^5.4.0", "chalk": "^2.4.2", "discord.js": "^11.5.1", - "enmap": "^4.8.7", + "enmap": "^5.0.0", "inquirer": "^6.3.1", "moment": "^2.24.0", "moment-duration-format": "^2.3.2" diff --git a/setup.js b/setup.js index 3f4fc92c..a61eae8b 100644 --- a/setup.js +++ b/setup.js @@ -59,7 +59,7 @@ let prompts = [ baseConfig = baseConfig .replace("{{ownerID}}", answers.ownerID) - .replace("{{token}}", `"${answers.token}"`) + .replace("{{token}}", `"${answers.token}"`); fs.writeFileSync("./config.js", baseConfig); console.log("REMEMBER TO NEVER SHARE YOUR TOKEN WITH ANYONE!");