Get multiple google results

This commit is contained in:
Dragon Fire
2021-03-13 15:25:45 -05:00
parent 3820b12e16
commit b55be97ca3
+6 -7
View File
@@ -2,7 +2,6 @@ const Command = require('../../structures/Command');
const request = require('node-superfetch'); const request = require('node-superfetch');
const cheerio = require('cheerio'); const cheerio = require('cheerio');
const { URLSearchParams, URL } = require('url'); const { URLSearchParams, URL } = require('url');
const { trimArray } = require('../../util/Util');
module.exports = class GoogleCommand extends Command { module.exports = class GoogleCommand extends Command {
constructor(client) { constructor(client) {
@@ -39,14 +38,14 @@ module.exports = class GoogleCommand extends Command {
} }
async run(msg, { query }) { async run(msg, { query }) {
let href; let hrefs;
try { try {
href = await this.search(query, msg.channel.nsfw || false); hrefs = await this.search(query, msg.channel.nsfw || false);
} catch { } catch {
href = `http://lmgtfy.com/?iie=1&q=${encodeURIComponent(query)}`; hrefs = [`http://lmgtfy.com/?iie=1&q=${encodeURIComponent(query)}`];
} }
if (!href) return msg.say('Could not find any results.'); if (!hrefs) return msg.say('Could not find any results.');
return msg.say(`<${href}>`); return msg.say(hrefs.map(href => `<${href}>`).join('\n\n'));
} }
async search(query, nsfw) { async search(query, nsfw) {
@@ -74,6 +73,6 @@ module.exports = class GoogleCommand extends Command {
} }
}); });
if (!links.length) return null; if (!links.length) return null;
return links[0]; return links.slice(0, 3);
} }
}; };