choco-bot
Version:
Whatsapp-bot
40 lines (32 loc) • 1.09 kB
JavaScript
const fs = require('fs');
function getlist(remainingMessage, msg) {
const mess = remainingMessage.trim();
const args = mess.split(' ');
// Check if there are enough arguments
const requestedListName = mess;
const lists = require('../lists.json');
// Check if the requested list is "~all"
if (requestedListName === '~all') {
let details = '';
// Iterate through all lists and get their details
for (const [listName, participants] of Object.entries(lists)) {
details += `${listName}: *${participants.length}* participants\n`;
}
if (details) {
msg.reply(`Details of all lists:\n${details}`);
} else {
msg.reply('No lists available.');
}
} else {
// Check if the requested list exists
if (lists[requestedListName]) {
const listLength = lists[requestedListName].length;
msg.reply(`List "${requestedListName}" has *${listLength}* participants.`);
} else {
msg.reply(`List "${requestedListName}" does not exist.`);
}
}
}
module.exports = {
getlist,
};