urbandict

This commit is contained in:
Flummi 2017-11-28 19:30:42 +01:00
parent 38fc17e74c
commit 31985a96f2

25
src/inc/trigger/urban.js Normal file
View File

@ -0,0 +1,25 @@
const rp = require("request-promise");
const url = "https://api.urbandictionary.com/v0/define"
module.exports = bot => {
bot._trigger.set("urbandict", new bot.trigger({
call: /^(\.|\/)ud .*/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();
rp(`${url}?term=${term}`, { json: true }).then(data => {
if(data.result_type === "no_results")
e.reply("Term not found");
if(!data.list[index-1])
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, "")}`);
})
}
}));
};