mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-10-24 10:35:14 -05:00
Prevent multiple Discord clients
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user