Skip to content

Commit

Permalink
Refactor REST and Player classes for improved code organization and r…
Browse files Browse the repository at this point in the history
…eadability
  • Loading branch information
EvarinDev committed Aug 10, 2024
1 parent 20a516a commit 6db42a5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
8 changes: 4 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
const globals = require("globals");
const pluginJs = require( "@eslint/js");
const tseslint = require( "typescript-eslint");


export default [
module.exports = [
{ files: ["**/*.{js,mjs,cjs,ts}"] },
{ files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } },
{ languageOptions: { globals: globals.browser } },
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"test:player": "bun test/player.ts"
},
"devDependencies": {
"@eslint/js": "^9.7.0",
"@eslint/js": "^9.9.0",
"@types/bun": "latest",
"eslint": "^9.7.0",
"globals": "^15.8.0",
"typescript-eslint": "^8.0.0",
"eslint": "^9.9.0",
"globals": "^15.9.0",
"typescript-eslint": "^8.0.1",
"@babel/cli": "^7.24.8",
"@babel/core": "^7.24.9",
"@babel/preset-env": "^7.24.8",
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.3",
"@babel/preset-typescript": "^7.24.7"
},
"publishConfig": {
Expand Down
6 changes: 3 additions & 3 deletions src/structures/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class Manager extends TypedEmitter<ManagerEvents> {
const _query: SearchQuery = typeof options.query === "string" ? { query: options.query } : options.query;
const _source = Manager.DEFAULT_SOURCES[_query.source ?? this.options.defaultSearchPlatform] ?? _query.source;
let search = _query.query;
let code = this.CheckURL(options.query);
const code = this.CheckURL(options.query);
if (!/^https?:\/\//.test(search)) search = `${_source}:${search}`;
return { search, code };
}
Expand All @@ -219,7 +219,7 @@ export class Manager extends TypedEmitter<ManagerEvents> {
return null;
}

private async fetchTracks(node: any, search: string): Promise<LavalinkResponse> {
private async fetchTracks(node: Node, search: string): Promise<LavalinkResponse> {
const res = await node.rest.get(`/v4/loadtracks?identifier=${encodeURIComponent(search)}`) as LavalinkResponse;
if (!res) throw new Error("Query not found.");
return res;
Expand Down Expand Up @@ -292,7 +292,7 @@ export class Manager extends TypedEmitter<ManagerEvents> {
}
}
private CheckURL(uri: string): string {
let data = this.regex_link(uri);
const data = this.regex_link(uri);
if (!data) return uri;
if (data === "yt") {
const videoCode = uri.match(/v=([^&]+)/)?.[1];
Expand Down
2 changes: 0 additions & 2 deletions src/structures/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,8 @@ export class Node {
} else if (queueRepeat) {
queue.add(queue.current);
}

queue.previous = queue.current;
queue.current = queue.shift();

this.manager.emit("TrackEnd", player, track, payload);

if (payload.reason === "stopped") {
Expand Down
8 changes: 4 additions & 4 deletions src/structures/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-var-requires*/
/* eslint-disable @typescript-eslint/no-unused-vars*/
import { ClientUser, User } from "discord.js";
import { Manager } from "./Manager";
import { Node, NodeStats } from "./Node";
Expand Down Expand Up @@ -219,9 +219,9 @@ export class Plugin {
}

const structures = {
Player: require("./Player").Player,
Queue: require("./Queue").Queue,
Node: require("./Node").Node,
Player: Player,
Queue: Queue,
Node: Node,
};

export interface UnresolvedQuery {
Expand Down

0 comments on commit 6db42a5

Please sign in to comment.