mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 12:49:57 +00:00
TMA module downloader
This commit is contained in:
parent
2eaa03b3d3
commit
835b56f311
73
commands/modarchive.js
Normal file
73
commands/modarchive.js
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
const axios = require('axios');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const { getStrings } = require('../plugins/checklang.js');
|
||||||
|
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
||||||
|
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
||||||
|
|
||||||
|
async function downloadModule(moduleId) {
|
||||||
|
try {
|
||||||
|
const downloadUrl = `https://api.modarchive.org/downloads.php?moduleid=${moduleId}`;
|
||||||
|
const response = await axios({
|
||||||
|
url: downloadUrl,
|
||||||
|
method: 'GET',
|
||||||
|
responseType: 'stream',
|
||||||
|
});
|
||||||
|
|
||||||
|
const disposition = response.headers['content-disposition'];
|
||||||
|
let fileName = moduleId;
|
||||||
|
|
||||||
|
if (disposition && disposition.includes('filename=')) {
|
||||||
|
fileName = disposition
|
||||||
|
.split('filename=')[1]
|
||||||
|
.split(';')[0]
|
||||||
|
.replace(/['"]/g, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
const filePath = path.resolve(__dirname, fileName);
|
||||||
|
|
||||||
|
const writer = fs.createWriteStream(filePath);
|
||||||
|
response.data.pipe(writer);
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
writer.on('finish', () => resolve({ filePath, fileName }));
|
||||||
|
writer.on('error', reject);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = (bot) => {
|
||||||
|
bot.command(['modarchive', 'tma'], spamwatchMiddleware, async (ctx) => {
|
||||||
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
|
const args = ctx.message.text.split(' ');
|
||||||
|
|
||||||
|
if (args.length !== 2) {
|
||||||
|
return ctx.reply(Strings.maInvalidModule, {
|
||||||
|
parse_mode: "Markdown",
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const moduleId = args[1];
|
||||||
|
|
||||||
|
const result = await downloadModule(moduleId);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
const { filePath, fileName } = result;
|
||||||
|
|
||||||
|
await ctx.replyWithDocument({
|
||||||
|
source: filePath,
|
||||||
|
caption: fileName,
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.unlinkSync(filePath);
|
||||||
|
} else {
|
||||||
|
ctx.reply(Strings.maDownloadError, {
|
||||||
|
parse_mode: "Markdown",
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
@ -46,10 +46,12 @@
|
|||||||
"mainCommands": "Main commands",
|
"mainCommands": "Main commands",
|
||||||
"mainCommandsDesc": "*Main commands*\n\n- /help: Show bot's help\n- /start: Start the bot\n- /privacy: Read the bot's Privacy Policy",
|
"mainCommandsDesc": "*Main commands*\n\n- /help: Show bot's help\n- /start: Start the bot\n- /privacy: Read the bot's Privacy Policy",
|
||||||
"usefulCommands": "Useful commands",
|
"usefulCommands": "Useful commands",
|
||||||
"usefulCommandsDesc": "*Useful commands*\n\n- /chatinfo: Send information about the group\n- /userinfo: Send information about yourself\n- /d | /device `<model>`: Search for a device on GSMArena and show its specs.\n- /lt | /lmu | /last | /lfm `<username>`: Show the last song from a specified Last.fm profile + number of plays.\n- /weather | /clima `city`: See weather status for a specific location.",
|
"usefulCommandsDesc": "*Useful commands*\n\n- /chatinfo: Send information about the group\n- /userinfo: Send information about yourself\n- /d | /device `<model>`: Search for a device on GSMArena and show its specs.\n- /lt | /lmu | /last | /lfm `<username>`: Show the last song from a specified Last.fm profile + number of plays.\n- /weather | /clima `<city>`: See weather status for a specific location.\n- /modarchive | /tma `<module id>`: Download a module from The Mod Archive",
|
||||||
"funnyCommands": "Funny commands",
|
"funnyCommands": "Funny commands",
|
||||||
"funnyCommandsDesc": "*Funny commands*\n\n- /gay: Check if you are gay\n- /furry: Check if you are a furry\n- /random: Pick a random number between 0-10",
|
"funnyCommandsDesc": "*Funny commands*\n\n- /gay: Check if you are gay\n- /furry: Check if you are a furry\n- /random: Pick a random number between 0-10",
|
||||||
"interactiveEmojis": "Interactive emojis",
|
"interactiveEmojis": "Interactive emojis",
|
||||||
"interactiveEmojisDesc": "*Interactive emojis*\n\n- /dice: Roll a dice\n- /idice: Infinitely roll a colored dice\n- /slot: Try to combine the figures!\n- /ball: Try to kick the ball into the goal!\n- /bowling: Try to hit the pins!\n- /dart: Try to hit the target!",
|
"interactiveEmojisDesc": "*Interactive emojis*\n\n- /dice: Roll a dice\n- /idice: Infinitely roll a colored dice\n- /slot: Try to combine the figures!\n- /ball: Try to kick the ball into the goal!\n- /bowling: Try to hit the pins!\n- /dart: Try to hit the target!",
|
||||||
"goBack": "Back"
|
"goBack": "Back",
|
||||||
|
"maInvalidModule": "Please provide a valid module ID from The Mod Archive.\nExample: `/modarchive 81574`",
|
||||||
|
"maDownloadError": "Error downloading the file. Check the module ID and try again."
|
||||||
}
|
}
|
@ -46,10 +46,12 @@
|
|||||||
"mainCommands": "Comandos principais",
|
"mainCommands": "Comandos principais",
|
||||||
"mainCommandsDesc": "*Comandos principais*\n\n- /help: Exibe a ajuda do bot\n- /start: Inicia o bot\n- /privacy: Leia a política de privacidade do bot",
|
"mainCommandsDesc": "*Comandos principais*\n\n- /help: Exibe a ajuda do bot\n- /start: Inicia o bot\n- /privacy: Leia a política de privacidade do bot",
|
||||||
"usefulCommands": "Comandos úteis",
|
"usefulCommands": "Comandos úteis",
|
||||||
"usefulCommandsDesc": "*Comandos úteis*\n\n- /chatinfo: Envia informações sobre o grupo\n- /userinfo: Envia informações sobre você\n- /d | /device `<modelo>`: Pesquisa um dispositivo no GSMArena e mostra suas especificações.\n- /lt | /lmu | /last | /lfm `<usuário>`: Mostra a última música de um perfil especificado no Last.fm + o número de reproduções.\n- /weather | /clima `cidade`: Veja o status do clima para uma localização específica",
|
"usefulCommandsDesc": "*Comandos úteis*\n\n- /chatinfo: Envia informações sobre o grupo\n- /userinfo: Envia informações sobre você\n- /d | /device `<modelo>`: Pesquisa um dispositivo no GSMArena e mostra suas especificações.\n- /lt | /lmu | /last | /lfm `<usuário>`: Mostra a última música de um perfil especificado no Last.fm + o número de reproduções.\n- /weather | /clima `<cidade>`: Veja o status do clima para uma localização específica\n- /modarchive | /tma `<id do módulo>`: Baixa um módulo do The Mod Archive",
|
||||||
"funnyCommands": "Comandos engraçados",
|
"funnyCommands": "Comandos engraçados",
|
||||||
"funnyCommandsDesc": "*Comandos engraçados*\n\n- /gay: Verifique se você é gay\n- /furry: Verifique se você é furry\n- /random: Escolhe um número aleatório entre 0-10",
|
"funnyCommandsDesc": "*Comandos engraçados*\n\n- /gay: Verifique se você é gay\n- /furry: Verifique se você é furry\n- /random: Escolhe um número aleatório entre 0-10",
|
||||||
"interactiveEmojis": "Emojis interativos",
|
"interactiveEmojis": "Emojis interativos",
|
||||||
"interactiveEmojisDesc": "*Emojis interativos*\n\n- /dice: Jogue um dado\n- /idice: Role infinitamente um dado colorido\n- /slot: Tente combinar as figuras!\n- /ball: Tente chutar a bola no gol!\n- /bowling: Tente derrubar os pinos!\n- /dart: Tente acertar o alvo!",
|
"interactiveEmojisDesc": "*Emojis interativos*\n\n- /dice: Jogue um dado\n- /idice: Role infinitamente um dado colorido\n- /slot: Tente combinar as figuras!\n- /ball: Tente chutar a bola no gol!\n- /bowling: Tente derrubar os pinos!\n- /dart: Tente acertar o alvo!",
|
||||||
"goBack": "Voltar"
|
"goBack": "Voltar",
|
||||||
|
"maInvalidModule": "Por favor, forneça um ID de módulo válido do The Mod Archive.\nExemplo: `/modarchive 81574`",
|
||||||
|
"maDownloadError": "Erro ao baixar o arquivo. Verifique o ID do módulo e tente novamente."
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user