|
1 | 1 | import { Database } from 'bun:sqlite'
|
2 | 2 | import { existsSync, readFileSync, readdirSync } from 'fs'
|
3 |
| -import { dirname, join } from 'path' |
| 3 | +import { join } from 'path' |
4 | 4 | import { Client as APIClient } from '@revanced/bot-api'
|
5 | 5 | import { createLogger } from '@revanced/bot-shared'
|
6 | 6 | import { Client as DiscordClient, type Message, Partials } from 'discord.js'
|
7 | 7 | 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 |
15 | 8 |
|
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' |
30 | 10 |
|
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' |
38 | 12 |
|
39 |
| -export const __getConfig = () => currentConfig |
| 13 | +import { __getConfig, config } from './config' |
| 14 | +export { config, __getConfig } |
40 | 15 |
|
41 | 16 | export const logger = createLogger({
|
42 | 17 | level: config.logLevel === 'none' ? Number.MAX_SAFE_INTEGER : config.logLevel,
|
43 | 18 | })
|
44 | 19 |
|
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' |
47 | 22 |
|
48 | 23 | export const api = {
|
49 | 24 | client: new APIClient({
|
|
0 commit comments