refactor: [YT] Reply downloading or uploading status

This commit is contained in:
GiovaniFZ 2024-09-27 15:30:14 -03:00
parent 452aed5fd3
commit 9749f8a685
No known key found for this signature in database
GPG key ID: 63DD92181B575322
3 changed files with 13 additions and 10 deletions

View file

@ -1,5 +1,6 @@
var exec = require('child_process').exec;
const fs = require('fs');
const { getStrings } = require('../plugins/checklang');
async function DownloadFromYoutube(command) {
return new Promise((resolve, reject) => {
@ -16,19 +17,17 @@ async function DownloadFromYoutube(command) {
module.exports = (bot) => {
bot.command('yt', async (ctx) => {
const Strings = getStrings(ctx.from.language_code);
const args = ctx.message.text.split(' ').slice(1).join(' ');
const ytCommand = 'yt-dlp ' + args + ' -o video.mp4';
ctx.reply(Strings.downloading);
await DownloadFromYoutube(ytCommand);
try {
ctx.reply(Strings.uploading);
await ctx.replyWithVideo({ source: 'video.mp4' });
} catch (error) {
console.log(error);
ctx.reply('Error!')
}
try {
fs.unlinkSync('video.mp4');
} catch (error) {
console.log(error)
}
}
)
fs.unlinkSync('video.mp4');
})
}