snekfetch

This commit is contained in:
Daniel Odendahl Jr
2017-05-15 03:31:13 +00:00
parent d1148a0966
commit 87c0646233
40 changed files with 236 additions and 210 deletions
+7 -5
View File
@@ -1,5 +1,5 @@
const { Command } = require('discord.js-commando');
const request = require('superagent');
const snekfetch = require('snekfetch');
const cheerio = require('cheerio');
const querystring = require('querystring');
@@ -14,8 +14,7 @@ module.exports = class GoogleCommand extends Command {
{
key: 'query',
prompt: 'What would you like to search for?',
type: 'string',
parse: query => encodeURIComponent(query)
type: 'string'
}
]
});
@@ -25,8 +24,11 @@ module.exports = class GoogleCommand extends Command {
const { query } = args;
const message = await msg.say('Searching...');
try {
const { text } = await request
.get(`https://www.google.com/search?q=${query}`);
const { text } = await snekfetch
.get(`https://www.google.com/search`)
.query({
q: query
});
const $ = cheerio.load(text);
let href = $('.r').first().find('a').first().attr('href');
if (!href) throw new Error('No Results.');