This commit is contained in:
Daniel Odendahl Jr
2017-06-17 03:26:31 +00:00
parent 5bb78126a9
commit fd4e35533a
129 changed files with 322 additions and 319 deletions
+13 -9
View File
@@ -9,7 +9,7 @@ module.exports = class GoogleCommand extends Command {
name: 'google',
group: 'search',
memberName: 'google',
description: 'Searches Google.',
description: 'Searches Google for your query.',
args: [
{
key: 'query',
@@ -23,13 +23,17 @@ module.exports = class GoogleCommand extends Command {
async run(msg, args) {
const { query } = args;
const message = await msg.say('Searching...');
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) return message.edit('No Results.');
href = querystring.parse(href.replace('/url?', ''));
return message.edit(href.q);
try {
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');
href = querystring.parse(href.replace('/url?', ''));
return message.edit(href.q);
} catch (err) {
return message.edit(err.message);
}
}
};