-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
77 lines (59 loc) · 1.9 KB
/
index.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
import { WechatyBuilder } from 'wechaty';
import { bindListeners, startVcorp } from './src/listeners.js';
import { PuppetPadlocal } from 'wechaty-puppet-padlocal';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import dotenv from 'dotenv';
dotenv.config();
process.on('uncaughtException', (err) => {
console.error('An uncaught exception occurred!');
console.error(err.stack);
});
process.on('unhandledRejection', (err) => {
console.error('An unhandled promise rejection occurred!');
console.error(err);
});
interface CommandLineArgs {
NAME: string;
MODE?: string;
PAD_LOCAL_KEY?: string;
VCORP_AI_KEY?: string;
VCORP_AI_URL?: string;
VEID?: string;
}
// 解析命令行参数
const argv = yargs(hideBin(process.argv)).argv as Partial<CommandLineArgs>;
// 使用命令行参数覆盖 .env 配置
export const NAME = argv.NAME || process.env.NAME;
export const MODE = argv.MODE || process.env.MODE;
const PAD_LOCAL_KEY = argv.PAD_LOCAL_KEY || process.env.PAD_LOCAL_KEY;
export const VCORP_AI_KEY = argv.VCORP_AI_KEY || process.env.VCORP_AI_KEY;
export const VCORP_AI_URL = argv.VCORP_AI_URL || process.env.VCORP_AI_URL;
export const VEID = argv.VEID || process.env.VEID;
console.log("Command line is: ", argv, "VEID:", VEID);
setWindowTitle(NAME!);
if (MODE === 'powerbot') {
console.log("Using padlocal.");
const puppet = new PuppetPadlocal({
token: PAD_LOCAL_KEY,
});
const bot = WechatyBuilder.build({
name: 'chaty-wechat-bot',
puppet,
});
startVcorp();
await bindListeners(bot).start();
}
else {
console.log(NAME + " started using default settings.");
const bot = WechatyBuilder.build();
startVcorp();
await bindListeners(bot).start();
}
function setWindowTitle(title: string) {
if (process.platform === 'win32') {
process.stdout.write('\x1B]0;' + title + '\x07');
} else {
process.stdout.write('\x1B]2;' + title + '\x1B\\');
}
}