JaBa/commands/General/shorturl.js

38 lines
1 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js"),
Discord = require("discord.js"),
fetch = require("node-fetch");
class ShortURL extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "shorturl",
dirname: __dirname,
enabled: true,
guildOnly: false,
2021-12-26 19:29:37 +05:00
aliases: ["minimize"],
2021-12-10 21:39:54 +05:00
memberPermissions: [],
2021-12-26 19:29:37 +05:00
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 1000
2021-12-10 21:39:54 +05:00
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
2021-12-10 21:39:54 +05:00
const url = args[0];
2021-12-11 01:11:50 +05:00
if (!url) return message.error("general/shorturl:MISSING_URL");
2021-12-10 21:39:54 +05:00
const res = await fetch(`https://is.gd/create.php?format=simple&url=${encodeURI(url)}`);
const body = await res.text();
2021-12-11 01:11:50 +05:00
if (body === "Error: Please enter a valid URL to shorten") return message.error("general/shorturl:MISSING_URL");
2021-12-10 21:39:54 +05:00
const embed = new Discord.MessageEmbed()
.setColor(data.config.embed.color)
2022-01-03 23:20:33 +05:00
.setFooter({ text: data.config.embed.footer })
2021-12-10 21:39:54 +05:00
.setDescription(body);
2022-01-03 23:20:33 +05:00
message.channel.send({ embeds: [embed] });
2021-12-10 21:39:54 +05:00
}
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
module.exports = ShortURL;