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 CHANGED
@@ -1,4 +1,13 @@
1
1
  ## 更新日志
2
+
3
+ ### V1.2.6(2022-12-01)
4
+
5
+ 1、添加私聊消息同步到其他群或好友
6
+
7
+ ### V1.2.5(2022-11-30)
8
+
9
+ 1、修复回调事件带参
10
+
2
11
  ### V1.1.21(2022-10-31)
3
12
 
4
13
  1、添加群中关键词触发是否需要@功能
package/README.md CHANGED
@@ -51,6 +51,8 @@ Wechaty Web Panel 插件,让你的 wechaty 机器人快速接入 web 控制面
51
51
  - [ ] 更多待你发现
52
52
  - [x] 进群自动欢迎
53
53
  - [x] 加好友自动回复
54
+ - [x] 自定义回调事件
55
+ - [x] 私聊消息同步到群或好友
54
56
 
55
57
  * 自动更新配置文件,无需重启
56
58
 
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 指定用户消息转发到群或好友 如果被拦截成功 则不进行其他回复操作
3
+ * @returns {Promise<boolean>}
4
+ */
5
+ export function privateForward({ that, msg, name, config }: {
6
+ that: any;
7
+ msg: any;
8
+ name: any;
9
+ config: any;
10
+ }): Promise<boolean>;
11
+ //# sourceMappingURL=hook.d.ts.map
@@ -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(`发消息人${await contact.name()}:${content}`);
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());
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
6
6
  */
7
7
  exports.packageJson = {
8
8
  "name": "wechaty-web-panel",
9
- "version": "1.2.4",
9
+ "version": "1.2.6",
10
10
  "description": "",
11
11
  "exports": {
12
12
  ".": {
@@ -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
- data[mItem.key] = data[mItem.value];
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,11 @@
1
+ /**
2
+ * 指定用户消息转发到群或好友 如果被拦截成功 则不进行其他回复操作
3
+ * @returns {Promise<boolean>}
4
+ */
5
+ export function privateForward({ that, msg, name, config }: {
6
+ that: any;
7
+ msg: any;
8
+ name: any;
9
+ config: any;
10
+ }): Promise<boolean>;
11
+ //# sourceMappingURL=hook.d.ts.map
@@ -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(`发消息人${await contact.name()}:${content}`);
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());
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.2.4",
6
+ "version": "1.2.6",
7
7
  "description": "",
8
8
  "exports": {
9
9
  ".": {
@@ -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
- data[mItem.key] = data[mItem.value];
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-web-panel",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {