Change in the way Requests work

This commit is contained in:
Daniel Odendahl Jr
2017-04-03 20:38:18 +00:00
parent 0d05032bb3
commit 06e1cd9c50
18 changed files with 213 additions and 118 deletions
+6 -3
View File
@@ -27,14 +27,17 @@ module.exports = class GoogleCommand extends commando.Command {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
console.log(`[Command] ${message.content}`);
let thingToSearch = encodeURI(args.query);
let thingToSearch = args.query;
let searchMsg = await message.say('Searching...');
try {
let response = await request
.get(`https://www.google.com/search?q=${thingToSearch}`);
.get(`https://www.google.com/search`)
.query({
q: thingToSearch
});
const $ = cheerio.load(response.text);
let href = $('.r').first().find('a').first().attr('href');
if (!href) return searchMsg.edit(':x: Error! No Results Found!');
//if (!href) return searchMsg.edit(':x: Error! No Results Found!');
href = querystring.parse(href.replace('/url?', ''));
return searchMsg.edit(href.q);
}