Skip to content
This repository has been archived by the owner on Jun 24, 2020. It is now read-only.

Commit

Permalink
chore: Improve how existing settings are handled
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahsnider committed Nov 1, 2018
1 parent e649895 commit 3c05b27
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
21 changes: 6 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,14 @@ class KeyvProvider extends SettingProvider {
*/
async set(guild, key, val) {
const target = this.constructor.getGuildID(guild);
const prev = await this.keyv.get(target);
const prev = await this.keyv.get(target) || {};

if (prev) {
const cur = prev;
cur[key] = val;
const cur = prev;
cur[key] = val;

return new Promise(resolve => {
this.keyv.set(target, cur).then(() => resolve(val));
});
} else {
const cur = {};
cur[key] = val;

return new Promise(resolve => {
this.keyv.set(target, cur).then(() => resolve(val));
});
}
return new Promise(resolve => {
this.keyv.set(target, cur).then(() => resolve(val));
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
"generate-docs:production": "npm run generate-docs:jsdoc && npm run generate-docs:parcel",
"lint": "eslint ."
},
"version": "1.0.3"
"version": "1.0.4"
}

0 comments on commit 3c05b27

Please sign in to comment.