1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | Object.defineProperty(exports, "__esModule", { value: true });
|
23 |
|
24 | require('dotenv').config();
|
25 | const config_1 = require("../src/config");
|
26 | const io_client_1 = require("../src/io-client");
|
27 | const wechaty_1 = require("../src/wechaty");
|
28 | const welcome = `
|
29 | | __ __ _ _
|
30 | | \\ \\ / /__ ___| |__ __ _| |_ _ _
|
31 | | \\ \\ /\\ / / _ \\/ __| '_ \\ / _\` | __| | | |
|
32 | | \\ V V / __/ (__| | | | (_| | |_| |_| |
|
33 | | \\_/\\_/ \\___|\\___|_| |_|\\__,_|\\__|\\__, |
|
34 | | |___/
|
35 |
|
36 | =============== Powered by Wechaty ===============
|
37 | -------- https://www.chatie.io --------
|
38 |
|
39 | My super power: download cloud bot from www.chatie.io
|
40 |
|
41 | __________________________________________________
|
42 |
|
43 | `;
|
44 | async function main() {
|
45 | const token = config_1.config.token;
|
46 | if (!token) {
|
47 | throw new Error('token not found: please set WECHATY_TOKEN in environment before run io-client');
|
48 | }
|
49 | console.info(welcome);
|
50 | config_1.log.info('Client', 'Starting for WECHATY_TOKEN: %s', token);
|
51 | const wechaty = new wechaty_1.Wechaty({ name: token });
|
52 | let port;
|
53 | if (process.env['WECHATY_HOSTIE_PORT']) {
|
54 | |
55 |
|
56 |
|
57 | config_1.log.warn('Wechaty', [
|
58 | '',
|
59 | 'WECHATY_HOSTIE_PORT is deprecated.',
|
60 | 'Use WECHATY_PUPPET_SERVER_PORT instead.',
|
61 | 'See: https://github.com/wechaty/wechaty/issues/2122',
|
62 | ].join(' '));
|
63 | port = parseInt(process.env['WECHATY_HOSTIE_PORT']);
|
64 | }
|
65 | else if (process.env['WECHATY_PUPPET_SERVER_PORT']) {
|
66 | port = parseInt(process.env['WECHATY_PUPPET_SERVER_PORT']);
|
67 | }
|
68 | const options = {
|
69 | token,
|
70 | wechaty,
|
71 | };
|
72 | if (port) {
|
73 | options.port = port;
|
74 | }
|
75 | const client = new io_client_1.IoClient(options);
|
76 | client.start()
|
77 | .catch(onError.bind(client));
|
78 | }
|
79 | async function onError(e) {
|
80 | config_1.log.error('Client', 'start() fail: %s', e);
|
81 | await this.quit();
|
82 | process.exit(-1);
|
83 | }
|
84 | main()
|
85 | .catch(console.error);
|
86 |
|
\ | No newline at end of file |