Skip to content

Commit

Permalink
BETA Ended v2.0.2-beta -> v2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
SxMAbel committed Jul 13, 2023
1 parent 78d68e8 commit 0c49e33
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 180 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "magmastream",
"version": "2.0.2-beta",
"version": "2.0.3",
"description": "A user-friendly Lavalink client designed for NodeJS.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
32 changes: 16 additions & 16 deletions src/structures/Filters.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
import { Player } from "./Player";

export class Filters {
public player: Player;
public volume: number;
public distortion: distortionOptions;
public equalizer: Band[];
public vibrato: vibratoOptions;
public karaoke: karaokeOptions;
public player: Player;
public rotation: rotationOptions;
public timescale: timescaleOptions;
public karaoke: karaokeOptions;
public distortion: distortionOptions;
public vibrato: vibratoOptions;
public volume: number;

constructor(player: Player) {
this.player = player;
this.volume = 1.0;
this.distortion = null;
this.equalizer = [];
this.vibrato = null;
this.karaoke = null;
this.player = player;
this.rotation = null;
this.timescale = null;
this.karaoke = null;
this.distortion = null;
this.vibrato = null;
this.volume = 1.0;
}

private updateFilters(): this {
const {
distortion,
equalizer,
karaoke,
rotation,
timescale,
vibrato,
rotation,
volume,
distortion,
} = this;

this.player.node.rest.updatePlayer({
guildId: this.player.guild,
data: {
filters: {
volume,
distortion,
equalizer,
karaoke,
rotation,
timescale,
vibrato,
rotation,
distortion,
volume,
},
},
guildId: this.player.guild,
});

return this;
Expand Down
76 changes: 10 additions & 66 deletions src/structures/Manager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/* eslint-disable no-async-promise-executor */
import { Collection } from "@discordjs/collection";
import { EventEmitter } from "events";
import { VoiceState } from "..";
import { Node, NodeOptions } from "./Node";
import { Player, PlayerOptions, Track, UnresolvedTrack } from "./Player";
import {
LoadType,
Plugin,
Expand All @@ -18,66 +13,15 @@ import {
VoiceServer,
WebSocketClosedEvent,
} from "./Utils";
import { Collection } from "@discordjs/collection";
import { EventEmitter } from "events";
import { Node, NodeOptions } from "./Node";
import { Player, PlayerOptions, Track, UnresolvedTrack } from "./Player";
import { VoiceState } from "..";
import managerCheck from "../utils/managerCheck";

const REQUIRED_KEYS = ["event", "guild_id", "op", "sessionId"];

function check(options: ManagerOptions) {
if (!options) throw new TypeError("ManagerOptions must not be empty.");

if (typeof options.send !== "function")
throw new TypeError(
'Manager option "send" must be present and a function.'
);

if (
typeof options.clientId !== "undefined" &&
!/^\d+$/.test(options.clientId)
)
throw new TypeError(
'Manager option "clientId" must be a non-empty string.'
);

if (typeof options.nodes !== "undefined" && !Array.isArray(options.nodes))
throw new TypeError('Manager option "nodes" must be a array.');

if (
typeof options.shards !== "undefined" &&
typeof options.shards !== "number"
)
throw new TypeError('Manager option "shards" must be a number.');

if (typeof options.plugins !== "undefined" && !Array.isArray(options.plugins))
throw new TypeError('Manager option "plugins" must be a Plugin array.');

if (
typeof options.autoPlay !== "undefined" &&
typeof options.autoPlay !== "boolean"
)
throw new TypeError('Manager option "autoPlay" must be a boolean.');

if (
typeof options.trackPartial !== "undefined" &&
!Array.isArray(options.trackPartial)
)
throw new TypeError(
'Manager option "trackPartial" must be a string array.'
);

if (
typeof options.clientName !== "undefined" &&
typeof options.clientName !== "string"
)
throw new TypeError('Manager option "clientName" must be a string.');

if (
typeof options.defaultSearchPlatform !== "undefined" &&
typeof options.defaultSearchPlatform !== "string"
)
throw new TypeError(
'Manager option "defaultSearchPlatform" must be a string.'
);
}

export interface Manager {
/**
* Emitted when a Node is created.
Expand Down Expand Up @@ -265,7 +209,7 @@ export class Manager extends EventEmitter {
constructor(options: ManagerOptions) {
super();

check(options);
managerCheck(options);

Structure.get("Player").init(this);
Structure.get("Node").init(this);
Expand Down Expand Up @@ -588,10 +532,10 @@ export interface ManagerOptions {
}

export type SearchPlatform =
| "youtube"
| "youtube music"
| "deezer"
| "soundcloud"
| "deezer";
| "youtube music"
| "youtube";

export interface SearchQuery {
/** The source to search from. */
Expand Down
59 changes: 6 additions & 53 deletions src/structures/Node.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/* eslint-disable no-case-declarations */
import WebSocket from "ws";
import { Dispatcher, Pool } from "undici";
import { Manager } from "./Manager";
import { Player, Track, UnresolvedTrack } from "./Player";
import {
PlayerEvent,
PlayerEvents,
Expand All @@ -13,55 +9,12 @@ import {
TrackStuckEvent,
WebSocketClosedEvent,
} from "./Utils";
import { Manager } from "./Manager";
import { Player, Track, UnresolvedTrack } from "./Player";
import { Pool } from "undici";
import { Rest } from "./Rest";

function check(options: NodeOptions) {
if (!options) throw new TypeError("NodeOptions must not be empty.");

if (typeof options.host !== "string" || !/.+/.test(options.host))
throw new TypeError(
'Node option "host" must be present and be a non-empty string.'
);

if (typeof options.port !== "undefined" && typeof options.port !== "number")
throw new TypeError('Node option "port" must be a number.');

if (
typeof options.password !== "undefined" &&
(typeof options.password !== "string" || !/.+/.test(options.password))
)
throw new TypeError('Node option "password" must be a non-empty string.');

if (
typeof options.secure !== "undefined" &&
typeof options.secure !== "boolean"
)
throw new TypeError('Node option "secure" must be a boolean.');

if (
typeof options.identifier !== "undefined" &&
typeof options.identifier !== "string"
)
throw new TypeError('Node option "identifier" must be a non-empty string.');

if (
typeof options.retryAmount !== "undefined" &&
typeof options.retryAmount !== "number"
)
throw new TypeError('Node option "retryAmount" must be a number.');

if (
typeof options.retryDelay !== "undefined" &&
typeof options.retryDelay !== "number"
)
throw new TypeError('Node option "retryDelay" must be a number.');

if (
typeof options.requestTimeout !== "undefined" &&
typeof options.requestTimeout !== "number"
)
throw new TypeError('Node option "requestTimeout" must be a number.');
}
import nodeCheck from "../utils/nodeCheck";
import WebSocket from "ws";

export class Node {
/** The socket for the node. */
Expand Down Expand Up @@ -110,7 +63,7 @@ export class Node {
return this.manager.nodes.get(options.identifier || options.host);
}

check(options);
nodeCheck(options);

this.options = {
port: 2333,
Expand Down
45 changes: 3 additions & 42 deletions src/structures/Player.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
import { Filters } from "./Filters";
import { Manager, SearchQuery, SearchResult } from "./Manager";
import { Node } from "./Node";
import { Queue } from "./Queue";
import { Filters } from "./Filters";
import { Sizes, State, Structure, TrackUtils, VoiceState } from "./Utils";
import * as _ from "lodash";

function check(options: PlayerOptions) {
if (!options) throw new TypeError("PlayerOptions must not be empty.");

if (!/^\d+$/.test(options.guild))
throw new TypeError(
'Player option "guild" must be present and be a non-empty string.'
);

if (options.textChannel && !/^\d+$/.test(options.textChannel))
throw new TypeError(
'Player option "textChannel" must be a non-empty string.'
);

if (options.voiceChannel && !/^\d+$/.test(options.voiceChannel))
throw new TypeError(
'Player option "voiceChannel" must be a non-empty string.'
);

if (options.node && typeof options.node !== "string")
throw new TypeError('Player option "node" must be a non-empty string.');

if (
typeof options.volume !== "undefined" &&
typeof options.volume !== "number"
)
throw new TypeError('Player option "volume" must be a number.');

if (
typeof options.selfMute !== "undefined" &&
typeof options.selfMute !== "boolean"
)
throw new TypeError('Player option "selfMute" must be a boolean.');

if (
typeof options.selfDeafen !== "undefined" &&
typeof options.selfDeafen !== "boolean"
)
throw new TypeError('Player option "selfDeafen" must be a boolean.');
}
import playerCheck from "../utils/playerCheck";

export class Player {
/** The Queue for the Player. */
Expand Down Expand Up @@ -121,7 +82,7 @@ export class Player {
return this.manager.players.get(options.guild);
}

check(options);
playerCheck(options);

this.guild = options.guild;
this.voiceState = Object.assign({
Expand Down
Loading

0 comments on commit 0c49e33

Please sign in to comment.