diff --git a/README.md b/README.md index 067d0df7..e764dc2a 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,7 @@ API. All are free unless otherwise stated. - [Maps Static API](https://console.developers.google.com/apis/library/static-maps-backend.googleapis.com) - [Google Calendar API](https://console.developers.google.com/apis/library/calendar-json.googleapis.com) - [Books API](https://console.developers.google.com/apis/library/books.googleapis.com) + - [Safe Browsing API](https://console.developers.google.com/apis/library/safebrowsing.googleapis.com) - Go to the [Perspective API website](https://www.perspectiveapi.com/#/home) to set up the Perspective API. * `GOV_KEY` can be obtained at the [NASA Open APIs portal](https://api.nasa.gov/). * `IDIOT_PAGE_ID` is the ID of a Wikipedia article for use in the `idiot` command. Not required, and defaults to `Donald_Trump`. If this offends you, I don't care. @@ -252,7 +253,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 532 +Total: 533 ### Utility: @@ -522,6 +523,7 @@ Total: 532 * **has-transparency:** Determines if an image has transparency in it. * **image-size:** Determines the size of an image. * **read-qr-code:** Reads a QR Code. +* **safe-url:** Determines if a URL is safe or not. * **scrabble-score:** Responds with the scrabble score of a word. * **severe-toxicity:** Determines the toxicity of text, but less sensitive to milder language. * **toxicity:** Determines the toxicity of text. @@ -1117,6 +1119,7 @@ here. * phoebe-teaching-joey ([Noto Font](https://www.google.com/get/noto/)) * pills ([Noto Font](https://www.google.com/get/noto/)) * plankton-plan ([Noto Font](https://www.google.com/get/noto/)) + * safe-url ([Safe Browsing API](https://developers.google.com/safe-browsing/)) * scroll-of-truth ([Noto Font](https://www.google.com/get/noto/)) * sonic-says ([Noto Font](https://www.google.com/get/noto/)) * sos ([Noto Font](https://www.google.com/get/noto/)) diff --git a/commands/analyze/safe-url.js b/commands/analyze/safe-url.js new file mode 100644 index 00000000..e973b9e4 --- /dev/null +++ b/commands/analyze/safe-url.js @@ -0,0 +1,55 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { version } = require('../../package'); +const { GOOGLE_KEY } = process.env; + +module.exports = class SafeUrlCommand extends Command { + constructor(client) { + super(client, { + name: 'safe-url', + aliases: ['check-url', 'safe-browsing', 'virus', 'safe-link', 'check-link'], + group: 'analyze', + memberName: 'safe-url', + description: 'Determines if a URL is safe or not.', + credit: [ + { + name: 'Google', + url: 'https://www.google.com/', + reason: 'Safe Browsing API', + reasonURL: 'https://developers.google.com/safe-browsing/' + } + ], + args: [ + { + key: 'url', + prompt: 'What URL do you want to test?', + type: 'string' + } + ] + }); + } + + async run(msg, { url }) { + try { + const { body } = await request + .post('https://safebrowsing.googleapis.com/v4/threatMatches:find') + .query({ key: GOOGLE_KEY }) + .send({ + client: { + clientId: 'xiao-discord', + clientVersion: version + }, + threatInfo: { + threatTypes: ['MALWARE', 'SOCIAL_ENGINEERING'], + platformTypes: ['ANY_PLATFORM'], + threatEntryTypes: ['URL'], + threatEntries: [{ url }] + } + }); + if (body.matches.length) return msg.reply('⚠️ This link is unsafe! **Do not click it!** ⚠️'); + return msg.reply(`👍 Good to go! This link is safe!`); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 04e92255..3a79d670 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "119.13.0", + "version": "119.14.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {