mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-03-21 18:04:10 -05:00
Prevent multiple Discord clients
This commit is contained in:
parent
d9fb2657e6
commit
45c315978d
|
|
@ -393,11 +393,13 @@ export class EmbeddedPresenceMonitor extends ZncDiscordPresence {
|
|||
await this.loop();
|
||||
}
|
||||
|
||||
if (this._running === 0) {
|
||||
if (this._running === 0 && !this.onStop) {
|
||||
// Run one more time after the loop ends
|
||||
const result = await this.loopRun();
|
||||
}
|
||||
|
||||
await this.onStop?.();
|
||||
|
||||
debug('Monitor for user %s finished', this.data.nsoAccount.user.name);
|
||||
} finally {
|
||||
this._running = 0;
|
||||
|
|
@ -449,11 +451,13 @@ export class EmbeddedProxyPresenceMonitor extends ZncProxyDiscordPresence {
|
|||
await this.loop();
|
||||
}
|
||||
|
||||
if (this._running === 0) {
|
||||
if (this._running === 0 && !this.onStop) {
|
||||
// Run one more time after the loop ends
|
||||
const result = await this.loopRun();
|
||||
}
|
||||
|
||||
await this.onStop?.();
|
||||
|
||||
debug('Monitor for presence URL %s finished', this.presence_url);
|
||||
} finally {
|
||||
this._running = 0;
|
||||
|
|
|
|||
|
|
@ -304,6 +304,12 @@ class ZncDiscordPresenceClient {
|
|||
// @ts-expect-error
|
||||
client.transport.on('close', reconnect);
|
||||
|
||||
if (this.rpc) {
|
||||
// Another client connected first
|
||||
client!.destroy();
|
||||
return (this.rpc as {client: DiscordRpcClient}).client;
|
||||
}
|
||||
|
||||
this.rpc = {client: client!, id: client_id};
|
||||
this.onUpdateClient?.call(null, client!);
|
||||
if (this.last_activity) this.rpc.client.setActivity(this.last_activity.activity);
|
||||
|
|
@ -450,6 +456,10 @@ export class ZncDiscordPresence extends ZncNotifications {
|
|||
if (user) await this.updatePresenceForSplatNet2Monitors([user]);
|
||||
}
|
||||
|
||||
async onStop() {
|
||||
await this.discord.setActivity(null);
|
||||
}
|
||||
|
||||
saved_presence = new Map<string, number>();
|
||||
|
||||
async savePresenceForTitleUpdateAt(id: string, presence: Presence, title_since = Date.now()) {
|
||||
|
|
@ -532,6 +542,10 @@ export class ZncProxyDiscordPresence extends Loop {
|
|||
await this.updatePresenceForSplatNet2Monitor(presence, this.presence_url);
|
||||
}
|
||||
|
||||
async onStop() {
|
||||
await this.discord.setActivity(null);
|
||||
}
|
||||
|
||||
async updatePresenceForSplatNet2Monitors(friends: (CurrentUser | Friend)[]) {
|
||||
for (const friend of friends) {
|
||||
await this.updatePresenceForSplatNet2Monitor(friend.presence, friend.nsaId, friend.name);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user