Skip to content

Commit

Permalink
Merge pull request #28 from EwarinDev/dev
Browse files Browse the repository at this point in the history
Added Type
  • Loading branch information
EvarinDev authored Sep 7, 2024
2 parents 7457e44 + 5835076 commit 8189edc
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 47 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 FAYStarNext
Copyright (c) 2024 EwarinDev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sunday.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"version": "1.1.0",
"version": "1.1.1",
"description": "Sunday a lavalink wrapper",
"license": "MIT",
"author": "EwarinDev",
Expand Down
38 changes: 19 additions & 19 deletions src/structures/Filters.ts → src/Structures/Filters.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Band, bassBoostEqualizer, softEqualizer, trebleBassEqualizer, tvEqualizer, vaporwaveEqualizer } from "../utils/filtersEqualizers";
import { Band, bassBoostEqualizer, softEqualizer, trebleBassEqualizer, tvEqualizer, vaporwaveEqualizer } from "../Utils/FiltersEqualizers";
import { Player } from "./Player";

export class Filters {
public distortion: distortionOptions | null;
public distortion: DistortionOptions | null;
public equalizer: Band[];
public karaoke: karaokeOptions | null;
public karaoke: KaraokeOptions | null;
public player: Player;
public rotation: rotationOptions | null;
public timescale: timescaleOptions | null;
public vibrato: vibratoOptions | null;
public rotation: RotationOptions | null;
public timescale: TimescaleOptions | null;
public vibrato: VibratoOptions | null;
public volume: number;

private filterStatus: {
Expand Down Expand Up @@ -68,7 +68,7 @@ export class Filters {
return this;
}

private setFilterStatus(filter: keyof availableFilters, status: boolean): this {
private setFilterStatus(filter: keyof AvailableFilters, status: boolean): this {
this.filterStatus[filter] = status;
return this;
}
Expand Down Expand Up @@ -144,30 +144,30 @@ export class Filters {
}

/** Applies the karaoke options specified by the filter. */
public setKaraoke(karaoke?: karaokeOptions): this {
public setKaraoke(karaoke?: KaraokeOptions): this {
return this.applyFilter({
property: "karaoke",
value: karaoke,
}).setFilterStatus("karaoke", true);
}

/** Applies the timescale options specified by the filter. */
public setTimescale(timescale?: timescaleOptions): this {
public setTimescale(timescale?: TimescaleOptions): this {
return this.applyFilter({ property: "timescale", value: timescale });
}

/** Applies the vibrato options specified by the filter. */
public setVibrato(vibrato?: vibratoOptions): this {
public setVibrato(vibrato?: VibratoOptions): this {
return this.applyFilter({ property: "vibrato", value: vibrato });
}

/** Applies the rotation options specified by the filter. */
public setRotation(rotation?: rotationOptions): this {
public setRotation(rotation?: RotationOptions): this {
return this.applyFilter({ property: "rotation", value: rotation });
}

/** Applies the distortion options specified by the filter. */
public setDistortion(distortion?: distortionOptions): this {
public setDistortion(distortion?: DistortionOptions): this {
return this.applyFilter({ property: "distortion", value: distortion });
}

Expand Down Expand Up @@ -199,13 +199,13 @@ export class Filters {
}

/** Returns the status of the specified filter . */
public getFilterStatus(filter: keyof availableFilters): boolean {
public getFilterStatus(filter: keyof AvailableFilters): boolean {
return this.filterStatus[filter];
}
}

/** Options for adjusting the timescale of audio. */
interface timescaleOptions {
interface TimescaleOptions {
/** The speed factor for the timescale. */
speed?: number;
/** The pitch factor for the timescale. */
Expand All @@ -215,21 +215,21 @@ interface timescaleOptions {
}

/** Options for applying vibrato effect to audio. */
interface vibratoOptions {
interface VibratoOptions {
/** The frequency of the vibrato effect. */
frequency: number;
/** * The depth of the vibrato effect.*/
depth: number;
}

/** Options for applying rotation effect to audio. */
interface rotationOptions {
interface RotationOptions {
/** The rotation speed in Hertz (Hz). */
rotationHz: number;
}

/** Options for applying karaoke effect to audio. */
interface karaokeOptions {
interface KaraokeOptions {
/** The level of karaoke effect. */
level?: number;
/** The mono level of karaoke effect. */
Expand All @@ -240,7 +240,7 @@ interface karaokeOptions {
filterWidth?: number;
}

interface distortionOptions {
interface DistortionOptions {
sinOffset?: number;
sinScale?: number;
cosOffset?: number;
Expand All @@ -251,7 +251,7 @@ interface distortionOptions {
scale?: number;
}

interface availableFilters {
interface AvailableFilters {
bassboost: boolean;
distort: boolean;
eightD: boolean;
Expand Down
7 changes: 3 additions & 4 deletions src/structures/Manager.ts → src/Structures/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import {
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";
import managerCheck from "../Utils/ManagerCheck";
import { ClientUser, User } from "discord.js";
import { TypedEmitter } from "tiny-typed-emitter";

Expand Down Expand Up @@ -176,7 +175,7 @@ export class Manager extends TypedEmitter<ManagerEvents> {
throw new Error("No available nodes.");
}
if (this.options.caches.enabled && this.options.caches.time > 0 && typeof query === "string") {
let data = this.caches.get(query);
const data = this.caches.get(query);
if (data) return data;
}
const _query: SearchQuery = typeof query === "string" ? { query } : query;
Expand Down Expand Up @@ -421,7 +420,7 @@ export interface ManagerOptions {
defaultSearchPlatform?: SearchPlatform;
/** Whether the YouTube video titles should be replaced if the Author does not exactly match. */
replaceYouTubeCredentials?: boolean;
caches?: {
caches: {
/** Whether to cache the search results. */
enabled: boolean;
/** The time to cache the search results. */
Expand Down
4 changes: 1 addition & 3 deletions src/structures/Node.ts → src/Structures/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { LavalinkResponse, Manager, PlaylistRawData } from "./Manager";
import { Player, Track, UnresolvedTrack } from "./Player";
import { Rest } from "./Rest";
import nodeCheck from "../utils/nodeCheck";
import nodeCheck from "../Utils/NodeCheck";
import WebSocket from "ws";

export class Node {
Expand Down Expand Up @@ -128,7 +128,6 @@ export class Node {
if (players.size) players.forEach((p) => p.destroy());

this.socket.close(1000, "destroy");
// @ts-ignore
this.socket.removeAllListeners();
this.socket = null;

Expand All @@ -147,7 +146,6 @@ export class Node {
this.manager.emit("NodeError", this, error);
return this.destroy();
}
// @ts-ignore
this.socket?.removeAllListeners();
this.socket = null;
this.manager.emit("NodeReconnect", this);
Expand Down
6 changes: 2 additions & 4 deletions src/structures/Player.ts → src/Structures/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LavalinkInfo, Node } from "./Node";
import { Queue } from "./Queue";
import { Sizes, State, Structure, TrackSourceName, TrackUtils, VoiceState } from "./Utils";
import * as _ from "lodash";
import playerCheck from "../utils/playerCheck";
import playerCheck from "../Utils/PlayerCheck";
import { ClientUser, Message, User } from "discord.js";

export class Player {
Expand Down Expand Up @@ -545,9 +545,7 @@ export class Player {
if (!this.queue.current) return undefined;
position = Number(position);

if (isNaN(position)) {
throw new RangeError("Position must be a number.");
}
if (isNaN(position)) throw new RangeError("Position must be a number.");
if (position < 0 || position > this.queue.current.duration) position = Math.max(Math.min(position, this.queue.current.duration), 0);

this.position = position;
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions src/structures/Rest.ts → src/Structures/Rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Rest {
}

/* Sends a GET request to the specified endpoint and returns the response data. */
private async request(method: string, endpoint: string, body?: unknown): Promise<unknown> {
private async request(method: Method, endpoint: string, body?: unknown): Promise<unknown> {
const config: AxiosRequestConfig = {
method,
url: this.url + endpoint,
Expand All @@ -63,7 +63,6 @@ export class Rest {
this.node.destroy();
this.node.manager.createNode(this.node.options).connect();
}

return null;
}
}
Expand Down Expand Up @@ -118,3 +117,5 @@ interface playOptions {
noReplace?: boolean;
};
}

export type Method = "GET" | "POST" | "PATCH" | "DELETE";
File renamed without changes.
File renamed without changes.
10 changes: 6 additions & 4 deletions src/utils/managerCheck.ts → src/Utils/ManagerCheck.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ManagerOptions } from "../structures/Manager";
import { ManagerOptions } from "../Structures/Manager";

export default function managerCheck(options: ManagerOptions) {
export default function ManagerCheck(options: ManagerOptions) {
if (!options) throw new TypeError("ManagerOptions must not be empty.");

const { autoPlay, clientId, clientName, defaultSearchPlatform, nodes, plugins, send, shards, trackPartial, usePriority, useNode, replaceYouTubeCredentials } =
const { autoPlay, clientId, clientName, defaultSearchPlatform, nodes, plugins, send, shards, trackPartial, usePriority, useNode, replaceYouTubeCredentials, caches } =
options;

if (typeof autoPlay !== "undefined" && typeof autoPlay !== "boolean") {
Expand All @@ -17,7 +17,9 @@ export default function managerCheck(options: ManagerOptions) {
if (typeof clientName !== "undefined" && typeof clientName !== "string") {
throw new TypeError('Manager option "clientName" must be a string.');
}

if (typeof caches !== "undefined" && typeof caches !== "object") {
throw new TypeError('Manager option "caches" must be a object.');
}
if (typeof defaultSearchPlatform !== "undefined" && typeof defaultSearchPlatform !== "string") {
throw new TypeError('Manager option "defaultSearchPlatform" must be a string.');
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/nodeCheck.ts → src/Utils/NodeCheck.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NodeOptions } from "../structures/Node";
import { NodeOptions } from "../Structures/Node";

export default function nodeCheck(options: NodeOptions) {
export default function NodeCheck(options: NodeOptions) {
if (!options) throw new TypeError("NodeOptions must not be empty.");

const { host, identifier, password, port, requestTimeout, resumeStatus, resumeTimeout, retryAmount, retryDelay, secure, priority } = options;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/playerCheck.ts → src/Utils/PlayerCheck.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PlayerOptions } from "../structures/Player";
import { PlayerOptions } from "../Structures/Player";

export default function playerCheck(options: PlayerOptions) {
export default function PlayerCheck(options: PlayerOptions) {
if (!options) throw new TypeError("PlayerOptions must not be empty.");

const { guild, node, selfDeafen, selfMute, textChannel, voiceChannel, volume } = options;
Expand Down
16 changes: 11 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
export * from "./structures/Manager";
export * from "./structures/Node";
export * from "./structures/Player";
export * from "./structures/Queue";
export * from "./structures/Utils";
export * from "./Structures/Manager";
export * from "./Structures/Node";
export * from "./Structures/Player";
export * from "./Structures/Queue";
export * from "./Structures/Utils";
export * from "./Structures/Filters";
export * from "./Structures/Rest";
export * from "./Utils/FiltersEqualizers";
export * from "./Utils/ManagerCheck";
export * from "./Utils/NodeCheck";
export * from "./Utils/PlayerCheck";

0 comments on commit 8189edc

Please sign in to comment.