add autocomplete to dictionary and urbandictionary

This commit is contained in:
bignutty 2024-11-12 15:10:36 +01:00
parent c3ac88ea3f
commit 74408053dc
5 changed files with 67 additions and 3 deletions

View file

@ -0,0 +1,24 @@
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://api.urbandictionary.com/v0/autocomplete-extra")
.query({
term: context.value
})
choices = suggestions.body.results
}catch(e){
// idk sucks ig?
}
}
return context.respond({ choices: choices.splice(0, 20).map((l)=>({
name: `${l.term} - ${stringwrap(l.preview, 20, false)}`,
value: l.term
}))});
}