Skip to content

Commit

Permalink
- Added: #496
Browse files Browse the repository at this point in the history
- Fix formatting issues and update code
  • Loading branch information
appujet committed Feb 6, 2024
1 parent a30ff7c commit 1d95db6
Show file tree
Hide file tree
Showing 33 changed files with 297 additions and 168 deletions.
26 changes: 13 additions & 13 deletions Lavalink/example.application.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
server: # REST and WS server
port: 2333
port: 2333 # The port that the server listens on
address: 0.0.0.0
http2:
enabled: false # Whether to enable HTTP/2 support
plugins:
lavasrc:
sources:
Expand All @@ -11,8 +9,8 @@ plugins:
deezer: true # Enable Deezer source
yandexmusic: true # Enable Yandex Music source
spotify:
clientId: "" # your spotify client id
clientSecret: "" # your spotify client secret
clientId: ""
clientSecret: ""
countryCode: "US" # the country code you want to use for filtering the artists top tracks. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
playlistLoadLimit: 6 # The number of pages at 100 tracks each
albumLoadLimit: 6 # The number of pages at 50 tracks each
Expand All @@ -25,12 +23,16 @@ plugins:
masterDecryptionKey: "" # the master key used for decrypting the deezer tracks. (yes this is not here you need to get it from somewhere else)
yandexmusic:
accessToken: "" # the token used for accessing the yandex music api. See https://github.com/TopiSenpai/LavaSrc#yandex-music

lavalink:
plugins:
- dependency: "com.github.topi314.lavasrc:lavasrc-plugin:4.0.1"
repository: "https://maven.lavalink.dev/releases"
snapshot: false
- dependency: "com.github.topi314.sponsorblock:sponsorblock-plugin:3.0.0"
repository: "https://maven.lavalink.dev/releases" # this is optional for lavalink v4.0.0-beta.5 or greater
snapshot: false

pluginsDir: "./plugins"
server:
password: "youshallnotpass"
sources:
Expand All @@ -52,10 +54,10 @@ lavalink:
rotation: true
channelMix: true
lowPass: true
bufferDurationMs: 400 # The duration of the NAS buffer. Higher values fare better against longer GC pauses. Duration <= 0 to disable JDA-NAS. Minimum of 40ms, lower values may introduce pauses.
frameBufferDurationMs: 5000 # How many milliseconds of audio to keep buffered
bufferDurationMs: 400 # The duration of the NAS buffer. Higher values fare better against longer GC pauses. Duration <= 0 to disable JDA-NAS. Minimum of 40ms, lower values may introduce
frameBufferDurationMs: 1000 # How many milliseconds of audio to keep buffered
opusEncodingQuality: 10 # Opus encoder quality. Valid values range from 0 to 10, where 10 is best quality but is the most expensive on the CPU.
resamplingQuality: LOW # Quality of resampling operations. Valid values are LOW, MEDIUM and HIGH, where HIGH uses the most CPU.
resamplingQuality: MEDIUM # Quality of resampling operations. Valid values are LOW, MEDIUM and HIGH, where HIGH uses the most CPU.
trackStuckThresholdMs: 10000 # The threshold for how long a track can be stuck. A track is stuck if does not return any audio data.
useSeekGhosting: true # Seek ghosting is the effect where whilst a seek is in progress, the audio buffer is read from until empty, or until seek is ready.
youtubePlaylistLoadLimit: 6 # Number of pages at 100 each
Expand All @@ -64,7 +66,7 @@ lavalink:
soundcloudSearchEnabled: true
gc-warnings: true
#ratelimit:
#ipBlocks: ["1.0.0.0/8", "..."] # list of ip blocks
#ipBlocks: ["2001:470:28:d66::/64"] # list of ip blocks
#excludedIps: ["...", "..."] # ips which should be explicit excluded from usage by lavalink
#strategy: "RotateOnBan" # RotateOnBan | LoadBalance | NanoSwitch | RotatingNanoSwitch
#searchTriggersFail: true # Whether a search 429 should trigger marking the ip as failing
Expand All @@ -77,7 +79,6 @@ lavalink:
#proxyPort: 3128 # Proxy port, 3128 is the default for squidProxy
#proxyUser: "" # Optional user for basic authentication fields, leave blank if you don't use basic auth
#proxyPassword: "" # Password for basic authentication

