mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-17 00:07:36 +02:00
Safe URL Command
This commit is contained in:
@@ -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!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user