This commit is contained in:
Dragon Fire
2021-03-08 17:02:02 -05:00
parent 15565f0d8b
commit a833c43428
3 changed files with 26 additions and 17 deletions
+4 -8
View File
@@ -1,7 +1,5 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
const { URL } = require('url');
const validURL = require('valid-url');
module.exports = class IsItDownCommand extends Command {
constructor(client) {
@@ -20,21 +18,19 @@ module.exports = class IsItDownCommand extends Command {
],
args: [
{
key: 'site',
key: 'url',
prompt: 'What URL do you want to test?',
type: 'string',
validate: site => Boolean(validURL.isWebUri(site))
type: 'url'
}
]
});
}
async run(msg, { site }) {
const parsed = new URL(site);
async run(msg, { url }) {
try {
const { text } = await request
.post('https://www.isitdownrightnow.com/check.php')
.query({ domain: parsed.host });
.query({ domain: url.host });
const down = text.includes('div class="statusdown"');
if (!down) return msg.reply('👍 This site is up and running.');
return msg.reply('👎 Looks like this site is down for everyone...');
+5 -9
View File
@@ -1,7 +1,5 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
const { URL } = require('url');
const validURL = require('valid-url');
module.exports = class ScreenshotCommand extends Command {
constructor(client) {
@@ -21,22 +19,20 @@ module.exports = class ScreenshotCommand extends Command {
],
args: [
{
key: 'site',
key: 'url',
prompt: 'What webpage do you want to take a screenshot of?',
type: 'string',
validate: site => Boolean(validURL.isWebUri(site))
type: 'url'
}
]
});
}
async run(msg, { site }) {
async run(msg, { url }) {
try {
const parsed = new URL(site);
if (!msg.channel.nsfw && this.client.adultSiteList.includes(parsed.host)) {
if (!msg.channel.nsfw && this.client.adultSiteList.includes(url.host)) {
return msg.reply('This site is NSFW.');
}
const { body } = await request.get(`https://image.thum.io/get/width/1920/crop/675/noanimate/${site}`);
const { body } = await request.get(`https://image.thum.io/get/width/1920/crop/675/noanimate/${url.href}`);
return msg.say({ files: [{ attachment: body, name: 'screenshot.png' }] });
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results. Invalid URL?');
+17
View File
@@ -0,0 +1,17 @@
const { ArgumentType } = require('discord.js-commando');
const { URL } = require('url');
const validURL = require('valid-url');
module.exports = class UrlType extends ArgumentType {
constructor(client) {
super(client, 'url');
}
validate(value) {
return Boolean(validURL.isWebUri(value));
}
async parse(value) {
return new URL(value);
}
};