magmastream
Version:
A user-friendly Lavalink client designed for NodeJS.
83 lines (82 loc) • 3.79 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = playerCheck;
const Enums_1 = require("../structures/Enums");
const MagmastreamError_1 = require("../structures/MagmastreamError");
/**
* Validates the provided PlayerOptions object.
* @param options - The options to validate.
* @throws {MagmaStreamError} Throws if any required option is missing or invalid.
*/
function playerCheck(options) {
if (!options) {
throw new MagmastreamError_1.MagmaStreamError({
code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_CONFIG,
message: "PlayerOptions must not be empty.",
});
}
const { guildId, nodeIdentifier, selfDeafen, selfMute, textChannelId, voiceChannelId, volume, applyVolumeAsFilter, pauseOnDisconnect } = options;
if (!/^\d+$/.test(guildId)) {
throw new MagmastreamError_1.MagmaStreamError({
code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_CONFIG,
message: 'Player option "guildId" must be present and a non-empty string.',
context: { guildId },
});
}
if (nodeIdentifier && typeof nodeIdentifier !== "string") {
throw new MagmastreamError_1.MagmaStreamError({
code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_CONFIG,
message: 'Player option "nodeIdentifier" must be a non-empty string.',
context: { nodeIdentifier },
});
}
if (typeof selfDeafen !== "undefined" && typeof selfDeafen !== "boolean") {
throw new MagmastreamError_1.MagmaStreamError({
code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_CONFIG,
message: 'Player option "selfDeafen" must be a boolean.',
context: { selfDeafen },
});
}
if (typeof selfMute !== "undefined" && typeof selfMute !== "boolean") {
throw new MagmastreamError_1.MagmaStreamError({
code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_CONFIG,
message: 'Player option "selfMute" must be a boolean.',
context: { selfMute },
});
}
if (textChannelId && !/^\d+$/.test(textChannelId)) {
throw new MagmastreamError_1.MagmaStreamError({
code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_CONFIG,
message: 'Player option "textChannelId" must be a non-empty string.',
context: { textChannelId },
});
}
if (voiceChannelId && !/^\d+$/.test(voiceChannelId)) {
throw new MagmastreamError_1.MagmaStreamError({
code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_CONFIG,
message: 'Player option "voiceChannelId" must be a non-empty string.',
context: { voiceChannelId },
});
}
if (typeof volume !== "undefined" && typeof volume !== "number") {
throw new MagmastreamError_1.MagmaStreamError({
code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_CONFIG,
message: 'Player option "volume" must be a number.',
context: { volume },
});
}
if (typeof applyVolumeAsFilter !== "undefined" && typeof applyVolumeAsFilter !== "boolean") {
throw new MagmastreamError_1.MagmaStreamError({
code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_CONFIG,
message: 'Player option "applyVolumeAsFilter" must be a boolean.',
context: { applyVolumeAsFilter },
});
}
if (typeof pauseOnDisconnect !== "undefined" && typeof pauseOnDisconnect !== "boolean") {
throw new MagmastreamError_1.MagmaStreamError({
code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_CONFIG,
message: 'Player option "pauseOnDisconnect" must be a boolean.',
context: { pauseOnDisconnect },
});
}
}