mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-17 00:07:36 +02:00
23
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user