Spaces:
Paused
Paused
| import config from '../../config.cjs'; | |
| import axios from 'axios'; | |
| const cricketScore = async (m, Matrix) => { | |
| const prefix = config.PREFIX; | |
| const cmd = m.body.startsWith(prefix) ? m.body.slice(prefix.length).split(' ')[0].toLowerCase() : ''; | |
| const text = m.body.slice(prefix.length + cmd.length).trim(); | |
| const validCommands = ['score', 'crick', 'crickterscore', 'cricket']; | |
| if (validCommands.includes(cmd)) { | |
| if (!text) { | |
| await m.React("โ"); | |
| return m.reply(`*Provide a match ID for cricket score.*\nExample: ${prefix}cricketscore 12345`); | |
| } | |
| const matchId = encodeURIComponent(text); | |
| try { | |
| const apiUrl = `https://iol.apinepdev.workers.dev/${matchId}`; | |
| const response = await axios.get(apiUrl); | |
| if (!response.status === 200) { | |
| await m.React("โ"); | |
| return m.reply(`Invalid response from the cricket score API. Status code: ${response.status}`); | |
| } | |
| const result = response.data; | |
| let formattedResult = `โญโโโโโโโโโโโโโโโขโโขโโโฎ\n`; | |
| formattedResult += `โโฟป *๐ข๐๐๐๐ฆ-๐๐ฟ ๐ ๐ฅ*\n`; | |
| formattedResult += `โโฟป *LIVE MATCH INFO* โจ\n`; | |
| formattedResult += `โโฟป\n`; | |
| if (result.code === 200) { | |
| formattedResult += `โโฟป *${result.data.title}*\n`; | |
| formattedResult += `โโฟป *${result.data.update}*\n`; | |
| formattedResult += `โโฟป \n`; | |
| } else { | |
| await m.reply(`*Update:* Data not found for the specified match ID.`); | |
| await m.React("โ"); | |
| return; | |
| } | |
| if (result.data.liveScore && result.data.liveScore.toLowerCase() !== "data not found") { | |
| formattedResult += `โโฟป *Live Score:* ${result.data.liveScore}\n`; | |
| formattedResult += `โโฟป *Run Rate:* ${result.data.runRate}\n`; | |
| formattedResult += `โโฟป\n`; | |
| formattedResult += `โโฟป *Batter 1:* ${result.data.batsmanOne}\n`; | |
| formattedResult += `โโฟป *${result.data.batsmanOneRun} (${result.data.batsmanOneBall})* SR: ${result.data.batsmanOneSR}\n`; | |
| formattedResult += `โโฟป\n`; | |
| formattedResult += `โโฟป *Batter 2:* ${result.data.batsmanTwo}\n`; | |
| formattedResult += `โโฟป *${result.data.batsmanTwoRun} (${result.data.batsmanTwoBall})* SR: ${result.data.batsmanTwoSR}\n`; | |
| formattedResult += `โโฟป\n`; | |
| formattedResult += `โโฟป *Bowler 1:* ${result.data.bowlerOne}\n`; | |
| formattedResult += `โโฟป *${result.data.bowlerOneOver} overs, ${result.data.bowlerOneRun}/${result.data.bowlerOneWickets}, Econ:* ${result.data.bowlerOneEconomy}\n`; | |
| formattedResult += `โโฟป\n`; | |
| formattedResult += `โโฟป *Bowler 2:* ${result.data.bowlerTwo}\n`; | |
| formattedResult += `โโฟป *${result.data.bowlerTwoOver} overs, ${result.data.bowlerTwoRun}/${result.data.bowlerTwoWicket}, Econ:* ${result.data.bowlerTwoEconomy}\n`; | |
| } | |
| formattedResult += `โฐโโโขโโขโโโโโโโโโโโโโโโโฏ `; | |
| await m.reply(formattedResult); | |
| await m.React("โ "); | |
| } catch (error) { | |
| console.error(error); | |
| await m.React("โ"); | |
| return m.reply(`An error occurred while processing the cricket score request. ${error.message}`); | |
| } | |
| } | |
| }; | |
| export default cricketScore; | |