// plugins/tools/telegramnft.js /* * Telegram NFT Gift Scraper * Creator: t.me/FreeScrape * Type: Plugins ESM * Modified for Lulli Bot * Channel: https://whatsapp.com/channel/0029VbCMK1N35fLocOdiz00T */ import https from 'node:https'; import * as cheerio from 'cheerio'; class TelegramNFTScraper { constructor() { this.userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36'; } async _fetchHtml(url) { return new Promise((resolve, reject) => { const targetUrl = url.startsWith('http') ? url : `https://${url}`; const req = https.get(targetUrl, { headers: { 'User-Agent': this.userAgent, 'Accept-Language': 'en-US,en;q=0.9' } }, (res) => { if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { return this._fetchHtml(res.headers.location).then(resolve).catch(reject); } let data = ''; res.on('data', chunk => data += chunk); res.on('end', () => resolve(data)); }); req.on('error', reject); }); } _getTableValue($, label) { const row = $('.tgme_gift_table tbody tr').filter((i, el) => { return $(el).find('th').text().trim() === label; }).first(); if (row.length === 0) return null; const tdText = row.find('td').text().trim(); const markText = row.find('mark').text().trim(); return { value: tdText.replace(markText, '').trim(), rarity: markText || null }; } async scrape(url) { const html = await this._fetchHtml(url); const $ = cheerio.load(html); const title = $('meta[property="og:title"]').attr('content') || $('title').text(); const description = $('meta[property="og:description"]').attr('content') || ''; const imageUrl = $('meta[property="og:image"]').attr('content') || ''; const ownerData = this._getTableValue($, 'Owner'); const modelData = this._getTableValue($, 'Model'); const backdropData = this._getTableValue($, 'Backdrop'); const symbolData = this._getTableValue($, 'Symbol'); const quantityRaw = this._getTableValue($, 'Quantity')?.value || ''; const qtyMatch = quantityRaw.match(/([\d\s]+)\/([\d\s]+)/); const issued = qtyMatch ? parseInt(qtyMatch[1].replace(/\s/g, '')) : 0; const total = qtyMatch ? parseInt(qtyMatch[2].replace(/\s/g, '')) : 0; const deepLink = $('a[href^="tg://nft"]').attr('href') || null; return { name: title, slug: deepLink ? deepLink.split('slug=')[1] : null, description: description, image: imageUrl, attributes: { model: modelData?.value || null, modelRarity: modelData?.rarity || null, backdrop: backdropData?.value || null, backdropRarity: backdropData?.rarity || null, symbol: symbolData?.value || null, symbolRarity: symbolData?.rarity || null }, supply: { issued: issued, total: total, remaining: total - issued }, owner: ownerData?.value || null, deepLink: deepLink }; } } export default { run: async (a, i, { func, cfg }) => { const chat = a.chat; const prefix = a.prefix || '.'; const cmd = (a.cmd || '').toLowerCase().replace(/^[.!?#\/\\]+/, ''); const cmdDisplay = prefix + cmd; const text = String(a.text || '').trim(); if (!text) { return i.sendMessage(chat, { text: `āŒ Masukkan link NFT Telegram!\nContoh: *${cmdDisplay} t.me/nft/ViceCream-19430*` }, { quoted: a }); } // Validasi URL const urlMatch = text.match(/(?:https?:\/\/)?t\.me\/nft\/([a-zA-Z0-9_-]+)/i); if (!urlMatch) { return i.sendMessage(chat, { text: `āŒ Link tidak valid. Gunakan format seperti *t.me/nft/ViceCream-19430*` }, { quoted: a }); } const url = `https://t.me/nft/${urlMatch[1]}`; await i.sendReact(chat, 'ā±ļø', a.key).catch(() => {}); try { const scraper = new TelegramNFTScraper(); const data = await scraper.scrape(url); if (!data.name || data.name.includes('Telegram')) { throw new Error('Gagal mengambil data. Pastikan link NFT valid dan publik.'); } // Format Teks let caption = `šŸŽ *TELEGRAM NFT GIFT*\n\n`; caption += `šŸ“Œ *Name:* ${data.name}\n`; if (data.description) caption += `šŸ“ *Desc:* ${data.description}\n`; if (data.slug) caption += `šŸ”— *Slug:* ${data.slug}\n`; caption += `\nšŸ“¦ *Supply:*\n`; caption += `• Issued: ${data.supply.issued.toLocaleString('id-ID')}\n`; caption += `• Total: ${data.supply.total.toLocaleString('id-ID')}\n`; caption += `• Remaining: ${data.supply.remaining.toLocaleString('id-ID')}\n`; caption += `\n✨ *Attributes:*\n`; if (data.attributes.model) caption += `• Model: ${data.attributes.model} ${data.attributes.modelRarity ? `(${data.attributes.modelRarity})` : ''}\n`; if (data.attributes.backdrop) caption += `• Backdrop: ${data.attributes.backdrop} ${data.attributes.backdropRarity ? `(${data.attributes.backdropRarity})` : ''}\n`; if (data.attributes.symbol) caption += `• Symbol: ${data.attributes.symbol} ${data.attributes.symbolRarity ? `(${data.attributes.symbolRarity})` : ''}\n`; if (data.owner) caption += `\nšŸ‘¤ *Owner:* ${data.owner}\n`; // BAGIAN YANG DIUBAH: Mengubah tg:// menjadi https:// agar dibaca sebagai link oleh WhatsApp if (data.slug) { const webLink = `https://t.me/nft/${data.slug}`; caption += `\nšŸ“² *Link:* ${webLink}`; } else if (data.deepLink) { caption += `\nšŸ“² *DeepLink:* ${data.deepLink}`; } await i.sendReact(chat, 'āœ…', a.key).catch(() => {}); // Kirim Gambar + Caption if (data.image) { await i.sendMessage(chat, { image: { url: data.image }, caption: caption }, { quoted: a }); } else { await i.sendMessage(chat, { text: caption }, { quoted: a }); } } catch (err) { console.error('[TGNFT] Error:', err.message); await i.sendReact(chat, 'āŒ', a.key).catch(() => {}); await i.sendMessage(chat, { text: `āŒ Gagal mengambil data NFT: ${err.message}` }, { quoted: a }); } }, cmd: 'telegramnft', alias: ['tgnft', 'nftgift'], use: '', type: 'tools', location: 'plugins/tools/telegramnft.js' };