Skip to content

Commit

Permalink
Merge pull request #7 from FAYStarNext/dev
Browse files Browse the repository at this point in the history
Use the magmastream code base
  • Loading branch information
EvarinDev authored Jul 22, 2024
2 parents 2fc6c0c + e896fe3 commit d94d2a1
Show file tree
Hide file tree
Showing 19 changed files with 2,194 additions and 1,611 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.
47 changes: 46 additions & 1 deletion 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 @@ -42,5 +42,50 @@ 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(process.env.TOKEN);
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
Loading

0 comments on commit d94d2a1

Please sign in to comment.