From b465ba29dd2dd578569c0ea7720ac550727ff029 Mon Sep 17 00:00:00 2001 From: Luquinhas Date: Fri, 10 Jan 2025 12:27:55 -0300 Subject: [PATCH] Some misc changes --- src/bot.js | 4 ++-- src/commands/youtube.js | 30 ++++++++++++------------------ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/bot.js b/src/bot.js index 72e6ff1..ad909db 100644 --- a/src/bot.js +++ b/src/bot.js @@ -7,7 +7,7 @@ require('./plugins/ytdlp-wrapper.js'); // require('./plugins/termlogger.js'); const bot = new Telegraf(process.env.botToken); -const MAX_RETRIES = 5; +const maxRetries = process.env.maxRetries || 5; let restartCount = 0; const loadCommands = () => { @@ -38,7 +38,7 @@ const startBot = async () => { restartCount = 0; } catch (error) { console.error('Failed to start bot:', error.message); - if (restartCount < MAX_RETRIES) { + if (restartCount < maxRetries) { restartCount++; console.log(`Retrying to start bot... Attempt ${restartCount}`); setTimeout(startBot, 5000); diff --git a/src/commands/youtube.js b/src/commands/youtube.js index 1a74b74..c881e14 100644 --- a/src/commands/youtube.js +++ b/src/commands/youtube.js @@ -129,23 +129,12 @@ module.exports = (bot) => { source: mp4File }, { caption: message, parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id, }); - - if (approxSizeInMB >= 50) { - await ctx.telegram.editMessageText( - ctx.chat.id, - downloadingMessage.message_id, - null, - Strings.ytDownload.sizeLimitWarn, { - parse_mode: 'Markdown', - reply_to_message_id: ctx.message.message_id, - }, - ); - } - + fs.unlinkSync(mp4File); } catch (error) { - if (error.includes("Request Entity Too Large")) { + if (toString(error).includes("Request Entity Too Large")) { await ctx.telegram.editMessageText( ctx.chat.id, downloadingMessage.message_id, @@ -188,10 +177,15 @@ module.exports = (bot) => { } } catch (error) { console.error(error); - await ctx.reply(Strings.ytDownload.uploadErr, { - parse_mode: 'Markdown', - reply_to_message_id: ctx.message.message_id, - }); + await ctx.telegram.editMessageText( + ctx.chat.id, + downloadingMessage.message_id, + null, + Strings.ytDownload.uploadErr, { + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id, + }, + ); } }); }; \ No newline at end of file