Merge branch 'main' into main
This commit is contained in:
commit
8788774492
15 changed files with 220 additions and 52 deletions
|
@ -62,7 +62,7 @@ async function handleAdminCommand(ctx, action, successMessage, errorMessage) {
|
|||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
} catch (error) {
|
||||
ctx.reply(errorMessage.replace('{error}', error.message), {
|
||||
ctx.reply(errorMessage.replace(/{error}/g, error.message), {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
|
@ -91,12 +91,12 @@ module.exports = (bot) => {
|
|||
handleAdminCommand(ctx, async () => {
|
||||
try {
|
||||
const commitHash = await getGitCommitHash();
|
||||
await ctx.reply(Strings.gitCurrentCommit.replace('{commitHash}', commitHash), {
|
||||
await ctx.reply(Strings.gitCurrentCommit.replace(/{commitHash}/g, commitHash), {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
} catch (error) {
|
||||
ctx.reply(Strings.gitErrRetrievingCommit.replace('{error}', error), {
|
||||
ctx.reply(Strings.gitErrRetrievingCommit.replace(/{error}/g, error), {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
|
@ -109,12 +109,12 @@ module.exports = (bot) => {
|
|||
handleAdminCommand(ctx, async () => {
|
||||
try {
|
||||
const result = await updateBot();
|
||||
await ctx.reply(Strings.botUpdated.replace('{result}', result), {
|
||||
await ctx.reply(Strings.botUpdated.replace(/{result}/g, result), {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
} catch (error) {
|
||||
ctx.reply(Strings.errorUpdatingBot.replace('{error}', error), {
|
||||
ctx.reply(Strings.errorUpdatingBot.replace(/{error}/g, error), {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
|
@ -127,7 +127,7 @@ module.exports = (bot) => {
|
|||
const botName = ctx.message.text.split(' ').slice(1).join(' ');
|
||||
handleAdminCommand(ctx, async () => {
|
||||
await ctx.telegram.setMyName(botName);
|
||||
}, Strings.botNameChanged.replace('{botName}', botName), Strings.botNameErr.replace('{error}', error));
|
||||
}, Strings.botNameChanged.replace(/{botName}/g, botName), Strings.botNameErr.replace(/{error}/g, error));
|
||||
});
|
||||
|
||||
bot.command('setbotdesc', spamwatchMiddleware, async (ctx) => {
|
||||
|
@ -135,7 +135,7 @@ module.exports = (bot) => {
|
|||
const botDesc = ctx.message.text.split(' ').slice(1).join(' ');
|
||||
handleAdminCommand(ctx, async () => {
|
||||
await ctx.telegram.setMyDescription(botDesc);
|
||||
}, Strings.botDescChanged.replace('{botDesc}', botDesc), Strings.botDescErr.replace('{error}', error));
|
||||
}, Strings.botDescChanged.replace(/{botDesc}/g, botDesc), Strings.botDescErr.replace(/{error}/g, error));
|
||||
});
|
||||
|
||||
bot.command('botkickme', spamwatchMiddleware, async (ctx) => {
|
||||
|
@ -159,7 +159,7 @@ module.exports = (bot) => {
|
|||
caption: botFile
|
||||
});
|
||||
} catch (error) {
|
||||
ctx.reply(Strings.unexpectedErr.replace('{error}', error.message), {
|
||||
ctx.reply(Strings.unexpectedErr.replace(/{error}/g, error.message), {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
|
|
|
@ -196,7 +196,11 @@ function extractMetaData(meta, key) {
|
|||
module.exports = (bot) => {
|
||||
bot.command(['d', 'device'], spamwatchMiddleware, async (ctx) => {
|
||||
const userId = ctx.from.id;
|
||||
const userName = ctx.from.first_name;
|
||||
let userName = String(ctx.from.first_name);
|
||||
|
||||
if(userName.includes("<") && userName.includes(">")) {
|
||||
userName = userName.replace("<", "").replace(">", "");
|
||||
}
|
||||
|
||||
const phone = ctx.message.text.split(" ").slice(1).join(" ");
|
||||
if (!phone) {
|
||||
|
|
|
@ -6,8 +6,8 @@ async function sendHelpMessage(ctx, isEditing) {
|
|||
const Strings = getStrings(ctx.from.language_code);
|
||||
const botInfo = await ctx.telegram.getMe();
|
||||
const helpText = Strings.botHelp
|
||||
.replace('{botName}', botInfo.first_name)
|
||||
.replace("{sourceLink}", process.env.botSource);
|
||||
.replace(/{botName}/g, botInfo.first_name)
|
||||
.replace(/{sourceLink}/g, process.env.botSource);
|
||||
const options = {
|
||||
parse_mode: 'Markdown',
|
||||
disable_web_page_preview: true,
|
||||
|
@ -35,7 +35,7 @@ module.exports = (bot) => {
|
|||
|
||||
bot.command("about", spamwatchMiddleware, async (ctx) => {
|
||||
const Strings = getStrings(ctx.from.language_code);
|
||||
const aboutMsg = Strings.botAbout.replace("{sourceLink}", `${process.env.botSource}`);
|
||||
const aboutMsg = Strings.botAbout.replace(/{sourceLink}/g, `${process.env.botSource}`);
|
||||
|
||||
ctx.reply(aboutMsg, {
|
||||
parse_mode: 'Markdown',
|
||||
|
|
|
@ -6,7 +6,7 @@ module.exports = (bot) => {
|
|||
bot.start(spamwatchMiddleware, async (ctx) => {
|
||||
const Strings = getStrings(ctx.from.language_code);
|
||||
const botInfo = await ctx.telegram.getMe();
|
||||
const startMsg = Strings.botWelcome.replace('{botName}', botInfo.first_name);
|
||||
const startMsg = Strings.botWelcome.replace(/{botName}/g, botInfo.first_name);
|
||||
|
||||
ctx.reply(startMsg, {
|
||||
parse_mode: 'Markdown',
|
||||
|
|
|
@ -41,7 +41,12 @@ const downloadFromYoutube = async (command, args) => {
|
|||
};
|
||||
|
||||
const getApproxSize = async (command, videoUrl) => {
|
||||
const args = [videoUrl, '--compat-opt', 'manifest-filesize-approx', '-O', 'filesize_approx'];
|
||||
let args = [];
|
||||
if (fs.existsSync(path.resolve(__dirname, "../props/cookies.txt"))) {
|
||||
args = [videoUrl, '--compat-opt', 'manifest-filesize-approx', '-O', 'filesize_approx', '--cookies', path.resolve(__dirname, "../props/cookies.txt")];
|
||||
} else {
|
||||
args = [videoUrl, '--compat-opt', 'manifest-filesize-approx', '-O', 'filesize_approx'];
|
||||
}
|
||||
try {
|
||||
const { stdout } = await downloadFromYoutube(command, args);
|
||||
const sizeInBytes = parseInt(stdout.trim(), 10);
|
||||
|
@ -94,14 +99,28 @@ module.exports = (bot) => {
|
|||
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(
|
||||
ctx.chat.id,
|
||||
downloadingMessage.message_id,
|
||||
null,
|
||||
Strings.ytDownload.downloadingVid, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id,
|
||||
},
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id,
|
||||
},
|
||||
);
|
||||
|
||||
const dlpArgs = [videoUrl, ...cmdArgs.split(' '), mp4File];
|
||||
|
@ -112,12 +131,12 @@ module.exports = (bot) => {
|
|||
downloadingMessage.message_id,
|
||||
null,
|
||||
Strings.ytDownload.uploadingVid, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id,
|
||||
},
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id,
|
||||
},
|
||||
);
|
||||
|
||||
if(fs.existsSync(tempMp4File)){
|
||||
if (fs.existsSync(tempMp4File)) {
|
||||
await downloadFromYoutube(ffmpegPath, ffmpegArgs);
|
||||
}
|
||||
|
||||
|
@ -126,23 +145,24 @@ module.exports = (bot) => {
|
|||
|
||||
try {
|
||||
await ctx.replyWithVideo({
|
||||
source: mp4File }, {
|
||||
source: mp4File
|
||||
}, {
|
||||
caption: message,
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id,
|
||||
});
|
||||
|
||||
|
||||
fs.unlinkSync(mp4File);
|
||||
} catch (error) {
|
||||
if (toString(error).includes("Request Entity Too Large")) {
|
||||
if (error.response.description.includes("Request Entity Too Large")) {
|
||||
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,
|
||||
},
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
const errMsg = Strings.ytDownload.uploadErr.replace("{error}", error)
|
||||
|
@ -151,9 +171,9 @@ module.exports = (bot) => {
|
|||
downloadingMessage.message_id,
|
||||
null,
|
||||
errMsg, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id,
|
||||
},
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -171,22 +191,21 @@ module.exports = (bot) => {
|
|||
downloadingMessage.message_id,
|
||||
null,
|
||||
Strings.ytDownload.libNotFound, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id,
|
||||
},
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id,
|
||||
},
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
const errMsg = Strings.ytDownload.uploadErr.replace("{error}", error)
|
||||
await ctx.telegram.editMessageText(
|
||||
ctx.chat.id,
|
||||
downloadingMessage.message_id,
|
||||
null,
|
||||
errMsg, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id,
|
||||
},
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id,
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue