diff --git a/commands/youtube.js b/commands/youtube.js index ee7dc46..cd6f507 100644 --- a/commands/youtube.js +++ b/commands/youtube.js @@ -60,30 +60,51 @@ module.exports = (bot) => { }); if (fs.existsSync(mp4File)) { - const userId = parseInt(ctx.match[2]); - const userName = ctx.from.first_name; const message = strings.ytUploadDesc .replace("{userId}", userId) - .replace("{userName}", userName); + .replace("{userName}", ctx.from.first_name); - await ctx.replyWithVideo({ - source: mp4File, - caption: `${message}`, - parse_mode: 'Markdown' + fs.stat(mp4File, async (err, stats) => { + if (err) { + console.error(err); + return; + }; + + const mbSize = stats.size / (1024 * 1024); + + if (mbSize > 50) { + await ctx.reply(strings.ytUploadLimit, { + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id, + }); + + fs.unlinkSync(mp4File); + } else { + try { + await ctx.replyWithVideo({ + source: mp4File, + caption: `${message}`, + parse_mode: 'Markdown', + }); + } catch (error) { + await ctx.reply(`\`${error}\``, { + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id, + }); + }; + }; }); - - fs.unlinkSync(mp4File); - } - } catch (error) { + }; + } catch (downloadError) { fs.unlinkSync(mp4File); const message = strings.ytDownloadErr .replace("{err}", error) .replace("{userName}", ctx.from.first_name); - ctx.reply(message, { + await ctx.reply(message, { parse_mode: 'Markdown', reply_to_message_id: ctx.message.message_id, }); } }); -}; \ No newline at end of file +}; diff --git a/locales/english.json b/locales/english.json index e2c0042..5ada41d 100644 --- a/locales/english.json +++ b/locales/english.json @@ -61,5 +61,6 @@ "ytDownloading": "*Downloading video...*", "ytUploading": "*Uploading video...*", "ytUploadDesc": "*[{userName}](tg://user?id={userId}), there is your downloaded video.*", - "ytDownloadErr": "*Error during YT video download:*\n\n`{err}`" + "ytDownloadErr": "*Error during YT video download:*\n\n`{err}`", + "ytUploadLimit": "*You have reached the 50MB upload limit for the bot. Try another video. We're trying our best to increase the limit.*" } \ No newline at end of file diff --git a/locales/portuguese.json b/locales/portuguese.json index a1c9e31..71a933f 100644 --- a/locales/portuguese.json +++ b/locales/portuguese.json @@ -61,5 +61,6 @@ "ytDownloading": "*Baixando vídeo...*", "ytUploading": "*Enviando video...*", "ytUploadDesc": "*[{userName}](tg://user?id={userId}), aqui está o seu vídeo baixado.*", - "ytDownloadErr": "*Erro durante o download do vídeo do YT:*\n\n`{err}`" + "ytDownloadErr": "*Erro durante o download do vídeo do YT:*\n\n`{err}`", + "ytUploadLimit": "*Você atingiu o limite de upload de 50MB para o bot. Tente outro vídeo. Estamos tentando o máximo para aumentar o limite.*" } \ No newline at end of file