Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Commit

Permalink
dropped support of non-English languages
Browse files Browse the repository at this point in the history
- this is not supported in the API anymore: meetDeveloper/freeDictionaryAPI#102 (comment)
  • Loading branch information
Supinic committed Oct 28, 2022
1 parent da73cd0 commit 16fedb0
Showing 1 changed file with 6 additions and 53 deletions.
59 changes: 6 additions & 53 deletions commands/dictionary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,13 @@ module.exports = {
Aliases: ["dict"],
Author: "supinic",
Cooldown: 10000,
Description: "Fetches the dictionary definition of a word. You can use \"lang:\" to specifiy a language, and if there are multiple definitions, you can add \"index:#\" with a number to access specific definition indexes.",
Description: "Fetches the dictionary definition of a word in English. If there are multiple definitions, you can add \"index:#\" with a number to access specific definition indexes.",
Flags: ["mention","non-nullable","pipe"],
Params: [
{ name: "index", type: "string" },
{ name: "lang", type: "string" },
{ name: "language", type: "string" }
{ name: "index", type: "string" }
],
Whitelist_Response: null,
Static_Data: (() => ({
languages: [
["en", "English"],
["hi", "Hindi"],
["es", "Spanish"],
["fr", "French"],
["ja", "Japanese"],
["ru", "Russian"],
["de", "German"],
["it", "Italian"],
["ko", "Korean"],
["pt-BR", "Brazilian Portuguese - only works via the code"],
["zh-CN", "Chinese"],
["ar", "Arabic"],
["tr", "Turkish"]
]
})),
Static_Data: null,
Code: (async function dictionary (context, ...args) {
if (args.length === 0) {
return {
Expand All @@ -47,27 +29,9 @@ module.exports = {
};
}

const languageIdentifier = context.params.lang ?? context.params.language ?? "en";
const language = (languageIdentifier.length < 5)
? languageIdentifier
: sb.Utils.modules.languageISO.getCode(languageIdentifier);

if (!language) {
return {
success: false,
reply: "Invalid language provided!"
};
}
else if (!this.staticData.languages.map(i => i[0]).includes(language)) {
return {
success: false,
reply: "Your provided language is not supported by the Dictionary API!"
};
}

const phrase = encodeURIComponent(args.join(" "));
const { statusCode, body: data } = await sb.Got({
url: `https://api.dictionaryapi.dev/api/v1/entries/${language}/${phrase}`,
url: `https://api.dictionaryapi.dev/api/v1/entries/en/${phrase}`,
throwHttpErrors: false,
responseType: "json"
});
Expand Down Expand Up @@ -103,29 +67,18 @@ module.exports = {
};
}),
Dynamic_Description: (async function (prefix) {
const { languages } = this.staticData;
const list = languages.map(([code, name]) => `<li><code>${code}</code> - ${name}</li>`).join("");

return [
"Fetches dictionary definitions of provided phrase, also in specific languages.",
"Fetches dictionary definitions of provided phrase in English.",
"If there's multiple, you can check a different definition by appending the index:# parameter.",
"",

`<code>${prefix}dictionary (word)</code>`,
"Will fetch the phrase's definition in the English language.",
"",

`<code>${prefix}dictionary lang:fr (word)</code>`,
`<code>${prefix}dictionary language:French (word)</code>`,
"Both of these will fetch the phrase's definition in the French language.",
"",

`<code>${prefix}dictionary (word) index:3</code>`,
"Will fetch the phrase's 4th (counting starts from zero) definition in the English language.",
"",

"List of supported languages:",
list
""
];
})
};

0 comments on commit 16fedb0

Please sign in to comment.