Fix no definitions
This commit is contained in:
parent
3cdf4dac45
commit
650e8446a0
@ -2,7 +2,7 @@
|
|||||||
"main": "plugin.js",
|
"main": "plugin.js",
|
||||||
"name": "diction",
|
"name": "diction",
|
||||||
"description": "Find definitions for words",
|
"description": "Find definitions for words",
|
||||||
"version": "1.3.0",
|
"version": "1.3.1",
|
||||||
"tags": ["commands", "utility", "dictionary"],
|
"tags": ["commands", "utility", "dictionary"],
|
||||||
"dependencies": ["simplecommands", "cron"],
|
"dependencies": ["simplecommands", "cron"],
|
||||||
"npmDependencies": []
|
"npmDependencies": []
|
||||||
|
@ -12,6 +12,12 @@ import {
|
|||||||
ProtocolFeatureFlag,
|
ProtocolFeatureFlag,
|
||||||
} from '@squeebot/core/lib/types';
|
} from '@squeebot/core/lib/types';
|
||||||
|
|
||||||
|
interface IApiResponse {
|
||||||
|
partOfSpeech: string;
|
||||||
|
text: string;
|
||||||
|
word: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface IDefinition {
|
interface IDefinition {
|
||||||
partOfSpeech: string;
|
partOfSpeech: string;
|
||||||
text: string;
|
text: string;
|
||||||
@ -167,13 +173,13 @@ class DictionPlugin extends Plugin {
|
|||||||
short ? limit : 100
|
short ? limit : 100
|
||||||
}&api_key=${key}`;
|
}&api_key=${key}`;
|
||||||
response = await httpGET(s);
|
response = await httpGET(s);
|
||||||
response = JSON.parse(response);
|
response = JSON.parse(response) as IApiResponse[];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
msg.resolve('Server did not respond.');
|
msg.resolve('Server did not respond.');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response || !response.length) {
|
if (!response?.length || response.every((item) => !item.word)) {
|
||||||
msg.resolve('No definitions found.');
|
msg.resolve('No definitions found.');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -186,7 +192,7 @@ class DictionPlugin extends Plugin {
|
|||||||
lastTime: Date.now(),
|
lastTime: Date.now(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
definitions: (response as Record<string, string>[])
|
definitions: response
|
||||||
.filter((entry) => entry.text)
|
.filter((entry) => entry.text)
|
||||||
.map((data) => ({
|
.map((data) => ({
|
||||||
partOfSpeech: data.partOfSpeech,
|
partOfSpeech: data.partOfSpeech,
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "diction",
|
"name": "diction",
|
||||||
"version": "1.3.0"
|
"version": "1.3.1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "fun",
|
"name": "fun",
|
||||||
|
Loading…
Reference in New Issue
Block a user