diff --git a/app.js b/app.js index cadf549..11bfce0 100644 --- a/app.js +++ b/app.js @@ -72,4 +72,8 @@ bot.on('message', (msg) => { } } + if (msg.text && msg.text.toString().toLowerCase().includes("set sub")) { + bot_subStatus.setSubStatus(bot, msg, logger) + } + }) \ No newline at end of file diff --git a/data/bot/functions/requests/updateSubStatus.js b/data/bot/functions/requests/updateSubStatus.js index e547c1f..af9a984 100644 --- a/data/bot/functions/requests/updateSubStatus.js +++ b/data/bot/functions/requests/updateSubStatus.js @@ -4,26 +4,24 @@ const admins = JSON.parse(process.env.ADMIN_ID) module.exports = { setSubStatus: (bot, msg, logger, name) => { let subs = JSON.parse(fs.readFileSync('./data/group/subs.json', 'utf8')) - const setSub = "set sub"; - if (msg.text && msg.text.toString().toLowerCase().includes(setSub)) { - if (admins.indexOf(msg.from.id) > -1) { - sub = msg.text.match(/(?<=set sub )(.*)(?= to (up|down))/g)[0] - status = msg.text.match(/\w+(?=( \w+){0}$)/g)[0] - logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " updated " + sub + " to " + status); - 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', JSON.stringify(subs)) - bot.sendMessage(msg.chat.id, sub + " sub updated") + if (admins.indexOf(msg.from.id) > -1) { + sub = msg.text.match(/(?<=set sub )(.*)(?= to (up|down))/g)[0] + status = msg.text.match(/\w+(?=( \w+){0}$)/g)[0] + logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " updated " + sub + " to " + status); + 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', JSON.stringify(subs)) + bot.sendMessage(msg.chat.id, sub + " sub updated") + } } + } \ No newline at end of file