@zhin.js/cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +120 -0
  2. package/dist/cli.d.ts +3 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +21 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/commands/build.d.ts +3 -0
  7. package/dist/commands/build.d.ts.map +1 -0
  8. package/dist/commands/build.js +61 -0
  9. package/dist/commands/build.js.map +1 -0
  10. package/dist/commands/dev.d.ts +3 -0
  11. package/dist/commands/dev.d.ts.map +1 -0
  12. package/dist/commands/dev.js +162 -0
  13. package/dist/commands/dev.js.map +1 -0
  14. package/dist/commands/init.d.ts +3 -0
  15. package/dist/commands/init.d.ts.map +1 -0
  16. package/dist/commands/init.js +784 -0
  17. package/dist/commands/init.js.map +1 -0
  18. package/dist/commands/start.d.ts +4 -0
  19. package/dist/commands/start.d.ts.map +1 -0
  20. package/dist/commands/start.js +212 -0
  21. package/dist/commands/start.js.map +1 -0
  22. package/dist/commands/stop.d.ts +3 -0
  23. package/dist/commands/stop.d.ts.map +1 -0
  24. package/dist/commands/stop.js +24 -0
  25. package/dist/commands/stop.js.map +1 -0
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +2 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/utils/env.d.ts +11 -0
  31. package/dist/utils/env.d.ts.map +1 -0
  32. package/dist/utils/env.js +64 -0
  33. package/dist/utils/env.js.map +1 -0
  34. package/dist/utils/logger.d.ts +8 -0
  35. package/dist/utils/logger.d.ts.map +1 -0
  36. package/dist/utils/logger.js +18 -0
  37. package/dist/utils/logger.js.map +1 -0
  38. package/dist/utils/process.d.ts +29 -0
  39. package/dist/utils/process.d.ts.map +1 -0
  40. package/dist/utils/process.js +308 -0
  41. package/dist/utils/process.js.map +1 -0
  42. package/package.json +36 -0
  43. package/src/cli.ts +25 -0
  44. package/src/commands/build.ts +68 -0
  45. package/src/commands/dev.ts +188 -0
  46. package/src/commands/init.ts +826 -0
  47. package/src/commands/start.ts +236 -0
  48. package/src/commands/stop.ts +27 -0
  49. package/src/index.ts +1 -0
  50. package/src/utils/env.ts +70 -0
  51. package/src/utils/logger.ts +21 -0
  52. package/src/utils/process.ts +348 -0
  53. package/tsconfig.json +24 -0
  54. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,826 @@
