// code from goatstore // api: https://store.agi.bd const axios = require("axios"); module.exports.config = { name: "cricket", version: "3.0.0", author: "Zihad", countDown: 5, role: 0, shortDescription: "Live Cricket Score", longDescription: "Global live cricket score", category: "sports", guide: "{pn}" }; const API = "https://hs-consumer-api.espncricinfo.com/v1"; async function get(url) { try { const r = await axios.get(url, { timeout: 15000, headers: { "User-Agent": "Mozilla/5.0 (Linux; Android 12) AppleWebKit/537.36 Chrome/120 Mobile Safari/537.36", "Accept": "application/json,text/plain,*/*", "Referer": "https://www.espncricinfo.com/" } }); return r.data; } catch (e) { return null; } } function teamName(x) { return ( x?.team?.name || x?.team?.longName || x?.name || "TBA" ); } function teamScore(x) { return ( x?.score || x?.scoreText || x?.displayScore || "" ); } function isLive(m) { const s = String(m?.state || "").toUpperCase(); const st = String(m?.stage || "").toUpperCase(); const status = String(m?.status || "").toUpperCase(); return ( s === "LIVE" || st === "RUNNING" || status === "LIVE" || status.includes("LIVE") || status.includes("IN PROGRESS") || status.includes("PLAYING") ); } function formatName(m) { return ( m?.format || m?.matchFormat || m?.series?.format || "CRICKET" ); } function getStatus(m) { return ( m?.statusText || m?.status || m?.description || "LIVE" ); } function makeMatch(m, detail) { const d = detail?.match || detail || {}; const teams = d?.teams || m?.teams || []; const t1 = teams[0] || {}; const t2 = teams[1] || {}; let score1 = teamScore(t1); let score2 = teamScore(t2); // Try common scorecard locations if (!score1) score1 = teamScore(d?.teams?.[0]); if (!score2) score2 = teamScore(d?.teams?.[1]); const title = d?.title || m?.title || "Live Match"; const series = d?.series?.name || m?.series?.name || "Cricket"; const status = getStatus(d) || getStatus(m); const ground = d?.ground?.name || m?.ground?.name || ""; let out = "šŸā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”šŸ\n" + " šŸ”“ CRICKET LIVE\n" + "šŸā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”šŸ\n\n"; out += `šŸ† ${series}\n`; out += `šŸ“Œ ${title}\n`; out += `⚔ ${formatName(d || m)}\n\n`; out += `šŸ“ ${teamName(t1)}`; if (score1) out += ` ${score1}`; out += "\n"; out += `šŸ“ ${teamName(t2)}`; if (score2) out += ` ${score2}`; out += "\n\n"; out += `šŸ”“ ${status}\n`; if (ground) { out += `šŸ“ ${ground}\n`; } out += "\nšŸā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”šŸ"; return out; } module.exports.run = async function ({ api, event }) { const threadID = event.threadID; try { // First try the dedicated LIVE endpoint let data = await get( `${API}/pages/matches/live?lang=en` ); // Fallback to CURRENT endpoint if (!data || !Array.isArray(data.matches)) { data = await get( `${API}/pages/matches/current?lang=en&latest=true` ); } if (!data || !Array.isArray(data.matches)) { return api.sendMessage( "āŒ Live Cricket Server Error\n\n" + "āš ļø Cricket live server ঄েকে data ą¦Ŗą¦¾ą¦“ą§Ÿą¦¾ ą¦Æą¦¾ą¦šą§ą¦›ą§‡ ą¦Øą¦¾ą„¤\n" + "šŸ”„ ą¦•ą¦æą¦›ą§ą¦•ą§ą¦·ą¦£ পরে আবার `cricket` ą¦²ą¦æą¦–ą§ą¦Øą„¤", threadID ); } const matches = data.matches.filter(isLive); if (!matches.length) { return api.sendMessage( "šŸā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”šŸ\n" + " CRICKET LIVE\n" + "šŸā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”šŸ\n\n" + "ā„¹ļø ą¦ą¦‡ ą¦®ą§ą¦¹ą§‚ą¦°ą§ą¦¤ą§‡ API-তে কোনো Live Cricket Match ą¦Ŗą¦¾ą¦“ą§Ÿą¦¾ ą¦Æą¦¾ą§Ÿą¦Øą¦æą„¤\n\n" + "šŸŒ International + Domestic\n" + "⚔ T20 / ODI / TEST সব ą¦®ą§ą¦Æą¦¾ą¦š ą¦–ą§‹ą¦ą¦œą¦¾ ą¦¹ą§Ÿą§‡ą¦›ą§‡ą„¤", threadID ); } let finalText = "šŸā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”šŸ\n" + " šŸŒ LIVE CRICKET\n" + "šŸā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”ā”šŸ\n\n"; for (let i = 0; i < matches.length; i++) { const m = matches[i]; const matchId = m?.objectId || m?.matchId || m?.id; const seriesId = m?.series?.objectId || m?.seriesId; let detail = null; // Get detailed live score if (matchId && seriesId) { detail = await get( `${API}/pages/match/home?lang=en&seriesId=${seriesId}&matchId=${matchId}` ); // Scorecard fallback if (!detail) { detail = await get( `${API}/pages/match/scorecard?lang=en&seriesId=${seriesId}&matchId=${matchId}` ); } } finalText += makeMatch(m, detail); finalText += "\n\n"; // Prevent extremely large Messenger messages if (finalText.length > 7500) { finalText += "\nšŸ“Œ আরও Live Match আছে...\n" + "šŸ আবার `cricket` লিখে ą¦¦ą§‡ą¦–ą§ą¦Øą„¤"; break; } } return api.sendMessage(finalText, threadID); } catch (err) { return api.sendMessage( "āŒ Cricket Command Error\n\n" + "āš ļø Live score data ą¦ą¦–ą¦Ø ą¦Ŗą¦¾ą¦“ą§Ÿą¦¾ ą¦Æą¦¾ą¦šą§ą¦›ą§‡ ą¦Øą¦¾ą„¤\n" + "šŸ”„ ą¦•ą¦æą¦›ą§ą¦•ą§ą¦·ą¦£ পরে আবার `cricket` ą¦²ą¦æą¦–ą§ą¦Øą„¤", threadID ); } };