From d8f596740cba343e1db4c9484dafc5a99d4b33a4 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Fri, 10 May 2024 10:06:44 -0400 Subject: [PATCH] Add google command --- commands/search/google.js | 46 +++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 commands/search/google.js diff --git a/commands/search/google.js b/commands/search/google.js new file mode 100644 index 00000000..1821cead --- /dev/null +++ b/commands/search/google.js @@ -0,0 +1,46 @@ +const Command = require('../../framework/Command'); +const google = require('googlethis'); +const { stripIndents } = require('common-tags'); + +module.exports = class GoogleCommand extends Command { + constructor(client) { + super(client, { + name: 'google', + aliases: ['google-this', 'search'], + group: 'search', + memberName: 'google', + description: 'Searches Google.', + credit: [ + { + name: 'Google', + url: 'https://www.google.com/', + reason: 'Search Results' + } + ], + args: [ + { + key: 'query', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + const results = await google.search(query, { + page: 0, + safe: !msg.channel.nsfw, + parse_ads: false, + additional_params: { + hl: 'en' + } + }); + if (!results.length) return msg.reply('Could not find any results.'); + const result = results[0]; + return msg.reply(stripIndents` + **${result.title}** + ${result.description} + <${result.url}> + `); + } +}; diff --git a/package.json b/package.json index 5a5eed9e..3f2610f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "151.0.0", + "version": "151.1.0", "description": "Your personal server companion.", "main": "Xiao.js", "private": true, @@ -52,6 +52,7 @@ "font-finder": "^1.1.0", "gifencoder": "^2.0.1", "gm": "^1.25.0", + "googlethis": "^1.8.0", "html-entities": "^2.5.2", "image-to-ascii": "^3.2.0", "ioredis": "^5.4.1",