1
+ import { Command } from 'commander';
2
+ import { logger } from '../utils/logger.js';
3
+ import fs from 'fs-extra';
4
+ import path from 'path';
5
+ import inquirer from 'inquirer';
6
+
7
+ interface InitOptions {
8
+ name?: string;
9
+ config?: 'json' | 'yaml' | 'toml' | 'ts' | 'js';
10
+ packageManager?: 'npm' | 'yarn' | 'pnpm';
11
+ runtime?: 'node' | 'bun';
12
+ yes?: boolean;
13
+ }
14
+
15
+ export const initCommand = new Command('init')
16
+ .description('初始化新的Zhin机器人项目')
17
+ .argument('[project-name]', '项目名称')
18
+ .option('-c, --config <format>', '配置文件格式 (json|yaml|toml|ts|js)', 'js')
19
+ .option('-p, --package-manager <manager>', '包管理器 (npm|yarn|pnpm)', 'pnpm')
20
+ .option('-r, --runtime <runtime>', '运行时 (node|bun)', 'bun')
21
+ .option('-y, --yes', '自动回答所有问题')
22
+ .action(async (projectName: string, options: InitOptions) => {
23
+ if(options.yes) {
24
+ options.config = 'js';
25
+ options.packageManager = 'pnpm';
26
+ options.runtime = 'bun';
27
+ }
28
+ try {
29
+ let name = projectName;
30
+
31
+ if (!name) {
32
+ const {projectName:inputName} = await inquirer.prompt([
33
+ {
34
+ type: 'input',
35
+ name: 'projectName',
36
+ message: '请输入项目名称:',
37
+ default: 'my-zhin-bot',
38
+ validate: (input: string) => {
39
+ if (!input.trim()) {
40
+ return '项目名称不能为空';
41
+ }
42
+ if (!/^[a-zA-Z0-9-_]+$/.test(input)) {
43
+ return '项目名称只能包含字母、数字、横线和下划线';
44
+ }
45
+ return true;
46
+ }
47
+ }
48
+ ]);
49
+ name = inputName;
50
+ }
51
+ if(!options.runtime) {
52
+ const {runtime:inputRuntime} = await inquirer.prompt([
53
+ {
54
+ type: 'list',
55
+ name: 'runtime',
56
+ message: '选择运行时:',
57
+ choices: [
58
+ { name: 'Bun (推荐)', value: 'bun' },
59
+ { name: 'Node.js', value: 'node' }
60
+ ],
61
+ default: options.runtime || 'bun'
62
+ },
63
+ ])
64
+ options.runtime=inputRuntime;
65
+ }
66
+ if(!options.packageManager) {
67
+ const {packageManager:inputPackageManager} = await inquirer.prompt([
68
+ {
69
+ type: 'list',
70
+ name: 'packageManager',
71
+ message: '选择包管理器:',
72
+ choices: [
73
+ { name: 'pnpm (推荐)', value: 'pnpm' },
74
+ { name: 'npm', value: 'npm' },
75
+ { name: 'yarn', value: 'yarn' }
76
+ ],
77
+ default: options.packageManager || 'pnpm'
78
+ }
79
+ ])
80
+ options.packageManager=inputPackageManager;
81
+ }
82
+ if(!options.config) {
83
+ const {configFormat:inputConfigFormat} = await inquirer.prompt([
84
+ {
85
+ type: 'list',
86
+ name: 'configFormat',
87
+ message: '选择配置文件格式:',
88
+ choices: [
89
+ { name: 'JavaScript (推荐)', value: 'js' },
90
+ { name: 'TypeScript', value: 'ts' },
91
+ { name: 'YAML', value: 'yaml' },
92
+ { name: 'JSON', value: 'json' },
93
+ { name: 'TOML', value: 'toml' }
94
+ ],
95
+ default: options.config || 'js'
96
+ }
97
+ ]);
98
+ options.config=inputConfigFormat;
99
+ }
100
+
101
+ const projectPath = path.resolve(process.cwd(), name);
102
+ const realName=path.basename(projectPath)
103
+ // 检查目录是否已存在
104
+ if (fs.existsSync(projectPath)) {
105
+ logger.error(`目录 ${realName} 已存在`);
106
+ process.exit(1);
107
+ }
108
+
109
+ logger.info(`正在创建项目 ${realName}...`);
110
+
111
+ // 创建项目目录结构
112
+ await createProjectStructure(projectPath, realName, options);
113
+
114
+ logger.success(`项目 ${realName} 创建成功!`);
115
+ logger.log('');
116
+ logger.log('🎉 下一步操作:');
117
+ logger.log(` cd ${realName}`);
118
+
119
+ const installCommand = getInstallCommand(options.packageManager!);
120
+ logger.log(` ${installCommand} # 安装依赖`);
121
+
122
+ logger.log(` npm run dev # 开发环境启动`);
123
+ logger.log(` npm run build # 构建项目`);
124
+ logger.log(` npm run start # 生产环境前台启动`);
125
+ logger.log(` npm run daemon # 生产环境后台启动`);
126
+ logger.log(` npm run stop # 停止机器人`);
127
+
128
+ logger.log('');
129
+ logger.log('📚 相关文档:');
130
+ logger.log(' https://github.com/zhinjs/zhin - 项目主页');
131
+ logger.log(' https://zhinjs.github.io - 官方文档');
132
+
133
+ } catch (error) {
134
+ logger.error(`创建项目失败: ${error}`);
135
+ process.exit(1);
136
+ }
137
+ });
138
+
139
+ function getInstallCommand(packageManager: string): string {
140
+ switch (packageManager) {
141
+ case 'yarn': return 'yarn install';
142
+ case 'pnpm': return 'pnpm install';
143
+ default: return 'npm install';
144
+ }
145
+ }
146
+
147
+ async function createProjectStructure(projectPath: string, projectName: string, options: InitOptions) {
148
+ // 创建目录结构
149
+ await fs.ensureDir(projectPath);
150
+ await fs.ensureDir(path.join(projectPath, 'src'));
151
+ await fs.ensureDir(path.join(projectPath, 'src', 'plugins'));
152
+ await fs.ensureDir(path.join(projectPath, 'dist'));
153
+ await fs.ensureDir(path.join(projectPath, 'data'));
154
+
155
+ // 创建 package.json
156
+ const packageJson = {
157
+ name: projectName,
158
+ version: '0.1.0',
159
+ description: `${projectName} 机器人`,
160
+ type: 'module',
161
+ main: 'src/index.ts',
162
+ scripts: {
163
+ dev: options.runtime === 'bun' ? 'zhin dev --bun' : 'zhin dev',
164
+ start: options.runtime === 'bun' ? 'zhin start --bun' : 'zhin start',
165
+ daemon: options.runtime === 'bun' ? 'zhin start --bun --daemon' : 'zhin start --daemon',
166
+ build: 'zhin build',
167
+ stop: 'zhin stop'
168
+ },
169
+ dependencies: {
170
+ '@zhin.js/core': 'workspace:*'
171
+ },
172
+ devDependencies: {
173
+ '@zhin.js/cli': 'workspace:*',
174
+ 'typescript': '^5.0.0',
175
+ ...(options.runtime === 'node' && { 'tsx': '^4.0.0' })
176
+ },
177
+ engines: {
178
+ node: '>=18.0.0'
179
+ }
180
+ };
181
+
182
+ await fs.writeJson(path.join(projectPath, 'package.json'), packageJson, { spaces: 2 });
183
+
184
+ // 创建 tsconfig.json
185
+ const tsConfig = {
186
+ compilerOptions: {
187
+ target: 'ES2022',
188
+ module: 'ESNext',
189
+ moduleResolution: 'bundler',
190
+ outDir: './dist',
191
+ strict: true,
192
+ esModuleInterop: true,
193
+ skipLibCheck: true,
194
+ forceConsistentCasingInFileNames: true,
195
+ resolveJsonModule: true,
196
+ isolatedModules: true,
197
+ allowSyntheticDefaultImports: true,
198
+ experimentalDecorators: true,
199
+ emitDecoratorMetadata: true,
200
+ declaration: false,
201
+ sourceMap: true,
202
+ baseUrl: './src',
203
+ paths: {
204
+ '@zhin.js/core': ['../../packages/core/src/index.ts'],
205
+ '@zhin.js/core/*': ['../../packages/core/src/*']
206
+ }
207
+ },
208
+ include: ['src/**/*'],
209
+ exclude: ['dist', 'node_modules']
210
+ };
211
+
212
+ await fs.writeJson(path.join(projectPath, 'tsconfig.json'), tsConfig, { spaces: 2 });
213
+
214
+ // 创建配置文件
215
+ await createConfigFile(projectPath, options.config!);
216
+
217
+ // 创建主入口文件
218
+ const indexContent = `import { createApp } from '@zhin.js/core';
219
+
220
+ // 启动机器人
221
+ async function main() {
222
+ try {
223
+ // 异步创建机器人实例 (自动从配置文件加载)
224
+ const app = await createApp();
225
+ await app.start();
226
+
227
+ // 优雅退出处理
228
+ const shutdown = async (signal: string) => {
229
+ await app.stop();
230
+ process.exit(0);
231
+ };
232
+
233
+ process.on('SIGINT', shutdown);
234
+ process.on('SIGTERM', shutdown);
235
+ } catch (error) {
236
+ console.error('机器人启动失败:', error);
237
+ process.exit(1);
238
+ }
239
+ }
240
+
241
+ // 启动应用
242
+ main().catch(console.error);
243
+ `;
244
+
245
+ await fs.writeFile(path.join(projectPath, 'src', 'index.ts'), indexContent);
246
+
247
+ // 创建示例插件
248
+ const pluginContent = `import {
249
+ onDispose,
250
+ addMiddleware, useContext, sendMessage, beforeSend, onGroupMessage,
251
+ } from '@zhin.js/core';
252
+ import * as process from "node:process";
253
+
254
+ onDispose(async ()=>{
255
+ console.log('插件已销毁')
256
+ })
257
+
258
+ addMiddleware(async (message, next)=>{ // 添加中间件到插件
259
+ // 在这里处理消息
260
+ return next()
261
+ })
262
+
263
+ let hasChanged=false
264
+ beforeSend((options)=>{
265
+ if(!hasChanged){
266
+ options.content='bar'
267
+ hasChanged=true
268
+ }
269
+ return options
270
+ })
271
+
272
+ onGroupMessage((m)=>{
273
+ if(m.channel.id==='629336764'){
274
+ m.reply('hello')
275
+ }
276
+ })
277
+
278
+ // 依赖process上下文
279
+ useContext('process',()=>{
280
+ sendMessage({
281
+ context:'process',
282
+ bot:\`\${process.pid}\`,
283
+ id:process.title,
284
+ type:'private',
285
+ content:'foo'
286
+ })
287
+ })
288
+ `;
289
+
290
+ await fs.writeFile(path.join(projectPath, 'src', 'plugins', 'test-plugin.ts'), pluginContent);
291
+
292
+ // 创建 .gitignore
293
+ const gitignoreContent = `# Dependencies
294
+ node_modules/
295
+
296
+ # Production builds
297
+ dist/
298
+
299
+ # Environment variables
300
+ .env
301
+ .env.local
302
+ .env.development
303
+ .env.production
304
+
305
+ # IDE
306
+ .vscode/
307
+ .idea/
308
+
309
+ # OS
310
+ .DS_Store
311
+ Thumbs.db
312
+
313
+ # Logs
314
+ *.log
315
+ npm-debug.log*
316
+ yarn-debug.log*
317
+ yarn-error.log*
318
+ pnpm-debug.log*
319
+
320
+ # PID files
321
+ .zhin.pid
322
+ .zhin-dev.pid
323
+
324
+ # Runtime data
325
+ pids
326
+ *.pid
327
+ *.seed
328
+ *.pid.lock
329
+
330
+ # Coverage directory used by tools like istanbul
331
+ coverage/
332
+ *.lcov
333
+
334
+ # nyc test coverage
335
+ .nyc_output
336
+
337
+ # Dependency directories
338
+ jspm_packages/
339
+
340
+ # Optional npm cache directory
341
+ .npm
342
+
343
+ # Optional eslint cache
344
+ .eslintcache
345
+
346
+ # Microbundle cache
347
+ .rpt2_cache/
348
+ .rts2_cache_cjs/
349
+ .rts2_cache_es/
350
+ .rts2_cache_umd/
351
+
352
+ # Optional REPL history
353
+ .node_repl_history
354
+
355
+ # Output of 'npm pack'
356
+ *.tgz
357
+
358
+ # Yarn Integrity file
359
+ .yarn-integrity
360
+
361
+ # parcel-bundler cache (https://parceljs.org/)
362
+ .cache
363
+ .parcel-cache
364
+
365
+ # Next.js build output
366
+ .next
367
+
368
+ # Nuxt.js build / generate output
369
+ .nuxt
370
+ dist
371
+
372
+ # Gatsby files
373
+ .cache/
374
+ public
375
+
376
+ # Storybook build outputs
377
+ .out
378
+ .storybook-out
379
+
380
+ # Temporary folders
381
+ tmp/
382
+ temp/
383
+ `;
384
+
385
+ await fs.writeFile(path.join(projectPath, '.gitignore'), gitignoreContent);
386
+
387
+ // 创建 README.md
388
+ const readmeContent = `# ${projectName}
389
+
390
+ 使用 Zhin 框架创建的机器人项目。
391
+
392
+ ## 🚀 快速开始
393
+
394
+ ### 安装依赖
395
+
396
+ \`\`\`bash
397
+ ${getInstallCommand(options.packageManager!)}
398
+ \`\`\`
399
+
400
+ ### 开发环境
401
+
402
+ \`\`\`bash
403
+ npm run dev
404
+ \`\`\`
405
+
406
+ ### 生产环境
407
+
408
+ \`\`\`bash
409
+ # 构建项目
410
+ npm run build
411
+
412
+ # 前台启动
413
+ npm run start
414
+
415
+ # 后台启动
416
+ npm run daemon
417
+ \`\`\`
418
+
419
+ ### 停止机器人
420
+
421
+ \`\`\`bash
422
+ npm run stop
423
+ \`\`\`
424
+
425
+ ## 📁 项目结构
426
+
427
+ \`\`\`
428
+ ${projectName}/
429
+ ├── src/
430
+ │ ├── index.ts # 主入口文件
431
+ │ └── plugins/ # 插件目录
432
+ │ └── test-plugin.ts # 示例插件
433
+ ├── dist/ # 构建输出目录
434
+ ├── data/ # 数据目录
435
+ ├── zhin.config.${options.config} # 配置文件
436
+ ├── package.json # 项目配置
437
+ └── tsconfig.json # TypeScript配置
438
+ \`\`\`
439
+
440
+ ## ⚙️ 配置
441
+
442
+ ### 机器人配置
443
+
444
+ 编辑 \`zhin.config.${options.config}\` 来配置你的机器人:
445
+
446
+ ${getConfigExample(options.config!)}
447
+
448
+ ## 🔌 插件开发
449
+
450
+ 在 \`src/plugins/\` 目录下创建你的插件文件。参考 \`test-plugin.ts\` 了解插件开发方式。
451
+
452
+ ### 插件示例
453
+
454
+ \`\`\`typescript
455
+ import { usePlugin, useLogger, addCommand } from '@zhin.js/core';
456
+
457
+ const plugin = usePlugin();
458
+ const logger = useLogger();
459
+
460
+ // 添加命令
461
+ addCommand('hello', (message, args) => {
462
+ logger.info('Hello command called:', args);
463
+ });
464
+ \`\`\`
465
+
466
+ ## 📚 相关链接
467
+
468
+ - [Zhin 官方文档](https://zhinjs.github.io)
469
+ - [插件开发指南](https://zhinjs.github.io/plugins)
470
+ - [GitHub 仓库](https://github.com/zhinjs/zhin)
471
+
472
+ ## 🤝 贡献
473
+
474
+ 欢迎提交 Issue 和 Pull Request!
475
+
476
+ ## 📄 许可证
477
+
478
+ MIT License
479
+ `;
480
+
481
+ await fs.writeFile(path.join(projectPath, 'README.md'), readmeContent);
482
+
483
+ // 创建 pnpm-workspace.yaml (如果使用 pnpm)
484
+ if (options.packageManager === 'pnpm') {
485
+ const workspaceContent = `packages:
486
+ - '.'
487
+ `;
488
+ await fs.writeFile(path.join(projectPath, 'pnpm-workspace.yaml'), workspaceContent);
489
+ }
490
+ }
491
+
492
+ async function createConfigFile(projectPath: string, format: string) {
493
+ const configContent = getConfigContent(format);
494
+ let fileName: string;
495
+
496
+ switch (format) {
497
+ case 'ts':
498
+ fileName = 'zhin.config.ts';
499
+ break;
500
+ case 'js':
501
+ fileName = 'zhin.config.js';
502
+ break;
503
+ default:
504
+ fileName = `zhin.config.${format}`;
505
+ }
506
+
507
+ await fs.writeFile(path.join(projectPath, fileName), configContent);
508
+ }
509
+
510
+ function getConfigContent(format: string): string {
511
+ switch (format) {
512
+ case 'json':
513
+ return JSON.stringify({
514
+ bots: [
515
+ {
516
+ name: `${process.pid}`,
517
+ context: 'process'
518
+ },
519
+ {
520
+ name: '1689919782',
521
+ context: 'icqq',
522
+ log_level: 'off',
523
+ platform: 4
524
+ }
525
+ ],
526
+ plugin_dirs: [
527
+ './src/plugins',
528
+ 'node_modules'
529
+ ],
530
+ plugins: [
531
+ 'icqq',
532
+ 'process',
533
+ 'test-plugin'
534
+ ],
535
+ debug: false
536
+ }, null, 2);
537
+
538
+ case 'yaml':
539
+ return `# Zhin Bot 配置文件
540
+
541
+ # 机器人配置
542
+ bots:
543
+ - name: \${process.pid}
544
+ context: process
545
+ - name: '1689919782'
546
+ context: icqq
547
+ log_level: off
548
+ platform: 4
549
+
550
+ # 插件目录
551
+ plugin_dirs:
552
+ - ./src/plugins
553
+ - node_modules
554
+
555
+ # 要加载的插件列表
556
+ plugins:
557
+ - icqq
558
+ - process
559
+ - test-plugin
560
+
561
+ # 调试模式
562
+ debug: false
563
+ `;
564
+
565
+ case 'toml':
566
+ return `# Zhin Bot 配置文件
567
+
568
+ # 机器人配置
569
+ [[bots]]
570
+ name = "\${process.pid}"
571
+ context = "process"
572
+
573
+ [[bots]]
574
+ name = "1689919782"
575
+ context = "icqq"
576
+ log_level = "off"
577
+ platform = 4
578
+
579
+ # 插件目录
580
+ plugin_dirs = ["./src/plugins", "node_modules"]
581
+
582
+ # 要加载的插件列表
583
+ plugins = ["icqq", "process", "test-plugin"]
584
+
585
+ # 调试模式
586
+ debug = false
587
+ `;
588
+
589
+ case 'ts':
590
+ return `import { defineConfig } from '@zhin.js/core';
591
+
592
+ export default defineConfig(async (env)=>{
593
+ return {
594
+ // 机器人配置
595
+ bots: [
596
+ {
597
+ name: \`\${process.pid}\`,
598
+ context: 'process'
599
+ },
600
+ {
601
+ name: '1689919782',
602
+ context: 'icqq',
603
+ log_level: 'off',
604
+ platform: 4
605
+ }
606
+ ],
607
+ // 插件目录
608
+ plugin_dirs: [
609
+ env.PLUGIN_DIR || './src/plugins',
610
+ 'node_modules'
611
+ ],
612
+ // 要加载的插件列表
613
+ plugins: [
614
+ 'icqq',
615
+ 'process',
616
+ 'test-plugin'
617
+ ],
618
+
619
+ // 调试模式
620
+ debug: env.DEBUG === 'true'
621
+ }
622
+ })
623
+ `;
624
+
625
+ case 'js':
626
+ return `import { defineConfig } from '@zhin.js/core';
627
+
628
+ export default defineConfig(async (env)=>{
629
+ return {
630
+ // 机器人配置
631
+ bots: [
632
+ {
633
+ name: \`\${process.pid}\`,
634
+ context: 'process'
635
+ },
636
+ {
637
+ name: '1689919782',
638
+ context: 'icqq',
639
+ log_level: 'off',
640
+ platform: 4
641
+ }
642
+ ],
643
+ // 插件目录
644
+ plugin_dirs: [
645
+ env.PLUGIN_DIR || './src/plugins',
646
+ 'node_modules'
647
+ ],
648
+ // 要加载的插件列表
649
+ plugins: [
650
+ 'icqq',
651
+ 'process',
652
+ 'test-plugin'
653
+ ],
654
+
655
+ // 调试模式
656
+ debug: env.DEBUG === 'true'
657
+ }
658
+ })
659
+ `;
660
+
661
+ default:
662
+ throw new Error(`不支持的配置格式: ${format}`);
663
+ }
664
+ }
665
+
666
+ function getConfigExample(format: string): string {
667
+ switch (format) {
668
+ case 'json':
669
+ return `\`\`\`json
670
+ {
671
+ "bots": [
672
+ {
673
+ "name": "\${process.pid}",
674
+ "context": "process"
675
+ },
676
+ {
677
+ "name": "1689919782",
678
+ "context": "icqq",
679
+ "log_level": "off",
680
+ "platform": 4
681
+ }
682
+ ],
683
+ "plugin_dirs": [
684
+ "./src/plugins",
685
+ "node_modules"
686
+ ],
687
+ "plugins": [
688
+ "icqq",
689
+ "process",
690
+ "test-plugin"
691
+ ],
692
+ "debug": false
693
+ }
694
+ \`\`\`
695
+ `;
696
+ case 'yaml':
697
+ return `\`\`\`yaml
698
+ # Zhin Bot 配置文件
699
+
700
+ # 机器人配置
701
+ bots:
702
+ - name: \${process.pid}
703
+ context: process
704
+ - name: '1689919782'
705
+ context: icqq
706
+ log_level: off
707
+ platform: 4
708
+
709
+ # 插件目录
710
+ plugin_dirs:
711
+ - ./src/plugins
712
+ - node_modules
713
+
714
+ # 要加载的插件列表
715
+ plugins:
716
+ - icqq
717
+ - process
718
+ - test-plugin
719
+
720
+ # 调试模式
721
+ debug: false
722
+ \`\`\`
723
+ `;
724
+ case 'toml':
725
+ return `\`\`\`toml
726
+ # Zhin Bot 配置文件
727
+
728
+ # 机器人配置
729
+ [[bots]]
730
+ name = "\${process.pid}"
731
+ context = "process"
732
+
733
+ [[bots]]
734
+ name = "1689919782"
735
+ context = "icqq"
736
+ log_level = "off"
737
+ platform = 4
738
+
739
+ # 插件目录
740
+ plugin_dirs = ["./src/plugins", "node_modules"]
741
+
742
+ # 要加载的插件列表
743
+ plugins = ["icqq", "process", "test-plugin"]
744
+
745
+ # 调试模式
746
+ debug = false
747
+ \`\`\`
748
+ `;
749
+ case 'ts':
750
+ return `\`\`\`typescript
751
+ import { defineConfig } from '@zhin.js/core';
752
+
753
+ export default defineConfig(async (env)=>{
754
+ return {
755
+ // 机器人配置
756
+ bots: [
757
+ {
758
+ name: \`\${process.pid}\`,
759
+ context: 'process'
760
+ },
761
+ {
762
+ name: '1689919782',
763
+ context: 'icqq',
764
+ log_level: 'off',
765
+ platform: 4
766
+ }
767
+ ],
768
+ // 插件目录
769
+ plugin_dirs: [
770
+ env.PLUGIN_DIR || './src/plugins',
771
+ 'node_modules'
772
+ ],
773
+ // 要加载的插件列表
774
+ plugins: [
775
+ 'icqq',
776
+ 'process',
777
+ 'test-plugin'
778
+ ],
779
+
780
+ // 调试模式
781
+ debug: env.DEBUG === 'true'
782
+ }
783
+ })
784
+ \`\`\`
785
+ `;
786
+ case 'js':
787
+ return `\`\`\`javascript
788
+ import { defineConfig } from '@zhin.js/core';
789
+
790
+ export default defineConfig(async (env)=>{
791
+ return {
792
+ // 机器人配置
793
+ bots: [
794
+ {
795
+ name: \`\${process.pid}\`,
796
+ context: 'process'
797
+ },
798
+ {
799
+ name: '1689919782',
800
+ context: 'icqq',
801
+ log_level: 'off',
802
+ platform: 4
803
+ }
804
+ ],
805
+ // 插件目录
806
+ plugin_dirs: [
807
+ env.PLUGIN_DIR || './src/plugins',
808
+ 'node_modules'
809
+ ],
810
+ // 要加载的插件列表
811
+ plugins: [
812
+ 'icqq',
813
+ 'process',
814
+ 'test-plugin'
815
+ ],
816
+
817
+ // 调试模式
818
+ debug: env.DEBUG === 'true'
819
+ }
820
+ })
821
+ \`\`\`
822
+ `;
823
+ default:
824
+ throw new Error(`不支持的配置格式: ${format}`);
825
+ }
826
+ }