sub status

This commit is contained in:
karl.hudgell 2020-06-25 22:44:18 +01:00
parent 0d88c20960
commit bcaa1ef4da
3 changed files with 29 additions and 18 deletions

3
app.js
View File

@ -17,6 +17,7 @@ const bot_questions = require('./data/bot/questions')
const bot_football = require('./data/bot/requests/football')
const bot_joke = require('./data/bot/requests/joke')
const bot_faq_subscription = require('./data/bot/faq/subscriptions')
const bot_subStatus = require('./data/bot/requests/updateSubStatus')
const token = process.env.BOT_TOKEN;
const name = process.env.BOT_NAME;
@ -65,7 +66,7 @@ bot.on('message', (msg) => {
// listen for "what sub should i buy?"
bot_questions.whatSubShouldIBuy(bot, msg, logger)
bot_questions.subStatus(bot, msg, logger)
bot_subStatus.setSubStatus(bot, msg, logger)
// FAQ susbcription prices
bot_faq_subscription.prices(bot, msg, logger)

View File

@ -1,17 +0,0 @@
const fs = require('fs')
const subs = JSON.parse(fs.readFileSync('./data/group/subs.json', 'utf8'))
module.exports = {
tellMe: (bot, msg, logger, name) => {
const subStatus = "sub status";
if (msg.text && msg.text.toString().toLowerCase().includes(subStatus)) {
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked how to get a subscription");
bot.sendMessage(msg.chat.id, subs)
}
}
}

View File

@ -0,0 +1,27 @@
const fs = require('fs')
const subs = JSON.parse(fs.readFileSync('./data/group/subs.json', 'utf8'))
module.exports = {
setSubStatus: (bot, msg, logger, name) => {
const setSub = "set sub";
if (msg.text && msg.text.toString().toLowerCase().includes(setSub)) {
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked how to get a subscription");
sub = msg.text.match(/\w+(?=( \w+){2}$)/g)[0]
status = msg.text.match(/\w+(?=( \w+){0}$)/g)[0]
if (status === "up") {
status = 1
} else {
status = 0
}
subs.forEach(function (element, index) {
if (element.SUB.toLowerCase() === sub) {
subs[index].STATUS = status; //set the value
}
})
console.log(subs);
fs.writeFileSync('./data/group/subs.json', subs)
bot.sendMessage(msg.chat.id, sub + " sub updated")
}
}
}