Prevent multiple Discord clients

This commit is contained in:
Samuel Elliott
2022-09-26 16:42:24 +01:00
parent d9fb2657e6
commit 45c315978d
2 changed files with 20 additions and 2 deletions

View File

@@ -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);