mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-04-28 09:15:57 +00:00
feat: better error handling and fixed file size checking for /yt
This commit is contained in:
parent
935385eb4f
commit
62e7a1393b
@ -6,6 +6,12 @@ require('@dotenvx/dotenvx').config({ path: "config.env" });
|
|||||||
require('./plugins/ytdlp-wrapper.js');
|
require('./plugins/ytdlp-wrapper.js');
|
||||||
// require('./plugins/termlogger.js');
|
// require('./plugins/termlogger.js');
|
||||||
|
|
||||||
|
// Ensures bot token is set, and not default value
|
||||||
|
if (!process.env.botToken || process.env.botToken === 'InsertYourBotTokenHere') {
|
||||||
|
console.error('Bot token is not set. Please set the bot token in the config.env file.')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
const bot = new Telegraf(process.env.botToken);
|
const bot = new Telegraf(process.env.botToken);
|
||||||
const maxRetries = process.env.maxRetries || 5;
|
const maxRetries = process.env.maxRetries || 5;
|
||||||
let restartCount = 0;
|
let restartCount = 0;
|
||||||
|
@ -94,6 +94,20 @@ module.exports = (bot) => {
|
|||||||
getApproxSize(ytDlpPath, videoUrl),
|
getApproxSize(ytDlpPath, videoUrl),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (approxSizeInMB > 50) {
|
||||||
|
await ctx.telegram.editMessageText(
|
||||||
|
ctx.chat.id,
|
||||||
|
downloadingMessage.message_id,
|
||||||
|
null,
|
||||||
|
Strings.ytDownload.uploadLimit, {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_to_message_id: ctx.message.message_id,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await ctx.telegram.editMessageText(
|
await ctx.telegram.editMessageText(
|
||||||
ctx.chat.id,
|
ctx.chat.id,
|
||||||
downloadingMessage.message_id,
|
downloadingMessage.message_id,
|
||||||
@ -134,7 +148,7 @@ module.exports = (bot) => {
|
|||||||
|
|
||||||
fs.unlinkSync(mp4File);
|
fs.unlinkSync(mp4File);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (toString(error).includes("Request Entity Too Large")) {
|
if (error.response.description.includes("Request Entity Too Large")) {
|
||||||
await ctx.telegram.editMessageText(
|
await ctx.telegram.editMessageText(
|
||||||
ctx.chat.id,
|
ctx.chat.id,
|
||||||
downloadingMessage.message_id,
|
downloadingMessage.message_id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user