UNPKG

choco-bot

Version:

Whatsapp-bot

46 lines (36 loc) 1.48 kB
const fs = require('fs'); async function mergelist(remainingMessage, msg) { const mess = remainingMessage.trim(); const args = mess.split(' '); // Check if there are enough arguments if (args.length < 2) { msg.reply('Usage: !mergelist <sourceList> <destinationList>'); return; } const sourceListName = args[0].toLowerCase(); const destinationListName = args[1].toLowerCase(); const lists = require('../lists.json'); if (!lists[sourceListName]) { msg.reply(`Source list "${sourceListName}" does not exist.`); return; } if (!lists[destinationListName]) { msg.reply(`Destination list "${destinationListName}" does not exist.`); return; } const sourceList = lists[sourceListName]; const destinationList = lists[destinationListName]; // Filter out duplicate elements from the source list const uniqueElements = sourceList.filter((element) => !destinationList.includes(element)); if (uniqueElements.length > 0) { lists[destinationListName] = [...destinationList, ...uniqueElements]; // Add unique elements fs.writeFileSync('lists.json', JSON.stringify(lists, null, 2)); // Update the JSON file msg.reply(`Merge complete. Total elements in "${destinationListName}": ${lists[destinationListName].length}`); } else { msg.reply(`No new elements to add from "${sourceListName}" to "${destinationListName}".`); } } module.exports = { mergelist, };