refactor: [YT] Reply downloading or uploading status
This commit is contained in:
parent
452aed5fd3
commit
9749f8a685
3 changed files with 13 additions and 10 deletions
|
@ -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');
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue