mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 04:39:57 +00:00
Add command for updating the bot
This commit is contained in:
parent
236bad0576
commit
3baee6b618
@ -17,6 +17,18 @@ function getGitCommitHash() {
|
||||
});
|
||||
}
|
||||
|
||||
function updateBot() {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec('git pull', (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(`Error: ${stderr}`);
|
||||
} else {
|
||||
resolve(stdout.trim());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function formatUptime(uptime) {
|
||||
const hours = Math.floor(uptime / 3600);
|
||||
const minutes = Math.floor((uptime % 3600) / 60);
|
||||
@ -91,12 +103,30 @@ module.exports = (bot) => {
|
||||
}, '', Strings.errorRetrievingCommit);
|
||||
});
|
||||
|
||||
bot.command('updatebot', spamwatchMiddleware, async (ctx) => {
|
||||
const Strings = getStrings(ctx.from.language_code);
|
||||
handleAdminCommand(ctx, async () => {
|
||||
try {
|
||||
await ctx.reply(Strings.botUpdated, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
updateBot();
|
||||
} catch (error) {
|
||||
ctx.reply(Strings.errorUpdatingBot.replace('{error}', error), {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
}
|
||||
}, '', Strings.errorUpdatingBot);
|
||||
});
|
||||
|
||||
bot.command('setbotname', spamwatchMiddleware, async (ctx) => {
|
||||
const Strings = getStrings(ctx.from.language_code);
|
||||
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('{tgErr}', '{error}'));
|
||||
}, Strings.botNameChanged.replace('{botName}', botName), Strings.botNameErr.replace('{error}', '{error}'));
|
||||
});
|
||||
|
||||
bot.command('setbotdesc', spamwatchMiddleware, async (ctx) => {
|
||||
@ -104,7 +134,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('{tgErr}', '{error}'));
|
||||
}, Strings.botDescChanged.replace('{botDesc}', botDesc), Strings.botDescErr.replace('{error}', '{error}'));
|
||||
});
|
||||
|
||||
bot.command('botkickme', spamwatchMiddleware, async (ctx) => {
|
||||
@ -119,13 +149,20 @@ module.exports = (bot) => {
|
||||
});
|
||||
|
||||
bot.command('getfile', spamwatchMiddleware, async (ctx) => {
|
||||
const Strings = getStrings(ctx.from.language_code);
|
||||
const botFile = ctx.message.text.split(' ').slice(1).join(' ');
|
||||
handleAdminCommand(ctx, async () => {
|
||||
try{
|
||||
await ctx.replyWithDocument({source: botFile});
|
||||
}catch (error){
|
||||
console.log('ERROR');
|
||||
try {
|
||||
await ctx.replyWithDocument({
|
||||
source: botFile,
|
||||
caption: botFile
|
||||
});
|
||||
} catch (error) {
|
||||
ctx.reply(Strings.fileError.replace('{error}', error.message), {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
}
|
||||
});
|
||||
}, '', Strings.fileError);
|
||||
});
|
||||
};
|
||||
|
@ -62,5 +62,8 @@
|
||||
"ytUploading": "*Uploading video...*",
|
||||
"ytUploadDesc": "*[{userName}](tg://user?id={userId}), there is your downloaded video.*",
|
||||
"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.*"
|
||||
"ytUploadLimit": "*You have reached the 50MB upload limit for the bot. Try another video. We're trying our best to increase the limit.*",
|
||||
"fileError": "Error uploading file",
|
||||
"botUpdated": "Bot updated with success.",
|
||||
"errorUpdatingBot": "Error updating bot\n\n{error}"
|
||||
}
|
@ -62,5 +62,8 @@
|
||||
"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}`",
|
||||
"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.*"
|
||||
"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.*",
|
||||
"fileError": "Erro ao enviar o arquivo",
|
||||
"botUpdated": "Bot atualizado com sucesso.",
|
||||
"errorUpdatingBot": "Erro ao atualizar o bot\n\n{error}"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user