-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkoishi.config.js
119 lines (108 loc) · 2.34 KB
/
koishi.config.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const fs = require('fs')
const path = require('path')
const YAML = require('yaml')
/**
* 引入配置文件
*/
const config = require('./config')
/**
* 引入本地化补丁文件
*/
config.plugins.locales = {
...(config.plugins?.locales || {}),
i18n: {
...require('./src/i18n-patch'),
...(config.plugins?.locales?.i18n || {}),
}
}
/**
* 配置 koishi
*/
const koishi = {
...config.options,
watch: config.watch ? {
root: 'src',
ignore: [],
} : {},
plugins: {
'database-mysql': config.mysql,
'adapter-onebot': { ...config.bots.onebot[0] },
'adapter-kook': { ...config.bots.kook[0] },
'adapter-telegram': { ...config.bots.telegram[0] },
// './src/adapters/telegram': { ...config.bots.telegram[0] },
help: {
options: false,
shortcut: false,
},
sudo: {},
recall: {},
'rate-limit': {},
commands: {
recall: { authority: 3 },
sudo: { authority: 4 },
},
console: {
// open: true,
// devMode: true,
},
logger: {},
status: {},
sandbox: {},
dataview: {},
...(process.env.NODE_ENV === 'development' ? {} : {
chat: {},
insight: {},
}),
// puppeteer: {},
}
}
/**
* 扫描并载入本地插件
*/
const scan = (dir) => fs.readdirSync(dir).map(subdir => path.join(dir, subdir))
for (const dir of [
...scan(path.join(__dirname, './src/services')),
...scan(path.join(__dirname, './src/plugins')),
...scan(path.join(__dirname, './src/commands')),
// ...scan(path.join(__dirname, './src/scripts')),
]) {
const name = path.basename(dir, path.extname(path.basename(dir)))
if (name == '_deprecated') {
continue
}
const pluginPath = './' + path.relative(__dirname, dir).replace(/\\/g, '/')
const pluginData = config.plugins[name] || {}
koishi.plugins[pluginPath] = pluginData
}
/**
* 应用全局变量
*/
const globals = {}
function expand(node, key = '') {
if (key) {
globals[key] = node
}
if (typeof node === 'object') {
const prefix = key ? key + '.' : ''
for (const i in node) {
expand(node[i], prefix + i)
}
}
}
function walk(node) {
for (const i in node) {
if (typeof node[i] === 'string' &&
node[i].startsWith('<') &&
node[i].endsWith('>') &&
Object.keys(globals).includes(node[i].slice(1, -1))
) {
node[i] = globals[node[i].slice(1, -1)]
}
if (typeof node[i] === 'object') {
walk(node[i])
}
}
}
expand(config.globals)
walk(koishi)
module.exports = koishi