56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
const { EmbedBuilder } = require('discord.js');
|
|
const fs = require('fs');
|
|
const { exec } = require("child_process");
|
|
|
|
module.exports = {
|
|
name: "short-url",
|
|
description: "Shortens a URL using small.ssh.surf",
|
|
options: [{
|
|
"name": "url",
|
|
"description": "The URL that you want shorter",
|
|
"required": true,
|
|
"type": 3 // 6 is type USER
|
|
}],
|
|
run: async (client, interaction) => {
|
|
let rand = Math.floor(Math.random() * 99999).toString();
|
|
let URL = interaction.options._hoistedOptions[0].value
|
|
var dir = '/var/www/html/short/' + rand;
|
|
|
|
const content = "<?php\nheader(\"Location: " + URL + "\")\n?>";
|
|
|
|
console.log(content)
|
|
|
|
if (!fs.existsSync(dir)) {
|
|
fs.mkdirSync(dir);
|
|
console.log("Created: " + '/var/www/html/short/' + rand)
|
|
|
|
try {
|
|
fs.writeFileSync('/var/www/html/short/' + rand + "/index.php", content);
|
|
// file written successfully
|
|
exec("chown -R www-data:www-data /var/www/html/short/", (error, stdout, stderr) => {
|
|
if (error) {
|
|
console.log(`error: ${error.message}`);
|
|
return;
|
|
}
|
|
if (stderr) {
|
|
console.log(`stderr: ${stderr}`);
|
|
return;
|
|
}
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setColor("#FF0000")
|
|
.setTitle("The URL has been shrunk!")
|
|
.setDescription("https://small.ssh.surf/" + rand)
|
|
.setTimestamp()
|
|
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
|
interaction.followUp({ embeds: [embed] });
|
|
rand = Math.floor(Math.random() * 99999).toString();
|
|
});
|
|
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
}
|
|
},
|
|
};
|