fix sub update

This commit is contained in:
karl.hudgell 2020-07-03 08:08:42 +01:00
parent 8c180e9a60
commit f3a46ccb3a
2 changed files with 22 additions and 20 deletions

4
app.js
View File

@ -72,4 +72,8 @@ bot.on('message', (msg) => {
}
}
if (msg.text && msg.text.toString().toLowerCase().includes("set sub")) {
bot_subStatus.setSubStatus(bot, msg, logger)
}
})

View File

@ -4,8 +4,6 @@ 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]
@ -20,10 +18,10 @@ module.exports = {
subs[index].STATUS = status; //set the value
}
})
console.log(subs);
// console.log(subs);
fs.writeFileSync('./data/group/subs.json', JSON.stringify(subs))
bot.sendMessage(msg.chat.id, sub + " sub updated")
}
}
}
}