feat(autopause): re-emit client enter/leave/move for instant pause/resume

This commit is contained in:
saopig1 committed 2026-05-30 14:50:52 +08:00
1 parent 4ba4b013b0
commit 8f5bb26b3a
2 files changed
+32

No files matched your search

+16
View File
@@ -159,6 +159,22 @@ export class BotInstance extends EventEmitter {
this.autoPaused = false;
this._startIdlePoller();
});
// React near-instantly to channel membership changes. The 30s idle
// poller remains the fallback if any of these events are missed.
this.tsClient.on("clientEnter", () => void this.refreshOccupancy());
this.tsClient.on("clientLeave", () => void this.refreshOccupancy());
this.tsClient.on("clientMoved", () => void this.refreshOccupancy());
}
private async refreshOccupancy(): Promise<void> {
if (!this.connected) return;
try {
const clients = await this.tsClient.getClientsInChannel();
this.handleOccupancy(clients.length - 1);
} catch {
// ignore — the 30s poll is the fallback
}
}
async connect(): Promise<void> {