@@ -7,6 +7,7 @@ const schedule = require('./schedule/index')
7
7
const config = require ( './config/index' )
8
8
const untils = require ( './untils/index' )
9
9
const superagent = require ( './superagent/index' )
10
+ const { FileBox} = require ( 'file-box' ) //文件读取模块
10
11
// 二维码生成
11
12
function onScan ( qrcode , status ) {
12
13
require ( 'qrcode-terminal' ) . generate ( qrcode ) // 在console端显示二维码
@@ -36,24 +37,26 @@ async function onMessage (msg) {
36
37
const contact = msg . from ( ) // 发消息人
37
38
const content = msg . text ( ) //消息内容
38
39
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
+ }
39
45
if ( room ) {
40
46
console . log ( `群名: ${ room . topic ( ) } 发消息人: ${ contact . name ( ) } 内容: ${ content } ` )
41
47
} else {
42
48
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
+ }
56
58
59
+ }
57
60
}
58
61
}
59
62
}
@@ -73,7 +76,7 @@ async function onFriendShip(friendship) {
73
76
* and accept this request by `request.accept()`
74
77
*/
75
78
case Friendship . Type . Receive :
76
- if ( / 微 信 每 日 说 | 微 信 机 器 人 | 微 信 | 每 日 说 / i. test ( friendship . hello ( ) ) ) {
79
+ if ( / 微 信 每 日 说 / i. test ( friendship . hello ( ) ) ) {
77
80
logMsg = '自动添加好友,因为验证信息中带关键字‘每日说’'
78
81
await friendship . accept ( )
79
82
} else {
0 commit comments