feat: Implement /yt command

This commit is contained in:
GiovaniFZ 2024-09-26 17:08:30 -03:00
parent 491a11ac85
commit 8521ad95db
No known key found for this signature in database
GPG key ID: 63DD92181B575322
4 changed files with 40 additions and 1 deletions

28
commands/youtube.js Normal file
View file

@ -0,0 +1,28 @@
var exec = require('child_process').exec;
async function DownloadFromYoutube(command) {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject({ error, stdout, stderr });
} else {
resolve({ error, stdout, stderr });
}
});
});
}
module.exports = (bot) => {
bot.command('yt', async (ctx) => {
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);
}
}
)
}