Advertisement
samiroexpikachu

Cricket

Jun 10th, 2024
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const a = require('axios');
  2. const c = require('cheerio');
  3.  
  4. const f = {
  5.   ' ': ' ',
  6.   'a': '𝚊', 'b': '𝚋', 'c': '𝚌', 'd': '𝚍', 'e': '𝚎', 'f': '𝚏', 'g': '𝚐', 'h': '𝚑',
  7.   'i': '𝚒', 'j': '𝚓', 'k': '𝚔', 'l': '𝚕', 'm': '𝚖', 'n': '𝚗', 'o': '𝚘', 'p': '𝚙', 'q': '𝚚',
  8.   'r': '𝚛', 's': '𝚜', 't': '𝚝', 'u': '𝚞', 'v': '𝚟', 'w': '𝚠', 'x': '𝚡', 'y': '𝚢', 'z': '𝚣',
  9.   'A': '𝙰', 'B': '𝙱', 'C': '𝙲', 'D': '𝙳', 'E': '𝙴', 'F': '𝙵', 'G': '𝙶', 'H': '𝙷',
  10.   'I': '𝙸', 'J': '𝙹', 'K': '𝙺', 'L': '𝙻', 'M': '𝙼', 'N': '𝙽', 'O': '𝙾', 'P': '𝙿', 'Q': '𝚀',
  11.   'R': '𝚁', 'S': '𝚂', 'T': '𝚃', 'U': '𝚄', 'V': '𝚅', 'W': '𝚆', 'X': '𝚇', 'Y': '𝚈', 'Z': '𝚉',
  12. };
  13.  
  14. function t(x) {
  15.   let y = '';
  16.   for (let z of x) {
  17.     y += f[z] || z;
  18.   }
  19.   return y;
  20. }
  21.  
  22. module.exports = {
  23.   config: {
  24.     name: "cricket",
  25.     version: "1.0",
  26.     author: "Samir Œ",
  27.     aliases: ["livecricket", "cricketscore"],
  28.     countDown: 5,
  29.     role: 0,
  30.     shortDescription: "Fetch live cricket scores",
  31.     longDescription: "Fetches live cricket scores from ESPN Cricinfo and sends the score in the chat.",
  32.     category: "Utility",
  33.     guide: "{pn}"
  34.   },
  35.   onStart: async function ({ message, api, event }) {
  36.     const u = 'https://www.espncricinfo.com/live-cricket-score';
  37.  
  38.     try {
  39.       const r = await a.get(u);
  40.       const h = r.data;
  41.       const $ = c.load(h);
  42.  
  43.       const m = $('.ds-flex.ds-flex-col.ds-mt-2.ds-mb-2').first();
  44.  
  45.       const t1 = m.find('.ci-team-score').first();
  46.       const t2 = m.find('.ci-team-score').last();
  47.  
  48.       const n1 = t1.find('p').text();
  49.       const s1 = t1.find('strong').text().split('/');
  50.       const sc1 = parseInt(s1[0]);
  51.       const w1 = s1[1];
  52.  
  53.       const n2 = t2.find('p').text();
  54.       const s2 = t2.find('strong').text().split('/');
  55.       const sc2 = parseInt(s2[0]);
  56.       const w2 = s2[1];
  57.       const md = t2.find('span').text().trim().match(/\((\d+) ov, T:(\d+)\)/);
  58.  
  59.       const o = md ? md[1] : 'N/A';
  60.       const tm = md ? md[2] : 'N/A';
  61.  
  62.       const rd = Math.abs(sc1 - sc2);
  63.       const wt = sc1 > sc2 ? n1 : n2;
  64.       const lt = sc1 > sc2 ? n2 : n1;
  65.       const rm = `${wt} won by ${rd} runs`;
  66.  
  67.       const mb = `
  68.         🏏 Live Cricket Score: 🏏
  69.  
  70.           Team 1: ${n1}:
  71.           Score: ${sc1}
  72.           Wickets: ${w1}
  73.  
  74.           Team 2: ${n2}:
  75.           Score: ${sc2}
  76.           Wickets: ${w2}
  77.  
  78.         ⏰ Time: ${tm} minutes
  79.         🔄 Overs: ${o}
  80.  
  81.         🏆 Result: ${rm}
  82.       `;
  83.  
  84.       let update = t(mb);
  85.       await api.sendMessage(update, event.threadID, event.messageID);
  86.  
  87.     } catch (e) {
  88.       console.error(`Error fetching the URL: ${e}`);
  89.       await api.sendMessage(`❌ Error fetching the live cricket score: ${e.message}`, event.threadID, event.messageID);
  90.     }
  91.   }
  92. };
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement