const fs = require('fs') const subs = JSON.parse(fs.readFileSync('./data/group/subs.json', 'utf8')) var subArray = [] subs.forEach(element => { if (element.COST != "X") { let arr = ["- " + element.SUB] subArray.push(arr) } }); subArray.push(["- Home"]) module.exports = { main: (bot, msg, logger) => { const whatAppShouldIUse = "- what app should i use?"; if (msg.text && msg.text.toString().toLowerCase() === whatAppShouldIUse) { logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked what app to use"); bot.sendMessage(msg.chat.id, "What Subscription do you have?", { "reply_markup": { "keyboard": subArray } }) } }, appSwitch: (bot, msg, logger) => { let string = "" if (subArray.splice(-1,1).some(v => msg.text.toString().includes(v))) { var checkSub = msg.text.substring(2) subs.forEach(element => { if (element.SUB === checkSub) { element.APPS.forEach(element => { let catString = element string += '\n' + catString; }) } } ); bot.sendMessage(msg.chat.id, "You can use -" + string + "\n\nAll can be downloaded from our FileLinked") } // } // if (subArray.indexOf(msg.text && msg.text.toString().toLowerCase())) { // var checkSub = msg.text.substring(2) // subs.forEach(element => { // if (element.SUB === checkSub) { // element.APPS.forEach(element => { // let catString = element // string += '\n' + catString; // }) // } // } // ); // bot.sendMessage(msg.chat.id, "You can use -" + string + "\n\nAll can be downloaded from our FileLinked") // } } }