wechaty-web-panel 1.2.8 → 1.2.10

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.
@@ -105,7 +105,7 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
105
105
  const contactName = contact.name();
106
106
  const roomName = await room.topic();
107
107
  const type = msg.type();
108
- const userSelfName = that.currentUser?.name() || that.userSelf()?.name();
108
+ const receiver = msg.to();
109
109
  let content = "";
110
110
  let replys = "";
111
111
  let contactId = contact.id || "111";
@@ -114,8 +114,9 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
114
114
  case that.Message.Type.Text:
115
115
  content = msg.text();
116
116
  console.log(`群名: ${roomName} 发消息人: ${contactName} 内容: ${content}`);
117
- const mentionSelf = content.includes(`@${userSelfName}`);
118
- content = content.replace(/@[^,,::\s@]+/g, "").trim();
117
+ const mentionSelf = await msg.mentionSelf();
118
+ const receiverName = receiver?.name();
119
+ content = content.replace(receiverName, "").trim();
119
120
  // 检测是否需要这条消息
120
121
  const isIgnore = checkIgnore(content, aibotConfig.ignoreMessages);
121
122
  if (isIgnore)
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
6
6
  */
7
7
  exports.packageJson = {
8
8
  "name": "wechaty-web-panel",
9
- "version": "1.2.8",
9
+ "version": "1.2.10",
10
10
  "description": "",
11
11
  "exports": {
12
12
  ".": {
@@ -2,8 +2,8 @@ declare namespace _default {
2
2
  export { geGPTReply };
3
3
  }
4
4
  export default _default;
5
- export function geGPTReply(content: any): Promise<RegExpMatchArray | {
5
+ export function geGPTReply(content: any): Promise<{
6
6
  type: number;
7
7
  content: string;
8
- }[] | null>;
8
+ }[]>;
9
9
  //# sourceMappingURL=chatgpt.d.ts.map
@@ -15,12 +15,18 @@ async function geGPTReply(content) {
15
15
  }
16
16
  const api = new chatgpt_1.ChatGPTAPI({ sessionToken: config.gpttoken });
17
17
  await api.ensureAuth();
18
- const threeMinutesMs = 2 * 60 * 1000;
18
+ const threeMinutesMs = 3 * 60 * 1000;
19
19
  const response = await (0, p_timeout_1.default)(api.sendMessage(content), {
20
20
  milliseconds: threeMinutesMs,
21
21
  message: 'ChatGPT返回超时了,用的人太多,太火爆了,等会再试吧'
22
22
  });
23
- let replys = response.match(/.{1,680}/g);
23
+ let replys = [];
24
+ let message = response;
25
+ while (message.length > 500) {
26
+ replys.push(message.slice(0, 500));
27
+ message = message.slice(500);
28
+ }
29
+ replys.push(message);
24
30
  replys = replys.map(item => {
25
31
  return {
26
32
  type: 1,
@@ -20,5 +20,5 @@ export function dispatchEventContent(that: any, eName: string, msg: string, name
20
20
  * @param {*} name 发消息人
21
21
  * @param {*} id 发消息人id
22
22
  */
23
- export function dispatchAiBot(bot: any, msg: any, name: any, id: any): Promise<any[] | "" | null | undefined>;
23
+ export function dispatchAiBot(bot: any, msg: any, name: any, id: any): Promise<any[] | "" | undefined>;
24
24
  //# sourceMappingURL=event-dispatch-service.d.ts.map
@@ -426,10 +426,8 @@ async function oneToMany(that, config, msg) {
426
426
  */
427
427
  async function dispatchAsync(that, msg, list) {
428
428
  try {
429
- const userSelfName = that.currentUser?.name?.();
430
429
  const type = msg.type();
431
- const content = msg.text();
432
- const mentionSelf = content.includes(`@${userSelfName}`);
430
+ const mentionSelf = await msg.mentionSelf();
433
431
  if (7 === type && mentionSelf) {
434
432
  // 如果内容中有提及机器人的内容,不进行转发
435
433
  return;
@@ -103,7 +103,7 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
103
103
  const contactName = contact.name();
104
104
  const roomName = await room.topic();
105
105
  const type = msg.type();
106
- const userSelfName = that.currentUser?.name() || that.userSelf()?.name();
106
+ const receiver = msg.to();
107
107
  let content = "";
108
108
  let replys = "";
109
109
  let contactId = contact.id || "111";
@@ -112,8 +112,9 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
112
112
  case that.Message.Type.Text:
113
113
  content = msg.text();
114
114
  console.log(`群名: ${roomName} 发消息人: ${contactName} 内容: ${content}`);
115
- const mentionSelf = content.includes(`@${userSelfName}`);
116
- content = content.replace(/@[^,,::\s@]+/g, "").trim();
115
+ const mentionSelf = await msg.mentionSelf();
116
+ const receiverName = receiver?.name();
117
+ content = content.replace(receiverName, "").trim();
117
118
  // 检测是否需要这条消息
118
119
  const isIgnore = checkIgnore(content, aibotConfig.ignoreMessages);
119
120
  if (isIgnore)
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.2.8",
6
+ "version": "1.2.10",
7
7
  "description": "",
8
8
  "exports": {
9
9
  ".": {
@@ -2,8 +2,8 @@ declare namespace _default {
2
2
  export { geGPTReply };
3
3
  }
4
4
  export default _default;
5
- export function geGPTReply(content: any): Promise<RegExpMatchArray | {
5
+ export function geGPTReply(content: any): Promise<{
6
6
  type: number;
7
7
  content: string;
8
- }[] | null>;
8
+ }[]>;
9
9
  //# sourceMappingURL=chatgpt.d.ts.map
@@ -9,12 +9,18 @@ async function geGPTReply(content) {
9
9
  }
10
10
  const api = new ChatGPTAPI({ sessionToken: config.gpttoken });
11
11
  await api.ensureAuth();
12
- const threeMinutesMs = 2 * 60 * 1000;
12
+ const threeMinutesMs = 3 * 60 * 1000;
13
13
  const response = await pTimeout(api.sendMessage(content), {
14
14
  milliseconds: threeMinutesMs,
15
15
  message: 'ChatGPT返回超时了,用的人太多,太火爆了,等会再试吧'
16
16
  });
17
- let replys = response.match(/.{1,680}/g);
17
+ let replys = [];
18
+ let message = response;
19
+ while (message.length > 500) {
20
+ replys.push(message.slice(0, 500));
21
+ message = message.slice(500);
22
+ }
23
+ replys.push(message);
18
24
  replys = replys.map(item => {
19
25
  return {
20
26
  type: 1,
@@ -20,5 +20,5 @@ export function dispatchEventContent(that: any, eName: string, msg: string, name
20
20
  * @param {*} name 发消息人
21
21
  * @param {*} id 发消息人id
22
22
  */
23
- export function dispatchAiBot(bot: any, msg: any, name: any, id: any): Promise<any[] | "" | null | undefined>;
23
+ export function dispatchAiBot(bot: any, msg: any, name: any, id: any): Promise<any[] | "" | undefined>;
24
24
  //# sourceMappingURL=event-dispatch-service.d.ts.map
@@ -397,10 +397,8 @@ async function oneToMany(that, config, msg) {
397
397
  */
398
398
  async function dispatchAsync(that, msg, list) {
399
399
  try {
400
- const userSelfName = that.currentUser?.name?.();
401
400
  const type = msg.type();
402
- const content = msg.text();
403
- const mentionSelf = content.includes(`@${userSelfName}`);
401
+ const mentionSelf = await msg.mentionSelf();
404
402
  if (7 === type && mentionSelf) {
405
403
  // 如果内容中有提及机器人的内容,不进行转发
406
404
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-web-panel",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {