Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
emit(message)
}
}
}
Object.assign(endowments, makeUtilsEndowments())
if (pid === 0) { // Root bot extra endowments
Object.assign(endowments, makeRootBotEndowments({
processes,
debugLog,
storageDir,
register,
updateHandlerFunc,
updateKilled
}))
}
return SES
.confine(
`${handlerFunc}; module.exports(botName, message, state, refs)`,
endowments
)
.then(result => {
handlerLog('Success:', result)
if (pid === 0 || !state[pid]) return {result}
const jsonStateFile = path.join(
storageDir, 'bots', `${pid}`, 'state.json'
)
const json = JSON.stringify(state[pid], null, 2)
return writeFile(jsonStateFile, json).then(() => {result})
})
.catch(err => {
handlerLog('Fail:', err.name, err.message, err.stack)
log(chalk.red(`PID ${pid} ${botName}:`),