2020-06-30 16:25:55 +00:00
var request = require ( "request" ) ;
var throttledRequest = require ( 'throttled-request' ) ( request ) ;
throttledRequest . configure ( { requests : 8 , milliseconds : 60000 } ) ; //send 1 request per second
cachedRequest = require ( 'cached-request' ) ( throttledRequest ) ;
cachedRequest . setCacheDirectory ( "./cache" ) ;
2023-12-05 13:39:29 +00:00
var emoji = require ( 'node-emoji' )
2020-06-30 16:25:55 +00:00
module . exports = {
football _today : async ( bot , msg , logger ) => {
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' ,
2021-10-23 16:54:05 +00:00
// qs: { tz: 'Europe/London', leagues: '2,5,8,23,24,27,45,81,1326', include: 'localTeam,visitorTeam' },
2023-12-05 13:39:29 +00:00
// qs: { tz: 'Europe/London', leagues: '2,5,8,23,24,27,45,81,1326,501', include: 'localTeam,visitorTeam' },
// qs: { tz: 'Europe/London', leagues: '2,5,8,23,24,27,501', include: 'localTeam,visitorTeam' }, // Champions Leage, Europa, Premier League, Community Shield, FA Cup, Carabo cup, Scottish
qs : { tz : 'Europe/London' , leagues : '2,5,8,23,501,732' , include : 'localTeam,visitorTeam' } , // Champions Leage, Europa, Premier League, Community Shield, Scottish
2020-06-30 16:25:55 +00:00
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 , async function ( error , response , body ) {
if ( error ) throw new Error ( error ) ;
let jsonBody = JSON . parse ( body )
if ( jsonBody . data . length > 0 ) {
bot . sendMessage ( msg . chat . id , 'Yes there is!' ) . then ( async ( ) => {
for ( const x of jsonBody . data ) {
var homeTeam = x . localTeam . data . name
var awayTeam = x . visitorTeam . data . name
var startTime = x . time . starting _at . time
await bot . sendMessage ( msg . chat . id , homeTeam + " VS " + awayTeam + " @ " + startTime )
}
} ) . then ( ( ) => {
2023-12-05 13:39:29 +00:00
return bot . sendMessage ( msg . chat . id , ` To see what channels the football is streaming on goto post ${ emoji . get ( 'one' ) } ${ emoji . get ( 'six' ) } in our updates page and join our football listings rooms. \n \n ${ emoji . get ( 'arrow_right' ) } <a href='https://t.me/c/1473840950/308'>PRESS HERE</a> ${ emoji . get ( 'arrow_left' ) } to go directly to post in updates page. ` , { parse _mode : 'HTML' , disable _web _page _preview : true } )
2020-06-30 16:25:55 +00:00
} )
} else {
2023-12-05 13:39:29 +00:00
bot . sendMessage ( msg . chat . id , ` Sadly, there is no football I care about on today ${ emoji . get ( 'cry' ) } but, Updates ${ emoji . get ( 'one' ) } ${ emoji . get ( 'six' ) } <a href='https://t.me/c/1473840950/308'>HERE</a> also has telegram rooms for all other sports. ` , { parse _mode : 'HTML' , disable _web _page _preview : true } )
2020-06-30 16:25:55 +00:00
}
} )
} ,
2021-10-23 16:54:05 +00:00
2020-06-30 16:25:55 +00:00
joke : ( bot , msg , logger , name ) => {
logger . info ( "ID - " + msg . from . id + " First Name - " + msg . from . first _name + " asked for a joke" ) ;
var options = {
method : 'GET' ,
url : 'https://joke3.p.rapidapi.com/v1/joke' ,
// qs: { tz: 'Europe/London', leagues: '8', include: 'localTeam,visitorTeam' },
headers : {
'x-rapidapi-host' : 'joke3.p.rapidapi.com' ,
'x-rapidapi-key' : process . env . RAPIDAPI _API _KEY ,
useQueryString : true
} ,
} ;
request ( options , function ( error , response , body ) {
if ( error ) throw new Error ( error ) ;
let jsonBody = JSON . parse ( body )
bot . sendMessage ( msg . chat . id , jsonBody . content )
}
)
2023-12-05 13:39:29 +00:00
} ,
// get_all_pages: async () => {
// full_list = []
// pages = [1,2,3,4,5]
// for (let i = 1; i < pages.length; i++) {
// var options = {
// method: 'GET',
// url: 'https://api.themoviedb.org/3/tv/airing_today?api_key=01fe1ed0ba2275d4a9ce618fbabdac92&language=en-GB&page=' + i,
// ttl: 18000000 //5 hours
// };
// return new Promise(function (resolve, reject) {
// request(options, function (error, response, body) {
// if (!error) {
// // resolve(body);
// full_list.push(JSON.parse(body))
// resolve(full_list[0])
// } else {
// reject(error);
// }
// })
// })
// }
// },
api _call : async ( currentPage ) => {
var options = {
method : 'GET' ,
url : 'https://api.themoviedb.org/3/tv/airing_today?api_key=01fe1ed0ba2275d4a9ce618fbabdac92&language=en-GB&page=' + currentPage ,
ttl : 18000000 //5 hours
} ;
return new Promise ( function ( resolve , reject ) {
request ( options , function ( error , response , body ) {
if ( ! error ) {
resolve ( JSON . parse ( body ) )
} else {
reject ( error ) ;
}
} )
} )
} ,
get _all _pages : async ( ) => {
let currentPage = 1 ;
full _list = [ ]
while ( currentPage <= 5 ) {
a = await module . exports . api _call ( currentPage ) ;
// let { data } = await module.exports.api_call(currentPage);
full _list . push ( a . results )
currentPage ++ ;
}
a = Array . prototype . concat . apply ( [ ] , full _list )
return a
} ,
tv _today : async ( bot , msg , logger ) => {
logger . info ( "ID - " + msg . from . id + " First Name - " + msg . from . first _name + " asked for tv today" ) ;
l = await module . exports . get _all _pages ( )
if ( l . length > 0 ) {
bot . sendMessage ( msg . chat . id , 'Yes there is!' ) . then ( async ( ) => {
a = [ ]
b = l . filter ( s => { return s . origin _country [ 0 ] == 'GB' || s . origin _country [ 0 ] == 'US' } )
for ( const x of b ) {
var showName = x . name
a . push ( showName )
}
new _ms = a . join ( '\n' )
await bot . sendMessage ( msg . chat . id , new _ms , { parse _mode : "HTML" } )
} ) . then ( ( ) => {
return bot . sendMessage ( msg . chat . id , ` Enjoy your TV Shows today!. ` , { parse _mode : 'HTML' , disable _web _page _preview : true } )
} )
} else {
bot . sendMessage ( msg . chat . id , ` Sadly, there is no tv shows on I care about on today ${ emoji . get ( 'cry' ) } . ` , { parse _mode : 'HTML' , disable _web _page _preview : true } )
}
2020-06-30 16:25:55 +00:00
}
2023-12-05 13:39:29 +00:00
// bot.sendMessage(msg.chat.id, jsonBody.content)
2020-06-30 16:25:55 +00:00
}