Skip to content

Commit

Permalink
✨First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
BigglesDevs committed Jan 19, 2024
0 parents commit 7bbead9
Show file tree
Hide file tree
Showing 71 changed files with 7,877 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
logs.log
config.js
node_modules
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<h1 align="center"><img src="https://cdn.discordapp.com/attachments/1171503036800184362/1197853153576615956/Music-Bot-WM.png?ex=65bcc6ae&is=65aa51ae&hm=23c121cbc5392e2a204c4ba1fff65cd4c0a08e1e4b402448f20e0c71ae15a594&" width="300"></h1>

<p align="center">
BD-MusicBotV2 is a feature-rich music bot designed to elevate your Discord server's audio experience. With seamless playlist support, Lavalink integration, and a robust set of over 30 slash commands, it offers a dynamic and engaging music playback experience for users.
</p>

[![Discord.js](https://img.shields.io/badge/Discord.js-latest-brightgreen)](https://discord.js.org/)
[![Lavalink](https://img.shields.io/badge/Lavalink-erela.js-ff69b4)](https://github.com/freyacodes/Lavalink)
[![TypeScript](https://img.shields.io/badge/TypeScript-latest-blue)](https://www.typescriptlang.org/)



## Prerequisites 🚨

- [Node.js 16+](https://nodejs.org/en/download/)
- [Lavalink Server](https://code.darrennathanael.com/how-to-lavalink)
- Run `npm run deploy` or `yarn deploy` locally to initialize slash commands

> NOTE: Lavalink is required for music functionality. Ensure you have a working Lavalink server.
## Features ✨

- **Playlist Support:** Manage and play your favorite playlists seamlessly.
- **Lavalink:** Leverage the power of the Erela.js library for smooth music playback.
- **Multiple Support:** Enjoy music from various sources, including Spotify, Youtube, Deezer, AppleMusic, and more.
- **Slash commands:** Access a comprehensive set of over 30 slash commands for convenient control.

## Install ⬇️

```bash
- git clone https://github.com/BigglesDevs/BD-MusicBotV2.git
- npm install
```

## Setup 📐

- Configure `config.js` and add a Lavalink host.
- Deploy Slash Commands: `npm run deploy`
- Start the bot: `node index.js or node .`

## Contributing 🚀

If you'd like to contribute, please follow these steps:
1. Fork the repository
2. Create a new branch: `git checkout -b feature-name`
3. Make your changes
4. Commit your changes: `git commit -m 'Description of your changes'`
5. Push to the branch: `git push origin feature-name`
6. Open a pull request

## License 📝

This project is licensed under the [MIT License](LICENSE).

## Support Server

Join our [Support Server](https://discord.gg/cpcM8gAxtv) for assistance with coding issues.
105 changes: 105 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const express = require("express");
const fs = require("fs");
const { EventEmitter } = require("events");
const { join } = require("path");
const session = require("express-session");
const DiscordStrategy = require("passport-discord").Strategy;
const passport = require("passport");
const getConfig = require("../util/getConfig");
const DiscordMusicBot = require("../lib/DiscordMusicBot");
const router = require("./router");

passport.serializeUser(function (user, done) {
done(null, user);
});

passport.deserializeUser(function (obj, done) {
done(null, obj);
});

class Server extends EventEmitter {
/**
* Create server ;-;
* @param {DiscordMusicBot} client
*/
constructor(client) {
super();
this.client = client;
getConfig().then(this.init.bind(this));
}

init(conf) {
this.config = conf;
this.app = express();

this.app.use(express.static(join(__dirname, "..", "public")));

// Static Routes for scripts
const dist = join(__dirname, "..", "dashboard", "out", "_next")

this.app.use("/_next", express.static(dist));

// Session and Passport
this.app.use(session({
resave: false,
saveUninitialized: false,
secret: this.config.cookieSecret,
cookie: {
secure: this.config.website.startsWith("https://"),
sameSite: true,
},
}));

this.initPassport();

this.app.use(router);

//API
fs.readdir(join(__dirname, "routes"), (err, files) => {
if (err) {
return console.log(err);
}
files.forEach((file) => {
this.app.use(
"/api/" + file.split(".")[0],
require(join(__dirname, "routes") + "/" + file),
);
});
});

this.listen();
}

initPassport() {
this.app.use(passport.initialize());

const strategy = new DiscordStrategy(
{
clientID: this.config.clientId,
clientSecret: this.config.clientSecret,
callbackURL: this.config.website + "/api/callback",
scope: this.config.scopes.filter(a => !a.startsWith("app")),
scopeSeparator: " ",
},
function (accessToken, refreshToken, profile, done) {
const data = {
accessToken,
refreshToken,
profile,
};

return done(null, data);
},
);
passport.use(strategy);

this.app.use(passport.session());
}

listen() {
this.app.listen(this.config.port);
console.log("[SERVER] Listening on port:", this.config.port);
}
}

module.exports = Server;
16 changes: 16 additions & 0 deletions api/middlewares/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @param {import("express").Request} req
* @param {import("express").Response} res
* @param {import("express").NextFunction} next
* @returns {Promise<void>}
*/

const Auth = (req, res, next) => {
if (!req.user) {
return res.redirect("/login");
} else {
next();
}
};

module.exports = Auth;
48 changes: 48 additions & 0 deletions api/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use strict";

const { Router } = require("express");
const passport = require("passport");
const { join } = require("path");
const Auth = require("./middlewares/auth");

const dist = join(__dirname, "..", "dashboard", "out");

const router = Router();

router.get("/", (req, res) => {
res.sendFile(join(dist, "index.html"));
});

router.get("/login", (req, res) => {
res.sendFile(join(dist, "login.html"));
});

router.get("/api/login", passport.authenticate("discord"));

router.get("/logout", (req, res) => {
res.sendFile(join(dist, "logout.html"));
});

router.get("/api/logout", (req, res) => {
req.session.destroy(() => {
res.redirect("/");
});
});

router.get("/dashboard", Auth, (_req, res) => {
res.sendFile(join(dist, "dashboard.html"));
});

router.get("/servers", Auth, (_req, res) => {
res.sendFile(join(dist, "servers.html"));
});

router.get("/api/callback", passport.authenticate('discord', {
failureRedirect: '/',
}), (req, res ) => {
req.session.save(() => {
res.redirect("/");
});
});

module.exports = router;
17 changes: 17 additions & 0 deletions api/routes/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { Router } = require("express");
const api = Router();
const { getClient } = require("../../");
const Auth = require("../middlewares/auth");

api.get("/", Auth, (req, res) => {
const client = getClient();
let data = {
commandsRan: client.commandsRan,
users: client.users.cache.size,
servers: client.guilds.cache.size,
songsPlayed: client.songsPlayed,
}
res.json(data);
})

module.exports = api
26 changes: 26 additions & 0 deletions api/routes/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { Router } = require("express");
const api = Router();

const package = require("../../package.json");
const { getClient } = require("../../");

api.get("/", (req, res) => {
const client = getClient();
let data = {
name: client.user.username,
version: package.version,
commands: client.slashCommands.map(cmd => {
return {
name: cmd.name,
description: cmd.description,
};
}),
inviteURL: `https://discord.com/oauth2/authorize?client_id=${ client.config.clientId
}&permissions=${ client.config.permissions
}&scope=${ client.config.scopes.toString().replace(/,/g, "%20") }`,
loggedIn: !!req.user,
};
res.json(data);
});

module.exports = api;
39 changes: 39 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "Discord-MusicBot",
"description": "Very simple discord music bot with the discord.js with Song Name playing. It can able to play music with the song name or link",
"repository": "https://github.com/BigglesDevs/BD-MusicBotV2",
"logo": "https://cdn.discordapp.com/avatars/750613142488481843/e6326038dbe2243ca551ba5b6ecd8bf2.png?size=1024",
"keywords": [
"node",
"discord",
"youtube",
"music",
"bot",
"lavalink",
"dashboard"
],
"image": "heroku/nodejs",
"buildpacks": [
{
"url": "heroku/nodejs"
}
],
"env": {
"token": {
"description": "The Discord Bot Token (https://discord.com/developers/applications)",
"required": "true"
},
"clientId": {
"description": "The Discord Bot ClientID",
"required": "true"
},
"clientSecret": {
"description": "The Discord Bot ClientSecret",
"required": "true"
},
"website": {
"description": "URL of your webserver (Example: https://domain.xyz). Change this if you want to use the web-dashboard.",
"value": "http://localhost"
}
}
}
Binary file added assets/logo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7bbead9

Please sign in to comment.