Skip to content

Commit

Permalink
chore: Update Player
Browse files Browse the repository at this point in the history
  • Loading branch information
EvarinDev committed Jul 22, 2024
1 parent 45438b4 commit e896fe3
Show file tree
Hide file tree
Showing 20 changed files with 2,188 additions and 1,632 deletions.
3 changes: 2 additions & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This project includes code from the Apache-licensed project erela.js
This project includes code from the Apache-licensed project magmastream, erela.js

Portions of this software are licensed under the Apache License, Version 2.0 (the "Apache License");
you may not use this file except in compliance with the Apache License. You may obtain a copy of the
Expand All @@ -9,3 +9,4 @@ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND
See the Apache License for the specific language governing permissions and limitations under the Apache License.

Copyright 2021 MenuDocs
Copyright 2023 Blackfort-Hosting
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ That's it! You have successfully installed Sunday.ts and are ready to start usin
```ts
import { Client } from "discord.js";
import { Manager } from "sunday.ts";
import "dotenv/config";

let client = new Client({
intents: [
Expand All @@ -79,7 +80,7 @@ let manager = new Manager({
host: 'localhost',
port: 2333,
password: 'youshallnotpass',
version: "v4",
resumeStatus: true,
},
],
clientId: "1234567890",
Expand All @@ -104,8 +105,53 @@ manager.on("PlayerCreate", (player) => {
manager.on("NodeError" , (node, error) => {
console.log(`Node ${node.options.host} has an error: ${error.message}`);
});
client.on("messageCreate", async (message) => {
console.log(message.content)
const [command, ...args] = message.content.slice(0).split(/\s+/g);
console.log(command)
console.log(command === 'play')
if (command === 'play') {
if (!message.member?.voice.channel) return message.reply('you need to join a voice channel.');
if (!args.length) return message.reply('you need to give me a URL or a search term.');

const search = args.join(' ');
let res;
try {
// Search for tracks using a query or url, using a query searches youtube automatically and the track requester object
res = await manager.search(search, message.author);
// 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.' };
}
} 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
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();
console.log(res)
await player.queue.add(res.tracks[0]);
// Checks if the client should play the track if it's the first one added
if (!player.playing && !player.paused && !player.queue.size) player.play();

return message.reply(`enqueuing ${res.tracks[0].title}.`);
}
});
client.on("raw", (data) => manager.updateVoiceState(data));
client.login("");
client.login(process.env.TOKEN);
```

## ⛏️ Built Using <a name = "built_using"></a>
Expand All @@ -115,5 +161,6 @@ client.login("");
## Credits

- [Erela.Js](https://github.com/MenuDocs/erela.js)
- [MagmaStream](https://github.com/Blackfort-Hosting/magmastream/)

See also the list of [contributors](https://github.com/FAYStarNext/Sunday.ts/contributors) who participated in this project.
50 changes: 41 additions & 9 deletions example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let manager = new Manager({
host: 'localhost',
port: 2333,
password: 'youshallnotpass',
version: "v4",
resumeStatus: true,
},
],
clientId: "1234567890",
Expand All @@ -44,15 +44,47 @@ manager.on("NodeError" , (node, error) => {
});
client.on("messageCreate", async (message) => {
console.log(message.content)
if (message.content === "message") {
let player = manager.create({
voiceChannel: message.member?.voice.channel?.id as string,
textChannel: message.channel.id,
const [command, ...args] = message.content.slice(0).split(/\s+/g);
console.log(command)
console.log(command === 'play')
if (command === 'play') {
if (!message.member?.voice.channel) return message.reply('you need to join a voice channel.');
if (!args.length) return message.reply('you need to give me a URL or a search term.');

const search = args.join(' ');
let res;
try {
// Search for tracks using a query or url, using a query searches youtube automatically and the track requester object
res = await manager.search(search, message.author);
// 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.' };
}
} 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
const player = manager.create({
guild: message.guild?.id as string,
selfDeafen: true,
selfMute: false,
})
if (player.state !== "CONNECTED") await player.connect();
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();
console.log(res)
await player.queue.add(res.tracks[0]);
// Checks if the client should play the track if it's the first one added
if (!player.playing && !player.paused && !player.queue.size) player.play();

return message.reply(`enqueuing ${res.tracks[0].title}.`);
}
});
client.on("raw", (data) => manager.updateVoiceState(data));
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"version": "1.0.4-indev",
"version": "1.0.5-indev",
"description": "Sunday a lavalink wrapper",
"license": "MIT",
"author": "FAYStarNext",
"scripts": {
"build:js": "npx babel src --out-dir dist --extensions \".ts,.tsx\" --source-maps inline",
"lint": "npx eslint src/**/*.ts",
Expand All @@ -24,6 +25,10 @@
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"bugs": {
"url": "https://github.com/FAYStarNext/Sunday.ts/issues"
},
"homepage": "https://github.com/FAYStarNext/Sunday.ts#readme",
"peerDependencies": {
"typescript": "^5.5.3"
},
Expand Down
4 changes: 0 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ export * from "./structures/Node";
export * from "./structures/Player";
export * from "./structures/Queue";
export * from "./structures/Utils";
export * from "./structures/Rest";
export * from "./types/Manager";
export * from "./types/Node";
export * from "./types/Rest";
Loading

0 comments on commit e896fe3

Please sign in to comment.