Skip to content

Commit

Permalink
fix(Node): fix overwrite redis cache after node reconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
Fab1o0107 committed Dec 27, 2023
1 parent ccfcb1c commit e0f82ee
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class Node {
const data = JSON.parse(message.toString());

if (!data) return undefined;
if (this.destroyed) return undefined;
if (this.destroyed || this.state === State.Reconnecting) return undefined;

this.manager.emit("raw", this.name, data);

Expand Down Expand Up @@ -434,24 +434,25 @@ export class Node {
await this.manager.redis?.set(RedisKey.NodeSession(this.name.toLowerCase()), this.sessionId!);
await this.rest.updateSession(this.manager.options.resume, this.manager.options.resumeTimeout);

const IDataCache = await this.manager.redis?.get(RedisKey.NodePlayers(this.name.toLowerCase()));
const dataCache = IDataCache ? (JSON.parse(IDataCache) as VoiceChannelOptions[]) : [];
if (data.resumed) {
const IDataCache = await this.manager.redis?.get(RedisKey.NodePlayers(this.name.toLowerCase()));
const dataCache = IDataCache ? (JSON.parse(IDataCache) as VoiceChannelOptions[]) : [];

for (const { guildId, channelId, shardId, mute, deaf } of dataCache) {
const player = await this.joinVoiceChannel({
guildId,
channelId,
shardId,
mute,
deaf
}).catch(() => undefined);

for (const { guildId, channelId, shardId, mute, deaf } of dataCache) {
const player = await this.joinVoiceChannel({
guildId,
channelId,
shardId,
mute,
deaf
}).catch(() => undefined);
// eslint-disable-next-line max-depth
if (player) continue;

if (!player) {
dataCache.splice(dataCache.indexOf(dataCache.find(({ guildId: id }) => id === guildId)!), 1);

await this.manager.redis?.set(RedisKey.NodePlayers(this.name.toLowerCase()), JSON.stringify(dataCache));

continue;
}
}

Expand Down

0 comments on commit e0f82ee

Please sign in to comment.