-
Notifications
You must be signed in to change notification settings - Fork 12
/
config.ts
78 lines (72 loc) · 1.79 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
72
73
74
75
76
77
78
import fs from 'fs'
import pack from './package.json'
const configPath = './config.json'
export interface Config {
version: string
app: {
nickname: string
master: string
// eslint-disable-next-line camelcase
master_uid: string
color: string
prefix: string
},
plugins: {
[key: string]: {
[key: string]: any
}
},
account: {
username: string,
password: string,
room: string
},
logger: {
level: string
}
}
const defaultConfig = {
version: pack.version,
app: {
nickname: '机器人昵称',
master: '主人用户名',
master_uid: '主人uid',
color: '消息颜色',
prefix: '.'
},
function: {
chat: {
disable: false,
api: 'Old'
},
pixiv: {
disable: false
}
},
account: {
username: '机器人用户名',
password: '机器人密码md5',
room: '房间id'
},
logger: {
level: 'INFO'
}
}
if (!fs.existsSync(configPath)) {
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, undefined, 4))
console.log('默认配置创建完成,请修改 config.json 后重新启动程序')
process.exit(0)
} else {
const conf = JSON.parse(fs.readFileSync('./config.json').toString())
if (!conf.version || conf.version !== pack.version) {
delete conf.function
delete conf.version
const newConf = Object.assign(defaultConfig, conf)
newConf.version = pack.version
fs.writeFileSync(configPath, JSON.stringify(newConf, undefined, 4))
console.log('配置文件版本不匹配,已更新完成,请参考 README.md 手动修改后重新启动程序')
process.exit(0)
}
}
const configData = JSON.parse(fs.readFileSync('./config.json').toString())
export default configData