mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-18 00:33:59 +00:00
fix(bots/discord): fix freeze on prod builds
This commit is contained in:
28
bots/discord/src/config.ts
Normal file
28
bots/discord/src/config.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { dirname, join } from 'path'
|
||||||
|
import _firstConfig from '../config.js'
|
||||||
|
|
||||||
|
let currentConfig = _firstConfig
|
||||||
|
|
||||||
|
// Other parts of the code will access properties of this proxy, they don't care what the target looks like
|
||||||
|
export const config = new Proxy(
|
||||||
|
{
|
||||||
|
INSPECTION_WARNING: 'Run `context.__getConfig()` to inspect the latest config.',
|
||||||
|
} as unknown as typeof currentConfig,
|
||||||
|
{
|
||||||
|
get(_, p, receiver) {
|
||||||
|
if (p === 'invalidate')
|
||||||
|
return async () => {
|
||||||
|
const path = join(dirname(Bun.main), '..', 'config.js')
|
||||||
|
Loader.registry.delete(path)
|
||||||
|
currentConfig = (await import(path)).default
|
||||||
|
}
|
||||||
|
|
||||||
|
return Reflect.get(currentConfig, p, receiver)
|
||||||
|
},
|
||||||
|
set(_, p, newValue, receiver) {
|
||||||
|
return Reflect.set(currentConfig, p, newValue, receiver)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
) as typeof _firstConfig & { invalidate(): void }
|
||||||
|
|
||||||
|
export const __getConfig = () => currentConfig
|
||||||
@@ -1,49 +1,24 @@
|
|||||||
import { Database } from 'bun:sqlite'
|
import { Database } from 'bun:sqlite'
|
||||||
import { existsSync, readFileSync, readdirSync } from 'fs'
|
import { existsSync, readFileSync, readdirSync } from 'fs'
|
||||||
import { dirname, join } from 'path'
|
import { join } from 'path'
|
||||||
import { Client as APIClient } from '@revanced/bot-api'
|
import { Client as APIClient } from '@revanced/bot-api'
|
||||||
import { createLogger } from '@revanced/bot-shared'
|
import { createLogger } from '@revanced/bot-shared'
|
||||||
import { Client as DiscordClient, type Message, Partials } from 'discord.js'
|
import { Client as DiscordClient, type Message, Partials } from 'discord.js'
|
||||||
import { drizzle } from 'drizzle-orm/bun-sqlite'
|
import { drizzle } from 'drizzle-orm/bun-sqlite'
|
||||||
import type { default as Command, CommandOptionsOptions, CommandType } from './classes/Command'
|
|
||||||
import * as schemas from './database/schemas'
|
import * as schemas from './database/schemas'
|
||||||
|
|
||||||
// Export some things first, as commands require them
|
import type { default as Command, CommandOptionsOptions, CommandType } from './classes/Command'
|
||||||
import _firstConfig from '../config.js'
|
|
||||||
|
|
||||||
let currentConfig = _firstConfig
|
import { __getConfig, config } from './config'
|
||||||
|
export { config, __getConfig }
|
||||||
// Other parts of the code will access properties of this proxy, they don't care what the target looks like
|
|
||||||
export const config = new Proxy(
|
|
||||||
{
|
|
||||||
INSPECTION_WARNING: 'Run `context.__getConfig()` to inspect the latest config.',
|
|
||||||
} as unknown as typeof currentConfig,
|
|
||||||
{
|
|
||||||
get(_, p, receiver) {
|
|
||||||
if (p === 'invalidate')
|
|
||||||
return async () => {
|
|
||||||
const path = join(dirname(Bun.main), '..', 'config.js')
|
|
||||||
Loader.registry.delete(path)
|
|
||||||
currentConfig = (await import(path)).default
|
|
||||||
logger.debug('New config set')
|
|
||||||
}
|
|
||||||
|
|
||||||
return Reflect.get(currentConfig, p, receiver)
|
|
||||||
},
|
|
||||||
set(_, p, newValue, receiver) {
|
|
||||||
return Reflect.set(currentConfig, p, newValue, receiver)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
) as typeof _firstConfig & { invalidate(): void }
|
|
||||||
|
|
||||||
export const __getConfig = () => currentConfig
|
|
||||||
|
|
||||||
export const logger = createLogger({
|
export const logger = createLogger({
|
||||||
level: config.logLevel === 'none' ? Number.MAX_SAFE_INTEGER : config.logLevel,
|
level: config.logLevel === 'none' ? Number.MAX_SAFE_INTEGER : config.logLevel,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Importing later because config needs to be exported before
|
// Export a few things before we initialize commands
|
||||||
const commands = await import('./commands')
|
import * as commands from './commands'
|
||||||
|
|
||||||
export const api = {
|
export const api = {
|
||||||
client: new APIClient({
|
client: new APIClient({
|
||||||
|
|||||||
Reference in New Issue
Block a user