diff --git a/.gitignore b/.gitignore index 5299ebf..b313e4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ node_modules dist data +docker-compose.override.yml +.env .vscode/schema diff --git a/.vscode/settings.json b/.vscode/settings.json index 8684cc6..58c7f13 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -51,4 +51,5 @@ }, ], "typescript.tsdk": "node_modules/typescript/lib", + "typescript.preferences.quoteStyle": "single", } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fcb8956 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,51 @@ +version: '3' + +services: + web: + build: . + command: nso http-server --listen \[::]:80 + restart: unless-stopped + labels: + traefik.enable: true + traefik.http.routers.nxapi-znc.entrypoints: websecure + traefik.http.routers.nxapi-znc.rule: Host(`${TRAEFIK_HOST:-nxapi.ta.fancy.org.uk}`) && PathPrefix(`/api/znc/`) + traefik.http.routers.nxapi-znc.tls: true + traefik.http.services.nxapi-znc.loadbalancer.server.port: 80 + environment: + DEBUG: '*,-express:*' + ZNCA_API_URL: http://znca-api/api/znca + volumes: + - data:/data + + znca-api: + image: ${COMPOSE_PROJECT_NAME:-nxapi}_web + command: + - android-znca-api-server-frida + - $ZNCA_API_ANDROID_DEVICE + - --exec-command + - ${ZNCA_API_EXEC_COMMAND:-} + - --frida-server-path + - ${ZNCA_API_FRIDA_SERVER_PATH:-/data/local/tmp/frida-server} + - --listen + - '[::]:80' + restart: unless-stopped + depends_on: + - web + labels: + traefik.enable: true + traefik.http.routers.nxapi-znca.entrypoints: websecure + traefik.http.routers.nxapi-znca.rule: Host(`${TRAEFIK_HOST:-nxapi.ta.fancy.org.uk}`) && PathPrefix(`/api/znca/`) + traefik.http.routers.nxapi-znca.tls: true + traefik.http.services.nxapi-znca.loadbalancer.server.port: 80 + environment: + DEBUG: '*,-express:*,-body-parser:*' + volumes: + - data:/data + healthcheck: + test: [ "ENTRYPOINT", "curl", "http://[::1]:80" ] + timeout: 45s + interval: 10s + retries: 10 + +volumes: + data: diff --git a/src/common/notify.ts b/src/common/notify.ts index 1f376ef..7b0d0ef 100644 --- a/src/common/notify.ts +++ b/src/common/notify.ts @@ -164,7 +164,7 @@ export class ZncNotifications extends Loop { this.splatnet2_monitors.size ? 'user' : null, ]); - await this.updatePresenceForNotifications(user, friends); + await this.updatePresenceForNotifications(user, friends, this.data.user.id, false); if (user) await this.updatePresenceForSplatNet2Monitors([user]); } @@ -219,7 +219,8 @@ export class NotificationManager { if (this.accounts.get(friend.nsaId) !== naid) continue; if (lastpresence?.updatedAt !== friend.presence.updatedAt && !initialRun) { - debug('%s\'s presence updated', friend.name, new Date(friend.presence.updatedAt * 1000).toString()); + debugFriends('%s\'s presence updated', friend.name, + new Date(friend.presence.updatedAt * 1000).toString()); } let type: PresenceEvent | undefined = undefined; @@ -250,10 +251,10 @@ export class NotificationManager { const lasttitle = lastpresence.game as Game; - debugFriends('%s is now offline%s, was playing title %s %s', friend.name, + debugFriends('%s is now offline%s, was playing title %s %s, logout time %s', friend.name, friend.presence.state !== PresenceState.OFFLINE ? ' (console still online)' : '', lasttitle.name, JSON.stringify(lasttitle.sysDescription), - new Date(friend.presence.logoutAt * 1000).toString()); + friend.presence.logoutAt ? new Date(friend.presence.logoutAt * 1000).toString() : null); if (friend.presence.state !== PresenceState.OFFLINE) { // Friend's console is still online @@ -305,8 +306,7 @@ export class NotificationManager { // Friend's console is now offline type = PresenceEvent.STATE_CHANGE; - debugFriends('%s\'s console is now offline', friend.name, - new Date(friend.presence.logoutAt * 1000).toString()); + debugFriends('%s\'s console is now offline', friend.name); } if (lastpresence?.updatedAt !== friend.presence.updatedAt && !initialRun) { diff --git a/src/common/presence.ts b/src/common/presence.ts index 047b5be..a4b7029 100644 --- a/src/common/presence.ts +++ b/src/common/presence.ts @@ -248,7 +248,7 @@ export class ZncDiscordPresence extends ZncNotifications { } } - await this.updatePresenceForNotifications(user, friends, this.data.user.id, true); + await this.updatePresenceForNotifications(user, friends, this.data.user.id, false); if (user) await this.updatePresenceForSplatNet2Monitors([user]); }