From 38e282186fbba6a7bb904c39a739da0bb938bbac Mon Sep 17 00:00:00 2001 From: Emily J Date: Sat, 10 Oct 2020 12:56:14 +1100 Subject: [PATCH] create complete data objects using defaults --- bot/util/redis.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/bot/util/redis.js b/bot/util/redis.js index 211c46e..c023106 100644 --- a/bot/util/redis.js +++ b/bot/util/redis.js @@ -36,6 +36,51 @@ class Redis { }); } + async getGuild (id) { + let result = await this.guild.hgetallAsync(id); + let defaults = this.client.config.defaultGuildData; + + if (result === null) return defaults; + + for (const defaultValue in defaults) { + if (!result[defaultValue]) { + result[defaultValue] = defaults[defaultValue]; + }; + }; + + return result; + }; + + async getMember (id) { + let result = await this.member.hgetallAsync(id); + let defaults = this.client.config.defaultMemberData; + + if (result === null) return defaults; + + for (const defaultValue in defaults) { + if (!result[defaultValue]) { + result[defaultValue] = defaults[defaultValue]; + }; + }; + + return result; + }; + + async getUser (id) { + let result = await this.user.hgetallAsync(id); + let defaults = this.client.config.defaultUserData; + + if (result === null) return defaults; + + for (const defaultValue in defaults) { + if (!result[defaultValue]) { + result[defaultValue] = defaults[defaultValue]; + }; + }; + + return result; + }; + async getGuildKey (id, key) { let result = await this.guild.hgetAsync(id, key);