From 452aed5fd31fe771ac36fd2506ddaab9b2a9fafa Mon Sep 17 00:00:00 2001 From: GiovaniFZ Date: Thu, 26 Sep 2024 21:56:50 -0300 Subject: [PATCH] conf: delete video from server --- commands/youtube.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/commands/youtube.js b/commands/youtube.js index 869ad61..7d4013a 100644 --- a/commands/youtube.js +++ b/commands/youtube.js @@ -1,8 +1,9 @@ var exec = require('child_process').exec; +const fs = require('fs'); async function DownloadFromYoutube(command) { return new Promise((resolve, reject) => { - + exec(command, (error, stdout, stderr) => { if (error) { reject({ error, stdout, stderr }); @@ -18,11 +19,16 @@ module.exports = (bot) => { const args = ctx.message.text.split(' ').slice(1).join(' '); const ytCommand = 'yt-dlp ' + args + ' -o video.mp4'; await DownloadFromYoutube(ytCommand); - try{ - await ctx.replyWithVideo({source: 'video.mp4'}); - }catch (error){ - console.log(error); - } + try { + await ctx.replyWithVideo({ source: 'video.mp4' }); + } catch (error) { + console.log(error); + } + try { + fs.unlinkSync('video.mp4'); + } catch (error) { + console.log(error) + } } ) } \ No newline at end of file