From ab21f02ce75cc41cba29eb857f42f89a7dbd9478 Mon Sep 17 00:00:00 2001 From: appujet Date: Sat, 14 Sep 2024 21:25:38 +0530 Subject: [PATCH] chore: update env and docker yml --- docker-compose.yml | 10 ++------ src/commands/music/Lyrics.ts | 2 +- src/env.ts | 44 +++++++++++++++++++++++++++----- src/structures/LavalinkClient.ts | 6 ++--- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8d42fdbd1..fc21b8cb0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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) diff --git a/src/commands/music/Lyrics.ts b/src/commands/music/Lyrics.ts index 64c8d1ff6..cd8b47ebd 100644 --- a/src/commands/music/Lyrics.ts +++ b/src/commands/music/Lyrics.ts @@ -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, diff --git a/src/env.ts b/src/env.ts index 5c3a42c4a..75277f8db 100644 --- a/src/env.ts +++ b/src/env.ts @@ -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 @@ -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 @@ -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 @@ -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 */ @@ -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; diff --git a/src/structures/LavalinkClient.ts b/src/structures/LavalinkClient.ts index a98fafc82..78840e5e6 100644 --- a/src/structures/LavalinkClient.ts +++ b/src/structures/LavalinkClient.ts @@ -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,