-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ts
71 lines (63 loc) · 1.54 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import fs from 'fs'
type ModuleVisibility = 'admin' | true | false | string
export interface Game {
name: string
iframeUrl: string
sourceUrl: string
thumbnail: string
cost: number
leaderboard: {
enabled: boolean
order: 'asc' | 'desc'
}
}
export interface Config {
visibleModules: {
[key: string]: ModuleVisibility
}
system_tags: string[]
games: Record<string, Game>
reservations: {
differentSexMultiplier: number
sameBedMultiplier: number
sameRoomMultiplier: number
cancelRefund: number
currentDay: string
sameRoommateMultiplier: number
}
ads: {
enabled: boolean
adBoostCost: number
adBoostAmount: number
earnPerAdWatch: number
adCreationCost: number
initialViews: number
adShowProbability: number
}
transactions: {
transactionUnlockCost: number
}
}
let config: Config = loadConfig()
export function loadConfig(): Config {
const str = fs.readFileSync('uploads/config.json', 'utf-8')
return JSON.parse(str) as Config
}
const watcher = fs.watch(import.meta.dir + '/uploads', (event, filename) => {
console.log(`Detected ${event} in ${filename}`)
if (event !== 'change' || filename !== 'config.json') return
const currConfig = JSON.parse(JSON.stringify(config))
try {
config = loadConfig()
} catch (err) {
console.error(err)
config = currConfig
fs.writeFileSync('uploads/config.json', JSON.stringify(config, null, 2))
}
})
process.on('SIGINT', () => {
watcher.close()
})
export default function getConfig(): Config {
return config
}