metrics:
prometheus:
enabled: false
Expand Down Expand Up @@ -106,8 +107,7 @@ logging:
includePayload: true
maxPayloadLength: 10000


logback:
rollingpolicy:
max-file-size: 1GB
max-history: 30
max-history: 30
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@

### **Need Help with plugins?** Join our [Discord Server]([support-server]) and ask for help in the `#support` channel.


## 📚 Commands

<details><summary>Click to View Commands</summary>
Expand Down Expand Up @@ -143,7 +142,7 @@ TOKEN="." # Your bot token
PREFIX= "!" # Your prefix
OWNER_IDS=["859640640640640640","859640640640640640"] # Your discord id, you can add multiple ids
GUILD_ID= "859640640640640640" # Your server Id if you want to use the for single server
PRODUCTION="true" # true for production
PRODUCTION="true" # true for production
SEARCH_ENGINE= "ytsearch" # ytsearch, scsearch or ytmsearch
MAX_PLAYLIST_SIZE= "100" # Max playlist size
MAX_QUEUE_SIZE= "100" # Max queue size
Expand Down Expand Up @@ -178,7 +177,6 @@ Edit docker-compose.yml and make sure to set the following variables:

your .env file should look like this or you can use the [.env.example](https://raw.githubusercontent.com/brblacky/lavamusic/main/.env.example) file


```yaml
TOKEN="." # Your bot token and remember, don't show everyone your bot token
PREFIX="!" # Your prefix
Expand Down Expand Up @@ -222,17 +220,15 @@ Do note that the bot will restart itself to update to the latest!

- ![Node.js](https://img.shields.io/badge/Node.js-43853D?style=for-the-badge&logo=node.js&logoColor=white) [Node.js](https://nodejs.org/en/download/)
- ![Discord.js](https://img.shields.io/badge/Discord.js-7289DA?style=for-the-badge&logo=discord&logoColor=white) [Discord.js](https://discord.js.org/#/)
- ![Lavalink](https://img.shields.io/badge/Lavalink-7289DA?style=for-the-badge&logo=discord&logoColor=white) [Lavalink](https://github.com/lavalink-devs/Lavalink)
- ![Lavalink](https://img.shields.io/badge/Lavalink-7289DA?style=for-the-badge&logo=discord&logoColor=white) [Lavalink](https://github.com/lavalink-devs/Lavalink)
- ![Docker](https://img.shields.io/badge/Docker-2496ED?style=for-the-badge&logo=docker&logoColor=white) [Docker](https://www.docker.com/)
- ![Docker-Compose](https://img.shields.io/badge/Docker--Compose-2496ED?style=for-the-badge&logo=docker&logoColor=white) [Docker-Compose](https://docs.docker.com/compose/)


### Errors

![image](https://cdn.discordapp.com/attachments/1147388529085780078/1165972143146815518/image_1.png)

- Fix this error to add database name in end of the `DATABASE_URL` like this `mongodb+srv://xxyydd:ejejeje@cluster0.f93tcdq.mongodb.net/Bot`

- Fix this error to add database name in end of the `DATABASE_URL` like this `mongodb+srv://xxyydd:ejejeje@cluster0.f93tcdq.mongodb.net/Bot`

## 📝 Tutorial

Expand Down Expand Up @@ -281,4 +277,4 @@ Thanks goes to these wonderful people :
[license-shield]: https://img.shields.io/github/license/brblacky/lavamusic.svg?style=for-the-badge
[license-url]: https://github.com/brblacky/lavamusic/blob/master/LICENSE
[support-server]: https://discord.gg/PMpJnJaHmy
[support-shield]: https://img.shields.io/discord/942117923001098260.svg?style=for-the-badge&logo=discord&colorB=7289DA
[support-shield]: https://img.shields.io/discord/942117923001098260.svg?style=for-the-badge&logo=discord&colorB=7289DA
Binary file added database/lavamusic.db-shm
Binary file not shown.
Binary file added database/lavamusic.db-wal
Binary file not shown.
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ services:
# lavalink exposes port 2333 to connect to for other containers (this is for documentation purposes only)
#- 2333
#ports:
# you only need this if you want to make your lavalink accessible from outside of containers
#- "2333:2333"
# you only need this if you want to make your lavalink accessible from outside of containers
#- "2333:2333"
healthcheck:
test: "curl -H \"Authorization: youshallnotpass\" -s http://localhost:2333/version"
test: 'curl -H "Authorization: youshallnotpass" -s http://localhost:2333/version'
interval: 10s
timeout: 10s
retries: 5
Expand All @@ -43,4 +43,4 @@ services:
restart: on-failure
depends_on:
lavalink:
condition: service_healthy
condition: service_healthy
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"name": "lavamusic",
"version": "4.0.5",
"version": "4.0.6",
"description": "LavaMusic is a music bot for Discord, written in JavaScript using the Discord.js, Typescript, Shoukaku (Lavalink) library.",
"main": "dist/index.js",
"type": "module",
"scripts": {
"prisma:generate": "npx prisma generate",
"start": "npm run build && node dist/index.js",
"dev": "npm run build && nodemon --watch dist --exec node dist/index.js",
"build": "tsc --project tsconfig.json",
"clean": "rm -rf dist",
"lint": "eslint . --cache --ext .js,.jsx,.ts,.tsx",
"lint:fix": "eslint . --fix --cache --ext .js,.jsx,.ts,.tsx",
"format": "prettier --check .",
"format:fix": "prettier --write ."
"format:fix": "prettier --write .",
"postinstall": "npm run build && node dist/index.js"
},
"repository": {
"type": "git",
Expand All @@ -37,25 +36,25 @@
"homepage": "https://github.com/brblacky/lavamusic#readme",
"devDependencies": {
"@types/better-sqlite3": "^7.6.9",
"@types/node": "^20.11.10",
"@types/node": "^20.11.16",
"@types/signale": "^1.4.7",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-unicorn": "^50.0.1",
"prettier": "^3.2.4",
"eslint-plugin-unicorn": "^51.0.0",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"dependencies": {
"better-sqlite3": "^9.3.0",
"better-sqlite3": "^9.4.0",
"discord.js": "^14.14.1",
"dotenv": "^16.4.1",
"shoukaku": "^4.0.1",
"signale": "^1.4.0",
"tslib": "^2.6.2",
"undici": "^6.5.0"
"undici": "^6.6.1"
},
"signale": {
"displayScope": true,
Expand All @@ -66,4 +65,4 @@
"displayTimestamp": true,
"underlineLabel": true
}
}
}
8 changes: 6 additions & 2 deletions src/commands/config/Dj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export default class Dj extends Command {
return await ctx.sendMessage({
embeds: [embed.setDescription('Please provide a role to add')],
});
const isExRole = client.db.getRoles(ctx.guild.id).find((r: any) => r.roleId === role.id);
const isExRole = client.db
.getRoles(ctx.guild.id)
.find((r: any) => r.roleId === role.id);
if (isExRole)
return await ctx.sendMessage({
embeds: [embed.setDescription(`The dj role <@&${role.id}> is already added`)],
Expand All @@ -101,7 +103,9 @@ export default class Dj extends Command {
return await ctx.sendMessage({
embeds: [embed.setDescription('Please provide a role to remove')],
});
const isExRole = client.db.getRoles(ctx.guild.id).find((r: any) => r.roleId === role.id);
const isExRole = client.db
.getRoles(ctx.guild.id)
.find((r: any) => r.roleId === role.id);
if (!isExRole)
return await ctx.sendMessage({
embeds: [embed.setDescription(`The dj role <@&${role.id}> is not added`)],
Expand Down
10 changes: 3 additions & 7 deletions src/commands/config/Prefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class Prefix extends Command {
if (!pre) {
embed.setDescription(
`The prefix for this server is \`${
prefix ? prefix.prefix : client.config.prefix
prefix ? prefix.prefix : client.config.prefix
}\``
);
return await ctx.sendMessage({ embeds: [embed] });
Expand All @@ -81,18 +81,14 @@ export default class Prefix extends Command {
client.db.setPrefix(ctx.guild.id, pre);
return await ctx.sendMessage({
embeds: [
embed.setDescription(
`The prefix for this server is now \`${pre}\``
),
embed.setDescription(`The prefix for this server is now \`${pre}\``),
],
});
} else {
client.db.setPrefix(ctx.guild.id, pre);
return await ctx.sendMessage({
embeds: [
embed.setDescription(
`The prefix for this server is now \`${pre}\``
),
embed.setDescription(`The prefix for this server is now \`${pre}\``),
],
});
}
Expand Down
6 changes: 4 additions & 2 deletions src/commands/config/Setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class Setup extends Command {
switch (subCommand) {
case 'create': {
const data = client.db.getSetup(ctx.guild.id);

if (data && data.textId && data.msgId)
return await ctx.sendMessage({
embeds: [
Expand Down Expand Up @@ -140,7 +140,9 @@ export default class Setup extends Command {
await ctx.guild.channels.cache
.get(data2.textId)
.delete()
.catch(() => {null});
.catch(() => {
null;
});
await ctx.sendMessage({
embeds: [
{
Expand Down
13 changes: 7 additions & 6 deletions src/commands/dev/Eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ export default class Eval extends Command {
let evaled = eval(code);

if (evaled == client.config) evaled = 'Nice try';

const button = new ButtonBuilder()
.setStyle(ButtonStyle.Danger)
.setLabel('Delete')
.setCustomId('eval-delete');
const row = new ActionRowBuilder().addComponents(button);

if (typeof evaled !== 'string') evaled = (await import('node:util')).inspect(evaled);

if (evaled.length > 2000) {
const response = await fetch('https://hasteb.in/post', {
method: 'POST',
headers: {
'Content-Type': 'text/plain',
},
body: evaled,
})
});

const json = await response.json() as { key: string };
const json = (await response.json()) as { key: string };
evaled = `https://hasteb.in/${json.key}`;
return await ctx.sendMessage({
content: evaled,
Expand All @@ -66,12 +66,13 @@ export default class Eval extends Command {
content: `\`\`\`js\n${evaled}\n\`\`\``,
components: [row],
});
const filter = (i): boolean => i.customId === 'eval-delete' && i.user.id === ctx.author.id;
const filter = (i): boolean =>
i.customId === 'eval-delete' && i.user.id === ctx.author.id;
const collector = msg.createMessageComponentCollector({
time: 60000,
filter: filter,
});
collector.on('collect', async (i) => {
collector.on('collect', async i => {
await i.deferUpdate();
await msg.delete();
});
Expand Down
6 changes: 4 additions & 2 deletions src/commands/music/Grab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ export default class Grab extends Command {
.setURL(song.info.uri)
.setThumbnail(song.info.artworkUrl)
.setDescription(
`**Duration:** ${song.info.isStream ? 'LIVE' : client.utils.formatTime(song.info.length)
}\n**Requested by:** ${song.info.requester}\n**Link:** [Click here](${song.info.uri
`**Duration:** ${
song.info.isStream ? 'LIVE' : client.utils.formatTime(song.info.length)
}\n**Requested by:** ${song.info.requester}\n**Link:** [Click here](${
song.info.uri
})`
)
.setColor(client.color.main);
Expand Down
4 changes: 3 additions & 1 deletion src/commands/music/Join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export default class Join extends Command {
embeds: [
embed
.setColor(this.client.color.main)
.setDescription(`Joined <#${player.node.manager.connections.get(ctx.guild.id).channelId}>`),
.setDescription(
`Joined <#${player.node.manager.connections.get(ctx.guild.id).channelId}>`
),
],
});
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/music/Leave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export default class Leave extends Command {
embeds: [
embed
.setColor(this.client.color.main)
.setDescription(`Left <#${player.node.manager.connections.get(ctx.guild.id).channelId}>`),
.setDescription(
`Left <#${player.node.manager.connections.get(ctx.guild.id).channelId}>`
),
],
});
player.destroy();
Expand Down
9 changes: 2 additions & 7 deletions src/commands/music/Play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,8 @@ export default class Play extends Command {
const query = args.join(' ');
let player = client.queue.get(ctx.guild.id);
const vc = ctx.member as any;
if (!player)
player = await client.queue.create(
ctx.guild,
vc.voice.channel,
ctx.channel
);

if (!player) player = await client.queue.create(ctx.guild, vc.voice.channel, ctx.channel);

const res = await this.client.queue.search(query);
const embed = this.client.embed();
switch (res.loadType) {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/music/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export default class Queue extends Command {
});
const queue = player.queue.map(
(track, index) =>
`${index + 1}. [${track.info.title}](${track.info.uri}) - Request By: ${track?.info
.requester} - Duration: ${
`${index + 1}. [${track.info.title}](${track.info.uri}) - Request By: ${
track?.info.requester
} - Duration: ${
track.info.isStream ? 'LIVE' : this.client.utils.formatTime(track.info.length)
}`
);
Expand Down
Loading

0 comments on commit 1d95db6

Please sign in to comment.