wechaty-web-panel 1.0.3 → 1.0.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.
@@ -1,7 +1,12 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="ChangeListManager">
4
- <list default="true" id="2e980355-75b9-47a9-b344-f25eda9493b2" name="Default Changelist" comment="feat(模块): 添加了个很棒的功能&#10;fix(模块): 修复了一些 bug&#10;docs(模块): 更新了一下文档&#10;UI(模块): 修改了一下样式&#10;chore(模块): 对脚手架做了些更改&#10;locale(模块): 为国际化做了微小的贡献" />
4
+ <list default="true" id="2e980355-75b9-47a9-b344-f25eda9493b2" name="Default Changelist" comment="feat(模块): 添加了个很棒的功能&#10;fix(模块): 修复了一些 bug&#10;docs(模块): 更新了一下文档&#10;UI(模块): 修改了一下样式&#10;chore(模块): 对脚手架做了些更改&#10;locale(模块): 为国际化做了微小的贡献">
5
+ <change beforePath="$PROJECT_DIR$/CHANGELOG.md" beforeDir="false" afterPath="$PROJECT_DIR$/CHANGELOG.md" afterDir="false" />
6
+ <change beforePath="$PROJECT_DIR$/src/handlers/on-message.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/handlers/on-message.js" afterDir="false" />
7
+ <change beforePath="$PROJECT_DIR$/src/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.js" afterDir="false" />
8
+ <change beforePath="$PROJECT_DIR$/src/service/event-dispatch-service.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/service/event-dispatch-service.js" afterDir="false" />
9
+ </list>
5
10
  <option name="SHOW_DIALOG" value="false" />
6
11
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
7
12
  <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -128,7 +133,14 @@
128
133
  <workItem from="1655357894259" duration="3028000" />
129
134
  <workItem from="1656644469354" duration="82000" />
130
135
  <workItem from="1657611185486" duration="30768000" />
131
- <workItem from="1657730101683" duration="5169000" />
136
+ <workItem from="1657730101683" duration="5453000" />
137
+ <workItem from="1657780584734" duration="4000" />
138
+ <workItem from="1657783060418" duration="100000" />
139
+ <workItem from="1657785079799" duration="18000" />
140
+ <workItem from="1657787236035" duration="654000" />
141
+ <workItem from="1657788805443" duration="1074000" />
142
+ <workItem from="1657790966316" duration="1506000" />
143
+ <workItem from="1657793837240" duration="3027000" />
132
144
  </task>
133
145
  <servers />
134
146
  </component>
package/CHANGELOG.md CHANGED
@@ -1,9 +1,14 @@
1
1
  ## 更新日志
2
+ ### V1.0.6(2022-07-14)
3
+
4
+ 1、修复机器人无法对话功能
5
+ 2、插件添加忽略关键词功能
6
+
2
7
  ### V1.0.3(2022-07-13)
3
8
 
4
9
  1、添加微信开发对话平台
5
10
  2、添加新闻分类事件
6
- 3
11
+ 3、修复头像上传无法展示问题
7
12
 
8
13
  ### V1.0.2(2022-02-21)
9
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-web-panel",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -60,6 +60,6 @@
60
60
  "publishConfig": {
61
61
  "registry": " https://registry.npmjs.org/"
62
62
  },
63
- "_id": "wechaty-web-panel@1.0.3",
64
- "_commitid": "edb8001"
63
+ "_id": "wechaty-web-panel@1.0.6",
64
+ "_commitid": "afa6242"
65
65
  }
@@ -3,6 +3,24 @@ const { getContactTextReply, getRoomTextReply } = require('../common/reply')
3
3
  const { delay } = require('../lib/index')
4
4
  const { dispatchAsync } = require('../service/room-async-service')
5
5
  const { allConfig } = require('../common/configDb')
