diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-09 14:31:19 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-09 14:31:19 +0200 |
commit | 72ac437e92c63b9eb085e6206fb5e0208a42fa0d (patch) | |
tree | 8d85609d72c767099af5895394dcc50528917d73 | |
parent | :bug: fix import (diff) | |
download | server-72ac437e92c63b9eb085e6206fb5e0208a42fa0d.tar.xz |
:bug: fix array key in config
-rw-r--r-- | util/src/util/Config.ts | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/util/src/util/Config.ts b/util/src/util/Config.ts index 255f425d..eeeaa2ce 100644 --- a/util/src/util/Config.ts +++ b/util/src/util/Config.ts @@ -12,6 +12,7 @@ export const Config = { if (config) return config; pairs = await ConfigEntity.find(); config = pairsToConfig(pairs); + console.log(config.guild.autoJoin); return this.set((config || {}).merge(DefaultConfigOptions)); }, @@ -47,16 +48,18 @@ function pairsToConfig(pairs: ConfigEntity[]) { pairs.forEach((p) => { const keys = p.key.split("_"); - let prev = ""; let obj = value; + let prev = ""; + let prevObj = obj; let i = 0; for (const key of keys) { - if (Number(key) && !obj[prev]) obj = obj[prev] = []; + if (!isNaN(Number(key)) && !prevObj[prev]?.length) prevObj[prev] = obj = []; if (i++ === keys.length - 1) obj[key] = p.value; else if (!obj[key]) obj[key] = {}; prev = key; + prevObj = obj; obj = obj[key]; } }); |