Skip to content

Commit d4c24b2

Browse files
author
chengeng
committed
添加自动发送群二维码功能,由于wechaty自动拉群功能失效
1 parent bd57a69 commit d4c24b2

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

index.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const schedule = require('./schedule/index')
77
const config = require('./config/index')
88
const untils = require('./untils/index')
99
const superagent = require('./superagent/index')
10+
const {FileBox} = require('file-box') //文件读取模块
1011
// 二维码生成
1112
function onScan (qrcode, status) {
1213
require('qrcode-terminal').generate(qrcode) // 在console端显示二维码
@@ -36,24 +37,26 @@ async function onMessage (msg) {
3637
const contact = msg.from() // 发消息人
3738
const content = msg.text() //消息内容
3839
const room = msg.room() //是否是群消息
40+
// const roomCode = FileBox.fromUrl('http://image.bloggeng.com/qun.png') //来自url的文件
41+
const roomCodeLocal = FileBox.fromFile('./static/qun.png') //添加本地文件
42+
if (msg.self()) {
43+
return
44+
}
3945
if(room){
4046
console.log(`群名: ${room.topic()} 发消息人: ${contact.name()} 内容: ${content}`)
4147
}else {
4248
console.log(`发消息人: ${contact.name()} 消息内容: ${content}`)
43-
}
44-
if (msg.self()) {
45-
return
46-
}
47-
if(/||/.test(content)){
48-
let keyRoom = await this.Room.find({topic: /^/i})
49-
if(keyRoom){
50-
try{
51-
await keyRoom.add(contact)
52-
await keyRoom.say('微信每日说:欢迎新朋友 ', contact)
53-
}catch (e) {
54-
console.error(e)
55-
}
49+
if(/|/.test(content)&&!room){
50+
let keyRoom = await this.Room.find({topic: /^/i})
51+
if(keyRoom){
52+
try{
53+
await contact.say(roomCodeLocal)
54+
await keyRoom.say('微信每日说:欢迎新朋友', contact)
55+
}catch (e) {
56+
console.error(e)
57+
}
5658

59+
}
5760
}
5861
}
5962
}
@@ -73,7 +76,7 @@ async function onFriendShip(friendship) {
7376
* and accept this request by `request.accept()`
7477
*/
7578
case Friendship.Type.Receive:
76-
if (/|||/i.test(friendship.hello())) {
79+
if (//i.test(friendship.hello())) {
7780
logMsg = '自动添加好友,因为验证信息中带关键字‘每日说’'
7881
await friendship.accept()
7982
} else {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"license": "ISC",
1111
"devDependencies": {
1212
"cheerio": "^1.0.0-rc.2",
13+
"file-box": "^0.8.27",
1314
"node-schedule": "^1.3.2",
1415
"qrcode-terminal": "^0.12.0",
1516
"superagent": "^4.1.0",

static/qun.png

254 KB
Loading

0 commit comments

Comments
 (0)