Last active
September 24, 2025 16:56
-
-
Save Corex24/056f8cedf32a07fd960be63b22be14b1 to your computer and use it in GitHub Desktop.
Plugin for livescoreπβ½οΈπππ§€
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Plugin by Corex π | |
| const { bot } = require('../lib/'); | |
| const fetch = (...args) => | |
| import('node-fetch').then(({ default: fetch }) => fetch(...args)); | |
| const API_KEY = '52d192da6e86b2e9121f15079b879c57'; | |
| bot( | |
| { | |
| pattern: 'livescore', | |
| desc: 'Get live football scores (or today\'s fixtures if none live)', | |
| type: 'sports', | |
| }, | |
| async (message, match) => { | |
| try { | |
| // 1. Fetch live matches first | |
| let res = await fetch('https://v3.football.api-sports.io/fixtures?live=all', { | |
| method: 'GET', | |
| headers: { | |
| 'x-apisports-key': API_KEY, | |
| }, | |
| }); | |
| let json = await res.json(); | |
| let matches = json.response; | |
| // 2. If no live matches, fallback to todayβs fixtures | |
| if (!matches || !matches.length) { | |
| const today = new Date().toISOString().split('T')[0]; | |
| res = await fetch(`https://v3.football.api-sports.io/fixtures?date=${today}`, { | |
| method: 'GET', | |
| headers: { | |
| 'x-apisports-key': API_KEY, | |
| }, | |
| }); | |
| json = await res.json(); | |
| matches = json.response; | |
| if (!matches || !matches.length) { | |
| return await message.send('β½ No matches found for today.'); | |
| } | |
| } | |
| // 3. Build fancy reply | |
| let replyText = `βββββββββββββββ β½ πππ©ππ¦ππ’π₯π β½ ββββββββββββββ\n\n`; | |
| for (let match of matches.slice(0, 8)) { | |
| const home = match.teams.home.name; | |
| const away = match.teams.away.name; | |
| const homeGoals = match.goals.home ?? 0; | |
| const awayGoals = match.goals.away ?? 0; | |
| const status = match.fixture.status.long; | |
| const league = match.league.name; | |
| const time = new Date(match.fixture.date).toLocaleTimeString('en-GB', { | |
| hour: '2-digit', | |
| minute: '2-digit', | |
| }); | |
| replyText += `π *${league}*\n`; | |
| replyText += `β‘ ${home} ${homeGoals} - ${awayGoals} ${away}\n`; | |
| replyText += `β° ${time} | π ${status}\n\n`; | |
| } | |
| replyText += `βββββββββββββββββββββββββββββββββββββββ\n`; | |
| replyText += `π¨βπ» Created by *Corex* with π\n`; | |
| replyText += `βββββββββββββββββββββββββββββββββββββββ`; | |
| await message.send(replyText.trim()); | |
| } catch (err) { | |
| console.error(err); | |
| await message.send('β Could not fetch football scores. Please try again later.'); | |
| } | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment