working in order football today
This commit is contained in:
parent
0b9b3b411c
commit
a021c61222
2
app.js
2
app.js
@ -14,7 +14,7 @@ const TelegramBot = require('node-telegram-bot-api');
|
|||||||
const bot_chat = require('./data/bot/functions/chat')
|
const bot_chat = require('./data/bot/functions/chat')
|
||||||
const bot_welcome = require('./data/bot/functions/welcomeMesage')
|
const bot_welcome = require('./data/bot/functions/welcomeMesage')
|
||||||
const bot_questions = require('./data/bot/functions/questions')
|
const bot_questions = require('./data/bot/functions/questions')
|
||||||
const bot_football = require('./data/bot/functions/requests/football')
|
const bot_football = require('./data/bot/lib/requests')
|
||||||
const bot_joke = require('./data/bot/functions/requests/joke')
|
const bot_joke = require('./data/bot/functions/requests/joke')
|
||||||
const bot_faq_subscription = require('./data/bot/functions/faq/subscriptions')
|
const bot_faq_subscription = require('./data/bot/functions/faq/subscriptions')
|
||||||
const bot_subStatus = require('./data/bot/functions/requests/updateSubStatus')
|
const bot_subStatus = require('./data/bot/functions/requests/updateSubStatus')
|
||||||
|
@ -5,9 +5,8 @@ throttledRequest.configure({ requests: 8, milliseconds: 60000 }); //send 1 reque
|
|||||||
cachedRequest = require('cached-request')(throttledRequest);
|
cachedRequest = require('cached-request')(throttledRequest);
|
||||||
cachedRequest.setCacheDirectory("./cache");
|
cachedRequest.setCacheDirectory("./cache");
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
gamesToday: (bot, msg, logger) => {
|
football_today: async (bot, msg, logger) => {
|
||||||
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " asked for football today");
|
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " asked for football today");
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
@ -22,21 +21,18 @@ module.exports = {
|
|||||||
ttl: 18000000 //5 hours
|
ttl: 18000000 //5 hours
|
||||||
};
|
};
|
||||||
|
|
||||||
cachedRequest(options, function (error, response, body) {
|
cachedRequest(options, async function (error, response, body) {
|
||||||
// console.log(response)
|
|
||||||
if (error) throw new Error(error);
|
if (error) throw new Error(error);
|
||||||
|
|
||||||
// console.log(body);
|
|
||||||
let jsonBody = JSON.parse(body)
|
let jsonBody = JSON.parse(body)
|
||||||
if (jsonBody.data.length > 0) {
|
if (jsonBody.data.length > 0) {
|
||||||
bot.sendMessage(msg.chat.id, 'Yes there is!').then(() => {
|
bot.sendMessage(msg.chat.id, 'Yes there is!').then(async () => {
|
||||||
return jsonBody.data.forEach(function (entry) {
|
for (const x of jsonBody.data) {
|
||||||
var homeTeam = entry.localTeam.data.name
|
var homeTeam = x.localTeam.data.name
|
||||||
var awayTeam = entry.visitorTeam.data.name
|
var awayTeam = x.visitorTeam.data.name
|
||||||
var startTime = entry.time.starting_at.time
|
var startTime = x.time.starting_at.time
|
||||||
// console.log(entry);
|
await bot.sendMessage(msg.chat.id, homeTeam + " VS " + awayTeam + " @ " + startTime)
|
||||||
bot.sendMessage(msg.chat.id, homeTeam + " VS " + awayTeam + " @ " + startTime)
|
}
|
||||||
});
|
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return bot.sendMessage(msg.chat.id, 'To see what channels the football is streaming on please join @footballontv')
|
return bot.sendMessage(msg.chat.id, 'To see what channels the football is streaming on please join @footballontv')
|
||||||
})
|
})
|
||||||
@ -44,5 +40,29 @@ module.exports = {
|
|||||||
bot.sendMessage(msg.chat.id, 'Sadly there is no football today :(')
|
bot.sendMessage(msg.chat.id, 'Sadly there is no football today :(')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
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
|
||||||
|
},
|
||||||
|
// ttl: 18000 //5 hours
|
||||||
|
};
|
||||||
|
|
||||||
|
request(options, function (error, response, body) {
|
||||||
|
// console.log(response)
|
||||||
|
|
||||||
|
if (error) throw new Error(error);
|
||||||
|
let jsonBody = JSON.parse(body)
|
||||||
|
bot.sendMessage(msg.chat.id, jsonBody.content)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,6 +8,10 @@ const commands = [
|
|||||||
{
|
{
|
||||||
"NAME": "/sub_status",
|
"NAME": "/sub_status",
|
||||||
"TEXT": []
|
"TEXT": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"NAME": "/start",
|
||||||
|
"TEXT": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
16
test.js
16
test.js
@ -17,7 +17,7 @@ const TelegramBot = require('node-telegram-bot-api');
|
|||||||
|
|
||||||
const common = require('./data/bot/lib/common')
|
const common = require('./data/bot/lib/common')
|
||||||
const questions = require('./data/bot/lib/questions')
|
const questions = require('./data/bot/lib/questions')
|
||||||
const football = require('./data/bot/functions/requests/football')
|
const requests = require('./data/bot/lib/requests')
|
||||||
|
|
||||||
const bot = new TelegramBot(token, { polling: true });
|
const bot = new TelegramBot(token, { polling: true });
|
||||||
|
|
||||||
@ -31,5 +31,15 @@ bot.on('message', (msg) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (msg.text && msg.text.toString().includes("/football_today")) {
|
if (msg.text && msg.text.toString().includes("/football_today")) {
|
||||||
football.gamesToday(bot, msg, logger)
|
requests.football_today(bot, msg, logger)
|
||||||
}})
|
}
|
||||||
|
|
||||||
|
if (msg.text && msg.text.toString().includes("/joke")) {
|
||||||
|
requests.joke(bot, msg, logger)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.text && msg.text.toString().includes("/start")) {
|
||||||
|
common.commands(bot, msg, logger)
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user