Skip to content

Commit

Permalink
chore: Update npm dependencies and Babel configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
EvarinDev committed Aug 9, 2024
1 parent 5b86800 commit 94a55f6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 53 deletions.
22 changes: 3 additions & 19 deletions example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ let manager = new Manager({
manager.on("NodeConnect", (node) => {
console.log(`Node ${node.options.host} connected`);
});
// manager.on("NodeRaw", async (node) => {
// console.log(`sent raw data: ${JSON.stringify(node)}`);
// });
manager.on("PlayerCreate", (player) => {
console.log(`Player created in guild ${player.guild}`);
});
Expand All @@ -54,36 +51,23 @@ client.on("messageCreate", async (message) => {
let res;
let end;
try {
// Search for tracks using a query or url, using a query searches youtube automatically and the track requester object
res = await manager.search({query: search});
end = `Time took: ${Math.round(performance.now() - start)}ms.`;
// Check the load type as this command is not that advanced for basics
if (res.loadType === 'empty') throw res;
if (res.loadType === 'playlist') {
throw { message: 'Playlists are not supported with this command.' };
}
if (res.loadType === 'playlist') throw Error('Playlists are not supported with this command.');
} catch (err) {
return message.reply(`there was an error while searching: ${err}`);
}

if (res.loadType === 'error') {
return message.reply('there was no tracks found with that query.');
}

// Create the player
if (res.loadType === 'error') return message.reply('there was no tracks found with that query.');
const player = manager.create({
guild: message.guild?.id as string,
voiceChannel: message.member?.voice.channel.id,
textChannel: message.channel.id,
volume: 100,
});

// Connect to the voice channel and add the track to the queue
player.connect();
await player.queue.add(res.tracks[0]);
// Checks if the client should play the track if it's the first one added
player.queue.add(res.tracks[0]);
if (!player.playing && !player.paused && !player.queue.size) player.play();

return message.reply(`enqueuing ${res.tracks[0].title}. ${end}`);
}
});
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.0.15-indev",
"version": "1.0.16",
"description": "Sunday a lavalink wrapper",
"license": "MIT",
"author": "FAYStarNext",
Expand Down
36 changes: 18 additions & 18 deletions src/structures/Filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Band, bassBoostEqualizer, softEqualizer, trebleBassEqualizer, tvEqualiz
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
24 changes: 9 additions & 15 deletions src/structures/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ export class Manager extends TypedEmitter<ManagerEvents> {

/** Returns the node to use. */
public get useableNodes(): Node {
return this.options.usePriority ? this.priorityNode : this.options.useNode === "leastLoad" ? this.leastLoadNode.first() : this.leastPlayersNode.first();
let selectedNode: Node;
if (this.options.usePriority) {
selectedNode = this.priorityNode;
} else if (this.options.useNode === "leastLoad") {
selectedNode = this.leastLoadNode.first();
} else {
selectedNode = this.leastPlayersNode.first();
}
return selectedNode;
}

/**
Expand Down Expand Up @@ -244,20 +252,6 @@ export class Manager extends TypedEmitter<ManagerEvents> {
throw new Error(err);
}
}

private ToOrginalURL(uri: string): string {
switch (uri.split(":")[0]) {
case "yt":
const videoCode = uri.match(/v=([^&]+)/)?.[1];
const playlistCode = uri.match(/list=([^&]+)/)?.[1];
if (playlistCode) {
return "https://www.youtube.com/playlist?list=" + playlistCode;
}
return "https://www.youtube.com/watch?v=" + (videoCode ?? "");
}
return uri;
}

private CheckURL(uri: string): string {
let data = this.regex_link(uri);
switch (data) {
Expand Down

0 comments on commit 94a55f6

Please sign in to comment.