| 11 | description: 'Download stickers from Telegram', |
| 12 | usage: '.tgstk <telegram sticker URL>', |
| 13 | async handler(sock, message, args, context) { |
| 14 | const { chatId, config, channelInfo } = context; |
| 15 | try { |
| 16 | if (!args[0]) { |
| 17 | await sock.sendMessage(chatId, { |
| 18 | text: '⚠️ Please enter the Telegram sticker URL!\n\nExample: .tgstk https://t.me/addstickers/Porcientoreal', |
| 19 | ...channelInfo |
| 20 | }, { quoted: message }); |
| 21 | return; |
| 22 | } |
| 23 | if (!args[0].match(/(https:\/\/t.me\/addstickers\/)/gi)) { |
| 24 | await sock.sendMessage(chatId, { |
| 25 | text: '❌ Invalid URL! Make sure it\'s a Telegram sticker URL.', |
| 26 | ...channelInfo |
| 27 | }, { quoted: message }); |
| 28 | return; |
| 29 | } |
| 30 | const packName = args[0].replace("https://t.me/addstickers/", ""); |
| 31 | const botToken = '7801479976:AAGuPL0a7kXXBYz6XUSR_ll2SR5V_W6oHl4'; |
| 32 | try { |
| 33 | const response = await fetch(`https://api.telegram.org/bot${botToken}/getStickerSet?name=${encodeURIComponent(packName)}`, { |
| 34 | method: "GET", |
| 35 | headers: { |
| 36 | "Accept": "application/json", |
| 37 | "User-Agent": "Mozilla/5.0" |
| 38 | } |
| 39 | }); |
| 40 | if (!response.ok) { |
| 41 | throw new Error(`HTTP error! status: ${response.status}`); |
| 42 | } |
| 43 | const stickerSet = await response.json(); |
| 44 | if (!stickerSet.ok || !stickerSet.result) { |
| 45 | throw new Error('Invalid sticker pack or API response'); |
| 46 | } |
| 47 | await sock.sendMessage(chatId, { |
| 48 | text: `📦 Found ${stickerSet.result.stickers.length} stickers\n⏳ Starting download...`, |
| 49 | ...channelInfo |
| 50 | }, { quoted: message }); |
| 51 | const tmpDir = path.join(process.cwd(), 'temp'); |
| 52 | if (!fs.existsSync(tmpDir)) { |
| 53 | fs.mkdirSync(tmpDir, { recursive: true }); |
| 54 | } |
| 55 | let successCount = 0; |
| 56 | for (let i = 0; i < stickerSet.result.stickers.length; i++) { |
| 57 | try { |
| 58 | const sticker = stickerSet.result.stickers[i]; |
| 59 | const fileId = sticker.file_id; |
| 60 | const fileInfo = await fetch(`https://api.telegram.org/bot${botToken}/getFile?file_id=${fileId}`); |
| 61 | if (!fileInfo.ok) |
| 62 | continue; |
| 63 | const fileData = await fileInfo.json(); |
| 64 | if (!fileData.ok || !fileData.result.file_path) |
| 65 | continue; |
| 66 | const fileUrl = `https://api.telegram.org/file/bot${botToken}/${fileData.result.file_path}`; |
| 67 | const imageResponse = await fetch(fileUrl); |
| 68 | const imageBuffer = Buffer.from(await imageResponse.arrayBuffer()); |
| 69 | const tempInput = path.join(tmpDir, `temp_${Date.now()}_${i}`); |
| 70 | const tempOutput = path.join(tmpDir, `sticker_${Date.now()}_${i}.webp`); |