Uwev2/src/inc/trigger/google.mjs
2019-08-22 13:51:02 +00:00

14 lines
523 B
JavaScript

import fetch from "flumm-fetch-cookies";
import config from "../../../cfg/config.json";
export default async bot => {
return [{
name: "googlesearch",
call: /^(\.|\/)google/i,
f: async e => {
const res = await (await fetch(`https://www.googleapis.com/customsearch/v1?q=${e.args.join(" ")}&num=3&cx=${config.apis.google.cx}&key=${config.apis.google.key}`)).json();
e.reply([ "Here are the top 3 Google results:", res.items.map((r, i) => `${i+1}: ${r.title} - ${r.link}`)].flat());
}
}];
};