Skip to content

Commit 8efb549

Browse files
committed
fix(bots/discord): fix freeze on prod builds
1 parent 79fea8b commit 8efb549

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

bots/discord/src/config.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { dirname, join } from 'path'
2+
import _firstConfig from '../config.js'
3+
4+
let currentConfig = _firstConfig
5+
6+
// Other parts of the code will access properties of this proxy, they don't care what the target looks like
7+
export const config = new Proxy(
8+
{
9+
INSPECTION_WARNING: 'Run `context.__getConfig()` to inspect the latest config.',
10+
} as unknown as typeof currentConfig,
11+
{
12+
get(_, p, receiver) {
13+
if (p === 'invalidate')
14+
return async () => {
15+
const path = join(dirname(Bun.main), '..', 'config.js')
16+
Loader.registry.delete(path)
17+
currentConfig = (await import(path)).default
18+
}
19+
20+
return Reflect.get(currentConfig, p, receiver)
21+
},
22+
set(_, p, newValue, receiver) {
23+
return Reflect.set(currentConfig, p, newValue, receiver)
24+
},
25+
},
26+
) as typeof _firstConfig & { invalidate(): void }
27+
28+
export const __getConfig = () => currentConfig

bots/discord/src/context.ts

+7-32
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,24 @@
11
import { Database } from 'bun:sqlite'
22
import { existsSync, readFileSync, readdirSync } from 'fs'
3-
import { dirname, join } from 'path'
3+
import { join } from 'path'
44
import { Client as APIClient } from '@revanced/bot-api'
55
import { createLogger } from '@revanced/bot-shared'
66
import { Client as DiscordClient, type Message, Partials } from 'discord.js'
77
import { drizzle } from 'drizzle-orm/bun-sqlite'
8-
import type { default as Command, CommandOptionsOptions, CommandType } from './classes/Command'
9-
import * as schemas from './database/schemas'
10-
11-
// Export some things first, as commands require them
12-
import _firstConfig from '../config.js'
13-
14-
let currentConfig = _firstConfig
158

16-
// Other parts of the code will access properties of this proxy, they don't care what the target looks like
17-
export const config = new Proxy(
18-
{
19-
INSPECTION_WARNING: 'Run `context.__getConfig()` to inspect the latest config.',
20-
} as unknown as typeof currentConfig,
21-
{
22-
get(_, p, receiver) {
23-
if (p === 'invalidate')
24-
return async () => {
25-
const path = join(dirname(Bun.main), '..', 'config.js')
26-
Loader.registry.delete(path)
27-
currentConfig = (await import(path)).default
28-
logger.debug('New config set')
29-
}
9+
import * as schemas from './database/schemas'
3010

31-
return Reflect.get(currentConfig, p, receiver)
32-
},
33-
set(_, p, newValue, receiver) {
34-
return Reflect.set(currentConfig, p, newValue, receiver)
35-
},
36-
},
37-
) as typeof _firstConfig & { invalidate(): void }
11+
import type { default as Command, CommandOptionsOptions, CommandType } from './classes/Command'
3812

39-
export const __getConfig = () => currentConfig
13+
import { __getConfig, config } from './config'
14+
export { config, __getConfig }
4015

4116
export const logger = createLogger({
4217
level: config.logLevel === 'none' ? Number.MAX_SAFE_INTEGER : config.logLevel,
4318
})
4419

45-
// Importing later because config needs to be exported before
46-
const commands = await import('./commands')
20+
// Export a few things before we initialize commands
21+
import * as commands from './commands'
4722

4823
export const api = {
4924
client: new APIClient({

0 commit comments

Comments
 (0)