Skip to content

Commit

Permalink
Update env
Browse files Browse the repository at this point in the history
  • Loading branch information
hwangsihu committed Oct 26, 2024
1 parent 390dade commit 439bad1
Showing 1 changed file with 1 addition and 68 deletions.
69 changes: 1 addition & 68 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,16 @@ const LavalinkNodeSchema = z.object({
});

const envSchema = z.object({
/**
* The discord app token
*/
TOKEN: z.string(),

/**
* The client id
*/
CLIENT_ID: z.string(),

/**
* The default language
*/
DEFAULT_LANGUAGE: z.string().default('EnglishUS'),

/**
* The bot prefix
*/
PREFIX: z.string().default('!'),

/**
* The owner ids
*/
OWNER_IDS: z.preprocess(val => (typeof val === 'string' ? JSON.parse(val) : val), z.string().array().optional()),

/**
* The guild id for devlopment purposes
*/
GUILD_ID: z.string().optional(),

/**
* The Top.gg api key
*/
TOPGG: z.string().optional(),

/**
* The keep alive boolean
*/
KEEP_ALIVE: z.preprocess(val => val === 'true', z.boolean().default(false)),

/**
* The log channel id
*/
LOG_CHANNEL_ID: z.string().optional(),

/**
* The log command id
*/
LOG_COMMANDS_ID: z.string().optional(),

/**
* The bot status online | idle | dnd | invisible
*/
BOT_STATUS: z.preprocess(
val => {
if (typeof val === 'string') {
Expand All @@ -85,29 +42,14 @@ const envSchema = z.object({
},
z.enum(['online', 'idle', 'dnd', 'invisible']).default('online'),
),

/**
* The bot activity
*/
BOT_ACTIVITY: z.string().default('Lavamusic'),

/**
* The bot activity type
*/
BOT_ACTIVITY_TYPE: z.preprocess(val => {
if (typeof val === 'string') {
return Number.parseInt(val, 10);
}
return val;
}, z.number().default(0)),
/**
* The database url
*/
DATABASE_URL: z.string().optional(),

/**
* Search engine
*/
SEARCH_ENGINE: z.preprocess(
val => {
if (typeof val === 'string') {
Expand All @@ -119,26 +61,17 @@ const envSchema = z.object({
.enum(['youtube', 'youtubemusic', 'soundcloud', 'spotify', 'apple', 'deezer', 'yandex', 'jiosaavn'])
.default('youtube'),
),
/**
* Node in json
*/
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>;

/**
* The environment variables
*/
export const env: Env = envSchema.parse(process.env);

for (const key in env) {
if (!(key in env)) {
throw new Error(`Missing env variable: ${key}`);
throw new Error(`Missing env variable: ${key}. Please check the .env file and try again.`);
}
}

Expand Down

0 comments on commit 439bad1

Please sign in to comment.