wechaty-web-panel 1.2.4 → 1.2.6
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 +9 -0
- package/README.md +2 -0
- package/dist/cjs/src/common/hook.d.ts +11 -0
- package/dist/cjs/src/common/hook.js +58 -0
- package/dist/cjs/src/handlers/on-message.js +8 -1
- package/dist/cjs/src/package-json.js +1 -1
- package/dist/cjs/src/service/msg-filters.js +3 -1
- package/dist/esm/src/common/hook.d.ts +11 -0
- package/dist/esm/src/common/hook.js +54 -0
- package/dist/esm/src/handlers/on-message.js +8 -1
- package/dist/esm/src/package-json.js +1 -1
- package/dist/esm/src/service/msg-filters.js +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.privateForward = void 0;
|
|
4
|
+
const index_js_1 = require("../lib/index.js");
|
|
5
|
+
/**
|
|
6
|
+
* 指定用户消息转发到群或好友 如果被拦截成功 则不进行其他回复操作
|
|
7
|
+
* @returns {Promise<boolean>}
|
|
8
|
+
*/
|
|
9
|
+
async function privateForward({ that, msg, name, config }) {
|
|
10
|
+
const { role } = config.userInfo;
|
|
11
|
+
const privateForwards = config.privateForwards;
|
|
12
|
+
if (role !== 'vip' || !privateForwards || !privateForwards.length || msg.text().includes('请在手机上查看]'))
|
|
13
|
+
return false;
|
|
14
|
+
let result = false;
|
|
15
|
+
try {
|
|
16
|
+
if (privateForwards.length) {
|
|
17
|
+
for (let item of privateForwards) {
|
|
18
|
+
if (item.name === name) {
|
|
19
|
+
result = true;
|
|
20
|
+
for (let roomName of item.rooms) {
|
|
21
|
+
await (0, index_js_1.delay)(500);
|
|
22
|
+
const room = await that.Room.find({ topic: roomName });
|
|
23
|
+
if (!room) {
|
|
24
|
+
console.log(`查找不到群:${roomName},请检查群名是否正确`);
|
|
25
|
+
}
|
|
26
|
+
// 只转发文字
|
|
27
|
+
if (item.type === 1 && msg.type() === 7) {
|
|
28
|
+
room && msg && msg.forward(room);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
room && msg && msg.forward(room);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
for (let contactName of item.contacts) {
|
|
35
|
+
await (0, index_js_1.delay)(500);
|
|
36
|
+
const contact = await that.Contact.find({ name: contactName });
|
|
37
|
+
if (!contact) {
|
|
38
|
+
console.log(`查找不到用户:${contactName},请检查用户昵称是否正确`);
|
|
39
|
+
}
|
|
40
|
+
// 只转发文字
|
|
41
|
+
if (item.type === 1 && msg.type === 7) {
|
|
42
|
+
contact && msg && msg.forward(contact);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
contact && msg && msg.forward(contact);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
console.log("error", e);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.privateForward = privateForward;
|
|
58
|
+
//# sourceMappingURL=hook.js.map
|
|
@@ -7,6 +7,7 @@ const room_async_service_js_1 = require("../service/room-async-service.js");
|
|
|
7
7
|
const configDb_js_1 = require("../db/configDb.js");
|
|
8
8
|
const aiDb_js_1 = require("../db/aiDb.js");
|
|
9
9
|
const roomDb_js_1 = require("../db/roomDb.js");
|
|
10
|
+
const hook_js_1 = require("../common/hook.js");
|
|
10
11
|
const ignoreRecord = [
|
|
11
12
|
{ type: "include", word: "加入了群聊" },
|
|
12
13
|
{ type: "include", word: "与群里其他人都不是朋友关系" },
|
|
@@ -37,16 +38,22 @@ function checkIgnore(msg, list) {
|
|
|
37
38
|
async function dispatchFriendFilterByMsgType(that, msg) {
|
|
38
39
|
try {
|
|
39
40
|
const aibotConfig = await (0, aiDb_js_1.getAibotConfig)();
|
|
41
|
+
const config = await (0, configDb_js_1.allConfig)();
|
|
40
42
|
const type = msg.type();
|
|
41
43
|
const contact = msg.talker(); // 发消息人
|
|
44
|
+
const name = await contact.name();
|
|
42
45
|
const isOfficial = contact.type() === that.Contact.Type.Official;
|
|
43
46
|
let content = "";
|
|
44
47
|
let replys = [];
|
|
48
|
+
const res = await (0, hook_js_1.privateForward)({ that, msg, name, config });
|
|
49
|
+
if (res) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
45
52
|
switch (type) {
|
|
46
53
|
case that.Message.Type.Text:
|
|
47
54
|
content = msg.text();
|
|
48
55
|
if (!isOfficial) {
|
|
49
|
-
console.log(`发消息人${
|
|
56
|
+
console.log(`发消息人${name}:${content}`);
|
|
50
57
|
const isIgnore = checkIgnore(content.trim(), aibotConfig.ignoreMessages);
|
|
51
58
|
if (content.trim() && !isIgnore) {
|
|
52
59
|
replys = await (0, reply_js_1.getContactTextReply)(that, contact, content.trim());
|
|
@@ -166,7 +166,9 @@ async function callbackEvent({ that, msg, name, id, config, room, isMention }) {
|
|
|
166
166
|
item.moreData &&
|
|
167
167
|
item.moreData.length &&
|
|
168
168
|
item.moreData.forEach((mItem) => {
|
|
169
|
-
|
|
169
|
+
if (mItem.key !== 'uid' && mItem.key !== 'word') {
|
|
170
|
+
data[mItem.key] = mItem.value;
|
|
171
|
+
}
|
|
170
172
|
});
|
|
171
173
|
if (item.type === 100) {
|
|
172
174
|
let res = await superagent_js_1.service.post(item.customUrl, data);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { delay } from "../lib/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* 指定用户消息转发到群或好友 如果被拦截成功 则不进行其他回复操作
|
|
4
|
+
* @returns {Promise<boolean>}
|
|
5
|
+
*/
|
|
6
|
+
export async function privateForward({ that, msg, name, config }) {
|
|
7
|
+
const { role } = config.userInfo;
|
|
8
|
+
const privateForwards = config.privateForwards;
|
|
9
|
+
if (role !== 'vip' || !privateForwards || !privateForwards.length || msg.text().includes('请在手机上查看]'))
|
|
10
|
+
return false;
|
|
11
|
+
let result = false;
|
|
12
|
+
try {
|
|
13
|
+
if (privateForwards.length) {
|
|
14
|
+
for (let item of privateForwards) {
|
|
15
|
+
if (item.name === name) {
|
|
16
|
+
result = true;
|
|
17
|
+
for (let roomName of item.rooms) {
|
|
18
|
+
await delay(500);
|
|
19
|
+
const room = await that.Room.find({ topic: roomName });
|
|
20
|
+
if (!room) {
|
|
21
|
+
console.log(`查找不到群:${roomName},请检查群名是否正确`);
|
|
22
|
+
}
|
|
23
|
+
// 只转发文字
|
|
24
|
+
if (item.type === 1 && msg.type() === 7) {
|
|
25
|
+
room && msg && msg.forward(room);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
room && msg && msg.forward(room);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (let contactName of item.contacts) {
|
|
32
|
+
await delay(500);
|
|
33
|
+
const contact = await that.Contact.find({ name: contactName });
|
|
34
|
+
if (!contact) {
|
|
35
|
+
console.log(`查找不到用户:${contactName},请检查用户昵称是否正确`);
|
|
36
|
+
}
|
|
37
|
+
// 只转发文字
|
|
38
|
+
if (item.type === 1 && msg.type === 7) {
|
|
39
|
+
contact && msg && msg.forward(contact);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
contact && msg && msg.forward(contact);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
console.log("error", e);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=hook.js.map
|
|
@@ -5,6 +5,7 @@ import { dispatchAsync } from "../service/room-async-service.js";
|
|
|
5
5
|
import { allConfig } from "../db/configDb.js";
|
|
6
6
|
import { getAibotConfig } from "../db/aiDb.js";
|
|
7
7
|
import { addRoomRecord } from "../db/roomDb.js";
|
|
8
|
+
import { privateForward } from "../common/hook.js";
|
|
8
9
|
const ignoreRecord = [
|
|
9
10
|
{ type: "include", word: "加入了群聊" },
|
|
10
11
|
{ type: "include", word: "与群里其他人都不是朋友关系" },
|
|
@@ -35,16 +36,22 @@ function checkIgnore(msg, list) {
|
|
|
35
36
|
async function dispatchFriendFilterByMsgType(that, msg) {
|
|
36
37
|
try {
|
|
37
38
|
const aibotConfig = await getAibotConfig();
|
|
39
|
+
const config = await allConfig();
|
|
38
40
|
const type = msg.type();
|
|
39
41
|
const contact = msg.talker(); // 发消息人
|
|
42
|
+
const name = await contact.name();
|
|
40
43
|
const isOfficial = contact.type() === that.Contact.Type.Official;
|
|
41
44
|
let content = "";
|
|
42
45
|
let replys = [];
|
|
46
|
+
const res = await privateForward({ that, msg, name, config });
|
|
47
|
+
if (res) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
43
50
|
switch (type) {
|
|
44
51
|
case that.Message.Type.Text:
|
|
45
52
|
content = msg.text();
|
|
46
53
|
if (!isOfficial) {
|
|
47
|
-
console.log(`发消息人${
|
|
54
|
+
console.log(`发消息人${name}:${content}`);
|
|
48
55
|
const isIgnore = checkIgnore(content.trim(), aibotConfig.ignoreMessages);
|
|
49
56
|
if (content.trim() && !isIgnore) {
|
|
50
57
|
replys = await getContactTextReply(that, contact, content.trim());
|
|
@@ -155,7 +155,9 @@ async function callbackEvent({ that, msg, name, id, config, room, isMention }) {
|
|
|
155
155
|
item.moreData &&
|
|
156
156
|
item.moreData.length &&
|
|
157
157
|
item.moreData.forEach((mItem) => {
|
|
158
|
-
|
|
158
|
+
if (mItem.key !== 'uid' && mItem.key !== 'word') {
|
|
159
|
+
data[mItem.key] = mItem.value;
|
|
160
|
+
}
|
|
159
161
|
});
|
|
160
162
|
if (item.type === 100) {
|
|
161
163
|
let res = await service.post(item.customUrl, data);
|