38 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2020-06-25 22:44:18 +01:00
const fs = require('fs')
2020-08-03 20:01:19 +01:00
let ad = JSON.parse(fs.readFileSync('./data/group/admins.json', 'utf8'))
2025-04-21 07:46:35 +00:00
let adminArray = []
// const questions = require('./data/bot/lib/questions')
const questions = require('../../lib/questions')
2020-08-03 20:01:19 +01:00
for (const x of ad) {
adminArray.push(x.ADMIN)
}
2020-06-25 22:44:18 +01:00
module.exports = {
setSubStatus: (bot, msg, logger, name) => {
2020-06-26 12:16:25 +01:00
let subs = JSON.parse(fs.readFileSync('./data/group/subs.json', 'utf8'))
2020-08-03 20:01:19 +01:00
if (adminArray.indexOf(msg.from.id) > -1) {
2020-07-02 08:43:16 +01:00
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-26 18:30:10 +01:00
}
2020-07-02 08:43:16 +01:00
subs.forEach(function (element, index) {
2020-07-04 11:59:23 +01:00
if (element.SUB.toLowerCase() === sub.toLowerCase()) {
2020-07-02 08:43:16 +01:00
subs[index].STATUS = status; //set the value
}
})
2020-07-02 09:13:20 +01:00
// console.log(subs);
2020-07-02 08:43:16 +01:00
fs.writeFileSync('./data/group/subs.json', JSON.stringify(subs))
bot.sendMessage(msg.chat.id, sub + " sub updated")
2025-04-21 07:46:35 +00:00
msg.chat.id = process.env.CHANNEL_ID
questions.subStatus(bot, msg, logger, true)
2020-07-02 08:43:16 +01:00
}
2020-06-25 22:44:18 +01:00
}
2020-07-02 08:43:16 +01:00
2020-06-25 22:44:18 +01:00
}