67 lines
3.0 KiB
JavaScript
67 lines
3.0 KiB
JavaScript
|
|
||
|
const startCompCalled = "start comp called";
|
||
|
if (msg.text && msg.text.toString().toLowerCase().includes(startCompCalled)) {
|
||
|
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked who is an admin");
|
||
|
test = msg.text.match(/\b(\w+)$/gm);
|
||
|
fs.writeFileSync('./data/' + test + '.json', '[]')
|
||
|
bot.sendMessage(msg.chat.id, 'Comp created')
|
||
|
}
|
||
|
|
||
|
const stopCompCalled = "stop comp called";
|
||
|
if (msg.text && msg.text.toString().toLowerCase().includes(stopCompCalled)) {
|
||
|
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked who is an admin");
|
||
|
test = msg.text.match(/\b(\w+)$/gm);
|
||
|
fs.unlinkSync('./data/' + test + '.json', '[]')
|
||
|
bot.sendMessage(msg.chat.id, 'Comp removed')
|
||
|
}
|
||
|
|
||
|
const comp = "entered the comp";
|
||
|
if (msg.text && msg.text.toString().toLowerCase().includes(comp)) {
|
||
|
if (admins.indexOf(msg.from.id) > -1) {
|
||
|
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked who is an admin");
|
||
|
user = msg.text.match(/^([\w\-]+)/gm)[0];
|
||
|
let comp_name = msg.text.match(/\b(\w+)$/gm)[0];
|
||
|
|
||
|
comp_users = JSON.parse(fs.readFileSync('./data/' + comp_name + '.json', 'utf8'))
|
||
|
|
||
|
let new_comp_users = comp_users.concat(user)
|
||
|
|
||
|
fs.writeFileSync('./data/' + comp_name + '.json', JSON.stringify(new_comp_users))
|
||
|
|
||
|
bot.sendMessage(msg.chat.id, user + " has been added to the competition")
|
||
|
} else {
|
||
|
console.log('not found')
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const enteredTheComp = "how many in comp";
|
||
|
if (msg.text && msg.text.toString().toLowerCase().includes(enteredTheComp)) {
|
||
|
if (admins.indexOf(msg.from.id) > -1) {
|
||
|
let comp_name = msg.text.match(/\b(\w+)$/gm)[0];
|
||
|
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked who is an admin");
|
||
|
var comp_entered = JSON.parse(fs.readFileSync('./data/' + comp_name + '.json', 'utf8'))
|
||
|
bot.sendMessage(msg.chat.id, "There are " + comp_entered.length + " people in the comp")
|
||
|
} else {
|
||
|
console.log('not found')
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const whoWon = "who won comp";
|
||
|
if (msg.text && msg.text.toString().toLowerCase().includes(whoWon)) {
|
||
|
if (admins.indexOf(msg.from.id) > -1) {
|
||
|
let comp_name = msg.text.match(/\b(\w+)$/gm)[0];
|
||
|
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked who is an admin");
|
||
|
var comp_entered = JSON.parse(fs.readFileSync('./data/' + comp_name + '.json', 'utf8'))
|
||
|
|
||
|
var winner = comp_entered[Math.floor(Math.random() * comp_entered.length)];
|
||
|
|
||
|
bot.sendMessage(msg.chat.id, "There winner is .....").then(() => {
|
||
|
return bot.sendMessage(msg.chat.id, winner)
|
||
|
})
|
||
|
} else {
|
||
|
console.log('not found')
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}),
|
||
|
|