From 8b31e868798f4bed67625e197e245b40fc854cf2 Mon Sep 17 00:00:00 2001 From: Andrzej Stepien Date: Sat, 12 Aug 2023 19:17:09 +0200 Subject: [PATCH] db calls refactor --- database-calls/getAcceptablePrompts.mjs | 30 ------------------------- social-interaction/receiveMention.mjs | 4 ++-- social-interaction/sendReply.mjs | 5 +++++ 3 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 database-calls/getAcceptablePrompts.mjs create mode 100644 social-interaction/sendReply.mjs diff --git a/database-calls/getAcceptablePrompts.mjs b/database-calls/getAcceptablePrompts.mjs deleted file mode 100644 index aaedf67..0000000 --- a/database-calls/getAcceptablePrompts.mjs +++ /dev/null @@ -1,30 +0,0 @@ -import logger from "../logger.mjs" -import { db } from "./db.mjs" -import config from "../config.mjs" - -const blocklist = db.union([ - db('bad_words').select('word'), - db('medical_dictionary').select('word'), - db('published').select('word') -]) - -export default async () => { - logger.trace("getAcceptablePrompt called") - try { - return db('dictionary') - .select('*') - .where({ - derivative: 0, - scientific: 0, - }) - .andWhere('count', '<', config.maxCount) - .andWhere('count', '>', config.minCount) - .andWhere('word', 'not in', blocklist) - .whereRaw('length(word) > 3') - .whereNotNull('pronunciation') - .orderByRaw('count desc') - } catch (error) { - logger.error("getAcceptablePrompts failed!") - throw error - } -} \ No newline at end of file diff --git a/social-interaction/receiveMention.mjs b/social-interaction/receiveMention.mjs index 945ae93..93e247d 100644 --- a/social-interaction/receiveMention.mjs +++ b/social-interaction/receiveMention.mjs @@ -1,6 +1,6 @@ import logger from "../logger.mjs" -import getAcceptablePrompts from "../database-calls/getAcceptablePrompts.mjs" import { checkSpelling } from "spellchecker" +import { wordIsAlreadyInBuffer, getAcceptablePrompts } from "../database-calls/db.mjs" export default async function (note) { const childLogger = logger.child({note}) @@ -13,7 +13,7 @@ export default async function (note) { const word = textArray[0] if(checkSpelling(word)){ if(await getAcceptablePrompts().indexOf(word)!=-1){ - if(/*wordIsAlreadyInBuffer*/true){ + if(!wordIsAlreadyInBuffer(word)){ } } diff --git a/social-interaction/sendReply.mjs b/social-interaction/sendReply.mjs new file mode 100644 index 0000000..8ff310c --- /dev/null +++ b/social-interaction/sendReply.mjs @@ -0,0 +1,5 @@ + + +export default async () => { + +} \ No newline at end of file