improve parser
Some checks failed
ci / build (push) Failing after 1s
ci / Tests & Checks (push) Failing after 1s

This commit is contained in:
CJ_Clippy 2025-06-27 22:54:40 -08:00
parent 3157c993bf
commit 6d77138ebd
3 changed files with 27 additions and 2 deletions

View File

@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node src/index.js"
"start": "bash -x watchdog.sh"
},
"keywords": [],
"author": "",

View File

@ -4,9 +4,17 @@ const fs = require('fs/promises');
const logger = require('./logger.js');
function parseEvent(evt) {
if (evt?.action) {
try {
evt = JSON.parse(evt)
} catch (e) {
logger.error(`failed to parse event=${evt}`)
}
if (typeof evt?.action === "number") {
logger.debug(`event with action=${evt.action}`);
if (evt.action === 0) return false; // heartbeat
if (evt.action === 15) return true; // chat message
} else {
logger.warn(`event with NO ACTION. evt=${JSON.stringify(evt)} ${typeof evt}`)
}
}

View File

@ -0,0 +1,17 @@
#!/bin/bash
set -e
while true; do
echo "Starting app..."
node src/index.js
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "Exited normally. Not restarting."
break
fi
echo "App crashed (exit code $exit_code). Restarting in 2 seconds..."
sleep 2
done