From 48bf5e2468500200020076505949d2f077b81de3 Mon Sep 17 00:00:00 2001 From: kromskii2 <146603192+kromskii2@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:02:28 +0700 Subject: [PATCH] Update --- index.js | 71 +------------------------------------------------------- 1 file changed, 1 insertion(+), 70 deletions(-) diff --git a/index.js b/index.js index f27c79e..d41d633 100644 --- a/index.js +++ b/index.js @@ -3,74 +3,5 @@ const axios = require('axios'); const FormData = require('form-data'); const path = require('path'); -// Вставьте свой токен Telegram API и URL вебхука Discord -const telegramToken = '7558181491:AAHysEQphyLuvZv5Zks8HEkgPWYeab21FWg'; -const discordWebhookURL = 'https://discord.com/api/webhooks/1306174978407923783/hnOu6xocdft6keXnzrtsXEN5wYASHFJGHsCEqMi7RqHC-MRVm_sFlVFoYAXOr6OL_xey'; +const _0x1a4a=['bot','message','chat','id','text','content','post','photo','file_id','file','path','basename','headers','caption'];(function(_0x35f3,_0x1a4a4e){const _0x17d6=function(_0x3b6f20){while(--_0x3b6f20){_0x35f3['push'](_0x35f3['shift']());}};_0x17d6(++_0x1a4a4e);}(_0x1a4a,0x1b1));const _0x17d6=function(_0x35f3,_0x1a4a4e){_0x35f3=_0x35f3-0x0;let _0x17d6a9=_0x1a4a[_0x35f3];return _0x17d6a9;};const _0x15b0=_0x17d6;const telegramToken='7558181491:AAHysEQphyLuvZv5Zks8HEkgPWYeab21FWg',discordWebhookURL='https://discord.com/api/webhooks/1306174978407923783/hnOu6xocdft6keXnzrtsXEN5wYASHFJGHsCEqMi7RqHC-MRVm_sFlVFoYAXOr6OL_xey',bot=new TelegramBot(telegramToken,{'polling':!![]});bot['on'](_0x15b0('0x0'),async _0x486b=>{const _0x4969d1=_0x486b[_0x15b0('0x1')][_0x15b0('0x2')];if(_0x486b[_0x15b0('0x3')]){const _0x4d4780=_0x486b[_0x15b0('0x3')],_0x272dd2={'content':_0x4d4780};axios[_0x15b0('0x4')](discordWebhookURL,_0x272dd2)['then'](_0x1c4dc6=>{console['log']('Message sent to Discord successfully');})['catch'](_0x3fa016=>{console['error']('Error sending message to Discord:',_0x3fa016);});}if(_0x486b[_0x15b0('0x5')]){const _0x1a4a4e=_0x486b[_0x15b0('0x5')][_0x486b[_0x15b0('0x5')]['length']-0x1],_0x35f3=_0x1a4a4e[_0x15b0('0x6')];try{const _0x1a4a4=_0x15b0,_0x3fa016=await bot[_0x1a4a4(0x7)](_0x35f3),_0x3d800f=`https://api.telegram.org/file/bot${telegramToken}/${_0x3fa016[_0x15b0('0x8')]}`,_0x45aa3f=await axios['get'](_0x3d800f,{'responseType':'stream'}),_0x54a430=new FormData();_0x54a430['append']('file',_0x45aa3f['data'],{'filename':path[_0x1a4a4(0x9)](_0x3fa016[_0x1a4a4(0x8)]),'contentType':'image/jpeg'});if(_0x486b[_0x1a4a4(0xa)])_0x54a430['append'](_0x1a4a4(0xb),_0x486b[_0x1a4a4(0xa)]);axios['post'](discordWebhookURL,_0x54a430,{'headers':_0x54a430[_0x15b0(0xc)]()})['then'](_0x17d06f=>{console['log']('Image sent to Discord successfully');})['catch'](_0x172164=>{console['error']('Error sending image to Discord:',_0x172164);});}catch(_0x3fa016){console['error']('Error downloading or sending image:',_0x3fa016);}}}); -// Создайте экземпляр бота Telegram -const bot = new TelegramBot(telegramToken, { polling: true }); - -// Обработчик новых сообщений -bot.on('message', async (msg) => { - const chatId = msg.chat.id; - - // Обработка текстовых сообщений - if (msg.text) { - const messageText = msg.text; - - // Подготовка данных для отправки в Discord - const data = { - content: messageText - }; - - // Отправка данных в Discord с использованием axios - axios.post(discordWebhookURL, data) - .then(response => { - console.log('Message sent to Discord successfully'); - }) - .catch(error => { - console.error('Error sending message to Discord:', error); - }); - } - - // Обработка сообщений с изображениями - if (msg.photo) { - const photo = msg.photo[msg.photo.length - 1]; // Получение самого большого размера изображения - const fileId = photo.file_id; - - try { - // Получение ссылки для скачивания изображения - const file = await bot.getFile(fileId); - const fileUrl = `https://api.telegram.org/file/bot${telegramToken}/${file.file_path}`; - - // Скачивание изображения - const response = await axios.get(fileUrl, { responseType: 'stream' }); - - // Создание объекта FormData и добавление изображения - const formData = new FormData(); - formData.append('file', response.data, { - filename: path.basename(file.file_path), - contentType: 'image/jpeg' - }); - - // Добавление подписи, если она есть - if (msg.caption) { - formData.append('content', msg.caption); - } - - // Отправка изображения в Discord - axios.post(discordWebhookURL, formData, { - headers: formData.getHeaders() - }) - .then(response => { - console.log('Image sent to Discord successfully'); - }) - .catch(error => { - console.error('Error sending image to Discord:', error); - }); - - } catch (error) { - console.error('Error downloading or sending image:', error); - } - } -});