conf: delete video from server

This commit is contained in:
GiovaniFZ 2024-09-26 21:56:50 -03:00
parent 9e2c1104ba
commit 452aed5fd3
No known key found for this signature in database
GPG Key ID: 63DD92181B575322

View File

@ -1,8 +1,9 @@
var exec = require('child_process').exec; var exec = require('child_process').exec;
const fs = require('fs');
async function DownloadFromYoutube(command) { async function DownloadFromYoutube(command) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => { exec(command, (error, stdout, stderr) => {
if (error) { if (error) {
reject({ error, stdout, stderr }); reject({ error, stdout, stderr });
@ -18,11 +19,16 @@ module.exports = (bot) => {
const args = ctx.message.text.split(' ').slice(1).join(' '); const args = ctx.message.text.split(' ').slice(1).join(' ');
const ytCommand = 'yt-dlp ' + args + ' -o video.mp4'; const ytCommand = 'yt-dlp ' + args + ' -o video.mp4';
await DownloadFromYoutube(ytCommand); await DownloadFromYoutube(ytCommand);
try{ try {
await ctx.replyWithVideo({source: 'video.mp4'}); await ctx.replyWithVideo({ source: 'video.mp4' });
}catch (error){ } catch (error) {
console.log(error); console.log(error);
} }
try {
fs.unlinkSync('video.mp4');
} catch (error) {
console.log(error)
}
} }
) )
} }