31 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2020-06-30 16:25:55 +00:00
const fs = require('fs')
const admins = JSON.parse(process.env.ADMIN_ID)
2023-12-05 13:39:29 +00:00
const questions = require('../../lib/questions')
2020-06-30 16:25:55 +00:00
module.exports = {
setSubStatus: (bot, msg, logger, name) => {
let subs = JSON.parse(fs.readFileSync('./data/group/subs.json', 'utf8'))
2020-07-03 08:08:42 +01:00
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
2020-06-30 16:25:55 +00:00
}
2020-07-03 08:08:42 +01:00
subs.forEach(function (element, index) {
2020-07-04 11:27:03 +01:00
if (element.SUB.toLowerCase() === sub.toLowerCase()) {
2020-07-03 08:08:42 +01:00
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")
2023-12-05 13:39:29 +00:00
msg.chat.id = process.env.CHANNEL_ID
questions.subStatus(bot, msg, logger, true)
2020-07-03 08:08:42 +01:00
}
2020-06-30 16:25:55 +00:00
}
2020-07-03 08:08:42 +01:00
2020-06-26 20:51:38 +01:00
}