From 4d06675f25090c7f92931eb8cdf9ec6d87bcc791 Mon Sep 17 00:00:00 2001 From: "karl.hudgell" Date: Thu, 2 Jul 2020 08:43:16 +0100 Subject: [PATCH] working set sub logic --- app.js | 15 +++++--- .../bot/functions/requests/updateSubStatus.js | 38 +++++++++---------- data/group/subs.json | 2 +- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/app.js b/app.js index 189fb7e..e98098e 100644 --- a/app.js +++ b/app.js @@ -37,7 +37,6 @@ bot.on('new_chat_members', (msg) => { }); bot.on('message', (msg) => { - bot_subStatus.setSubStatus(bot, msg, logger) if (msg.text && msg.text.toString().includes("/sub_status")) { questions.subStatus(bot, msg, logger) @@ -60,7 +59,6 @@ bot.on('message', (msg) => { bot_faq_subscription.prices(bot, msg, logger) } - for (const x of jointArray) { if (msg.text && msg.text.toString() === x.NAME) { common.chat(bot, msg, x.NAME, logger) @@ -77,14 +75,19 @@ bot.on('message', (msg) => { const chatId = msg.chat.id; match = msg.text.match(/([^\s]+)/g); const resp = match[1]; // the captured "whatever" - + // for (const x of jointArray) { - // if (resp === x.NAME) { - // common.chat(bot, msg, resp) - // } + // if (resp === x.NAME) { + // common.chat(bot, msg, resp) // } + // } + console.log('chat') bot.sendMessage(msg.chat.id, resp, logger) } + if (msg.text && msg.text.toString().includes("set sub")) { + bot_subStatus.setSubStatus(bot, msg, logger) + } + }); diff --git a/data/bot/functions/requests/updateSubStatus.js b/data/bot/functions/requests/updateSubStatus.js index 2a3fc62..f630c7f 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 diff --git a/data/group/subs.json b/data/group/subs.json index 4106091..0495313 100644 --- a/data/group/subs.json +++ b/data/group/subs.json @@ -1 +1 @@ -[{"SUB":"Premium Plus","COST":30,"STATUS":1,"APPS":["XCIPTV Blue","Sky Q Yellow","SMARTERS Green"]},{"SUB":"VIP","COST":25,"STATUS":1,"APPS":["XCIPTV Blue","Sky Q Yellow","SMARTERS Green"]},{"SUB":"Old Premium","COST":17,"STATUS":1,"APPS":["XCIPTV Blue","Sky Q Yellow","SMARTERS Green"]},{"SUB":"Bluemoon","COST":15,"STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"KDB","COST":14,"STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"Gold","COST":13,"STATUS":1,"APPS":["XCIPTV Red","Sky Q Yellow","SMARTERS Green"]},{"SUB":"Technoid","COST":13,"STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"Bronze","COST":10,"STATUS":1,"APPS":["XCIPTV Red","SMARTERS Green"]},{"SUB":"SOL","COST":10,"STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"New Premium (tvob)","COST":"X","STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"Gambler","COST":"X","STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"All of em","COST":"X","STATUS":"X"}] \ No newline at end of file +[{"SUB":"Premium Plus","COST":30,"STATUS":1,"APPS":["XCIPTV Blue","Sky Q Yellow","SMARTERS Green"]},{"SUB":"VIP","COST":25,"STATUS":1,"APPS":["XCIPTV Blue","Sky Q Yellow","SMARTERS Green"]},{"SUB":"Old Premium","COST":17,"STATUS":1,"APPS":["XCIPTV Blue","Sky Q Yellow","SMARTERS Green"]},{"SUB":"Bluemoon","COST":15,"STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"KDB","COST":14,"STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"Gold","COST":13,"STATUS":1,"APPS":["XCIPTV Red","Sky Q Yellow","SMARTERS Green"]},{"SUB":"Technoid","COST":13,"STATUS":0,"APPS":["SMARTERS Green"]},{"SUB":"Bronze","COST":10,"STATUS":1,"APPS":["XCIPTV Red","SMARTERS Green"]},{"SUB":"SOL","COST":10,"STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"New Premium (tvob)","COST":"X","STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"Gambler","COST":"X","STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"All of em","COST":"X","STATUS":"X"}] \ No newline at end of file