From 650e8446a079448374f75382d5096aab45712f65 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Fri, 7 Jun 2024 23:06:50 +0300 Subject: [PATCH] Fix no definitions --- diction/plugin.json | 2 +- diction/plugin.ts | 12 +++++++++--- squeebot.repo.json | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/diction/plugin.json b/diction/plugin.json index ef48f32..324fdd7 100644 --- a/diction/plugin.json +++ b/diction/plugin.json @@ -2,7 +2,7 @@ "main": "plugin.js", "name": "diction", "description": "Find definitions for words", - "version": "1.3.0", + "version": "1.3.1", "tags": ["commands", "utility", "dictionary"], "dependencies": ["simplecommands", "cron"], "npmDependencies": [] diff --git a/diction/plugin.ts b/diction/plugin.ts index 4234853..f2cb578 100644 --- a/diction/plugin.ts +++ b/diction/plugin.ts @@ -12,6 +12,12 @@ import { ProtocolFeatureFlag, } from '@squeebot/core/lib/types'; +interface IApiResponse { + partOfSpeech: string; + text: string; + word: string; +} + interface IDefinition { partOfSpeech: string; text: string; @@ -167,13 +173,13 @@ class DictionPlugin extends Plugin { short ? limit : 100 }&api_key=${key}`; response = await httpGET(s); - response = JSON.parse(response); + response = JSON.parse(response) as IApiResponse[]; } catch (e) { msg.resolve('Server did not respond.'); return true; } - if (!response || !response.length) { + if (!response?.length || response.every((item) => !item.word)) { msg.resolve('No definitions found.'); return true; } @@ -186,7 +192,7 @@ class DictionPlugin extends Plugin { lastTime: Date.now(), }, ], - definitions: (response as Record[]) + definitions: response .filter((entry) => entry.text) .map((data) => ({ partOfSpeech: data.partOfSpeech, diff --git a/squeebot.repo.json b/squeebot.repo.json index 3e0c8b9..9a55169 100644 --- a/squeebot.repo.json +++ b/squeebot.repo.json @@ -11,7 +11,7 @@ }, { "name": "diction", - "version": "1.3.0" + "version": "1.3.1" }, { "name": "fun",