mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 14:13:02 -04:00
add autocomplete to dictionary and urbandictionary
This commit is contained in:
parent
c3ac88ea3f
commit
74408053dc
5 changed files with 67 additions and 3 deletions
34
labscore/parameters/autocomplete/googleDictionary.js
Normal file
34
labscore/parameters/autocomplete/googleDictionary.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
|
||||
const { stringwrap } = require("#utils/markdown");
|
||||
const superagent = require("superagent");
|
||||
|
||||
module.exports = async (context)=>{
|
||||
let choices = [];
|
||||
if(context.value){
|
||||
try {
|
||||
let suggestions = await superagent.get("https://www.google.com/complete/search")
|
||||
.query({
|
||||
client: "dictionary-widget",
|
||||
hl: "en",
|
||||
requiredfields: "corpus:en-us",
|
||||
q: context.value
|
||||
})
|
||||
|
||||
suggestions = JSON.parse(suggestions.text.substring(19,suggestions.text.length - 1))
|
||||
choices = suggestions[1].map((m)=>m[0])
|
||||
|
||||
// Additional checks
|
||||
if(choices.includes(context.value.toLowerCase())) {
|
||||
choices = choices.filter((m)=>m!==context.value.toLowerCase())
|
||||
choices.unshift(context.value.toLowerCase())
|
||||
}
|
||||
}catch(e){
|
||||
// idk sucks ig?
|
||||
}
|
||||
}
|
||||
|
||||
return context.respond({ choices: choices.splice(0, 20).map((l)=>({
|
||||
name: l,
|
||||
value: l
|
||||
}))});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue