wechaty-web-panel 1.1.9 → 1.1.11

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.
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const aibotk_js_1 = require("../proxy/aibotk.js");
4
+ const mqtt_js_1 = require("../proxy/mqtt.js");
4
5
  /**
5
6
  * 登出事件
6
7
  */
7
8
  async function onLogout(user) {
8
9
  await (0, aibotk_js_1.setQrCode)('qrcode', '6');
9
10
  console.log(`用户${user}已登出`);
11
+ (0, mqtt_js_1.closeMqtt)();
10
12
  }
11
13
  exports.default = onLogout;
12
14
  //# sourceMappingURL=on-logout.js.map
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
6
6
  */
7
7
  exports.packageJson = {
8
8
  "name": "wechaty-web-panel",
9
- "version": "1.1.9",
9
+ "version": "1.1.11",
10
10
  "description": "",
11
11
  "exports": {
12
12
  ".": {
@@ -1,3 +1,4 @@
1
+ export function closeMqtt(): void;
1
2
  declare namespace _default {
2
3
  export { initMqtt };
3
4
  }
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.initMqtt = void 0;
26
+ exports.initMqtt = exports.closeMqtt = void 0;
27
27
  const mqtt = __importStar(require("mqtt"));
28
28
  const configDb_js_1 = require("../db/configDb.js");
29
29
  const index_js_1 = require("../common/index.js");
@@ -31,6 +31,7 @@ const aibotk_js_1 = require("./aibotk.js");
31
31
  const event_dispatch_service_js_1 = require("../service/event-dispatch-service.js");
32
32
  const index_js_2 = require("../task/index.js");
33
33
  const index_js_3 = require("../lib/index.js");
34
+ let mqttclient = null;
34
35
  async function initMqtt(that) {
35
36
  try {
36
37
  await (0, aibotk_js_1.getConfig)(); // 获取配置文件
@@ -39,13 +40,15 @@ async function initMqtt(that) {
39
40
  if (role === 'vip') {
40
41
  const config = await (0, aibotk_js_1.getMqttConfig)();
41
42
  const { host, port, username, password, clientId } = config;
42
- let mqttclient = host
43
- ? mqtt.connect(`${host}:${port}`, {
44
- username: username,
45
- password: password,
46
- clientId: clientId + (0, index_js_3.randomRange)(1, 10000),
47
- })
48
- : null;
43
+ if (!mqttclient) {
44
+ mqttclient = host
45
+ ? mqtt.connect(`${host}:${port}`, {
46
+ username: username,
47
+ password: password,
48
+ clientId: clientId + (0, index_js_3.randomRange)(1, 10000),
49
+ })
50
+ : null;
51
+ }
49
52
  if (mqttclient) {
50
53
  mqttclient.on('connect', function () {
51
54
  console.debug('connect to Wechaty mqtt----------');
@@ -118,6 +121,13 @@ async function initMqtt(that) {
118
121
  }
119
122
  }
120
123
  exports.initMqtt = initMqtt;
124
+ function closeMqtt() {
125
+ if (mqttclient && mqttclient.connected) {
126
+ mqttclient.end();
127
+ mqttclient = null;
128
+ }
129
+ }
130
+ exports.closeMqtt = closeMqtt;
121
131
  exports.default = {
122
132
  initMqtt,
123
133
  };
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
@@ -29,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
6
  exports.getTencentOpenReply = void 0;
30
7
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
31
8
  const configDb_js_1 = require("../db/configDb.js");
32
- const axios = __importStar(require("axios"));
9
+ const axios_1 = __importDefault(require("axios"));
33
10
  async function getSignature(id, encodingAESKey) {
34
11
  const token = jsonwebtoken_1.default.sign({
35
12
  userid: id,
@@ -188,7 +165,7 @@ async function getTencentOpenReply({ msg, id, userInfo }) {
188
165
  signature,
189
166
  query: msg,
190
167
  };
191
- const res = await axios.post(`https://openai.weixin.qq.com/openapi/aibot/${config.tencentToken}`, data, {});
168
+ const res = await axios_1.default.post(`https://openai.weixin.qq.com/openapi/aibot/${config.tencentToken}`, data, {});
192
169
  const resData = res.data;
193
170
  if (!resData.errcode) {
194
171
  let answer = resData.answer; // 存放回答
@@ -175,6 +175,7 @@ async function dispatchEventContent(that, eName, msg, name, id, avatar, room) {
175
175
  case 'updateConfig':
176
176
  await (0, aibotk_js_1.getConfig)();
177
177
  await (0, index_js_2.initTaskLocalSchedule)(that);
178
+ await (0, index_js_2.initTimeSchedule)(that);
178
179
  content = '更新配置成功,请稍等一分钟后生效';
179
180
  break;
180
181
  default:
@@ -1,10 +1,12 @@
1
1
  import { setQrCode } from '../proxy/aibotk.js';
2
+ import { closeMqtt } from '../proxy/mqtt.js';
2
3
  /**
3
4
  * 登出事件
4
5
  */
5
6
  async function onLogout(user) {
6
7
  await setQrCode('qrcode', '6');
7
8
  console.log(`用户${user}已登出`);
9
+ closeMqtt();
8
10
  }
9
11
  export default onLogout;
10
12
  //# sourceMappingURL=on-logout.js.map
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.1.9",
6
+ "version": "1.1.11",
7
7
  "description": "",
8
8
  "exports": {
9
9
  ".": {
@@ -1,3 +1,4 @@
1
+ export function closeMqtt(): void;
1
2
  declare namespace _default {
2
3
  export { initMqtt };
3
4
  }
@@ -5,6 +5,7 @@ import { getConfig, getMqttConfig } from './aibotk.js';
5
5
  import { dispatchEventContent } from '../service/event-dispatch-service.js';
6
6
  import { sendRoomTaskMessage, sendContactTaskMessage } from '../task/index.js';
7
7
  import { randomRange } from '../lib/index.js';
8
+ let mqttclient = null;
8
9
  async function initMqtt(that) {
9
10
  try {
10
11
  await getConfig(); // 获取配置文件
@@ -13,13 +14,15 @@ async function initMqtt(that) {
13
14
  if (role === 'vip') {
14
15
  const config = await getMqttConfig();
15
16
  const { host, port, username, password, clientId } = config;
16
- let mqttclient = host
17
- ? mqtt.connect(`${host}:${port}`, {
18
- username: username,
19
- password: password,
20
- clientId: clientId + randomRange(1, 10000),
21
- })
22
- : null;
17
+ if (!mqttclient) {
18
+ mqttclient = host
19
+ ? mqtt.connect(`${host}:${port}`, {
20
+ username: username,
21
+ password: password,
22
+ clientId: clientId + randomRange(1, 10000),
23
+ })
24
+ : null;
25
+ }
23
26
  if (mqttclient) {
24
27
  mqttclient.on('connect', function () {
25
28
  console.debug('connect to Wechaty mqtt----------');
@@ -91,6 +94,12 @@ async function initMqtt(that) {
91
94
  console.log('mqtt 创建链接失败', e);
92
95
  }
93
96
  }
97
+ export function closeMqtt() {
98
+ if (mqttclient && mqttclient.connected) {
99
+ mqttclient.end();
100
+ mqttclient = null;
101
+ }
102
+ }
94
103
  export { initMqtt };
95
104
  export default {
96
105
  initMqtt,
@@ -1,6 +1,6 @@
1
1
  import jwt from 'jsonwebtoken';
2
2
  import { allConfig } from '../db/configDb.js';
3
- import * as axios from 'axios';
3
+ import axios from 'axios';
4
4
  async function getSignature(id, encodingAESKey) {
5
5
  const token = jwt.sign({
6
6
  userid: id,
@@ -2,7 +2,7 @@ import api from '../proxy/api.js';
2
2
  import { getConfig, getRoomPhotoConfig, getMeiNv, getWordCloudConfig, getWordCloud } from '../proxy/aibotk.js';
3
3
  import { getConstellation, msgArr, getRoomAvatar, getNewsType } from '../lib/index.js';
4
4
  import { generateAvatar, generateRoomImg } from '../puppeteer-paint/lanuch.js';
5
- import { initTaskLocalSchedule } from '../task/index.js';
5
+ import { initTaskLocalSchedule, initTimeSchedule } from "../task/index.js";
6
6
  import { updateContactAndRoom, updateContactOnly, updateRoomOnly } from '../common/index.js';
7
7
  import { chatTencent } from '../proxy/tencent.js';
8
8
  import { getTencentOpenReply } from '../proxy/tencent-open.js';
@@ -169,6 +169,7 @@ async function dispatchEventContent(that, eName, msg, name, id, avatar, room) {
169
169
  case 'updateConfig':
170
170
  await getConfig();
171
171
  await initTaskLocalSchedule(that);
172
+ await initTimeSchedule(that);
172
173
  content = '更新配置成功,请稍等一分钟后生效';
173
174
  break;
174
175
  default:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-web-panel",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {