From 39605dae96c5c56abc491eb6ee01ab95244398d9 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 13 Mar 2021 15:22:36 -0500 Subject: [PATCH] Add NSFW filtering to google results --- commands/search/google.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/commands/search/google.js b/commands/search/google.js index 2c178eae..2149da94 100644 --- a/commands/search/google.js +++ b/commands/search/google.js @@ -1,7 +1,8 @@ const Command = require('../../structures/Command'); const request = require('node-superfetch'); const cheerio = require('cheerio'); -const { URLSearchParams } = require('url'); +const { URLSearchParams, URL } = require('url'); +const { trimArray } = require('../../util/Util'); module.exports = class GoogleCommand extends Command { constructor(client) { @@ -65,10 +66,14 @@ module.exports = class GoogleCommand extends Command { const href = $(h3).parent().attr('href'); if (href) { const params = new URLSearchParams(href); - links.push(params.get('url')); + const url = new URL(params.get('url')); + if (nsfw || !this.client.adultSiteList.includes(url.host)) { + links.push(url.href); + } } } }); + if (!links.length) return null; return links[0]; } };