Skip to content

Commit

Permalink
node
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasB25 committed Aug 19, 2024
1 parent c5f577e commit 8c702e3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
10 changes: 6 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ BOT_ACTIVITY_TYPE= 0 # Activity type is a number from 0 to 5. See more here: htt
BOT_ACTIVITY=" Lavamusic" # Your bot activity.
DATABASE_URL= "" # Your database url (If you want to use sqlite, then you can leave it blank.).
AUTO_NODE=" false" # true for auto node. It is given from lavainfo-api (https://lavainfo-api.deno.dev).
LAVALINK_URL= "localhost:2333" # Your Lavalink url (If auto node is true, then you can leave it blank).
LAVALINK_AUTH= "youshallnotpass" # Your Lavalink password (If auto node is true, then you can leave it blank.).
LAVALINK_NAME= "Lavamusic" # Your Lavalink name (If auto node is true, then you can leave it blank.).
LAVALINK_SECURE= "false" # true for secure Lavalink (If auto node is true, then you can leave it blank.).
MAX_PLAYLIST_SIZE= "100" # Max playlist size.
MAX_QUEUE_SIZE= "100" # Max queue size.

# Configuration for multiple Lavalink servers
LAVALINK_SERVERS = '[
{"url":"localhost:2333","auth":"youshallnotpass","name":"Local Node","secure":false},
{"url":"localhost:2333","auth":"youshallnotpass2","name":"Another Node","secure":false}
]'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@types/i18n": "^0.13.12",
"@types/node": "^22.4.0",
"@types/node": "^22.4.1",
"@types/signale": "^1.4.7",
"prisma": "^5.18.0",
"typescript": "^5.5.4"
Expand Down
25 changes: 15 additions & 10 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import "dotenv/config";
import { SearchEngine } from "./types.js";

const parseBoolean = (value?: string): boolean => value?.trim().toLowerCase() === "true";
const parseBoolean = (value) => {
if (typeof value !== "string") return false;
return value.trim().toLowerCase() === "true";
};

export default {
token: process.env.TOKEN,
Expand Down Expand Up @@ -41,7 +44,7 @@ export default {
topGG: process.env.TOPGG,
keepAlive: parseBoolean(process.env.KEEP_ALIVE),
autoNode: parseBoolean(process.env.AUTO_NODE),
searchEngine: SearchEngine.YouTube, // YouTube (YouTube Search), YouTubeMusic (YouTube Music Search), Spotify (Spotify Search), SoundCloud (SoundCloud Search), Apple (Apple Search) or Yandex (Yandex Search).
searchEngine: SearchEngine.YouTubeMusic, // YouTube (YouTube Search), YouTubeMusic (YouTube Music Search), Spotify (Spotify Search), SoundCloud (SoundCloud Search), Apple (Apple Search) or Yandex (Yandex Search).
maxPlaylistSize: parseInt(process.env.MAX_PLAYLIST_SIZE || "100"),
botStatus: process.env.BOT_STATUS || "online",
botActivity: process.env.BOT_ACTIVITY || "Lavamusic",
Expand All @@ -64,14 +67,16 @@ export default {
jiosaavn: "https://i.imgur.com/N9Nt80h.png",
},
production: parseBoolean(process.env.PRODUCTION) ?? true,
lavalink: [
{
url: process.env.LAVALINK_URL,
auth: process.env.LAVALINK_AUTH,
name: process.env.LAVALINK_NAME,
secure: parseBoolean(process.env.LAVALINK_SECURE),
},
],
lavalink: process.env.LAVALINK_SERVERS
? JSON.parse(process.env.LAVALINK_SERVERS).map((server) => {
return {
url: server.url,
auth: server.auth,
name: server.name,
secure: parseBoolean(server.secure),
};
})
: [],
};

/**
Expand Down
14 changes: 8 additions & 6 deletions src/structures/Shoukaku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ export default class ShoukakuClient extends Shoukaku {
public client: Lavamusic;
constructor(client: Lavamusic, nodes: NodeOption[]) {
super(new Connectors.DiscordJS(client), nodes, {
moveOnDisconnect: false,
resume: false,
reconnectInterval: 30,
reconnectTries: 2,
restTimeout: 10000,
userAgent: "Lavamusic (@appujet)", // don't change this
resume: true, // Whether to resume a connection on disconnect to Lavalink (Server Side) (Note: DOES NOT RESUME WHEN THE LAVALINK SERVER DIES)
resumeTimeout: 30,
resumeByLibrary: true, // Whether to resume the players by doing it in the library side (Client Side) (Note: TRIES TO RESUME REGARDLESS OF WHAT HAPPENED ON A LAVALINK SERVER)
reconnectTries: 25,
reconnectInterval: 5,
restTimeout: 60,
moveOnDisconnect: false, // Whether to move players to a different Lavalink node when a node disconnects
//voiceConnectionTimeout: 15,
nodeResolver: (nodes) =>
[...nodes.values()]
.filter((node) => node.state === 2)
Expand Down

0 comments on commit 8c702e3

Please sign in to comment.