UNPKG

choco-bot

Version:

Whatsapp-bot

74 lines (71 loc) 2.59 kB
const commands = { 'archivechat': { variations: ['archive chat', 'archive this chat', 'hide chat', 'hide this chat'], }, 'unarchivechat': { variations: ['unarchive chat', 'unarchive this chat', 'show chat', 'show this chat'], }, 'takeover': { variations: ['set afk on', 'takeover from here', 'keep this chat alive'], }, 'broadcast': { variations: ['broadcast this', 'send to all', 'broadcast message'], }, 'dwp': { variations: ['download this site', 'download source code', 'provide source code for', 'files for'], }, 'createlist': { variations: ['createlist', 'create list', 'build a new list', 'make a new list'], }, 'addtolist': { variations: ['addtolist', 'add to list', 'add participants'], }, 'groupdata': { variations: ['get group info', 'gimme group info', 'where am i'], }, 'reminder': { variations: ['reminder', 'set reminder', 'remind me', 'remind me to'], }, 'invitetogroup': { variations: ['invitetogroup', 'invite to group', 'add members'], }, 'exportcontacts': { variations: ['exportcontacts', 'export contacts', 'get contacts'], }, 'currency_converter': { variations: ['convert currency', 'currency conversion', 'exchange rate'], }, 'screenshotweb': { variations: ['screenshotweb', 'take screenshot', 'capture web page'], }, 'temp-vote': { variations: ['start voting process', 'start castilo'], }, 'mergelist': { variations: ['import list', 'merge list', 'add list'], }, 'getlist': { variations: ['get list', 'list info', 'list detail'], }, 'dictionary': { variations: ['dictionary', 'define word', 'lookup word'], }, 'getgroups': { variations: ['get groups', 'show groups'], }, }; function processCommand(command, callback) { for (const [cmd, commandInfo] of Object.entries(commands)) { if (commandInfo.variations.some(variation => command.toLowerCase().includes(variation))) { const trigger = commandInfo.variations.find(variation => command.toLowerCase().includes(variation)); const remainingMessage = command.replace(new RegExp(trigger, 'i'), '').trim(); callback(cmd, remainingMessage); return; } } // Handle unrecognized command here console.log(`Unrecognized command: ${command}`); } module.exports = { processCommand, };