31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
import fetch from "../fetch";
|
|
|
|
const url = "https://api.urbandictionary.com/v0/define"
|
|
|
|
export default bot => {
|
|
bot._trigger.set("urbandict", new bot.trigger({
|
|
call: /^(\.|\/)ud .*/i,
|
|
set: "nxy",
|
|
help: {
|
|
text: "Searches for a term on Urbandict and returns first result",
|
|
usage: "[b].ud[/b] [i]<term>[/i] [i](<index>)[/i]"
|
|
},
|
|
f: e => {
|
|
let index = 1;
|
|
if(!isNaN(e.args[e.args.length - 1]) && e.args.length > 1)
|
|
index = parseInt(e.args.pop());
|
|
const term = e.args.join(" ").trim().toLowerCase();
|
|
|
|
fetch(`${url}?term=${term}`)
|
|
.then(res => res.json())
|
|
.then(data => {
|
|
if(data.result_type === "no_results")
|
|
return e.reply("Term not found");
|
|
if(!data.list[index-1])
|
|
return e.reply("Index not found");
|
|
const res = data.list[index-1];
|
|
e.reply(`[${index}/${data.list.length}] [b]${res.word}[/b]: ${res.definition.replace(/\r\n/g, "")} - ${res.example.replace(/\r\n/g, "")}`);
|
|
}).catch(err => console.log(err));
|
|
}
|
|
}));
|
|
}; |