Skip to content

Commit

Permalink
chore: release 6.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
twlite committed Jul 31, 2024
1 parent 2725277 commit d436729
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 44 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions packages/discord-player/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions packages/discord-player/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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": {
Expand All @@ -78,4 +77,4 @@
"readmeFile": "./README.md",
"tsconfig": "./tsconfig.json"
}
}
}
45 changes: 26 additions & 19 deletions packages/discord-player/src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions packages/discord-player/src/queue/GuildQueuePlayerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,9 @@ export class GuildQueuePlayerNode<Meta = unknown> {
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) {
Expand Down
32 changes: 25 additions & 7 deletions packages/discord-player/src/utils/IPRotator.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
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;
public readonly cidr: string;
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() {
Expand Down Expand Up @@ -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) {
Expand All @@ -84,7 +102,7 @@ export class IPRotator {
// Author: Jesse Tane <[email protected]>
// NPMJS: https://npmjs.org/random-ip

const bytes = ip.toBuffer(address);
const bytes = ensureIp().toBuffer(address);
const ipv6 = bytes.length === 16;
const bytesize = 8;

Expand Down
2 changes: 1 addition & 1 deletion packages/extractor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@
"readmeFile": "./README.md",
"tsconfig": "./tsconfig.json"
}
}
}
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit d436729

Please sign in to comment.