mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-16 15:57:54 +02:00
Fix Google Scrape Search
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.118 Safari/537.36"
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ const Command = require('../../structures/Command');
|
|||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
const querystring = require('querystring');
|
const querystring = require('querystring');
|
||||||
|
const { agent } = require('../../assets/json/user-agent');
|
||||||
const { GOOGLE_KEY, CUSTOM_SEARCH_ID } = process.env;
|
const { GOOGLE_KEY, CUSTOM_SEARCH_ID } = process.env;
|
||||||
|
|
||||||
module.exports = class GoogleCommand extends Command {
|
module.exports = class GoogleCommand extends Command {
|
||||||
@@ -43,10 +44,10 @@ module.exports = class GoogleCommand extends Command {
|
|||||||
let href;
|
let href;
|
||||||
const nsfw = msg.channel.nsfw || false;
|
const nsfw = msg.channel.nsfw || false;
|
||||||
try {
|
try {
|
||||||
href = await this.customSearch(query, nsfw);
|
href = await this.searchGoogle(query, nsfw);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
try {
|
try {
|
||||||
href = await this.searchGoogle(query, nsfw);
|
href = await this.customSearch(query, nsfw);
|
||||||
} catch (err2) {
|
} catch (err2) {
|
||||||
href = `http://lmgtfy.com/?iie=1&q=${encodeURIComponent(query)}`;
|
href = `http://lmgtfy.com/?iie=1&q=${encodeURIComponent(query)}`;
|
||||||
}
|
}
|
||||||
@@ -61,7 +62,8 @@ module.exports = class GoogleCommand extends Command {
|
|||||||
.query({
|
.query({
|
||||||
safe: nsfw ? 'off' : 'on',
|
safe: nsfw ? 'off' : 'on',
|
||||||
q: query
|
q: query
|
||||||
});
|
})
|
||||||
|
.set('User-Agent', agent);
|
||||||
const $ = cheerio.load(text);
|
const $ = cheerio.load(text);
|
||||||
let href = $('.r').first().find('a').first().attr('href');
|
let href = $('.r').first().find('a').first().attr('href');
|
||||||
if (!href) return null;
|
if (!href) return null;
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "110.0.2",
|
"version": "110.0.3",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user