Skip to content

Commit ecee7e8

Browse files
committed
fix: make voice channelId nullable in fetch/update player response
1 parent 7827f06 commit ecee7e8

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎src/Node/REST.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { HttpStatusCode } from "../Typings";
55
import { DefaultRestOptions, Routes } from "../Constants";
66
import { isArray, isNumber, isRecord, isString } from "../Functions";
77
import type {
8-
APIPlayer,
98
APITrack,
109
LavalinkInfo,
1110
LoadResult,
@@ -19,6 +18,7 @@ import type {
1918
RoutePlannerStatus,
2019
SessionUpdateRequestBody,
2120
SessionUpdateResponseBody,
21+
PlayerUpdateResponseBody,
2222
} from "../Typings";
2323

2424
export class REST {
@@ -212,14 +212,14 @@ export class REST {
212212

213213
async fetchPlayers(sessionId = this.sessionId!) {
214214
if (!isString(sessionId, "non-empty")) throw new Error("Session Id neither set nor provided");
215-
const response = await this.request<APIPlayer[]>(Routes.player(sessionId));
215+
const response = await this.request<PlayerUpdateResponseBody[]>(Routes.player(sessionId));
216216
return response.data;
217217
}
218218

219219
async fetchPlayer(guildId: string, sessionId = this.sessionId!) {
220220
if (!isString(guildId, "non-empty")) throw new Error("Guild Id must be a non-empty string");
221221
if (!isString(sessionId, "non-empty")) throw new Error("Session Id neither set nor provided");
222-
const response = await this.request<APIPlayer>(Routes.player(sessionId, guildId));
222+
const response = await this.request<PlayerUpdateResponseBody>(Routes.player(sessionId, guildId));
223223
return response.data;
224224
}
225225

@@ -232,7 +232,7 @@ export class REST {
232232
if (!isString(guildId, "non-empty")) throw new Error("Guild Id must be a non-empty string");
233233
if (!isString(sessionId, "non-empty")) throw new Error("Session Id neither set nor provided");
234234
if (!isRecord(options, "non-empty")) throw new Error("Player update options cannot be empty");
235-
const response = await this.request<APIPlayer>(Routes.player(sessionId, guildId), {
235+
const response = await this.request<PlayerUpdateResponseBody>(Routes.player(sessionId, guildId), {
236236
method: "PATCH",
237237
data: options,
238238
params: { ...params },

‎src/Queue/QueueManager.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
TrackExceptionEventPayload,
2020
TrackStuckEventPayload,
2121
QueueContext,
22+
PlayerUpdateResponseBody,
2223
} from "../Typings";
2324
import type { Player } from "../Main";
2425

@@ -253,7 +254,7 @@ export class QueueManager<Context extends Record<string, unknown> = QueueContext
253254
return this.#cache.get(guildId);
254255
}
255256

256-
[UpdateSymbol](guildId: string, payload: Partial<APIPlayer>, partial = true) {
257+
[UpdateSymbol](guildId: string, payload: Partial<PlayerUpdateResponseBody>, partial = true) {
257258
const data = this.#cache.get(guildId);
258259
if (data !== undefined) Object.assign(data, payload);
259260
else if (!partial) this.#cache.set(guildId, payload as APIPlayer);

‎src/Typings/API/Rest.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import type { CommonPluginFilters, CommonPluginInfo, CommonUserData, EmptyObject, JsonObject } from "../Utility";
1+
import type {
2+
CommonPluginFilters,
3+
CommonPluginInfo,
4+
CommonUserData,
5+
EmptyObject,
6+
JsonObject,
7+
NullableProp,
8+
} from "../Utility";
29
import type { Exception, PlayerState } from "./Websocket";
310

411
export const enum LoadType {
@@ -580,6 +587,10 @@ export interface PlayerUpdateRequestBody {
580587
voice?: APIVoiceState;
581588
}
582589

590+
export interface PlayerUpdateResponseBody extends Omit<APIPlayer, "voice"> {
591+
voice: NullableProp<APIVoiceState, "channelId">;
592+
}
593+
583594
export interface PlayerUpdateTrackData<UserData extends JsonObject = CommonUserData> {
584595
/**
585596
* The base64 encoded track to play. `null` stops the current track.

‎src/Typings/Utility.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ export type JsonObject = { [x: string]: JsonLike };
2525
*/
2626
export type RequiredProp<T, P extends keyof T> = Omit<T, P> & Required<Pick<T, P>>;
2727

28+
/**
29+
* Makes select properties nullable
30+
*/
31+
export type NullableProp<T, P extends keyof T> = {
32+
[K in keyof T]: K extends P ? T[K] | null : T[K];
33+
};
34+
2835
/**
2936
* Makes select properties non-nullable
3037
*/

0 commit comments

Comments
 (0)