1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
24 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
25 | };
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | exports.config = exports.VERSION = exports.looseInstanceOfFileBox = exports.Raven = exports.MemoryCard = exports.FileBox = exports.log = exports.isProduction = exports.qrcodeValueToImageUrl = exports.AT_SEPARATOR_REGEX = exports.FOUR_PER_EM_SPACE = exports.qrCodeForChatie = exports.CHATIE_OFFICIAL_ACCOUNT_ID = exports.Config = void 0;
|
28 | const os_1 = __importDefault(require("os"));
|
29 | const raven_1 = __importDefault(require("raven"));
|
30 | exports.Raven = raven_1.default;
|
31 | const read_pkg_up_1 = __importDefault(require("read-pkg-up"));
|
32 | const wechaty_puppet_1 = require("wechaty-puppet");
|
33 | Object.defineProperty(exports, "FileBox", { enumerable: true, get: function () { return wechaty_puppet_1.FileBox; } });
|
34 | Object.defineProperty(exports, "MemoryCard", { enumerable: true, get: function () { return wechaty_puppet_1.MemoryCard; } });
|
35 | Object.defineProperty(exports, "log", { enumerable: true, get: function () { return wechaty_puppet_1.log; } });
|
36 | const mod_1 = require("./helper-functions/mod");
|
37 | const puppet_config_1 = require("./puppet-config");
|
38 | const version_1 = require("./version");
|
39 | Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
|
40 | const pkg = read_pkg_up_1.default.sync({ cwd: __dirname }).packageJson;
|
41 |
|
42 |
|
43 |
|
44 | raven_1.default.disableConsoleAlerts();
|
45 | raven_1.default
|
46 | .config(isProduction()
|
47 | && 'https://f6770399ee65459a82af82650231b22c:d8d11b283deb441e807079b8bb2c45cd@sentry.io/179672', {
|
48 | release: version_1.VERSION,
|
49 | tags: {
|
50 | git_commit: version_1.GIT_COMMIT_HASH,
|
51 | platform: process.env['WECHATY_DOCKER']
|
52 | ? 'docker'
|
53 | : os_1.default.platform(),
|
54 | },
|
55 | })
|
56 | .install();
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | if (wechaty_puppet_1.log.level() === 'verbose' || wechaty_puppet_1.log.level() === 'silly') {
|
72 | wechaty_puppet_1.log.info('Config', 'registering process.on("unhandledRejection") for development/debug');
|
73 | |
74 |
|
75 |
|
76 |
|
77 | process.on('unhandledRejection', (reason, promise) => {
|
78 | wechaty_puppet_1.log.error('Config', '###########################');
|
79 | wechaty_puppet_1.log.error('Config', 'unhandledRejection: %s %s', reason.stack || reason, promise);
|
80 | wechaty_puppet_1.log.error('Config', '###########################');
|
81 | promise.catch(err => {
|
82 | wechaty_puppet_1.log.error('Config', 'process.on(unhandledRejection) promise.catch(%s)', err.message);
|
83 | console.error('Config', err);
|
84 | });
|
85 | });
|
86 | process.on('uncaughtException', function (error) {
|
87 | const origin = arguments[1];
|
88 | wechaty_puppet_1.log.error('Config', '###########################');
|
89 | wechaty_puppet_1.log.error('Config', 'uncaughtException: %s %s', error.stack, origin);
|
90 | wechaty_puppet_1.log.error('Config', '###########################');
|
91 | });
|
92 | }
|
93 | const DEFAULT_SETTING = pkg['wechaty'];
|
94 | class Config {
|
95 | constructor() {
|
96 | this.default = DEFAULT_SETTING;
|
97 | this.apihost = process.env['WECHATY_APIHOST'] || DEFAULT_SETTING.DEFAULT_APIHOST;
|
98 | this.serviceIp = process.env['WECHATY_PUPPET_SERVICE_IP'] || '';
|
99 | this.name = process.env['WECHATY_NAME'];
|
100 |
|
101 | this.token = process.env['WECHATY_TOKEN'];
|
102 | this.debug = !!(process.env['WECHATY_DEBUG']);
|
103 | this.httpPort = process.env['PORT']
|
104 | || process.env['WECHATY_PORT']
|
105 | || DEFAULT_SETTING.DEFAULT_PORT;
|
106 | this.docker = !!(process.env['WECHATY_DOCKER']);
|
107 | wechaty_puppet_1.log.verbose('Config', 'constructor()');
|
108 | this.validApiHost(this.apihost);
|
109 | }
|
110 | systemPuppetName() {
|
111 | return (process.env['WECHATY_PUPPET'] || puppet_config_1.PUPPET_NAME_DEFAULT).toLowerCase();
|
112 | }
|
113 | validApiHost(apihost) {
|
114 | if (/^[a-zA-Z0-9.\-_]+:?[0-9]*$/.test(apihost)) {
|
115 | return true;
|
116 | }
|
117 | throw new Error('validApiHost() fail for ' + apihost);
|
118 | }
|
119 | }
|
120 | exports.Config = Config;
|
121 | exports.CHATIE_OFFICIAL_ACCOUNT_ID = 'gh_051c89260e5d';
|
122 | function qrCodeForChatie() {
|
123 | const CHATIE_OFFICIAL_ACCOUNT_QRCODE = 'http://weixin.qq.com/r/qymXj7DEO_1ErfTs93y5';
|
124 | return wechaty_puppet_1.FileBox.fromQRCode(CHATIE_OFFICIAL_ACCOUNT_QRCODE);
|
125 | }
|
126 | exports.qrCodeForChatie = qrCodeForChatie;
|
127 |
|
128 |
|
129 | exports.FOUR_PER_EM_SPACE = String.fromCharCode(0x2005);
|
130 |
|
131 | exports.AT_SEPARATOR_REGEX = /[\u2005\u0020]/;
|
132 | function qrcodeValueToImageUrl(qrcodeValue) {
|
133 | return [
|
134 | 'https://wechaty.js.org/qrcode/',
|
135 | encodeURIComponent(qrcodeValue),
|
136 | ].join('');
|
137 | }
|
138 | exports.qrcodeValueToImageUrl = qrcodeValueToImageUrl;
|
139 | function isProduction() {
|
140 | return process.env['NODE_ENV'] === 'production'
|
141 | || process.env['NODE_ENV'] === 'prod';
|
142 | }
|
143 | exports.isProduction = isProduction;
|
144 | const looseInstanceOfFileBox = mod_1.looseInstanceOfClass(wechaty_puppet_1.FileBox);
|
145 | exports.looseInstanceOfFileBox = looseInstanceOfFileBox;
|
146 | exports.config = new Config();
|
147 |
|
\ | No newline at end of file |