Skip to content

Commit

Permalink
chore: update env and docker yml
Browse files Browse the repository at this point in the history
  • Loading branch information
appujet committed Sep 14, 2024
1 parent 72aad7f commit ab21f02
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
10 changes: 2 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,8 @@ services:
container_name: lavamusic
image: ghcr.io/appujet/lavamusic:main
environment:
# Your lavalink url
- LAVALINK_URL=lavalink:2333
# Your lavalink password
- LAVALINK_AUTH=youshallnotpass
# Your lavalink name
- LAVALINK_NAME=LavaMusic
# Your lavalink secure (true or false)
- LAVALINK_SECURE=false
# lavalink nodes
- NODES=[{"id":"LavaMusic","host":"lavalink","port":2333,"authorization":"youshallnotpass"}]
# database url
# - DATABASE_URL= put your database url here (mongodb or postgres)
# - DATABASE_URL=postgresql://lavamusic:lavamusic@postgres:5432/lavamusic (for postgres)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/Lyrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class Lyrics extends Command {
await ctx.sendDeferMessage(ctx.locale("cmd.lyrics.searching", { trackTitle }));

const options = {
apiKey: "client.config.lyricsApi",
apiKey: client.env.GENIUS_API,
title: trackTitle,
artist: artistName,
optimizeQuery: true,
Expand Down
44 changes: 38 additions & 6 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ config({
path: path.join(__dirname, "../.env"),
});

const LavalinkNodeSchema = z.object({
id: z.string(),
host: z.string(),
port: z.number(),
authorization: z.string(),
secure: z.boolean().optional(),
sessionId: z.string().optional(),
regions: z.string().array().optional(),
retryAmount: z.number().optional(),
retryDelay: z.number().optional(),
requestSignalTimeoutMS: z.number().optional(),
closeOnError: z.boolean().optional(),
heartBeatInterval: z.number().optional(),
enablePingOnStatsCheck: z.boolean().optional(),
});

const envSchema = z.object({
/**
* The discord app token
Expand All @@ -30,7 +46,7 @@ const envSchema = z.object({
/**
* The owner ids
*/
OWNER_IDS: z.string().array().optional(),
OWNER_IDS: z.preprocess((val) => (typeof val === "string" ? JSON.parse(val) : val), z.string().array().optional()),

/**
* The guild id for devlopment purposes
Expand All @@ -45,7 +61,7 @@ const envSchema = z.object({
/**
* The keep alive boolean
*/
KEEP_ALIVE: z.boolean().default(false),
KEEP_ALIVE: z.preprocess((val) => val === "true", z.boolean().default(false)),

/**
* The log channel id
Expand All @@ -70,7 +86,12 @@ const envSchema = z.object({
/**
* The bot activity type
*/
BOT_ACTIVITY_TYPE: z.number().default(0),
BOT_ACTIVITY_TYPE: z.preprocess((val) => {
if (typeof val === "string") {
return parseInt(val, 10);
}
return val;
}, z.number().default(0)),
/**
* The database url
*/
Expand All @@ -79,12 +100,23 @@ const envSchema = z.object({
/**
* Search engine
*/
SEARCH_ENGINE: z.enum(["youtube", "youtubemusic", "soundcloud", "spotify", "apple", "deezer", "yandex", "jiosaavn"]).default("youtube"),

SEARCH_ENGINE: z.preprocess(
(val) => {
if (typeof val === "string") {
return val.toLowerCase();
}
return val;
},
z.enum(["youtube", "youtubemusic", "soundcloud", "spotify", "apple", "deezer", "yandex", "jiosaavn"]).default("youtube"),
),
/**
* Node in json
*/
NODES: z.string(),
NODES: z.preprocess((val) => (typeof val === "string" ? JSON.parse(val) : val), z.array(LavalinkNodeSchema)),
/**
* Genius api
*/
GENIUS_API: z.string().optional(),
});

type Env = z.infer<typeof envSchema>;
Expand Down
6 changes: 3 additions & 3 deletions src/structures/LavalinkClient.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { LavalinkManager, type SearchResult, type SearchPlatform } from "lavalink-client";
import type Lavamusic from "./Lavamusic";
import { LavalinkManager, type LavalinkNodeOptions, type SearchPlatform, type SearchResult } from "lavalink-client";
import { requesterTransformer } from "../utils/functions/player";
import type Lavamusic from "./Lavamusic";

export default class LavalinkClient extends LavalinkManager {
public client: Lavamusic;
constructor(client: Lavamusic) {
super({
nodes: JSON.parse(client.env.NODES),
nodes: client.env.NODES as LavalinkNodeOptions[],
sendToShard: (guildId, payload) => client.guilds.cache.get(guildId)?.shard?.send(payload),
queueOptions: {
maxPreviousTracks: 25,
Expand Down

0 comments on commit ab21f02

Please sign in to comment.