From 489e63821b2b575309f06834234bd915f99fc4fb Mon Sep 17 00:00:00 2001 From: Eris Date: Tue, 18 Apr 2023 20:14:22 -0400 Subject: [PATCH 1/3] Just take a Keyv object, don't go through the old mess --- src/BingAIClient.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/BingAIClient.js b/src/BingAIClient.js index 59d6e0a5..78301f0e 100644 --- a/src/BingAIClient.js +++ b/src/BingAIClient.js @@ -13,9 +13,13 @@ const genRanHex = size => [...Array(size)].map(() => Math.floor(Math.random() * export default class BingAIClient { constructor(options) { - const cacheOptions = options.cache || {}; - cacheOptions.namespace = cacheOptions.namespace || 'bing'; - this.conversationsCache = new Keyv(cacheOptions); + if (options.cache) { + if (!options.cache.namespace) { + console.warn("The given Keyv object has no namespace. This is a bad idea if you share a database.") + } + } + + this.conversationsCache = options.cache || new Keyv() this.setOptions(options); } From e07c5dd52859a10b946e4086c02638c4a26e57f4 Mon Sep 17 00:00:00 2001 From: Eris Date: Wed, 19 Apr 2023 16:41:38 -0400 Subject: [PATCH 2/3] Update BingAIClient.js --- src/BingAIClient.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/BingAIClient.js b/src/BingAIClient.js index 78301f0e..b1255fa1 100644 --- a/src/BingAIClient.js +++ b/src/BingAIClient.js @@ -13,13 +13,16 @@ const genRanHex = size => [...Array(size)].map(() => Math.floor(Math.random() * export default class BingAIClient { constructor(options) { - if (options.cache) { - if (!options.cache.namespace) { - console.warn("The given Keyv object has no namespace. This is a bad idea if you share a database.") + if (options.keyv) { + if (!options.keyv.namespace) { + console.warn("The given Keyv object has no namespace. This is a bad idea if you share a database."); } + this.conversationsCache = options.keyv; + } else { + const cacheOptions = options.cache || {}; + cacheOptions.namespace = cacheOptions.namespace || 'bing'; + this.conversationsCache = new Keyv(cacheOptions); } - - this.conversationsCache = options.cache || new Keyv() this.setOptions(options); } From 0db86e7ff42c4a16ddd6e447f1d0aab302184e42 Mon Sep 17 00:00:00 2001 From: Joel Date: Sat, 22 Apr 2023 01:23:01 -0700 Subject: [PATCH 3/3] chore: lint errors --- src/BingAIClient.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BingAIClient.js b/src/BingAIClient.js index b1255fa1..783d3a3e 100644 --- a/src/BingAIClient.js +++ b/src/BingAIClient.js @@ -15,13 +15,13 @@ export default class BingAIClient { constructor(options) { if (options.keyv) { if (!options.keyv.namespace) { - console.warn("The given Keyv object has no namespace. This is a bad idea if you share a database."); + console.warn('The given Keyv object has no namespace. This is a bad idea if you share a database.'); } this.conversationsCache = options.keyv; } else { const cacheOptions = options.cache || {}; cacheOptions.namespace = cacheOptions.namespace || 'bing'; - this.conversationsCache = new Keyv(cacheOptions); + this.conversationsCache = new Keyv(cacheOptions); } this.setOptions(options);