ensure settings always contain latest properties

This commit is contained in:
Erik 2022-07-30 17:59:35 +03:00
parent 746e395382
commit e3fbbd9a17
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -153,10 +153,19 @@ class GuildWrapper {
const data = await this.fetchData();
const { settings } = data;
const { defaultConfig } = this;
if(!settings) this._settings = { guildId: this.id, ...this.defaultConfig };
else this._settings = { ...this.defaultConfig, ...settings };
if (settings) {
// Ensure new settings properties are propagated to existing configs
const keys = Object.keys(settings);
for (const key of keys) {
if (!(key in defaultConfig)) continue;
defaultConfig[key] = { ...defaultConfig[key], ...settings[key] };
}
}
this._settings = defaultConfig;
return this._settings;
}