wechaty-web-panel 1.6.17 → 1.6.18

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## 更新日志
2
2
 
3
+ ### V1.6.18(2023-08-15)
4
+ 1、优化自定义对话配置
5
+
3
6
  ### V1.6.17(2023-08-12)
4
7
  1、优化换行在windows中的发送
5
8
  2、优化rss内容发送
@@ -57,7 +57,7 @@ class DifyAi {
57
57
  async getReply(content, uid, adminId = '', systemMessage = '') {
58
58
  try {
59
59
  if (!this.difyChat) {
60
- console.log('看到此消息说明已启用dify 对话平台');
60
+ console.log('启用dify对话平台');
61
61
  await this.init();
62
62
  }
63
63
  if (this.config.filter) {
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const gptConfig_js_1 = require("./gptConfig.js");
3
4
  class Config {
4
5
  constructor() {
5
6
  this.apiKey = '';
7
+ this.gptconfig = [];
6
8
  }
7
9
  getApikey() {
8
10
  return this.apiKey;
@@ -10,6 +12,23 @@ class Config {
10
12
  setApikey(val) {
11
13
  this.apiKey = val;
12
14
  }
15
+ getAllGptConfig() {
16
+ return this.gptconfig;
17
+ }
18
+ updateAllGptConfig(list) {
19
+ this.gptconfig = list;
20
+ }
21
+ getGptConfigById(id) {
22
+ return this.gptconfig.find(item => item.id === id);
23
+ }
24
+ updateOneGptConfig(id, info) {
25
+ this.gptconfig = this.gptconfig.map(item => {
26
+ if (item.id === id) {
27
+ return info;
28
+ }
29
+ return item;
30
+ });
31
+ }
13
32
  }
14
33
  if (!global.configHandler) {
15
34
  global.configHandler = new Config();
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
6
6
  */
7
7
  exports.packageJson = {
8
8
  "name": "wechaty-web-panel",
9
- "version": "1.6.17",
9
+ "version": "1.6.18",
10
10
  "description": "智能微秘书插件",
11
11
  "exports": {
12
12
  ".": {
@@ -1,12 +1,15 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getPromotInfo = exports.updateChatRecord = exports.getFireNews = exports.getMaterial = exports.getOne = exports.getMeiNv = exports.getMqttConfig = exports.updatePanelVersion = exports.asyncData = exports.sendRoom = exports.sendFriend = exports.putqn = exports.sendRobotInfo = exports.sendHeartBeat = exports.setQrCode = exports.updateSchedule = exports.setSchedule = exports.getScheduleList = exports.getConfig = exports.getPanelVersion = exports.getRssConfig = exports.getGptConfig = exports.getWordCloud = exports.getWordCloudConfig = exports.getWordCloudRoom = void 0;
4
7
  const superagent_js_1 = require("./superagent.js");
5
8
  const configDb_js_1 = require("../db/configDb.js");
6
9
  const package_json_js_1 = require("../package-json.js");
7
- const gptConfig_js_1 = require("../db/gptConfig.js");
8
10
  const rssConfig_js_1 = require("../db/rssConfig.js");
9
11
  const puppet_type_js_1 = require("../const/puppet-type.js");
12
+ const global_js_1 = __importDefault(require("../db/global.js"));
10
13
  /**
11
14
  * 获取美女图片
12
15
  */
@@ -211,8 +214,7 @@ async function getGptConfig() {
211
214
  let content = await (0, superagent_js_1.aiBotReq)(option);
212
215
  if (content.data) {
213
216
  const list = content.data.map(item => ({ ...item, _id: item.id }));
214
- (0, gptConfig_js_1.resetData)();
215
- await (0, gptConfig_js_1.updateAllGptConfig)(list);
217
+ global_js_1.default.updateAllGptConfig(list);
216
218
  }
217
219
  }
218
220
  catch (error) {
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.dispatchBot = void 0;
4
7
  const chatgpt_js_1 = require("./chatgpt.js");
5
8
  const chatgpt_web_js_1 = require("./chatgpt-web.js");
6
9
  const dify_js_1 = require("./dify.js");
7
- const gptConfig_js_1 = require("../../db/gptConfig.js");
8
10
  const aibotk_js_1 = require("../aibotk.js");
11
+ const global_js_1 = __importDefault(require("../../db/global.js"));
9
12
  /**
10
13
  * 消息转发
11
14
  * @param {botType: 机器人类别, content: 消息内容, uid: 说话的用户id, updateId: 更新的用户id, adminId: 对话实例id,用于分割不同配置, config: 机器人配置}
@@ -14,7 +17,7 @@ const aibotk_js_1 = require("../aibotk.js");
14
17
  async function dispatchBot({ botType, content, uid, adminId, config }) {
15
18
  console.log('进入定制机器人回复');
16
19
  try {
17
- const gptConfig = await (0, gptConfig_js_1.getGptConfigById)(adminId);
20
+ const gptConfig = global_js_1.default.getGptConfigById(adminId);
18
21
  let res, replys;
19
22
  switch (botType) {
20
23
  case 6:
@@ -40,7 +43,7 @@ async function dispatchBot({ botType, content, uid, adminId, config }) {
40
43
  }
41
44
  if (replys.length) {
42
45
  void (0, aibotk_js_1.updateChatRecord)(adminId, gptConfig.usedNum + 1);
43
- void (0, gptConfig_js_1.updateOneGptConfig)(adminId, { ...gptConfig, usedNum: gptConfig.usedNum + 1 });
46
+ global_js_1.default.updateOneGptConfig(adminId, { ...gptConfig, usedNum: gptConfig.usedNum + 1 });
44
47
  }
45
48
  return replys;
46
49
  }
@@ -119,8 +119,9 @@ async function initMqtt(that) {
119
119
  }
120
120
  else if (topic === `aibotk/${userId}/gptconfig`) {
121
121
  await (0, aibotk_js_1.getGptConfig)();
122
+ console.log('更新最新自定义对话配置');
122
123
  if (content.event === 'update' || content.event === 'delete') {
123
- console.log('更新gpt配置');
124
+ console.log('更新自定义对话配置,重置对话');
124
125
  (0, chatgpt_js_1.reset)(content.updateId);
125
126
  (0, chatgpt_web_js_1.reset)(content.updateId);
126
127
  (0, dify_js_1.reset)(content.updateId);
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.filterRoomMsg = exports.filterFriendMsg = void 0;
7
7
  const configDb_js_1 = require("../db/configDb.js");
8
- const gptConfig_js_1 = require("../db/gptConfig.js");
8
+ const global_js_1 = __importDefault(require("../db/global.js"));
9
9
  const msg_filters_js_1 = __importDefault(require("./msg-filters.js"));
10
10
  const WEIXINOFFICIAL = ['朋友推荐消息', '微信支付', '微信运动', '微信团队', 'recommendation message']; // 微信官方账户,针对此账户不做任何回复
11
11
  const DELETEFRIEND = '开启了朋友验证'; // 被人删除后,防止重复回复
@@ -41,7 +41,7 @@ async function getMsgReply(resArray, { that, msg, name, contact, config, avatar,
41
41
  async function filterFriendMsg(that, contact, msg) {
42
42
  try {
43
43
  const config = await (0, configDb_js_1.allConfig)(); // 获取配置信息
44
- const gptConfig = await (0, gptConfig_js_1.getAllGptConfig)(); // 获取gpt配置信息
44
+ const gptConfig = global_js_1.default.getAllGptConfig(); // 获取gpt配置信息
45
45
  const name = contact.name();
46
46
  const id = contact.id;
47
47
  const avatar = await contact.avatar();
@@ -82,7 +82,7 @@ exports.filterFriendMsg = filterFriendMsg;
82
82
  async function filterRoomMsg({ that, msg, name, id, avatar, room, isMention, roomName, roomId }) {
83
83
  try {
84
84
  const config = await (0, configDb_js_1.allConfig)(); // 获取配置信息
85
- const gptConfig = await (0, gptConfig_js_1.getAllGptConfig)(); // 获取gpt配置信息
85
+ const gptConfig = global_js_1.default.getAllGptConfig(); // 获取gpt配置信息
86
86
  const resArray = [
87
87
  { bool: msg === '', method: 'emptyMsg' },
88
88
  { bool: config.callBackEvents && config.callBackEvents.length > 0, method: 'callbackEvent' },
@@ -10,7 +10,7 @@ const index_js_1 = require("../lib/index.js");
10
10
  const index_js_2 = require("../common/index.js");
11
11
  const superagent_js_1 = require("../proxy/superagent.js");
12
12
  const dispatch_js_1 = require("../proxy/bot/dispatch.js");
13
- const gptConfig_js_1 = require("../db/gptConfig.js");
13
+ const global_js_1 = __importDefault(require("../db/global.js"));
14
14
  function emptyMsg({ room, isMention }) {
15
15
  if (room && !isMention)
16
16
  return [];
@@ -290,7 +290,7 @@ async function robotMsg({ msg, name, id, config, isMention, room }) {
290
290
  exports.robotMsg = robotMsg;
291
291
  async function customChat({ msg, name, id, config, isMention, room, roomId, roomName }) {
292
292
  try {
293
- const gptConfigs = await (0, gptConfig_js_1.getAllGptConfig)();
293
+ const gptConfigs = global_js_1.default.getAllGptConfig();
294
294
  if (gptConfigs && gptConfigs.length) {
295
295
  let finalConfig = '';
296
296
  if (room) {
@@ -323,15 +323,24 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
323
323
  if (keyword || !finalConfig?.keywords.length) {
324
324
  msg = keyword ? msg.replace(keyword, '') : msg;
325
325
  if (finalConfig.limitNum > 0 && finalConfig.limitNum <= finalConfig.usedNum) {
326
- return [{ type: 1, content: '聊天次数已用完,请联系管理员充值' }];
326
+ return [{ type: 1, content: finalConfig.rechargeTip || '聊天次数已用完,请联系管理员充值' }];
327
327
  }
328
328
  const msgArr = await (0, dispatch_js_1.dispatchBot)({ botType: finalConfig.robotType, content: msg, uid: id, adminId: finalConfig.id, config: finalConfig.botConfig });
329
- return msgArr;
329
+ if (msgArr.length)
330
+ return msgArr;
331
+ console.log('自定义回复获取内容失败,启用全局配置');
332
+ return [];
330
333
  }
331
334
  }
332
335
  return [];
333
336
  }
334
- return finalConfig.defaultReply ? [{ type: 1, content: finalConfig.defaultReply }] : [];
337
+ else {
338
+ // 如果没有开启对话 也要检测一下是不是需要@ 才返回默认回复
339
+ if ((isRoom && finalConfig.needAt === 1 && isMention) || isRoom & !finalConfig.needAt || !isRoom) {
340
+ return finalConfig.defaultReply ? [{ type: 1, content: finalConfig.defaultReply }] : [{ type: 1, content: '' }];
341
+ }
342
+ return [];
343
+ }
335
344
  }
336
345
  return [];
337
346
  }
@@ -52,7 +52,7 @@ class DifyAi {
52
52
  async getReply(content, uid, adminId = '', systemMessage = '') {
53
53
  try {
54
54
  if (!this.difyChat) {
55
- console.log('看到此消息说明已启用dify 对话平台');
55
+ console.log('启用dify对话平台');
56
56
  await this.init();
57
57
  }
58
58
  if (this.config.filter) {
@@ -1,6 +1,8 @@
1
+ import { getGptConfigById, updateAllGptConfig, updateOneGptConfig } from "./gptConfig.js";
1
2
  class Config {
2
3
  constructor() {
3
4
  this.apiKey = '';
5
+ this.gptconfig = [];
4
6
  }
5
7
  getApikey() {
6
8
  return this.apiKey;
@@ -8,6 +10,23 @@ class Config {
8
10
  setApikey(val) {
9
11
  this.apiKey = val;
10
12
  }
13
+ getAllGptConfig() {
14
+ return this.gptconfig;
15
+ }
16
+ updateAllGptConfig(list) {
17
+ this.gptconfig = list;
18
+ }
19
+ getGptConfigById(id) {
20
+ return this.gptconfig.find(item => item.id === id);
21
+ }
22
+ updateOneGptConfig(id, info) {
23
+ this.gptconfig = this.gptconfig.map(item => {
24
+ if (item.id === id) {
25
+ return info;
26
+ }
27
+ return item;
28
+ });
29
+ }
11
30
  }
12
31
  if (!global.configHandler) {
13
32
  global.configHandler = new Config();
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.6.17",
6
+ "version": "1.6.18",
7
7
  "description": "智能微秘书插件",
8
8
  "exports": {
9
9
  ".": {
@@ -1,9 +1,9 @@
1
1
  import { aiBotReq, req } from './superagent.js';
2
2
  import { updateConfig } from '../db/configDb.js';
3
3
  import { packageJson } from '../package-json.js';
4
- import { updateAllGptConfig, resetData } from "../db/gptConfig.js";
5
4
  import { updateAllRssConfig, resetRssData } from "../db/rssConfig.js";
6
5
  import { getPuppetEol } from "../const/puppet-type.js";
6
+ import globalConfig from "../db/global.js";
7
7
  /**
8
8
  * 获取美女图片
9
9
  */
@@ -201,8 +201,7 @@ export async function getGptConfig() {
201
201
  let content = await aiBotReq(option);
202
202
  if (content.data) {
203
203
  const list = content.data.map(item => ({ ...item, _id: item.id }));
204
- resetData();
205
- await updateAllGptConfig(list);
204
+ globalConfig.updateAllGptConfig(list);
206
205
  }
207
206
  }
208
207
  catch (error) {
@@ -1,8 +1,8 @@
1
1
  import { getChatGPTReply } from "./chatgpt.js";
2
2
  import { getChatGPTWebReply } from "./chatgpt-web.js";
3
3
  import { getDifyAiReply } from "./dify.js";
4
- import { updateOneGptConfig, getGptConfigById } from "../../db/gptConfig.js";
5
4
  import { updateChatRecord } from "../aibotk.js";
5
+ import globalConfig from '../../db/global.js';
6
6
  /**
7
7
  * 消息转发
8
8
  * @param {botType: 机器人类别, content: 消息内容, uid: 说话的用户id, updateId: 更新的用户id, adminId: 对话实例id,用于分割不同配置, config: 机器人配置}
@@ -11,7 +11,7 @@ import { updateChatRecord } from "../aibotk.js";
11
11
  export async function dispatchBot({ botType, content, uid, adminId, config }) {
12
12
  console.log('进入定制机器人回复');
13
13
  try {
14
- const gptConfig = await getGptConfigById(adminId);
14
+ const gptConfig = globalConfig.getGptConfigById(adminId);
15
15
  let res, replys;
16
16
  switch (botType) {
17
17
  case 6:
@@ -37,7 +37,7 @@ export async function dispatchBot({ botType, content, uid, adminId, config }) {
37
37
  }
38
38
  if (replys.length) {
39
39
  void updateChatRecord(adminId, gptConfig.usedNum + 1);
40
- void updateOneGptConfig(adminId, { ...gptConfig, usedNum: gptConfig.usedNum + 1 });
40
+ globalConfig.updateOneGptConfig(adminId, { ...gptConfig, usedNum: gptConfig.usedNum + 1 });
41
41
  }
42
42
  return replys;
43
43
  }
@@ -93,8 +93,9 @@ async function initMqtt(that) {
93
93
  }
94
94
  else if (topic === `aibotk/${userId}/gptconfig`) {
95
95
  await getGptConfig();
96
+ console.log('更新最新自定义对话配置');
96
97
  if (content.event === 'update' || content.event === 'delete') {
97
- console.log('更新gpt配置');
98
+ console.log('更新自定义对话配置,重置对话');
98
99
  reset(content.updateId);
99
100
  webReset(content.updateId);
100
101
  difyReset(content.updateId);
@@ -1,5 +1,5 @@
1
1
  import { allConfig } from '../db/configDb.js';
2
- import { getAllGptConfig } from '../db/gptConfig.js';
2
+ import globalConfig from '../db/global.js';
3
3
  import msgFilter from './msg-filters.js';
4
4
  const WEIXINOFFICIAL = ['朋友推荐消息', '微信支付', '微信运动', '微信团队', 'recommendation message']; // 微信官方账户,针对此账户不做任何回复
5
5
  const DELETEFRIEND = '开启了朋友验证'; // 被人删除后,防止重复回复
@@ -35,7 +35,7 @@ async function getMsgReply(resArray, { that, msg, name, contact, config, avatar,
35
35
  async function filterFriendMsg(that, contact, msg) {
36
36
  try {
37
37
  const config = await allConfig(); // 获取配置信息
38
- const gptConfig = await getAllGptConfig(); // 获取gpt配置信息
38
+ const gptConfig = globalConfig.getAllGptConfig(); // 获取gpt配置信息
39
39
  const name = contact.name();
40
40
  const id = contact.id;
41
41
  const avatar = await contact.avatar();
@@ -75,7 +75,7 @@ async function filterFriendMsg(that, contact, msg) {
75
75
  async function filterRoomMsg({ that, msg, name, id, avatar, room, isMention, roomName, roomId }) {
76
76
  try {
77
77
  const config = await allConfig(); // 获取配置信息
78
- const gptConfig = await getAllGptConfig(); // 获取gpt配置信息
78
+ const gptConfig = globalConfig.getAllGptConfig(); // 获取gpt配置信息
79
79
  const resArray = [
80
80
  { bool: msg === '', method: 'emptyMsg' },
81
81
  { bool: config.callBackEvents && config.callBackEvents.length > 0, method: 'callbackEvent' },
@@ -4,7 +4,7 @@ import { contentDistinguish, setLocalSchedule, isRealDate } from '../lib/index.j
4
4
  import { addRoom } from '../common/index.js';
5
5
  import { service, callbackAibotApi } from '../proxy/superagent.js';
6
6
  import { dispatchBot } from '../proxy/bot/dispatch.js';
7
- import { getAllGptConfig } from "../db/gptConfig.js";
7
+ import globalConfig from "../db/global.js";
8
8
  function emptyMsg({ room, isMention }) {
9
9
  if (room && !isMention)
10
10
  return [];
@@ -274,7 +274,7 @@ async function robotMsg({ msg, name, id, config, isMention, room }) {
274
274
  }
275
275
  async function customChat({ msg, name, id, config, isMention, room, roomId, roomName }) {
276
276
  try {
277
- const gptConfigs = await getAllGptConfig();
277
+ const gptConfigs = globalConfig.getAllGptConfig();
278
278
  if (gptConfigs && gptConfigs.length) {
279
279
  let finalConfig = '';
280
280
  if (room) {
@@ -307,15 +307,24 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
307
307
  if (keyword || !finalConfig?.keywords.length) {
308
308
  msg = keyword ? msg.replace(keyword, '') : msg;
309
309
  if (finalConfig.limitNum > 0 && finalConfig.limitNum <= finalConfig.usedNum) {
310
- return [{ type: 1, content: '聊天次数已用完,请联系管理员充值' }];
310
+ return [{ type: 1, content: finalConfig.rechargeTip || '聊天次数已用完,请联系管理员充值' }];
311
311
  }
312
312
  const msgArr = await dispatchBot({ botType: finalConfig.robotType, content: msg, uid: id, adminId: finalConfig.id, config: finalConfig.botConfig });
313
- return msgArr;
313
+ if (msgArr.length)
314
+ return msgArr;
315
+ console.log('自定义回复获取内容失败,启用全局配置');
316
+ return [];
314
317
  }
315
318
  }
316
319
  return [];
317
320
  }
318
- return finalConfig.defaultReply ? [{ type: 1, content: finalConfig.defaultReply }] : [];
321
+ else {
322
+ // 如果没有开启对话 也要检测一下是不是需要@ 才返回默认回复
323
+ if ((isRoom && finalConfig.needAt === 1 && isMention) || isRoom & !finalConfig.needAt || !isRoom) {
324
+ return finalConfig.defaultReply ? [{ type: 1, content: finalConfig.defaultReply }] : [{ type: 1, content: '' }];
325
+ }
326
+ return [];
327
+ }
319
328
  }
320
329
  return [];
321
330
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-web-panel",
3
- "version": "1.6.17",
3
+ "version": "1.6.18",
4
4
  "description": "智能微秘书插件",
5
5
  "exports": {
6
6
  ".": {