wechaty-web-panel 0.2.15 → 1.0.1
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/.idea/workspace.xml +22 -23
- package/CHANGELOG.md +13 -0
- package/README.md +16 -9
- package/package.json +12 -12
- package/src/common/index.js +10 -10
- package/src/handlers/on-login.js +2 -2
- package/src/handlers/on-message.js +1 -1
- package/src/lib/index.js +9 -5
- package/src/proxy/api.js +20 -43
- package/src/proxy/mqtt.js +1 -1
- package/src/service/event-dispatch-service.js +0 -1
- package/src/service/room-async-service.js +52 -8
package/.idea/workspace.xml
CHANGED
|
@@ -2,28 +2,7 @@
|
|
|
2
2
|
<project version="4">
|
|
3
3
|
<component name="ChangeListManager">
|
|
4
4
|
<list default="true" id="2e980355-75b9-47a9-b344-f25eda9493b2" name="Default Changelist" comment="feat(模块): 添加了个很棒的功能 fix(模块): 修复了一些 bug docs(模块): 更新了一下文档 UI(模块): 修改了一下样式 chore(模块): 对脚手架做了些更改 locale(模块): 为国际化做了微小的贡献">
|
|
5
|
-
<change afterPath="$PROJECT_DIR$/CHANGELOG.md" afterDir="false" />
|
|
6
|
-
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
|
7
5
|
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
8
|
-
<change beforePath="$PROJECT_DIR$/src/common/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/common/index.js" afterDir="false" />
|
|
9
|
-
<change beforePath="$PROJECT_DIR$/src/handlers/on-error.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/handlers/on-error.js" afterDir="false" />
|
|
10
|
-
<change beforePath="$PROJECT_DIR$/src/handlers/on-friend.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/handlers/on-friend.js" afterDir="false" />
|
|
11
|
-
<change beforePath="$PROJECT_DIR$/src/handlers/on-heartbeat.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/handlers/on-heartbeat.js" afterDir="false" />
|
|
12
|
-
<change beforePath="$PROJECT_DIR$/src/handlers/on-login.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/handlers/on-login.js" afterDir="false" />
|
|
13
|
-
<change beforePath="$PROJECT_DIR$/src/handlers/on-message.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/handlers/on-message.js" afterDir="false" />
|
|
14
|
-
<change beforePath="$PROJECT_DIR$/src/handlers/on-ready.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/handlers/on-ready.js" afterDir="false" />
|
|
15
|
-
<change beforePath="$PROJECT_DIR$/src/handlers/on-roomjoin.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/handlers/on-roomjoin.js" afterDir="false" />
|
|
16
|
-
<change beforePath="$PROJECT_DIR$/src/handlers/on-roomtopic.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/handlers/on-roomtopic.js" afterDir="false" />
|
|
17
|
-
<change beforePath="$PROJECT_DIR$/src/lib/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/index.js" afterDir="false" />
|
|
18
|
-
<change beforePath="$PROJECT_DIR$/src/proxy/aibotk.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/proxy/aibotk.js" afterDir="false" />
|
|
19
|
-
<change beforePath="$PROJECT_DIR$/src/proxy/api.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/proxy/api.js" afterDir="false" />
|
|
20
|
-
<change beforePath="$PROJECT_DIR$/src/proxy/superagent.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/proxy/superagent.js" afterDir="false" />
|
|
21
|
-
<change beforePath="$PROJECT_DIR$/src/proxy/tencent.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/proxy/tencent.js" afterDir="false" />
|
|
22
|
-
<change beforePath="$PROJECT_DIR$/src/service/event-dispatch-service.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/service/event-dispatch-service.js" afterDir="false" />
|
|
23
|
-
<change beforePath="$PROJECT_DIR$/src/service/msg-filter-service.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/service/msg-filter-service.js" afterDir="false" />
|
|
24
|
-
<change beforePath="$PROJECT_DIR$/src/service/msg-filters.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/service/msg-filters.js" afterDir="false" />
|
|
25
|
-
<change beforePath="$PROJECT_DIR$/src/service/room-async-service.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/service/room-async-service.js" afterDir="false" />
|
|
26
|
-
<change beforePath="$PROJECT_DIR$/src/task/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/task/index.js" afterDir="false" />
|
|
27
6
|
</list>
|
|
28
7
|
<option name="SHOW_DIALOG" value="false" />
|
|
29
8
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -68,10 +47,10 @@
|
|
|
68
47
|
<component name="RecentsManager">
|
|
69
48
|
<key name="CopyFile.RECENT_KEYS">
|
|
70
49
|
<recent name="$PROJECT_DIR$" />
|
|
50
|
+
<recent name="$PROJECT_DIR$/test" />
|
|
71
51
|
<recent name="$PROJECT_DIR$/koa/bash" />
|
|
72
52
|
<recent name="$PROJECT_DIR$/koa/pubilc/static" />
|
|
73
53
|
<recent name="$PROJECT_DIR$/koa/pubilc/static/img" />
|
|
74
|
-
<recent name="$PROJECT_DIR$/koa/pubilc/static/font" />
|
|
75
54
|
</key>
|
|
76
55
|
</component>
|
|
77
56
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="应用程序级" UseSingleDictionary="true" transferred="true" />
|
|
@@ -98,7 +77,27 @@
|
|
|
98
77
|
<workItem from="1634271782737" duration="2406000" />
|
|
99
78
|
<workItem from="1634278985825" duration="1179000" />
|
|
100
79
|
<workItem from="1634544457610" duration="4850000" />
|
|
101
|
-
<workItem from="1634642615016" duration="
|
|
80
|
+
<workItem from="1634642615016" duration="19868000" />
|
|
81
|
+
<workItem from="1634781971524" duration="5097000" />
|
|
82
|
+
<workItem from="1636020036226" duration="4142000" />
|
|
83
|
+
<workItem from="1636700616248" duration="611000" />
|
|
84
|
+
<workItem from="1637723811654" duration="126000" />
|
|
85
|
+
<workItem from="1638588076329" duration="34000" />
|
|
86
|
+
<workItem from="1639099930278" duration="1299000" />
|
|
87
|
+
<workItem from="1639129806549" duration="77000" />
|
|
88
|
+
<workItem from="1639464210268" duration="219000" />
|
|
89
|
+
<workItem from="1639473278118" duration="72000" />
|
|
90
|
+
<workItem from="1639486141688" duration="66000" />
|
|
91
|
+
<workItem from="1639539045086" duration="75000" />
|
|
92
|
+
<workItem from="1639712956341" duration="178000" />
|
|
93
|
+
<workItem from="1640929149202" duration="6000" />
|
|
94
|
+
<workItem from="1641278400321" duration="13000" />
|
|
95
|
+
<workItem from="1641442984815" duration="5000" />
|
|
96
|
+
<workItem from="1642212984216" duration="11645000" />
|
|
97
|
+
<workItem from="1642384832300" duration="994000" />
|
|
98
|
+
<workItem from="1642386021423" duration="4268000" />
|
|
99
|
+
<workItem from="1642647009185" duration="3937000" />
|
|
100
|
+
<workItem from="1642657426395" duration="254000" />
|
|
102
101
|
</task>
|
|
103
102
|
<servers />
|
|
104
103
|
</component>
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -107,6 +107,8 @@ Wechaty Web Panel 插件,让你的 wechaty 机器人快速接入 web 控制面
|
|
|
107
107
|
|
|
108
108
|
## 开始
|
|
109
109
|
|
|
110
|
+
> 环境node > 16
|
|
111
|
+
|
|
110
112
|
### Step 1: 安装
|
|
111
113
|
|
|
112
114
|
```
|
|
@@ -124,18 +126,23 @@ npm install wechaty-web-panel@latest wechaty@latest --save --canvas_binary_host_
|
|
|
124
126
|
```
|
|
125
127
|
$ vim mybot.js
|
|
126
128
|
|
|
127
|
-
const {
|
|
128
|
-
const WechatyWebPanelPlugin = require('
|
|
129
|
+
const {WechatyBuilder} = require('wechaty')
|
|
130
|
+
const WechatyWebPanelPlugin = require('../src/index')
|
|
131
|
+
|
|
129
132
|
const name = 'wechat-assistant'
|
|
130
|
-
const bot = new Wechaty({
|
|
131
|
-
name, // generate xxxx.memory-card.json and save login data for the next login
|
|
132
|
-
puppet: 'wechaty-puppet-wechat',
|
|
133
|
-
});
|
|
134
133
|
|
|
134
|
+
const bot = WechatyBuilder.build({
|
|
135
|
+
name, // generate xxxx.memory-card.json and save login data for the next login
|
|
136
|
+
puppet: 'wechaty-puppet-wechat',
|
|
137
|
+
})
|
|
135
138
|
bot
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
.use(WechatyWebPanelPlugin({
|
|
140
|
+
apiKey: '',
|
|
141
|
+
apiSecret: ''
|
|
142
|
+
}))
|
|
143
|
+
.start()
|
|
144
|
+
.catch((e) => console.error(e))
|
|
145
|
+
|
|
139
146
|
|
|
140
147
|
```
|
|
141
148
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wechaty-web-panel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -36,32 +36,32 @@
|
|
|
36
36
|
"eslint-config-prettier": "^6.11.0",
|
|
37
37
|
"eslint-plugin-prettier": "^3.1.4",
|
|
38
38
|
"prettier": "^2.0.5",
|
|
39
|
-
"wechaty": "^
|
|
40
|
-
"wechaty-puppet-wechat": "^
|
|
39
|
+
"wechaty": "^1.11.41",
|
|
40
|
+
"wechaty-puppet-wechat": "^1.11.12"
|
|
41
41
|
},
|
|
42
42
|
"readme": "README.md",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"
|
|
44
|
+
"ix": "^4.5.2",
|
|
45
45
|
"mcanvas": "^2.0.8",
|
|
46
46
|
"mqtt": "^4.2.6",
|
|
47
|
+
"mustache": "^4.2.0",
|
|
47
48
|
"nedb": "^1.8.0",
|
|
48
49
|
"node-schedule": "^1.3.2",
|
|
49
50
|
"qrcode-terminal": "^0.12.0",
|
|
50
51
|
"superagent": "^5.2.2",
|
|
51
|
-
"tencentcloud-sdk-nodejs": "^4.0.30"
|
|
52
|
-
"wechaty-plugin-contrib": "^0.14.17"
|
|
52
|
+
"tencentcloud-sdk-nodejs": "^4.0.30"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"wechaty": "^
|
|
56
|
-
"wechaty-puppet-wechat": "^
|
|
55
|
+
"wechaty": "^1.11.41",
|
|
56
|
+
"wechaty-puppet-wechat": "^1.11.12"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"registry": " https://registry.npmjs.org/"
|
|
60
60
|
},
|
|
61
61
|
"engines": {
|
|
62
|
-
"node": ">=
|
|
63
|
-
"npm": ">=
|
|
62
|
+
"node": ">=16.0",
|
|
63
|
+
"npm": ">=8.1"
|
|
64
64
|
},
|
|
65
|
-
"_id": "wechaty-web-panel@0.
|
|
66
|
-
"_commitid": "
|
|
65
|
+
"_id": "wechaty-web-panel@1.0.1",
|
|
66
|
+
"_commitid": "ae2833a"
|
|
67
67
|
}
|
package/src/common/index.js
CHANGED
|
@@ -2,8 +2,8 @@ const { getNews, getTXweather, getSweetWord } = require('../proxy/api')
|
|
|
2
2
|
const { sendFriend, sendRoom, asyncData, getOne } = require('../proxy/aibotk')
|
|
3
3
|
const { getUser } = require('../common/userDb')
|
|
4
4
|
const { formatDate, getDay, MD5, groupArray, delay } = require('../lib')
|
|
5
|
-
const {
|
|
6
|
-
|
|
5
|
+
const { UrlLink, MiniProgram } = require('wechaty')
|
|
6
|
+
const { FileBox } = require('file-box')
|
|
7
7
|
/**
|
|
8
8
|
* 获取每日新闻内容
|
|
9
9
|
* @param {*} sortId 新闻资讯分类Id
|
|
@@ -12,7 +12,7 @@ const { FileBox, UrlLink, MiniProgram } = require('wechaty')
|
|
|
12
12
|
async function getEveryDayRoomContent(sortId, endWord = '微信小助手') {
|
|
13
13
|
let today = formatDate(new Date()) //获取今天的日期
|
|
14
14
|
let news = await getNews(sortId)
|
|
15
|
-
let content = `${today}
|
|
15
|
+
let content = `${today}\n${news}\n————————${endWord}`
|
|
16
16
|
return content
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -28,7 +28,7 @@ async function getEveryDayContent(date, city, endWord) {
|
|
|
28
28
|
let today = formatDate(new Date()) //获取今天的日期
|
|
29
29
|
let memorialDay = getDay(date) //获取纪念日天数
|
|
30
30
|
let sweetWord = await getSweetWord() // 土味情话
|
|
31
|
-
let str = `${today}
|
|
31
|
+
let str = `${today}\n我们在一起的第${memorialDay}天\n\n元气满满的一天开始啦,要开心噢^_^\n\n今日天气\n${weather.weatherTips}\n${weather.todayWeather}\n每日一句:\n${one}\n\n情话对你说:\n${sweetWord}\n\n————————${endWord}`
|
|
32
32
|
return str
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -42,9 +42,9 @@ async function updateContactInfo(that) {
|
|
|
42
42
|
const contactList = await that.Contact.findAll()
|
|
43
43
|
let res = []
|
|
44
44
|
const notids = ['filehelper', 'fmessage']
|
|
45
|
-
let realContact = hasWeixin ? contactList.filter((item) => item.
|
|
45
|
+
let realContact = hasWeixin ? contactList.filter((item) => item._payload.type == 1 && item._payload.friend && !notids.includes(item._payload.id)) : contactList
|
|
46
46
|
for (let i of realContact) {
|
|
47
|
-
let contact = i.
|
|
47
|
+
let contact = i._payload
|
|
48
48
|
let obj = {
|
|
49
49
|
robotId: hasWeixin ? contactSelf.weixin : MD5(contactSelf.name),
|
|
50
50
|
contactId: hasWeixin ? contact.id : MD5(contactSelf.name + contact.name + contact.alias + contact.province + contact.city + contact.gender),
|
|
@@ -75,7 +75,7 @@ async function updateContactInfo(that) {
|
|
|
75
75
|
*/
|
|
76
76
|
async function updateFriendInfo(list, num) {
|
|
77
77
|
const arr = groupArray(list, num)
|
|
78
|
-
for (let i =
|
|
78
|
+
for (let i = 0; i < arr.length; i++) {
|
|
79
79
|
const item = arr[i]
|
|
80
80
|
await sendFriend(item)
|
|
81
81
|
await delay(500)
|
|
@@ -92,7 +92,7 @@ async function updateRoomInfo(that) {
|
|
|
92
92
|
const roomList = await that.Room.findAll()
|
|
93
93
|
let res = []
|
|
94
94
|
for (let i of roomList) {
|
|
95
|
-
let room = i.
|
|
95
|
+
let room = i._payload
|
|
96
96
|
let obj = {
|
|
97
97
|
robotId: hasWeixin ? contactSelf.weixin : MD5(contactSelf.name),
|
|
98
98
|
roomId: MD5(room.topic),
|
|
@@ -117,7 +117,7 @@ async function updateRoomInfo(that) {
|
|
|
117
117
|
*/
|
|
118
118
|
async function updateRoomsInfo(list, num) {
|
|
119
119
|
const arr = groupArray(list, num)
|
|
120
|
-
for (let i =
|
|
120
|
+
for (let i = 0; i < arr.length; i++) {
|
|
121
121
|
const item = arr[i]
|
|
122
122
|
await sendRoom(item)
|
|
123
123
|
await delay(500)
|
|
@@ -135,7 +135,7 @@ async function addRoomWelcomeSay(room, roomName, contactName, msg) {
|
|
|
135
135
|
if (msg.type === 1 && msg.content !== '') {
|
|
136
136
|
// 文字
|
|
137
137
|
console.log('回复内容', msg.content)
|
|
138
|
-
await room.say(`${roomName}:欢迎新朋友 @${contactName}
|
|
138
|
+
await room.say(`${roomName}:欢迎新朋友 @${contactName},\n${msg.content}`)
|
|
139
139
|
} else if (msg.type === 2 && msg.url !== '') {
|
|
140
140
|
// url文件
|
|
141
141
|
let obj = FileBox.fromUrl(msg.url)
|
package/src/handlers/on-login.js
CHANGED
|
@@ -20,8 +20,8 @@ async function onLogin(user) {
|
|
|
20
20
|
const config = await allConfig()
|
|
21
21
|
const { userId } = config.userInfo
|
|
22
22
|
const userInfo = {
|
|
23
|
-
...user.
|
|
24
|
-
robotId: user.
|
|
23
|
+
...user._payload,
|
|
24
|
+
robotId: user._payload.weixin || MD5(user.name()),
|
|
25
25
|
}
|
|
26
26
|
await addUser(userInfo) // 全局存储登录用户信息
|
|
27
27
|
const file = await user.avatar()
|
|
@@ -67,7 +67,7 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
|
|
|
67
67
|
const contactName = contact.name()
|
|
68
68
|
const roomName = await room.topic()
|
|
69
69
|
const type = msg.type()
|
|
70
|
-
const userSelfName = that.
|
|
70
|
+
const userSelfName = that.currentUser.name()
|
|
71
71
|
let content = ''
|
|
72
72
|
let replys = ''
|
|
73
73
|
let contactId = contact.id || '111'
|
package/src/lib/index.js
CHANGED
|
@@ -416,7 +416,7 @@ function filterContacts(contacts, query) {
|
|
|
416
416
|
let { name, alias, friend, type, gender, province, city, address } = query
|
|
417
417
|
return contacts.filter((item) => {
|
|
418
418
|
let arr = []
|
|
419
|
-
let { payload } = item
|
|
419
|
+
let { _payload: payload } = item
|
|
420
420
|
if (friend) {
|
|
421
421
|
let bool = Number(friend) === 1 ? true : false
|
|
422
422
|
arr.push(bool === payload.friend)
|
|
@@ -440,7 +440,7 @@ function formatContacts(data) {
|
|
|
440
440
|
let arr = data.map(function (item) {
|
|
441
441
|
// const file = await item.avatar()
|
|
442
442
|
// let avatar = await file.toBase64(file.name, true);
|
|
443
|
-
let payload = item.
|
|
443
|
+
let payload = item._payload
|
|
444
444
|
return {
|
|
445
445
|
id: payload.id,
|
|
446
446
|
name: payload.name,
|
|
@@ -517,10 +517,11 @@ async function getRoomAvatarList(room, name) {
|
|
|
517
517
|
let res = []
|
|
518
518
|
console.log('正在努力获取群成员信息...')
|
|
519
519
|
for (let i of members) {
|
|
520
|
-
let member = i.
|
|
520
|
+
let member = i._payload
|
|
521
521
|
try {
|
|
522
522
|
const avatar = await i.avatar()
|
|
523
|
-
if (avatar.
|
|
523
|
+
if (avatar._mediaType && avatar._name) {
|
|
524
|
+
console.log(avatar)
|
|
524
525
|
const base64 = member.weixin ? member.avatar : await avatar.toDataURL()
|
|
525
526
|
let obj = {
|
|
526
527
|
img: base64,
|
|
@@ -541,7 +542,7 @@ async function getRoomAvatarList(room, name) {
|
|
|
541
542
|
console.log('获取群成员信息完成...')
|
|
542
543
|
return res
|
|
543
544
|
} catch (e) {
|
|
544
|
-
console.log('
|
|
545
|
+
console.log('获取群成员头像列表失败', e)
|
|
545
546
|
}
|
|
546
547
|
}
|
|
547
548
|
|
|
@@ -592,6 +593,9 @@ async function getRoomAvatar(roomObj, roomName, name) {
|
|
|
592
593
|
async function cropImg(list, size = 74) {
|
|
593
594
|
try {
|
|
594
595
|
const arr = []
|
|
596
|
+
if (list.length >= 100) {
|
|
597
|
+
console.log('群成员数量超过100,生成群合影速度可能比较慢,请耐心等待')
|
|
598
|
+
}
|
|
595
599
|
for (const i of list) {
|
|
596
600
|
try {
|
|
597
601
|
if (i.img) {
|
package/src/proxy/api.js
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
1
|
-
const cheerio = require('cheerio')
|
|
2
1
|
const { req, txReq } = require('./superagent')
|
|
3
2
|
const { EMOHOST, TULING, ONE, MEINV } = require('./config')
|
|
4
3
|
const { randomRange, MD5 } = require('../lib/index')
|
|
5
4
|
const { allConfig } = require('../common/configDb')
|
|
6
5
|
|
|
7
|
-
/**
|
|
8
|
-
* 获取每日一句,暂时弃用,已改为api调用
|
|
9
|
-
*/
|
|
10
|
-
async function getOne() {
|
|
11
|
-
try {
|
|
12
|
-
let option = {
|
|
13
|
-
spider: true,
|
|
14
|
-
method: 'GET',
|
|
15
|
-
url: ONE,
|
|
16
|
-
params: '',
|
|
17
|
-
}
|
|
18
|
-
let res = await req(option)
|
|
19
|
-
let $ = cheerio.load(res)
|
|
20
|
-
let todayOneList = $('#carousel-one .carousel-inner .item')
|
|
21
|
-
let todayOne = $(todayOneList[0])
|
|
22
|
-
.find('.fp-one-cita')
|
|
23
|
-
.text()
|
|
24
|
-
.replace(/(^\s*)|(\s*$)/g, '')
|
|
25
|
-
return todayOne
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.log('获取每日一句失败:', error)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
6
|
/**
|
|
32
7
|
* 天行图灵聊天机器人
|
|
33
8
|
* @param {*} word 发送内容
|
|
@@ -150,7 +125,7 @@ async function getRubbishType(word) {
|
|
|
150
125
|
} else if (content.newslist[0].type == 3) {
|
|
151
126
|
type = '是其他(干)垃圾'
|
|
152
127
|
}
|
|
153
|
-
let response = `${content.newslist[0].name}${type}
|
|
128
|
+
let response = `${content.newslist[0].name}${type}\n解释:${content.newslist[0].explain}\n主要包括:${content.newslist[0].contain}\n投放提示:${content.newslist[0].tip}`
|
|
154
129
|
return response
|
|
155
130
|
} else {
|
|
156
131
|
console.log('查询失败提示:', content.msg)
|
|
@@ -174,7 +149,7 @@ async function getSweetWord() {
|
|
|
174
149
|
let content = await txReq(option)
|
|
175
150
|
if (content.code === 200) {
|
|
176
151
|
let sweet = content.newslist[0].content
|
|
177
|
-
let str = sweet.replace('\r\n', '
|
|
152
|
+
let str = sweet.replace('\r\n', '\n')
|
|
178
153
|
return str
|
|
179
154
|
} else {
|
|
180
155
|
console.log('获取土情话接口失败', content.msg)
|
|
@@ -199,7 +174,7 @@ async function getTXweather(city) {
|
|
|
199
174
|
let todayInfo = content.newslist[0]
|
|
200
175
|
let obj = {
|
|
201
176
|
weatherTips: todayInfo.tips,
|
|
202
|
-
todayWeather: `今天:${todayInfo.weather}
|
|
177
|
+
todayWeather: `今天:${todayInfo.weather}\n温度:${todayInfo.lowest}/${todayInfo.highest}\n${todayInfo.wind} ${todayInfo.windspeed}\n\n`,
|
|
203
178
|
}
|
|
204
179
|
return obj
|
|
205
180
|
} else {
|
|
@@ -225,12 +200,12 @@ async function getNews(id) {
|
|
|
225
200
|
if (content.code === 200) {
|
|
226
201
|
let newList = content.newslist
|
|
227
202
|
let news = ''
|
|
228
|
-
let shortUrl = 'https://www.tianapi.com/weixin/news/?col=' + id
|
|
203
|
+
// let shortUrl = 'https://www.tianapi.com/weixin/news/?col=' + id
|
|
229
204
|
for (let i in newList) {
|
|
230
205
|
let num = parseInt(i) + 1
|
|
231
|
-
news = `${news}
|
|
206
|
+
news = `${news}\n${num}.${newList[i].title}`
|
|
232
207
|
}
|
|
233
|
-
return `${news}
|
|
208
|
+
return `${news}\n`
|
|
234
209
|
}
|
|
235
210
|
} catch (error) {
|
|
236
211
|
console.log('获取天行新闻失败', error)
|
|
@@ -250,7 +225,7 @@ async function getMingYan() {
|
|
|
250
225
|
let content = await txReq(option)
|
|
251
226
|
if (content.code === 200) {
|
|
252
227
|
let newList = content.newslist
|
|
253
|
-
let news = `${newList[0].content}
|
|
228
|
+
let news = `${newList[0].content}\n——————————${newList[0].author}`
|
|
254
229
|
return news
|
|
255
230
|
}
|
|
256
231
|
} catch (error) {
|
|
@@ -274,7 +249,7 @@ async function getStar(astro) {
|
|
|
274
249
|
let newList = content.newslist
|
|
275
250
|
let news = ''
|
|
276
251
|
for (let item of newList) {
|
|
277
|
-
news = `${news}${item.type}:${item.content}
|
|
252
|
+
news = `${news}${item.type}:${item.content}\n`
|
|
278
253
|
}
|
|
279
254
|
return news
|
|
280
255
|
}
|
|
@@ -339,7 +314,7 @@ async function getLunar(date) {
|
|
|
339
314
|
let content = await txReq(option)
|
|
340
315
|
if (content.code === 200) {
|
|
341
316
|
let item = content.newslist[0]
|
|
342
|
-
let news =
|
|
317
|
+
let news = `\n阳历:${item.gregoriandate}\n阴历:${item.lunardate}\n节日:${item.lunar_festival}\n适宜:${item.fitness}\n不宜:${item.taboo}\n神位:${item.shenwei}\n胎神:${item.taishen}\n冲煞:${item.chongsha}\n岁煞:${item.suisha}`
|
|
343
318
|
return news
|
|
344
319
|
}
|
|
345
320
|
} catch (error) {
|
|
@@ -360,7 +335,7 @@ async function getGoldReply() {
|
|
|
360
335
|
let content = await txReq(option)
|
|
361
336
|
if (content.code === 200) {
|
|
362
337
|
let item = content.newslist[0]
|
|
363
|
-
let news = `标题:"${item.title}"
|
|
338
|
+
let news = `标题:"${item.title}"\n回复:${item.content}`
|
|
364
339
|
return news
|
|
365
340
|
}
|
|
366
341
|
} catch (error) {
|
|
@@ -527,13 +502,16 @@ async function getNcov() {
|
|
|
527
502
|
let content = await txReq(option)
|
|
528
503
|
if (content.code === 200) {
|
|
529
504
|
let newList = content.newslist[0].news
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
505
|
+
const riskarea = content.newslist[0].riskarea
|
|
506
|
+
const reply = `【疫情新闻暂时下线,目前只返回风险地区】\n\n全国风险地区\n\n【高风险地区】:\n${(riskarea.high && riskarea.high.length && riskarea.high.join('\n')) || '暂无'}\n【中风险地区】:\n${
|
|
507
|
+
(riskarea.mid && riskarea.mid.length && riskarea.mid.join('\n')) || '暂无'
|
|
508
|
+
}\n\n——————————数据来源:天行数据`
|
|
509
|
+
// let news = ''
|
|
510
|
+
// for (let i in newList) {
|
|
511
|
+
// let num = parseInt(i) + 1
|
|
512
|
+
// news = `${news}<br>>>${newList[i].pubDateStr}: ${newList[i].title}<br><br>${newList[i].summary}----------------${newList[i].infoSource}<br><br>`
|
|
513
|
+
// }
|
|
514
|
+
return reply
|
|
537
515
|
}
|
|
538
516
|
} catch (e) {
|
|
539
517
|
console.log('获取疫情数据失败', e)
|
|
@@ -559,7 +537,6 @@ async function getCname() {
|
|
|
559
537
|
}
|
|
560
538
|
}
|
|
561
539
|
module.exports = {
|
|
562
|
-
getOne,
|
|
563
540
|
getResByTXTL,
|
|
564
541
|
getResByTX,
|
|
565
542
|
getResByTL,
|
package/src/proxy/mqtt.js
CHANGED
|
@@ -53,7 +53,7 @@ async function initMqtt(that) {
|
|
|
53
53
|
}
|
|
54
54
|
} else if (content.target === 'Contact') {
|
|
55
55
|
console.log(`收到联系人:${content.alias || content.name}发送消息请求: ${content.message.content || content.message.url}`)
|
|
56
|
-
let contact = (await that.Contact.find({
|
|
56
|
+
let contact = (await that.Contact.find({ name: content.name })) || (await that.Contact.find({ alias: content.alias })) || (await that.Contact.find({ weixin: content.weixin })) // 获取你要发送的联系人
|
|
57
57
|
if (!contact) {
|
|
58
58
|
console.log(`查找不到联系人:${content.name || content.alias},请检查联系人名称是否正确`)
|
|
59
59
|
return
|
|
@@ -4,7 +4,6 @@ const { getConstellation, msgArr, getAllSchedule, generateRoomImg, getRoomAvatar
|
|
|
4
4
|
const { initTaskLocalSchedule } = require('../task/index')
|
|
5
5
|
const { updateContactAndRoom, updateContactOnly, updateRoomOnly } = require('../common/index')
|
|
6
6
|
const { chatTencent } = require('../proxy/tencent')
|
|
7
|
-
const { log } = require('wechaty')
|
|
8
7
|
/**
|
|
9
8
|
* 根据事件名称分配不同的api处理,并获取返回内容
|
|
10
9
|
* @param {string} eName 事件名称
|
|
@@ -1,6 +1,50 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { log } = require('wechaty')
|
|
2
|
+
const { Message } = require('wechaty').types
|
|
3
|
+
const Mustache = require('mustache')
|
|
4
|
+
|
|
5
|
+
function roomTalker(options) {
|
|
6
|
+
log.verbose('WechatyPluginContrib', 'roomTalker(%s)', JSON.stringify(options))
|
|
7
|
+
if (!options) {
|
|
8
|
+
return () => undefined
|
|
9
|
+
}
|
|
10
|
+
if (!Array.isArray(options)) {
|
|
11
|
+
options = [options]
|
|
12
|
+
}
|
|
13
|
+
const optionList = options
|
|
14
|
+
return async function talkRoom(room, contact, mustacheView) {
|
|
15
|
+
log.verbose('WechatyPluginContrib', 'roomTalker() talkRoom(%s, %s, %s)', room, contact || '', mustacheView ? JSON.stringify(mustacheView) : '')
|
|
16
|
+
for (const option of optionList) {
|
|
17
|
+
let msg
|
|
18
|
+
if (option instanceof Function) {
|
|
19
|
+
msg = await option(room, contact)
|
|
20
|
+
} else {
|
|
21
|
+
msg = option
|
|
22
|
+
}
|
|
2
23
|
|
|
3
|
-
|
|
24
|
+
if (!msg) {
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof msg === 'string') {
|
|
29
|
+
if (mustacheView) {
|
|
30
|
+
msg = Mustache.render(msg, mustacheView)
|
|
31
|
+
}
|
|
32
|
+
if (contact) {
|
|
33
|
+
await room.say(msg, contact)
|
|
34
|
+
} else {
|
|
35
|
+
await room.say(msg)
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
/**
|
|
39
|
+
* FIXME(huan): https://github.com/microsoft/TypeScript/issues/14107
|
|
40
|
+
*/
|
|
41
|
+
await room.say(msg)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
await room.wechaty.sleep(1000)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
4
48
|
|
|
5
49
|
function messageMapper(mapperOptions, one) {
|
|
6
50
|
log.verbose('WechatyPluginContrib', 'messageMapper(%s)', typeof mapperOptions === 'function' ? 'function' : JSON.stringify(mapperOptions))
|
|
@@ -141,7 +185,7 @@ const bidirectionalMapper = async (message) => {
|
|
|
141
185
|
try {
|
|
142
186
|
const abbrRoomTopicForDevelopersHome = abbrRoomTopicByRegex(/\s*([^\s]*\s*[^\s]+)$/)
|
|
143
187
|
// Drop all messages if not Text
|
|
144
|
-
if (message.type() !== Message.
|
|
188
|
+
if (message.type() !== Message.Text) {
|
|
145
189
|
return
|
|
146
190
|
}
|
|
147
191
|
|
|
@@ -175,7 +219,7 @@ const unidirectionalMapper = async (message, one) => {
|
|
|
175
219
|
const room = message.room()
|
|
176
220
|
const topic = await room.topic()
|
|
177
221
|
switch (message.type()) {
|
|
178
|
-
case Message.
|
|
222
|
+
case Message.Text:
|
|
179
223
|
messageList.push(`${prefix}: ${message.text()}`)
|
|
180
224
|
break
|
|
181
225
|
|
|
@@ -187,7 +231,7 @@ const unidirectionalMapper = async (message, one) => {
|
|
|
187
231
|
* then we add a sender information for the destination rooms.
|
|
188
232
|
*/
|
|
189
233
|
if (topic === one) {
|
|
190
|
-
const type = Message
|
|
234
|
+
const type = Message[message.type()]
|
|
191
235
|
messageList.unshift(`${prefix}: ${type}`)
|
|
192
236
|
}
|
|
193
237
|
break
|
|
@@ -374,11 +418,11 @@ async function oneToMany(that, config, msg) {
|
|
|
374
418
|
*/
|
|
375
419
|
async function dispatchAsync(that, msg, list) {
|
|
376
420
|
try {
|
|
377
|
-
const userSelfName = that.
|
|
421
|
+
const userSelfName = that.currentUser.name()
|
|
378
422
|
const type = msg.type()
|
|
379
423
|
const content = msg.text()
|
|
380
424
|
const mentionSelf = content.includes(`@${userSelfName}`)
|
|
381
|
-
if (that.Message.
|
|
425
|
+
if (that.Message.Text === type && mentionSelf) {
|
|
382
426
|
// 如果内容中有提及机器人的内容,不进行转发
|
|
383
427
|
return
|
|
384
428
|
}
|
|
@@ -387,7 +431,7 @@ async function dispatchAsync(that, msg, list) {
|
|
|
387
431
|
config.blacklist = [async () => true]
|
|
388
432
|
if (config.forward === 1) {
|
|
389
433
|
config.map = bidirectionalMapper
|
|
390
|
-
config.whitelist = [async (message) => message.type() === Message.
|
|
434
|
+
config.whitelist = [async (message) => message.type() === Message.Text]
|
|
391
435
|
} else if (config.forward === 2) {
|
|
392
436
|
config.blacklist = []
|
|
393
437
|
config.map = unidirectionalMapper
|