Skip to content

Commit

Permalink
ci: add code analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
skick1234 committed Aug 15, 2023
1 parent 34ea719 commit 9df6b90
Show file tree
Hide file tree
Showing 17 changed files with 712 additions and 853 deletions.
15 changes: 15 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version = 1

exclude_patterns = ["tests/**"]

[[analyzers]]
name = "test-coverage"

[[analyzers]]
name = "javascript"

[analyzers.meta]
environment = [
"nodejs",
"jest"
]
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ jobs:

- name: Upload Coverage
uses: codecov/codecov-action@v3

- name: Report results to DeepSource
run: |
curl https://deepsource.io/cli | sh
./bin/deepsource report --analyzer test-coverage --key javascript --value-file ./coverage/cobertura-coverage.xml
env:
DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}
2 changes: 1 addition & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"collectCoverage": true,
"collectCoverageFrom": ["src/**/*.ts"],
"coverageDirectory": "coverage",
"coverageReporters": ["text", "lcov", "clover"],
"coverageReporters": ["text", "lcov", "clover", "cobertura"],
"testMatch": ["**/?(*.)+(spec|test).[jt]s?(x)"],
"verbose": true,
"roots": ["<rootDir>/tests/"],
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,43 +62,43 @@
"homepage": "https://distube.js.org/",
"dependencies": {
"@distube/ytdl-core": "^4.11.17",
"@distube/ytpl": "^1.1.1",
"@distube/ytpl": "^1.1.2",
"@distube/ytsr": "^1.1.9",
"prism-media": "npm:@distube/prism-media@latest",
"tiny-typed-emitter": "^2.1.0",
"tslib": "^2.6.1",
"undici": "^5.22.1"
"undici": "^5.23.0"
},
"devDependencies": {
"@babel/core": "^7.22.9",
"@babel/core": "^7.22.10",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-transform-private-methods": "^7.22.5",
"@babel/preset-env": "^7.22.9",
"@babel/preset-env": "^7.22.10",
"@babel/preset-typescript": "^7.22.5",
"@commitlint/cli": "^17.6.7",
"@commitlint/config-conventional": "^17.6.7",
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@discordjs/voice": "^0.16.0",
"@distubejs/docgen": "distubejs/docgen",
"@types/jest": "^29.5.3",
"@types/node": "^20.4.5",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"@types/node": "^20.4.9",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^6.3.0",
"babel-jest": "^29.6.2",
"discord.js": "^14.11.0",
"eslint": "^8.45.0",
"discord.js": "^14.12.1",
"eslint": "^8.46.0",
"eslint-config-distube": "^1.6.4",
"eslint-config-prettier": "^8.9.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-deprecation": "^1.5.0",
"eslint-plugin-jsdoc": "^46.4.5",
"eslint-plugin-jsdoc": "^46.4.6",
"husky": "^8.0.3",
"jest": "^29.6.2",
"jsdoc-babel": "^0.5.0",
"nano-staged": "^0.8.0",
"npm-check-updates": "^16.10.17",
"npm-check-updates": "^16.10.18",
"pinst": "^3.0.0",
"prettier": "^3.0.0",
"tsup": "^7.1.0",
"prettier": "^3.0.1",
"tsup": "^7.2.0",
"typescript": "^5.1.6"
},
"peerDependencies": {
Expand Down
69 changes: 27 additions & 42 deletions src/DisTube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
this.filters = { ...defaultFilters, ...this.options.customFilters };
// Default plugin
if (this.options.directLink) this.options.plugins.push(new DirectLinkPlugin());
this.options.plugins.map(p => p.init(this));
this.options.plugins.forEach(p => p.init(this));
/**
* Extractor Plugins
* @type {ExtractorPlugin[]}
Expand Down Expand Up @@ -183,7 +183,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
throw new DisTubeError("INVALID_TYPE", "Discord.GuildMember", member, "options.member");
}
const queue = this.getQueue(voiceChannel);
const queuing = !!queue && !queue._taskQueue.hasResolveTask;
const queuing = queue && !queue._taskQueue.hasResolveTask;
if (queuing) await queue?._taskQueue.queuing(true);
try {
if (typeof song === "string") {
Expand Down Expand Up @@ -214,7 +214,9 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
try {
e.name = "PlayError";
e.message = `${typeof song === "string" ? song : song.url}\n${e.message}`;
} catch {}
} catch {
// Throw original error
}
}
throw e;
} finally {
Expand Down Expand Up @@ -255,13 +257,13 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
const promises = filteredSongs.map((song: string | Song | SearchResult) =>
this.handler.resolve(song, { member, metadata }).catch(() => undefined),
);
resolvedSongs = (await Promise.all(promises)).filter((s: any): s is Song => !!s);
resolvedSongs = (await Promise.all(promises)).filter((s: any): s is Song => Boolean(s));
} else {
const resolved = [];
for (const song of filteredSongs) {
resolved.push(await this.handler.resolve(song, { member, metadata }).catch(() => undefined));
}
resolvedSongs = resolved.filter((s: any): s is Song => !!s);
resolvedSongs = resolved.filter((s: any): s is Song => Boolean(s));
}
return new Playlist(resolvedSongs, { member, properties, metadata });
}
Expand Down Expand Up @@ -346,16 +348,20 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
return this.queues.get(guild);
}

#getQueue(guild: GuildIdResolvable): Queue {
const queue = this.getQueue(guild);
if (!queue) throw new DisTubeError("NO_QUEUE");
return queue;
}

/**
* Pause the guild stream
* @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
* @returns {Queue} The guild queue
* @throws {Error}
*/
pause(guild: GuildIdResolvable): Queue {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.pause();
return this.#getQueue(guild).pause();
}

/**
Expand All @@ -365,9 +371,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* @throws {Error}
*/
resume(guild: GuildIdResolvable): Queue {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.resume();
return this.#getQueue(guild).resume();
}

/**
Expand All @@ -387,9 +391,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
stop(guild: GuildIdResolvable): Promise<void> {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.stop();
return this.#getQueue(guild).stop();
}

/**
Expand All @@ -408,9 +410,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
setVolume(guild: GuildIdResolvable, percent: number): Queue {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.setVolume(percent);
return this.#getQueue(guild).setVolume(percent);
}

/**
Expand All @@ -430,9 +430,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
skip(guild: GuildIdResolvable): Promise<Song> {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.skip();
return this.#getQueue(guild).skip();
}

/**
Expand All @@ -450,9 +448,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
previous(guild: GuildIdResolvable): Promise<Song> {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.previous();
return this.#getQueue(guild).previous();
}

/**
Expand All @@ -469,9 +465,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
shuffle(guild: GuildIdResolvable): Promise<Queue> {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.shuffle();
return this.#getQueue(guild).shuffle();
}

/**
Expand All @@ -493,9 +487,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
jump(guild: GuildIdResolvable, num: number): Promise<Song> {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.jump(num);
return this.#getQueue(guild).jump(num);
}

/**
Expand Down Expand Up @@ -532,9 +524,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* message.channel.send("Set repeat mode to `" + mode + "`");
*/
setRepeatMode(guild: GuildIdResolvable, mode?: number): number {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.setRepeatMode(mode);
return this.#getQueue(guild).setRepeatMode(mode);
}

/**
Expand All @@ -554,10 +544,9 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
toggleAutoplay(guild: GuildIdResolvable): boolean {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
q.autoplay = !q.autoplay;
return q.autoplay;
const queue = this.#getQueue(guild);
queue.autoplay = !queue.autoplay;
return queue.autoplay;
}

/**
Expand All @@ -566,9 +555,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* @returns {Promise<Song>} The guild queue
*/
addRelatedSong(guild: GuildIdResolvable): Promise<Song> {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.addRelatedSong();
return this.#getQueue(guild).addRelatedSong();
}

/**
Expand All @@ -586,9 +573,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
seek(guild: GuildIdResolvable, time: number): Queue {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.seek(time);
return this.#getQueue(guild).seek(time);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/core/DisTubeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class DisTubeHandler extends DisTubeBase {
query?: string,
): Promise<R | null> {
if (!isMessageInstance(message)) throw new DisTubeError("INVALID_TYPE", "Discord.Message", message, "message");
if (!Array.isArray(results) || results.length == 0) {
if (!Array.isArray(results) || results.length === 0) {
throw new DisTubeError("INVALID_TYPE", "Array<SearchResult|Song|Playlist>", results, "results");
}
if (this.options.searchSongs > 1) {
Expand Down Expand Up @@ -249,8 +249,7 @@ export class DisTubeHandler extends DisTubeBase {
if (limit > 1) {
results.splice(limit);
this.emit("searchResult", message, results, query);
const c = message.channel;
const answers = await c
const answers = await message.channel
.awaitMessages({
filter: (m: Message) => m.author.id === message.author.id,
max: 1,
Expand Down
Loading

0 comments on commit 9df6b90

Please sign in to comment.