From a1bbaed04b6dbc4381c0f3ffedf381b734a66c00 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 18 Mar 2021 17:08:12 -0400 Subject: [PATCH] Random user agents for google and rotten tomatoes --- commands/search/google.js | 3 ++- commands/search/rotten-tomatoes.js | 4 +++- package.json | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/commands/search/google.js b/commands/search/google.js index e1767f17..4eec521a 100644 --- a/commands/search/google.js +++ b/commands/search/google.js @@ -1,6 +1,7 @@ const Command = require('../../structures/Command'); const request = require('node-superfetch'); const cheerio = require('cheerio'); +const UserAgent = require('user-agents'); const { URLSearchParams, URL } = require('url'); module.exports = class GoogleCommand extends Command { @@ -57,7 +58,7 @@ module.exports = class GoogleCommand extends Command { filter: 0, q: query }) - .set({ 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1' }); + .set({ 'User-Agent': new UserAgent().toString() }); const $ = cheerio.load(text); const links = []; $('body').find('h3').each((i, h3) => { diff --git a/commands/search/rotten-tomatoes.js b/commands/search/rotten-tomatoes.js index aa23ac47..4ad4ff51 100644 --- a/commands/search/rotten-tomatoes.js +++ b/commands/search/rotten-tomatoes.js @@ -1,6 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); +const UserAgent = require('user-agents'); const { shorten } = require('../../util/Util'); module.exports = class RottenTomatoesCommand extends Command { @@ -57,7 +58,8 @@ module.exports = class RottenTomatoesCommand extends Command { .query({ limit: 10, q: query - }); + }) + .set({ 'User-Agent': new UserAgent().toString() }); if (!body.movies.length) return null; const find = body.movies.find(m => m.name.toLowerCase() === query.toLowerCase()) || body.movies[0]; return find.url.replace('/m/', ''); diff --git a/package.json b/package.json index aa895ca2..c9967b8d 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "tesseract.js": "^2.1.4", "text-diff": "^1.0.1", "tictactoe-minimax-ai": "^1.2.1", + "user-agents": "^1.0.594", "valid-url": "^1.0.9", "winston": "^3.3.3", "ytdl-core": "^4.5.0"