Skip to content

Commit

Permalink
Code reformatted, reordered entries, optimized imports (SudhanPlayz#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saud-97 authored Jun 26, 2022
1 parent 02e17de commit 4b207b5
Show file tree
Hide file tree
Showing 95 changed files with 10,976 additions and 3,773 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Please move lines that apply to you out of the comment:
- This PR **only** includes non-code changes, like changes to documentation, README, etc.
-->


# Important.

- Write in camelCase, not snake_case.
- Do not push to master/main without testing your changes first, make a branch
if you have to.
6 changes: 4 additions & 2 deletions .github/SUPPORT.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Seeking support?

We only use this issue tracker for bug reports and feature request. We are not able to provide general support or answer questions in the form of GitHub issues.
We only use this issue tracker for bug reports and feature request. We are not able to provide general support or answer
questions in the form of GitHub issues.

For general questions about the Music Bot and use please use the dedicated support channels in our Discord server: https://discord.gg/sbySMS7m3v
For general questions about the Music Bot and use please use the dedicated support channels in our Discord
server: https://discord.gg/sbySMS7m3v

Any issues that don't directly involve a bug or a feature request will likely be closed and redirected.
2 changes: 1 addition & 1 deletion .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ daysUntilStale: 60
daysUntilClose: 5
exemptLabels:
- Soon

markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ This Code of Conduct is adapted from the [Contributor Covenant][homepage], versi
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org

[version]: http://contributor-covenant.org/version/1/4/
3 changes: 2 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
- The bot-code should be used for **private hosting** and **personal usage** only.
- Using the code for public usage is **not allowed**.

> **Note:** if you are found to be violating any of the above stated rule you might be asked to takedown your bot, happy listening!! Incase of any doubts in the license contact owner.
> **Note:** if you are found to be violating any of the above stated rule you might be asked to takedown your bot, happy
> listening!! Incase of any doubts in the license contact owner.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

- [Node.js 16+](https://nodejs.org/en/download/)
- [Lavalink Server](https://code.darrennathanael.com/how-to-lavalink)
- You'll need to run `npm run deploy` or `yarn deploy`. to initialized the slash commands. _You can do this on your pc locally_
- You'll need to run `npm run deploy` or `yarn deploy`. to initialized the slash commands. _You can do this on your pc
locally_

> NOTE: Lavalink is needed for music functionality. You need to have a working Lavalink server to make the bot work.
## 📝 | Important Note if you're Switching from v4 to v5

1. Download and configure v5 in a seperate folder.
2. Kick your bot out of your server.
3. Reinvite the Bot with the right scopes. [Example Invite URL (Change CLIENT_ID)](https://discord.com/oauth2/authorize?client_id=CLIENT_ID&permissions=277083450689&scope=bot%20applications.commands)
3. Reinvite the Bot with the right
scopes. [Example Invite URL (Change CLIENT_ID)](https://discord.com/oauth2/authorize?client_id=CLIENT_ID&permissions=277083450689&scope=bot%20applications.commands)
4. Run `npm run deploy` or `yarn deploy` to initialize the slash commands. _You can do this on your pc locally_

## 📝 | Tutorial
Expand Down Expand Up @@ -41,6 +43,7 @@ Contributions are always welcomed :D Make sure to follow [Contributing.md](/CONT
</a>

## 🌟 | Made with

- [Discord.js](https://discord.js.org/)
- [Lavalink](https://github.com/freyacodes/Lavalink) with erela.js
- [Express](https://expressjs.com/)
Expand Down
194 changes: 99 additions & 95 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,107 +10,111 @@ const DiscordMusicBot = require("../lib/DiscordMusicBot");
const Auth = require("./middlewares/auth");

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

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

class Server extends EventEmitter {
/**
* Create server ;-;
* @param {DiscordMusicBot} client
*/
constructor(client) {
super();
getConfig()
.then((conf) => {
this.config = conf;
this.listen();
})
.catch((err) => {
throw Error(err);
});

this.app = express();

//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.app.use(express.static(join(__dirname, "..", "public")));

//Static Routes
let dist = join(__dirname, "..", "dashboard", "out")

this.app.use(express.static(dist));
this.app.get("/login", (_req, res) => {
res.sendFile(join(dist, "login.html"));
res.redirect("/api/callback")
});
this.app.get("/logout", (req, res) => {
if (req.user) req.logout();
res.sendFile(join(dist, "logout.html"));
});
this.app.get("/dashboard", Auth, (_req, res) => {
res.sendFile(join(dist, "dashboard.html"));
});
this.app.get("/servers", Auth, (_req, res) => {
res.sendFile(join(dist, "servers.html"));
});

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

passport.use(
new DiscordStrategy(
{
clientID: client.config.clientId,
clientSecret: client.config.clientSecret,
callbackURL: client.config.website + "/api/callback",
scope: client.config.scopes.filter(a => !a.startsWith("app")).join(" "),
},
function (accessToken, refreshToken, profile, done) {
process.nextTick(function () {
return done(null, profile);
});
}
)
);

this.app.get(
"/api/callback",
passport.authenticate("discord", {
failureRedirect: "/",
session: true
}),
function (req, res) {
res.redirect("/dashboard");
}
);
}

listen() {
this.app.listen(this.config.port);
}
/**
* Create server ;-;
* @param {DiscordMusicBot} client
*/
constructor(client) {
super();
getConfig()
.then((conf) => {
this.config = conf;
this.listen();
})
.catch((err) => {
throw Error(err);
});

this.app = express();

//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.app.use(express.static(join(__dirname, "..", "public")));

//Static Routes
let dist = join(__dirname, "..", "dashboard", "out")

this.app.use(express.static(dist));
this.app.get("/login", (_req, res) => {
res.sendFile(join(dist, "login.html"));
res.redirect("/api/callback")
});
this.app.get("/logout", (req, res) => {
if (req.user) {
req.logout();
}
res.sendFile(join(dist, "logout.html"));
});
this.app.get("/dashboard", Auth, (_req, res) => {
res.sendFile(join(dist, "dashboard.html"));
});
this.app.get("/servers", Auth, (_req, res) => {
res.sendFile(join(dist, "servers.html"));
});

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

passport.use(
new DiscordStrategy(
{
clientID: client.config.clientId,
clientSecret: client.config.clientSecret,
callbackURL: client.config.website + "/api/callback",
scope: client.config.scopes.filter(a => !a.startsWith("app")).join(" "),
},
function (accessToken, refreshToken, profile, done) {
process.nextTick(function () {
return done(null, profile);
});
},
),
);

this.app.get(
"/api/callback",
passport.authenticate("discord", {
failureRedirect: "/",
session: true,
}),
function (req, res) {
res.redirect("/dashboard");
},
);
}

listen() {
this.app.listen(this.config.port);
}
}

module.exports = Server;
9 changes: 6 additions & 3 deletions api/middlewares/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

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

module.exports = Auth;
14 changes: 7 additions & 7 deletions api/routes/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const client = require("../../");
const Auth = require("../middlewares/auth");

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

module.exports = api
28 changes: 14 additions & 14 deletions api/routes/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ const package = require("../../package.json");
const client = require("../../")

api.get("/", (req, res) => {
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")}`
}
res.json(data)
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") }`,
}
res.json(data)
});

module.exports = api;
20 changes: 10 additions & 10 deletions commands/context/hi.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { ContextMenuCommandBuilder } = require("@discordjs/builders");

module.exports = {
command: new ContextMenuCommandBuilder().setName("Say Hello").setType(2),

/**
* This function will handle context menu interaction
* @param {import("../lib/DiscordMusicBot")} client
* @param {import("discord.js").GuildContextMenuInteraction} interaction
*/
run: (client, interaction, options) => {
interaction.reply(`<@${interaction.options.getUser("user").id}>, Hello!`);
},
command: new ContextMenuCommandBuilder().setName("Say Hello").setType(2),
/**
* This function will handle context menu interaction
* @param {import("../lib/DiscordMusicBot")} client
* @param {import("discord.js").GuildContextMenuInteraction} interaction
*/
run: (client, interaction, options) => {
interaction.reply(`<@${ interaction.options.getUser("user").id }>, Hello!`);
},
};
Loading

0 comments on commit 4b207b5

Please sign in to comment.