Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

commit 22e998f4e25671985e6b6f3d512d7e27ecdc9dfb
parent f08d933f06add761da802631f4b6da38afde927a
Author: Demonstrandum <moi@knutsen.co>
Date:   Fri, 20 Mar 2020 02:55:18 +0000

Cache with number index stored

Diffstat:
Mlib/api/google.ts | 5+++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/api/google.ts b/lib/api/google.ts @@ -26,6 +26,7 @@ const CACHE = { // These web-places already have commands given to them. const web_search = (param : CSE) => new Promise((resolve, reject) => { + let query = param.query; const cache_keys = Object.keys(CACHE); // Retrieve cached query. if (param.query in CACHE) { @@ -39,14 +40,14 @@ const web_search = (param : CSE) => new Promise((resolve, reject) => { const num_match = param.query.trim().match(/[ ]+(\d+)$/); if (num_match) - param.query = param.query.slice(0, -num_match[1].length).trim(); + query = query.slice(0, -num_match[1].length).trim(); const result_index = Math.abs(num_match ? Number(num_match[1]) - 1 : 0) % 10; const cs = google.customsearch('v1'); cs.cse.list({ auth: param.key, cx: param.id, - q: param.query, + q: query, searchType: (param.kind === 'web') ? undefined : param.kind, start: 0, num: result_index + 1,