47 lines
2.0 KiB
JavaScript
47 lines
2.0 KiB
JavaScript
module.exports = {
|
|
gamesToday: (bot, msg, logger) => {
|
|
const footballToday = "football today";
|
|
if (msg.text && msg.text.toString().toLowerCase().includes(footballToday)) {
|
|
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " asked for football today");
|
|
|
|
var options = {
|
|
method: 'GET',
|
|
url: 'https://football-pro.p.rapidapi.com/api/v2.0/livescores',
|
|
qs: { tz: 'Europe/London', leagues: '8,9,2,5,23,24', include: 'localTeam,visitorTeam' },
|
|
headers: {
|
|
'x-rapidapi-host': 'football-pro.p.rapidapi.com',
|
|
'x-rapidapi-key': process.env.RAPIDAPI_API_KEY,
|
|
useQueryString: true
|
|
},
|
|
ttl: 18000000 //5 hours
|
|
};
|
|
|
|
cachedRequest(options, function (error, response, body) {
|
|
// console.log(response)
|
|
if (error) throw new Error(error);
|
|
|
|
// console.log(body);
|
|
let jsonBody = JSON.parse(body)
|
|
if (jsonBody.data.length > 0) {
|
|
bot.sendMessage(msg.chat.id, 'Yes there is!').then(() => {
|
|
return jsonBody.data.forEach(function (entry) {
|
|
var homeTeam = entry.localTeam.data.name
|
|
var awayTeam = entry.visitorTeam.data.name
|
|
var startTime = entry.time.starting_at.time
|
|
// console.log(entry);
|
|
bot.sendMessage(msg.chat.id, homeTeam + " VS " + awayTeam + " @ " + startTime)
|
|
});
|
|
}).then(() => {
|
|
return bot.sendMessage(msg.chat.id, 'To see what channels the football is streaming on please join @footballontv')
|
|
})
|
|
} else {
|
|
bot.sendMessage(msg.chat.id, 'Sadly there is no football today :(')
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
} |