Skip to content

Commit

Permalink
feat: new music lib
Browse files Browse the repository at this point in the history
  • Loading branch information
leomotors committed Oct 4, 2024
1 parent 50a5935 commit 2d3259a
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 66 deletions.
4 changes: 4 additions & 0 deletions packages/cocoa-discord/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ See also: [GitHub Releases](https://github.com/leomotors/cocoa-discord/releases)
- Not all change will be noted, see commits for _full_ changelog
- Some pre-release or beta build may not appear here

## [3.2.0] - 2024-10-05

- chore: bump deps

## [3.1.0] - 2023-09-25

- feat(template): status embed -> Running On fields now show Bun if is running on Bun
Expand Down
4 changes: 2 additions & 2 deletions packages/cocoa-discord/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cocoa-discord",
"version": "3.1.0",
"version": "3.2.0",
"description": "Yet another Discord Bot Utility npm package",
"main": "dist/main/index.js",
"type": "module",
Expand Down Expand Up @@ -38,7 +38,7 @@
"rimraf": "^6.0.1",
"sinon": "^19.0.2",
"ts-node": "^10.9.2",
"typedoc": "^0.26.7",
"typedoc": "^0.26.8",
"typescript": "^5.6.2",
"vitest": "^2.1.2"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/music-module/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ See also: [GitHub Releases](https://github.com/leomotors/cocoa-discord/releases)
- Not all change will be noted, see commits for _full_ changelog
- Some pre-release or beta build may not appear here

## [3.0.0] - 2024-10-05

- feat!: use [@distube/yt-dl](https://github.com/distubejs/ytdl-core) to play video,
search still be done using play-dl

## [2.0.0] - 2024-03-01

- chore: removed patch script as play-dl is fixed
Expand Down
5 changes: 3 additions & 2 deletions packages/music-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cocoa-discord/music-module",
"version": "2.0.0",
"version": "3.0.0",
"description": "discord.js music bot that can be run standalone or as a module for other bots",
"main": "dist/index.js",
"typings": "./dist/index.d.ts",
Expand Down Expand Up @@ -40,12 +40,13 @@
"libsodium-wrappers": "^0.7.15",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"typedoc": "^0.26.7",
"typedoc": "^0.26.8",
"typescript": "^5.6.2",
"vitest": "^2.1.2"
},
"dependencies": {
"@discordjs/voice": "^0.17.0",
"@distube/ytdl-core": "^4.14.4",
"chalk": "^5.3.0",
"cocoa-discord": "workspace:^",
"discord.js": "^14.16.3",
Expand Down
9 changes: 4 additions & 5 deletions packages/music-module/src/adapters/youtube.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ytdl from "@distube/ytdl-core";

import { CocoaEmbed, EmbedStyle } from "cocoa-discord";
import { SlashCommand } from "cocoa-discord/slash/class";

Expand All @@ -16,12 +18,9 @@ export class YoutubeAdapter implements Playable {
constructor(readonly video: play.YouTubeVideo) {}

async getAudioResource(): Promise<AudioResource> {
const stream = await play.stream(this.video.url);

const resource = createAudioResource(stream.stream, {
inputType: stream.type,
});
const stream = ytdl(this.video.url, { filter: "audioonly" });

const resource = createAudioResource(stream);
return resource;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/music-module/src/core/voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export async function playNextMusicInQueue(guildId: string) {
state.isPlaying = true;
state.playingSince = new Date().getTime();

console.log(state);

return await new Promise<boolean>((resolve, reject) => {
audioPlayer.on(AudioPlayerStatus.Idle, () => {
playNextMusicInQueue(guildId);
Expand Down
6 changes: 5 additions & 1 deletion packages/music-module/tests/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ center.addModules(
);
center.useHelpCommand(style);
center.on("error", async (name, err, ctx) => {
await ctx.channel?.send(`Error ${err}`);
if (ctx.channel?.isSendable()) {
await ctx.channel.send(`Error ${err}`);
} else {
console.error(`Error occured in unsendable channel: ${ctx.channelId}`);
}
await client.destroy();

// * FOR DEBUG PURPOSES ONLY, Don't do this on production
Expand Down
Loading

0 comments on commit 2d3259a

Please sign in to comment.