2023-12-05 13:39:29 +00:00

31 lines
1.2 KiB
JavaScript

const fs = require('fs')
const admins = JSON.parse(process.env.ADMIN_ID)
const questions = require('../../lib/questions')
module.exports = {
setSubStatus: (bot, msg, logger, name) => {
let subs = JSON.parse(fs.readFileSync('./data/group/subs.json', 'utf8'))
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.toLowerCase()) {
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")
msg.chat.id = process.env.CHANNEL_ID
questions.subStatus(bot, msg, logger, true)
}
}
}