// code from goatstore // api: https://store.agi.bd const { createCanvas, loadImage } = require('canvas'); const fs = require('fs-extra'); const path = require('path'); const axios = require('axios'); module.exports = { config: { name: "tiktok", version: "2.0.0", author: "Custom Bot", countDown: 5, role: 0, shortDescription: "Get TikTok profile stats image", longDescription: "Fetch TikTok user information and generate a stylish profile card.", category: "info", guide: { en: "{p}tiktok username" } }, onStart: async function ({ api, event, args }) { const { threadID, messageID } = event; let username = args[0]; if (!username) { return api.sendMessage( "āŒ Doya kore ekti tiktok username din!\nUsage: -tiktok ", threadID, messageID ); } if (username.startsWith('@')) { username = username.slice(1); } const parsingMsg = await api.sendMessage(`šŸ” Fetching TikTok data for @${username}...`, threadID); try { const response = await axios.get(`https://www.tikwm.com/api/user/info?unique_id=${username}`, { headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' }, timeout: 10000 }); const resData = response.data; if (!resData || resData.code !== 0 || !resData.data) { try { api.unsendMessage(parsingMsg.messageID); } catch(e){} return api.sendMessage(`āŒ TikTok user paoya jayni ba server busy: @${username}`, threadID, messageID); } const userInfo = resData.data.user; const stats = resData.data.stats; const nickname = userInfo.nickname || username; const avatarUrl = userInfo.avatarLarger || userInfo.avatarThumb || userInfo.avatarMedium; const followers = stats.followerCount || 0; const following = stats.followingCount || 0; const totalLikes = stats.heartCount || 0; const totalVideos = stats.videoCount || 0; // Canvas Generation const width = 1100; const height = 700; const canvas = createCanvas(width, height); const ctx = canvas.getContext('2d'); ctx.fillStyle = '#020306'; ctx.fillRect(0, 0, width, height); ctx.fillStyle = '#00f2fe'; ctx.font = '900 italic 55px sans-serif'; ctx.fillText('TIKTOK ANALYTICS', 60, 90); ctx.fillStyle = '#ffffff'; ctx.font = 'bold 20px sans-serif'; ctx.fillText('• OFFICIAL SYSTEM DATA •', 70, 130); // Avatar Box const boxX = 70; const boxY = 180; const boxSize = 320; ctx.fillStyle = '#112240'; ctx.fillRect(boxX, boxY, boxSize, boxSize); try { if (avatarUrl) { const userImg = await loadImage(avatarUrl); ctx.save(); ctx.beginPath(); ctx.rect(boxX, boxY, boxSize, boxSize); ctx.clip(); ctx.drawImage(userImg, boxX, boxY, boxSize, boxSize); ctx.restore(); } } catch (err) { console.log("Avatar load error:", err.message); } ctx.strokeStyle = '#ffffff'; ctx.lineWidth = 4; ctx.strokeRect(boxX, boxY, boxSize, boxSize); // Nickname & Username ctx.fillStyle = '#ffffff'; ctx.font = 'bold 32px sans-serif'; let dispNickname = nickname; if (dispNickname.length > 18) dispNickname = dispNickname.substring(0, 16) + '...'; ctx.fillText(dispNickname, boxX, boxY + boxSize + 50); ctx.fillStyle = '#00f2fe'; ctx.font = 'bold 22px sans-serif'; ctx.fillText(`@${username}`, boxX, boxY + boxSize + 85); // Stats const startX = 450; let startY = 200; const lineSpacing = 80; const formatNumber = (num) => { if (num >= 1000000) return (num / 1000000).toFixed(1) + 'M'; if (num >= 1000) return (num / 1000).toFixed(1) + 'K'; return num.toString(); }; const fields = [ { label: 'Total Followers', value: formatNumber(followers) }, { label: 'Total Following', value: formatNumber(following) }, { label: 'Total Likes', value: formatNumber(totalLikes) }, { label: 'Total Videos', value: formatNumber(totalVideos) } ]; fields.forEach((field) => { ctx.fillStyle = '#ffffff'; ctx.font = 'bold 26px sans-serif'; ctx.fillText(field.label, startX, startY); ctx.fillStyle = '#4a5568'; ctx.fillText(':', startX + 280, startY); ctx.fillStyle = '#00f2fe'; ctx.font = 'bold 28px sans-serif'; ctx.fillText(field.value, startX + 330, startY); startY += lineSpacing; }); const cachePath = path.join(__dirname, 'cache', `tiktok_${username}.png`); fs.ensureDirSync(path.join(__dirname, 'cache')); const buffer = canvas.toBuffer('image/png'); fs.writeFileSync(cachePath, buffer); try { api.unsendMessage(parsingMsg.messageID); } catch(e){} return api.sendMessage( { body: `✨ TikTok Profile Details for @${username}:\nšŸ‘¤ Name: ${nickname}\nšŸ‘„ Followers: ${formatNumber(followers)}\nā¤ļø Likes: ${formatNumber(totalLikes)}\nšŸŽ¬ Videos: ${totalVideos}`, attachment: fs.createReadStream(cachePath) }, threadID, () => fs.unlinkSync(cachePath), messageID ); } catch (error) { console.error(error); try { api.unsendMessage(parsingMsg.messageID); } catch(e){} return api.sendMessage("āŒ TikTok server theke data ante parlo na. Doya kore kichu somoy por abar chesta korun.", threadID, messageID); } } };