diff --git a/README.md b/README.md index 9dd7e230f..8ddeeccc2 100644 --- a/README.md +++ b/README.md @@ -85,9 +85,11 @@ $ npm install --save ffmpeg-binaries #### Streaming Library -YouTube streaming is not supported without installing one of the following package. If you want to add support for YouTube playback, you need to install a streaming library. This step is not needed if you do not plan on using youtube source. +**The following method is deprecated and will be removed in the future. Please switch to [discord-player-youtubei](https://npmjs.com/discord-player-youtubei).** + +**Not recommended**: -* The default Youtube streaming appears to be unstable due to recent changes. It is recommend to install [`discord-player-youtubei`](https://npm.im/discord-player-youtubei)* +YouTube streaming is not supported without installing one of the following package. If you want to add support for YouTube playback, you need to install a streaming library. This step is not needed if you do not plan on using youtube source. ```bash $ npm install --save youtube-ext @@ -101,8 +103,6 @@ $ npm install --save yt-stream $ npm install --save ytdl-core ``` -We recommend using `youtube-ext` for better performance. - Once you have completed these installations, let's proceed with writing a simple music bot. ### Setup diff --git a/packages/discord-player/README.md b/packages/discord-player/README.md index d3c2cea43..8ddeeccc2 100644 --- a/packages/discord-player/README.md +++ b/packages/discord-player/README.md @@ -85,6 +85,10 @@ $ npm install --save ffmpeg-binaries #### Streaming Library +**The following method is deprecated and will be removed in the future. Please switch to [discord-player-youtubei](https://npmjs.com/discord-player-youtubei).** + +**Not recommended**: + YouTube streaming is not supported without installing one of the following package. If you want to add support for YouTube playback, you need to install a streaming library. This step is not needed if you do not plan on using youtube source. ```bash @@ -99,8 +103,6 @@ $ npm install --save yt-stream $ npm install --save ytdl-core ``` -We recommend using `youtube-ext` for better performance. - Once you have completed these installations, let's proceed with writing a simple music bot. ### Setup diff --git a/packages/discord-player/package.json b/packages/discord-player/package.json index 618e08f98..57ddbbbb2 100644 --- a/packages/discord-player/package.json +++ b/packages/discord-player/package.json @@ -1,6 +1,6 @@ { "name": "discord-player", - "version": "6.7.0", + "version": "6.7.1", "description": "Complete framework to facilitate music commands using discord.js", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -55,7 +55,6 @@ "@discord-player/utils": "workspace:^", "@web-scrobbler/metadata-filter": "^3.1.0", "discord-voip": "^0.1.3", - "ip": "^2.0.1", "libsodium-wrappers": "^0.7.13" }, "peerDependencies": { @@ -78,4 +77,4 @@ "readmeFile": "./README.md", "tsconfig": "./tsconfig.json" } -} \ No newline at end of file +} diff --git a/packages/discord-player/src/errors/index.ts b/packages/discord-player/src/errors/index.ts index f635dd7cb..62081a719 100644 --- a/packages/discord-player/src/errors/index.ts +++ b/packages/discord-player/src/errors/index.ts @@ -3,133 +3,140 @@ const DiscordPlayerErrors = { name: 'ERR_OUT_OF_SPACE', type: RangeError, createError(target: string, capacity: number, total: number) { - return `[${this.name}] Max capacity reached for ${target} (Capacity ${capacity}/Total ${total})`; + return `[${this.constructor.name}] Max capacity reached for ${target} (Capacity ${capacity}/Total ${total})`; } }, ERR_INVALID_ARG_TYPE: { name: 'ERR_INVALID_ARG_TYPE', type: TypeError, createError(target: string, expectation: string, found: string) { - return `[${this.name}] Expected ${target} to be "${expectation}", received "${found}"`; + return `[${this.constructor.name}] Expected ${target} to be "${expectation}", received "${found}"`; } }, ERR_NO_RESULT: { name: 'ERR_NO_RESULT', type: Error, createError(message: string) { - return `[${this.name}] ${message}`; + return `[${this.constructor.name}] ${message}`; } }, ERR_NOT_IMPLEMENTED: { name: 'ERR_NOT_IMPLEMENTED', type: Error, createError(target: string) { - return `[${this.name}] ${target} is not yet implemented`; + return `[${this.constructor.name}] ${target} is not yet implemented`; } }, ERR_NOT_EXISTING: { name: 'ERR_NOT_EXISTING', type: Error, createError(target: string) { - return `[${this.name}] ${target} does not exist`; + return `[${this.constructor.name}] ${target} does not exist`; } }, ERR_OUT_OF_RANGE: { name: 'ERR_OUT_OF_RANGE', type: RangeError, createError(target: string, value: string, minimum: string, maximum: string) { - return `[${this.name}] ${target} is out of range (Expected minimum ${maximum} and maximum ${maximum}, got ${value})`; + return `[${this.constructor.name}] ${target} is out of range (Expected minimum ${maximum} and maximum ${maximum}, got ${value})`; } }, ERR_NO_VOICE_CONNECTION: { name: 'ERR_NO_VOICE_CONNECTION', type: Error, createError(message?: string) { - return `[${this.name}] ` + (message || 'No voice connection available, maybe connect to a voice channel first?'); + return `[${this.constructor.name}] ` + (message || 'No voice connection available, maybe connect to a voice channel first?'); } }, ERR_VOICE_CONNECTION_DESTROYED: { name: 'ERR_VOICE_CONNECTION_DESTROYED', type: Error, createError() { - return `[${this.name}] ` + 'Cannot use destroyed voice connection'; + return `[${this.constructor.name}] ` + 'Cannot use destroyed voice connection'; } }, ERR_NO_VOICE_CHANNEL: { name: 'ERR_NO_VOICE_CHANNEL', type: Error, createError() { - return `[${this.name}] ` + 'Could not get the voice channel'; + return `[${this.constructor.name}] ` + 'Could not get the voice channel'; } }, ERR_INVALID_VOICE_CHANNEL: { name: 'ERR_INVALID_VOICE_CHANNEL', type: Error, createError() { - return `[${this.name}] ` + 'Expected a voice channel'; + return `[${this.constructor.name}] ` + 'Expected a voice channel'; } }, ERR_NO_RECEIVER: { name: 'ERR_NO_RECEIVER', type: Error, createError(message?: string) { - return `[${this.name}] ` + (message || 'No voice receiver is available, maybe connect to a voice channel first?'); + return `[${this.constructor.name}] ` + (message || 'No voice receiver is available, maybe connect to a voice channel first?'); } }, ERR_FFMPEG_LOCATOR: { name: 'ERR_FFMPEG_LOCATOR', type: Error, createError(message: string) { - return `[${this.name}] ` + message; + return `[${this.constructor.name}] ` + message; } }, ERR_NO_AUDIO_RESOURCE: { name: 'ERR_NO_AUDIO_RESOURCE', type: Error, createError(message?: string) { - return `[${this.name}] ` + (message || 'Expected an audio resource'); + return `[${this.constructor.name}] ` + (message || 'Expected an audio resource'); } }, ERR_NO_GUILD_QUEUE: { name: 'ERR_NO_GUILD_QUEUE', type: Error, createError(message?: string) { - return `[${this.name}] ` + (message || 'Expected a guild queue'); + return `[${this.constructor.name}] ` + (message || 'Expected a guild queue'); } }, ERR_NO_GUILD: { name: 'ERR_NO_GUILD', type: Error, createError(message?: string) { - return `[${this.name}] ` + (message || 'Expected a guild'); + return `[${this.constructor.name}] ` + (message || 'Expected a guild'); } }, ERR_INFO_REQUIRED: { name: 'ERR_INFO_REQUIRED', type: Error, createError(target: string, actual: string) { - return `[${this.name}] Expected ${target}, found "${actual}"`; + return `[${this.constructor.name}] Expected ${target}, found "${actual}"`; } }, ERR_SERIALIZATION_FAILED: { name: 'ERR_SERIALIZATION_FAILED', type: Error, createError() { - return `[${this.name}]` + "Don't know how to serialize this data"; + return `[${this.constructor.name}]` + "Don't know how to serialize this data"; } }, ERR_DESERIALIZATION_FAILED: { name: 'ERR_DESERIALIZATION_FAILED', type: Error, createError() { - return `[${this.name}]` + "Don't know how to deserialize this data"; + return `[${this.constructor.name}]` + "Don't know how to deserialize this data"; } }, ERR_ILLEGAL_HOOK_INVOCATION: { name: 'ERR_ILLEGAL_HOOK_INVOCATION', type: Error, createError(target: string, message?: string) { - return `[${this.name}] ` + `Illegal invocation of ${target} hook.${message ? ` ${message}` : ''}`; + return `[${this.constructor.name}]` + `Illegal invocation of ${target} hook.${message ? ` ${message}` : ''}`; + } + }, + ERR_NOT_EXISTING_MODULE: { + name: 'ERR_NOT_EXISTING_MODULE', + type: Error, + createError(target: string, description = '') { + return `[${this.constructor.name}]` + `${target} module does not exist. Install it with \`npm install ${target}\`.${description ? ' ' + description : ''}`; } } } as const; diff --git a/packages/discord-player/src/queue/GuildQueuePlayerNode.ts b/packages/discord-player/src/queue/GuildQueuePlayerNode.ts index 1a6d0b3a9..64240aa1b 100644 --- a/packages/discord-player/src/queue/GuildQueuePlayerNode.ts +++ b/packages/discord-player/src/queue/GuildQueuePlayerNode.ts @@ -603,7 +603,9 @@ export class GuildQueuePlayerNode { const opusStream = $fmt === StreamType.Opus ? stream : $fmt === StreamType.OggOpus ? + // eslint-disable-next-line @typescript-eslint/no-explicit-any stream.pipe(new prism.opus.OggDemuxer() as any) : + // eslint-disable-next-line @typescript-eslint/no-explicit-any stream.pipe(new prism.opus.WebmDemuxer() as any); if (shouldPCM) { diff --git a/packages/discord-player/src/utils/IPRotator.ts b/packages/discord-player/src/utils/IPRotator.ts index 4f1808cf1..ed928fa5d 100644 --- a/packages/discord-player/src/utils/IPRotator.ts +++ b/packages/discord-player/src/utils/IPRotator.ts @@ -1,4 +1,22 @@ -import ip from 'ip'; +import { Util } from './Util'; +import { Exceptions } from '../errors'; + +// @ts-ignore +let ip: typeof import('ip'); + +function ensureIp() { + if (ip) return ip; + + const { error, module } = Util.require('ip'); + + if (error) { + throw Exceptions.ERR_NOT_EXISTING_MODULE('ip', 'ip package is required to use IPRotator.'); + } + + ip = module; + + return ip; +} export class IPBlock { public usage = 0; @@ -6,14 +24,14 @@ export class IPBlock { public readonly cidrSize: number; public constructor(public block: string) { - if (ip.isV4Format(block.split('/')[0]) && !block.includes('/')) { + if (ensureIp().isV4Format(block.split('/')[0]) && !block.includes('/')) { block += '/32'; - } else if (ip.isV6Format(block.split('/')[0]) && !block.includes('/')) { + } else if (ensureIp().isV6Format(block.split('/')[0]) && !block.includes('/')) { block += '/128'; } - this.cidr = ip.cidr(this.block); - this.cidrSize = ip.cidrSubnet(this.block).subnetMaskLength; + this.cidr = ensureIp().cidr(this.block); + this.cidrSize = ensureIp().cidrSubnet(this.block).subnetMaskLength; } public consume() { @@ -67,7 +85,7 @@ export class IPRotator { this.#retries = 0; block.consume(); - return { ip: random, family: ip.isV4Format(random) ? 4 : 6 }; + return { ip: random, family: ensureIp().isV4Format(random) ? 4 : 6 }; } public isFailedOrExcluded(ip: string) { @@ -84,7 +102,7 @@ export class IPRotator { // Author: Jesse Tane // NPMJS: https://npmjs.org/random-ip - const bytes = ip.toBuffer(address); + const bytes = ensureIp().toBuffer(address); const ipv6 = bytes.length === 16; const bytesize = 8; diff --git a/packages/extractor/package.json b/packages/extractor/package.json index ff3b0ab87..6c2468d1b 100644 --- a/packages/extractor/package.json +++ b/packages/extractor/package.json @@ -62,4 +62,4 @@ "readmeFile": "./README.md", "tsconfig": "./tsconfig.json" } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index 8f86273f1..f9af43807 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6047,7 +6047,6 @@ __metadata: discord-api-types: "npm:^0.37.0" discord-voip: "npm:^0.1.3" discord.js: "npm:^14.15.3" - ip: "npm:^2.0.1" libsodium-wrappers: "npm:^0.7.13" opusscript: "npm:^0.0.8" tsup: "npm:^7.2.0" @@ -8743,13 +8742,6 @@ __metadata: languageName: node linkType: hard -"ip@npm:^2.0.1": - version: 2.0.1 - resolution: "ip@npm:2.0.1" - checksum: 10/d6dd154e1bc5e8725adfdd6fb92218635b9cbe6d873d051bd63b178f009777f751a5eea4c67021723a7056325fc3052f8b6599af0a2d56f042c93e684b4a0349 - languageName: node - linkType: hard - "ipaddr.js@npm:1.9.1": version: 1.9.1 resolution: "ipaddr.js@npm:1.9.1"