Fix no definitions

This commit is contained in:
Evert Prants 2024-06-07 23:06:50 +03:00
parent 3cdf4dac45
commit 650e8446a0
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 11 additions and 5 deletions

View File

@ -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": []

View File

@ -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<string, string>[])
definitions: response
.filter((entry) => entry.text)
.map((data) => ({
partOfSpeech: data.partOfSpeech,

View File

@ -11,7 +11,7 @@
},
{
"name": "diction",
"version": "1.3.0"
"version": "1.3.1"
},
{
"name": "fun",