mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
URL type
This commit is contained in:
@@ -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...');
|
||||
|
||||
@@ -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?');
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user