6
+ const { getAibotConfig } = require('../common/aiDb')
7
+
8
+ /**
9
+ * 检测是否属于忽略的消息
10
+ * @param msg 用户信息
11
+ * @param list 需要忽略的列表
12
+ */
13
+ function checkIgnore(msg, list) {
14
+ if (!list.length) return false
15
+ for (let item of list) {
16
+ const word = item.word
17
+ const type = item.type
18
+ if ((type === 'start' && msg.startsWith(word)) || (type === 'end' && msg.endsWith(word)) || (type === 'equal' && msg === word) || (type === 'include' && msg.includes(word))) {
19
+ return true
20
+ }
21
+ }
22
+ return false
23
+ }
6
24
 
7
25
  /**
8
26
  * 根据消息类型过滤私聊消息事件
@@ -11,6 +29,7 @@ const { allConfig } = require('../common/configDb')
11
29
  */
12
30
  async function dispatchFriendFilterByMsgType(that, msg) {
13
31
  try {
32
+ const aibotConfig = await getAibotConfig()
14
33
  const type = msg.type()
15
34
  const contact = msg.talker() // 发消息人
16
35
  const isOfficial = contact.type() === that.Contact.Type.Official
@@ -21,8 +40,9 @@ async function dispatchFriendFilterByMsgType(that, msg) {
21
40
  content = msg.text()
22
41
  if (!isOfficial) {
23
42
  console.log(`发消息人${await contact.name()}:${content}`)
24
- if (content.trim()) {
25
- replys = await getContactTextReply(that, contact, content)
43
+ const isIgnore = checkIgnore(content.trim(), aibotConfig.ignoreMessages)
44
+ if (content.trim() && !isIgnore) {
45
+ replys = await getContactTextReply(that, contact, content.trim())
26
46
  for (let reply of replys) {
27
47
  await delay(1000)
28
48
  await contactSay(contact, reply)
@@ -62,6 +82,7 @@ async function dispatchFriendFilterByMsgType(that, msg) {
62
82
  * @param {*} msg 消息主体
63
83
  */
64
84
  async function dispatchRoomFilterByMsgType(that, room, msg) {
85
+ const aibotConfig = await getAibotConfig()
65
86
  try {
66
87
  const contact = msg.talker() // 发消息人
67
88
  const contactName = contact.name()
@@ -79,6 +100,9 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
79
100
  const mentionSelf = content.includes(`@${userSelfName}`)
80
101
  if (mentionSelf) {
81
102
  content = content.replace(/@[^,,::\s@]+/g, '').trim()
103
+ // 检测是否需要这条消息
104
+ const isIgnore = checkIgnore(content, aibotConfig.ignoreMessages)
105
+ if (isIgnore) return
82
106
  replys = await getRoomTextReply(that, content, contactName, contactId, contactAvatar, room)
83
107
  for (let reply of replys) {
84
108
  await delay(1000)
package/src/index.js CHANGED
@@ -25,19 +25,24 @@ module.exports = function WechatyWebPanelPlugin(config = { apiKey, apiSecret })
25
25
  const initConfig = {
26
26
  apiKey: envKey || config.apiKey,
27
27
  apiSecret: envSecret || config.apiSecret,
28
+ // 需要忽略的关键词 [{type:'start', word: ''},{type:'end', word: ''},{type:'equal', word: ''},{type:'include', word: ''}]
29
+ ignoreMessages: config.ignoreMessages || [],
30
+ // 需要忽略的事件 ['scan', 'login', 'logout', 'friendship', 'room-join', 'room-topic', 'room-leave', 'message', 'ready', 'heartbeat', 'error']
31
+ ignoreEvents: config.ignoreEvents || [],
28
32
  }
29
33
  addAibotConfig(initConfig)
30
34
  return function (bot) {
31
- bot.on('scan', onScan)
32
- bot.on('login', onLogin)
33
- bot.on('logout', onLogout)
34
- bot.on('friendship', onFriend)
35
- bot.on('room-join', onRoomjoin)
36
- bot.on('room-topic', onRoomtopic)
37
- bot.on('room-leave', onRoomleave)
38
- bot.on('message', onMessage)
39
- bot.on('ready', onReady)
40
- bot.on('heartbeat', onHeartbeat)
41
- bot.on('error', onError)
35
+ const ignoreEvents = initConfig.ignoreEvents
36
+ if (!ignoreEvents.includes('scan')) bot.on('scan', onScan)
37
+ if (!ignoreEvents.includes('login')) bot.on('login', onLogin)
38
+ if (!ignoreEvents.includes('logout')) bot.on('logout', onLogout)
39
+ if (!ignoreEvents.includes('friendship')) bot.on('friendship', onFriend)
40
+ if (!ignoreEvents.includes('room-join')) bot.on('room-join', onRoomjoin)
41
+ if (!ignoreEvents.includes('room-topic')) bot.on('room-topic', onRoomtopic)
42
+ if (!ignoreEvents.includes('room-leave')) bot.on('room-leave', onRoomleave)
43
+ if (!ignoreEvents.includes('message')) bot.on('message', onMessage)
44
+ if (!ignoreEvents.includes('ready')) bot.on('ready', onReady)
45
+ if (!ignoreEvents.includes('heartbeat')) bot.on('heartbeat', onHeartbeat)
46
+ if (!ignoreEvents.includes('error')) bot.on('error', onError)
42
47
  }
43
48
  }
@@ -317,7 +317,7 @@ async function drawRoomPhoto(roomName, list, contactName) {
317
317
  async function putqn(base, name) {
318
318
  try {
319
319
  const token = await getQiToken()
320
- const namebase = Buffer.from(name).toString('base64').replace('=', '')
320
+ const namebase = Buffer.from(name).toString('base64').replace(/=/g, '')
321
321
  let filename = 'wechat/avatar/' + namebase + '.jpeg'
322
322
  let base_file_name = Buffer.from(filename).toString('base64').replace('+', '-').replace('/', '_')
323
323
  let options = {
@@ -330,7 +330,7 @@ async function putqn(base, name) {
330
330
  }
331
331
  let content = await req(options)
332
332
  console.log('上传结果', content.key)
333
- return 'http://image.xkboke.com/' + content.key
333
+ return 'https://img.aibotk.com/' + content.key
334
334
  } catch (e) {
335
335
  console.log('上传失败', e.Error)
336
336
  }
@@ -162,7 +162,6 @@ async function getTencentOpenReply({ msg, id, userInfo }) {
162
162
  const data = {
163
163
  signature,
164
164
  query: msg,
165
- env: 'debug',
166
165
  }
167
166
  const res = await axios.post(`https://openai.weixin.qq.com/openapi/aibot/eTZV8kYIvKnmvQJgXsy7e7f3WDWeGf`, data, {})
168
167
  const resData = res.data
@@ -144,22 +144,22 @@ async function dispatchAiBot(bot, msg, name, id) {
144
144
  case 0:
145
145
  // 天行机器人
146
146
  res = await api.getResByTX(msg, id)
147
- replys = [{ type: 1, res }]
147
+ replys = [{ type: 1, content: res }]
148
148
  break
149
149
  case 1:
150
150
  // 天行图灵机器人
151
151
  res = await api.getResByTXTL(msg, id)
152
- replys = [{ type: 1, res }]
152
+ replys = [{ type: 1, content: res }]
153
153
  break
154
154
  case 2:
155
155
  // 图灵机器人
156
156
  res = await api.getResByTL(msg, id)
157
- replys = [{ type: 1, res }]
157
+ replys = [{ type: 1, content: res }]
158
158
  break
159
159
  case 3:
160
160
  // 微信闲聊
161
161
  res = await chatTencent(msg, id)
162
- replys = [{ type: 1, res }]
162
+ replys = [{ type: 1, content: res }]
163
163
  break
164
164
  case 5:
165
165
  // 微信开放对话平台