Files
xiao/types/url.js
T
2021-04-23 21:54:57 -04:00

19 lines
456 B
JavaScript

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) || validURL.isWebUri(`http://${value}`));
}
parse(value) {
if (!validURL.isWebUri(value)) return new URL(`http://${value}`);
return new URL(value);
}
};