Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Constants/Symbols.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export const LookupSymbol = Symbol("lookup");
export const UpdateSymbol = Symbol("update");

export const LastTrackSymbol = Symbol("lastTrack");

export const OnPingUpdateSymbol = Symbol("onPingUpdate");
Expand Down
3 changes: 1 addition & 2 deletions src/Queue/FilterManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { LookupSymbol } from "../Constants/Symbols";
import type { APIPlayer, FilterNames, FilterValue, JsonObject, Filters, CommonPluginFilters } from "../Typings";
import type { VoiceState } from "../Voice";
import type { Player } from "../Main";
Expand All @@ -13,7 +12,7 @@ export class FilterManager<PluginFilters extends JsonObject = CommonPluginFilter
constructor(player: Player, guildId: string) {
if (player.queues.has(guildId)) throw new Error(`A Queue already exists with its own FilterManager`);

const _player = player.queues[LookupSymbol](guildId);
const _player = player.queues.cache.get(guildId);
if (!_player) throw new Error(`No player found for guild '${guildId}'`);

const voice = player.voices.get(guildId);
Expand Down
6 changes: 3 additions & 3 deletions src/Queue/Queue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Severity } from "../Typings";
import { LastTrackSymbol, LookupSymbol, UpdateSymbol } from "../Constants/Symbols";
import { LastTrackSymbol, UpdateSymbol } from "../Constants/Symbols";
import { formatDuration, isArray, isNumber } from "../Functions";
import { Playlist, Track } from "../index";
import { VoiceState } from "../Voice";
Expand Down Expand Up @@ -44,7 +44,7 @@ export class Queue<Context extends Record<string, unknown> = QueueContext> {
constructor(player: Player, guildId: string, context?: Context) {
if (player.queues.has(guildId)) throw new Error("An identical queue already exists");

const _player = player.queues[LookupSymbol](guildId);
const _player = player.queues.cache.get(guildId);
if (!_player) throw new Error(`No player found for guild '${guildId}'`);

const voice = player.voices.get(guildId);
Expand Down Expand Up @@ -266,7 +266,7 @@ export class Queue<Context extends Record<string, unknown> = QueueContext> {
return;
}
if (target !== "remote") throw new Error("Target must be 'local' or 'remote'");
const voice = this.player.voices[LookupSymbol](this.guildId);
const voice = this.player.voices.cache.get(this.guildId);
if (!voice) return;
const player = this.#player;
const request: PlayerUpdateRequestBody = {
Expand Down
13 changes: 8 additions & 5 deletions src/Queue/QueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { setImmediate } from "node:timers/promises";
import { EventType, TrackEndReason } from "../Typings";
import {
LastTrackSymbol,
LookupSymbol,
OnEventUpdateSymbol,
OnPingUpdateSymbol,
OnStateUpdateSymbol,
Expand Down Expand Up @@ -54,6 +53,14 @@ export class QueueManager<Context extends Record<string, unknown> = QueueContext
return this.#queues.size;
}

/**
* Raw lavalink player objects.
* For reference or advanced usage only, do not `set` or `delete`
*/
get cache() {
return this.#cache as ReadonlyMap<string, APIPlayer>;
}

get(guildId: string) {
return this.#queues.get(guildId);
}
Expand Down Expand Up @@ -306,10 +313,6 @@ export class QueueManager<Context extends Record<string, unknown> = QueueContext
}
}

[LookupSymbol](guildId: string) {
return this.#cache.get(guildId);
}

[UpdateSymbol](guildId: string, payload: Partial<APIPlayer>, partial = true) {
const data = this.#cache.get(guildId);
if (data !== undefined) Object.assign(data, payload);
Expand Down
16 changes: 10 additions & 6 deletions src/Voice/VoiceManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { setTimeout } from "node:timers/promises";
import { VoiceCloseCodes } from "../Typings";
import { SnowflakeRegex, VoiceRegionIdRegex } from "../Constants";
import { LookupSymbol, OnVoiceCloseSymbol, UpdateSymbol } from "../Constants/Symbols";
import { OnVoiceCloseSymbol, UpdateSymbol } from "../Constants/Symbols";
import { isString, noop } from "../Functions";
import { VoiceRegion, VoiceState } from "./index";
import { Queue } from "../Queue";
Expand Down Expand Up @@ -54,6 +54,14 @@ export class VoiceManager implements Partial<Map<string, VoiceState>> {
return this.#voices.size;
}

/**
* Raw voice state objects.
* For reference or advanced usage only, do not `set` or `delete`
*/
get cache() {
return this.#cache as ReadonlyMap<string, BotVoiceState>;
}

get(guildId: string) {
return this.#voices.get(guildId);
}
Expand Down Expand Up @@ -89,7 +97,7 @@ export class VoiceManager implements Partial<Map<string, VoiceState>> {
const resolver = Promise.withResolvers<void>();
this.#destroys.set(guildId, resolver.promise);

if (this[LookupSymbol](guildId)?.connected) await voice.disconnect().catch(noop);
if (this.#cache.get(guildId)?.connected) await voice.disconnect().catch(noop);

this.#cache.delete(guildId);
this.#voices.delete(guildId);
Expand Down Expand Up @@ -341,10 +349,6 @@ export class VoiceManager implements Partial<Map<string, VoiceState>> {
}
}

[LookupSymbol](guildId: string) {
return this.#cache.get(guildId);
}

[UpdateSymbol](guildId: string, payload: Partial<BotVoiceState>, partial = true) {
const data = this.#cache.get(guildId);
if (data !== undefined) Object.assign(data, payload);
Expand Down
5 changes: 2 additions & 3 deletions src/Voice/VoiceState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { LookupSymbol } from "../Constants/Symbols";
import { noop } from "../Functions";
import type { APIPlayer, BotVoiceState, PlayerUpdateRequestBody } from "../Typings";
import type { Node } from "../Node";
Expand Down Expand Up @@ -28,10 +27,10 @@ export class VoiceState {
if (!_node) throw new Error(`Node '${node}' not found`);
if (!_node.ready) throw new Error(`Node '${node}' not ready`);

const state = player.voices[LookupSymbol](guildId);
const state = player.voices.cache.get(guildId);
if (!state) throw new Error(`No connection found for guild '${guildId}'`);

const _player = player.queues[LookupSymbol](guildId);
const _player = player.queues.cache.get(guildId);
if (!_player) throw new Error(`No player found for guild '${guildId}'`);

this.#node = _node;
Expand Down
Loading