Fix no definitions
This commit is contained in:
parent
3cdf4dac45
commit
650e8446a0
@ -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": []
|
||||
|
@ -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,
|
||||
|
@ -11,7 +11,7 @@
|
||||
},
|
||||
{
|
||||
"name": "diction",
|
||||
"version": "1.3.0"
|
||||
"version": "1.3.1"
|
||||
},
|
||||
{
|
||||
"name": "fun",
|
||||
|
Loading…
Reference in New Issue
Block a user