choco-bot
Version:
Whatsapp-bot
32 lines (26 loc) • 1.16 kB
JavaScript
const fs = require('fs');
async function addtolist(remainingMessage, msg) {
const mess = remainingMessage.trim();
const listName = mess.toLowerCase();
const lists = require('../lists.json');
// Check if the list exists
if (!lists[listName]) {
msg.reply(`List "${listName}" does not exist.`);
return;
}
const chat = await msg.getChat();
const participants = chat.participants;
const participantIds = participants.map((participant) => participant.id._serialized);
const uniqueParticipantIds = [...new Set(participantIds)];
const newParticipants = uniqueParticipantIds.filter((participantId) => !lists[listName].includes(participantId));
if (newParticipants.length > 0) {
lists[listName] = [...lists[listName], ...newParticipants]; // Add new participants
fs.writeFileSync('lists.json', JSON.stringify(lists, null, 2)); // Update the JSON file
msg.reply(`${newParticipants.length} participants added to list "${listName}". Total: ${lists[listName].length}`);
} else {
msg.reply(`No new participants to add to list "${listName}".`);
}
}
module.exports = {
addtolist,
}