Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Patch 17 #143

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ OWNER_ID=190190190190190190
LAVA_HOST=localhost
LAVA_PORT=2333
LAVA_PASS=youshallnotpass
LAVA_SECURE=false
ENABLE_SPOTIFY=false
# you will need these if you enabled spotify
SPOTIFY_ID=00000A0000
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 10
"ecmaVersion": 12
},
"rules": {
"indent": ["warn", 4],
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Music bot that uses Lavalink for its audio player.

## Prerequisites
- [Lavalink server](https://github.com/freyacodes/Lavalink#server-configuration).
- Node.js v12 or above.
- Node.js v16.6.x or above.

## Usage
- Rename `.env.example` to `.env` and replace those values with yours.
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Music bot that uses Lavalink for its audio player.",
"main": "index.js",
"scripts": {
"start": "node ."
"start": "node .",
"regscmd": "node scripts/registerslashcommand"
},
"repository": {
"type": "git",
Expand All @@ -17,13 +18,13 @@
},
"homepage": "https://github.com/Allvaa/lavalink-musicbot#readme",
"dependencies": {
"@lavacord/discord.js": "0.0.7",
"discord.js": "^12.5.3",
"discord.js": "^13.1.0",
"dotenv": "^10.0.0",
"lavasfy": "2.2.1",
"pretty-ms": "^7.0.1"
"lavasfy": "2.3.0",
"pretty-ms": "^7.0.1",
"shoukaku": "^2.0.0"
},
"devDependencies": {
"eslint": "^7.27.0"
"eslint": "^7.32.0"
}
}
6 changes: 6 additions & 0 deletions scripts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# the bot token
TOKEN=AAAAAAAAAAAAAAa
# the bot id
ID=000000000000
# guild id that used to develop the bot
DEV_GUILD=1111111111111111
42 changes: 42 additions & 0 deletions scripts/registerslashcommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const { Constants } = require("discord.js");
const { readdirSync } = require("fs");
const { resolve, join } = require("path");
const petitio = require("petitio");

require("dotenv").config({
path: resolve(__dirname, ".env")
});

process.argv[2] === "dev" ? console.log(`Running with dev arg. commands will only registered to dev guild (${process.env.DEV_GUILD})`) : console.log("Registering commands globally");

const baseURL = "https://discord.com/api/v9";

const commandsDir = resolve("src", "commands");
const commands = readdirSync(commandsDir)
.map(cmdFile => require(resolve(commandsDir, cmdFile)))
.map(({ name, description, options }) => ({
name,
description,
options: Object.entries(options ?? {})
.map(([name, { description, type, required }]) => ({
name,
description,
type: Constants.ApplicationCommandOptionTypes[type],
required
}))
}));

(async () => {
const res = await petitio(baseURL, "PUT")
.body(commands)
.header("Authorization", `Bot ${process.env.TOKEN}`)
.path(join("applications", process.env.ID, ...(process.argv[2] === "dev" ? ["guilds", process.env.DEV_GUILD] : []), "commands"))
.send();

if (!(res.statusCode >= 200 && res.statusCode < 300)) {
console.log(res.json());
return;
}

console.log(res.json().map((x, i) => `${++i}. ${x.name} registered`).join("\n"));
})();
7 changes: 6 additions & 1 deletion src/bot.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const { Intents } = require("discord.js");
const { GUILDS, GUILD_MESSAGES, GUILD_VOICE_STATES } = Intents.FLAGS;
const MusicClient = require("./structures/MusicClient");

const client = new MusicClient({
disableMentions: "everyone"
intents: [GUILDS, GUILD_MESSAGES, GUILD_VOICE_STATES],
allowedMentions: {
parse: ["users", "roles"]
}
});

client.build();
25 changes: 25 additions & 0 deletions src/commands/8d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const util = require("../util");
module.exports = {
name: "8d",
description: "8D filter",
aliases: ["rotation"],
exec: async (ctx) => {
const { music } = ctx;
if (!music.player?.track) return ctx.respond({
embeds: [util.embed().setDescription("❌ | Currently not playing anything.")]
});
if (!ctx.member.voice.channel)
return ctx.respond({
embeds: [util.embed().setDescription("❌ | You must be on a voice channel.")]
});
if (ctx.guild.me.voice.channel && !ctx.guild.me.voice.channel.equals(ctx.member.voice.channel))
return ctx.respond({
embeds: [util.embed().setDescription(`❌ | You must be on ${ctx.guild.me.voice.channel} to use this command.`)]
});

music.set8D(!music.filters["8d"]);
ctx.respond({
embeds: [util.embed().setDescription(`✅ | ${music.filters["8d"] ? "Enabled" : "Disabled"} **8D**`)]
});
}
};
35 changes: 35 additions & 0 deletions src/commands/bassboost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const util = require("../util");
module.exports = {
name: "bassboost",
description: "Set bassboost for player",
aliases: ["bb"],
options: {
value: {
description: "Basboost value; 0 to disable",
type: "INTEGER",
}
},
exec: async (ctx) => {
const { music, options } = ctx;
if (!music.player?.track) return ctx.respond({
embeds: [util.embed().setDescription("❌ | Currently not playing anything.")]
});
if (!ctx.member.voice.channel)
return ctx.respond({
embeds: [util.embed().setDescription("❌ | You must be on a voice channel.")]
});
if (ctx.guild.me.voice.channel && !ctx.guild.me.voice.channel.equals(ctx.member.voice.channel))
return ctx.respond({
embeds: [util.embed().setDescription(`❌ | You must be on ${ctx.guild.me.voice.channel} to use this command.`)]
});

if (!options.value) {
ctx.respond(util.embed().setDescription(`${music.filters.bassboost ? `✅ | BassBoost **${music.bassboost * 100}%**` : "❌ | BassBoost **off**"}`));
} else {
if (isNaN(options.value)) return ctx.respond(util.embed().setDescription("❌ | Specify a number"));
if (options.value < 1 || options.value > 100) return ctx.respond(util.embed().setDescription("❌ | You can only set the bassboost from 1 to 100."));
music.setBassboost(parseInt(options.value));
ctx.respond(util.embed().setDescription(`✅ | BassBoost set to **${ music.bassboost ? "off" : `${music.bassboost * 100}%` }**`));
}
}
};
24 changes: 14 additions & 10 deletions src/commands/clearqueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ module.exports = {
name: "clearqueue",
description:"Clean up the queue.",
aliases: ["clr", "clear"],
exec: (msg) => {
const { music } = msg.guild;
if (!music.player) return msg.channel.send(util.embed().setDescription("❌| Currently not playing anything."));
if (!music.queue.length) return msg.channel.send(util.embed().setDescription("❌ | Queue is empty."));

if (!msg.member.voice.channel)
return msg.channel.send(util.embed().setDescription("❌ | You must be on a voice channel."));
if (msg.guild.me.voice.channel && !msg.guild.me.voice.channel.equals(msg.member.voice.channel))
return msg.channel.send(util.embed().setDescription(`❌ | You must be on ${msg.guild.me.voice.channel} to use this command.`));
exec: (ctx) => {
const { music } = ctx;
if (!music.queue.length) return ctx.respond({
embeds: [util.embed().setDescription("❌ | Queue is empty.")]
});
if (!ctx.member.voice.channel)
return ctx.respond({
embeds: [util.embed().setDescription("❌ | You must be on a voice channel.")]
});
if (ctx.guild.me.voice.channel && !ctx.guild.me.voice.channel.equals(ctx.member.voice.channel))
return ctx.respond({
embeds: [util.embed().setDescription(`❌ | You must be on ${ctx.guild.me.voice.channel} to use this command.`)]
});

music.queue.splice(0, 1);
msg.channel.send(util.embed().setDescription("✅ | Cleared the queue.")).catch(e => e);
ctx.respond(util.embed().setDescription("✅ | Cleared the queue.")).catch(e => e);
}
};
23 changes: 23 additions & 0 deletions src/commands/doubletime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const util = require("../util");
module.exports = {
name: "doubletime",
description: "DT filter",
aliases: ["dt"],
exec: async (ctx) => {
const { music } = ctx;
if (!music.player?.track) return ctx.respond({ embded: [util.embed().setDescription("❌ | Currently not playing anything.")]});
if (!ctx.member.voice.channel)
return ctx.respond({
embeds: [util.embed().setDescription("❌ | You must be on a voice channel.")]
});
if (ctx.guild.me.voice.channel && !ctx.guild.me.voice.channel.equals(ctx.member.voice.channel))
return ctx.respond({
embeds: [util.embed().setDescription(`❌ | You must be on ${ctx.guild.me.voice.channel} to use this command.`)]
});

music.setDoubleTime(!music.filters.doubleTime);
ctx.respond({
embeds: [util.embed().setDescription(`✅ | ${music.filters.doubleTime ? "Enabled" : "Disabled"} **Double Time**`)]
});
}
};
29 changes: 22 additions & 7 deletions src/commands/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@ const { isValidURL } = require("../util");

module.exports = {
name: "eval",
description: "Evaluate JS code",
aliases: ["e"],
exec: async (msg, args) => {
if (msg.author.id !== process.env.OWNER_ID) return;
const isAsync = args.includes("--async");
const isSilent = args.includes("--silent");
const code = args.filter(e => !/^--(async|silent)$/.test(e)).join(" ");
options: {
code: {
description: "Code to eval",
type: "STRING",
required: true
},
async: {
description: "Async eval",
type: "BOOLEAN",
},
silent: {
description: "Dont send output",
type: "BOOLEAN",
}
},
exec: async (ctx) => {
if (ctx.author.id !== process.env.OWNER_ID) return;
console.log(ctx.options);
const { code, async: isAsync, silent: isSilent } = ctx.options;
try {
let result = eval(isAsync ? `(async()=>{${code}})()` : code);
let isResultPromise = false;
Expand All @@ -19,9 +34,9 @@ module.exports = {
if (isSilent) return;
let inspectedResult = inspect(result, { depth: 0 });
if (isResultPromise) inspectedResult = `Promise<${inspectedResult}>`;
await msg.channel.send(`${isValidURL(inspectedResult) ? inspectedResult : `\`\`\`js\n${inspectedResult}\`\`\``}`);
await ctx.respond(`${isValidURL(inspectedResult) ? inspectedResult : `\`\`\`js\n${inspectedResult}\`\`\``}`);
} catch (e) {
msg.channel.send(`\`\`\`js\n${e}\`\`\``);
ctx.respond(`\`\`\`js\n${e}\`\`\``);
}
}
};
11 changes: 6 additions & 5 deletions src/commands/help.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
const util = require("../util");

const unlisted = ["eval", "source"];
const unlisted = ["eval"];

module.exports = {
name: "help",
description: "List of commands",
aliases: ["commands", "?"],
exec: (msg) => {
const commands = msg.client.commands
exec: (ctx) => {
const commands = ctx.client.commands
.filter(c => !unlisted.includes(c.name))
.map(c => `\`${c.name}\``);

const embed = util.embed()
.setAuthor("Command List", msg.client.user.displayAvatarURL())
.setAuthor("Command List", ctx.client.user.displayAvatarURL())
.setDescription(commands.join(", "))
.setTimestamp();

msg.channel.send(embed);
ctx.respond({ embeds: [embed] });
}
};
Loading