Skip to content

Commit 9c1cae0

Browse files
author
chengeng
committed
更新readme
1 parent 70a90fa commit 9c1cae0

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

README.md

+40-26
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ index.js
6060
const config = require('./config/index')
6161
const untils = require('./untils/index')
6262
const superagent = require('./superagent/index')
63+
const {FileBox} = require('file-box') //文件读取模块
6364
// 二维码生成
6465
function onScan (qrcode, status) {
6566
require('qrcode-terminal').generate(qrcode) // 在console端显示二维码
@@ -84,29 +85,36 @@ index.js
8485
function onLogout(user) {
8586
console.log(`${user} 登出`)
8687
}
87-
// 自动加群功能
88+
// 监听对话 根据关键词自动加群
8889
async function onMessage (msg) {
8990
const contact = msg.from() // 发消息人
9091
const content = msg.text() //消息内容
9192
const room = msg.room() //是否是群消息
92-
if(room){
93-
console.log(`群名: ${room.topic()} 发消息人: ${contact.name()} 内容: ${content}`)
94-
}else {
95-
console.log(`发消息人: ${contact.name()} 消息内容: ${content}`)
96-
}
93+
const roomCodeUrl = FileBox.fromUrl(config.ROOMCODEURL) //来自url的文件
94+
const roomCodeLocal = FileBox.fromFile(config.ROOMLOCALPATH) //添加本地文件
9795
if (msg.self()) {
9896
return
9997
}
100-
if(/微信每日说|每日说|微信机器人/.test(content)){
101-
let keyRoom = await this.Room.find({topic: /^微信每日说/i})
102-
if(keyRoom){
103-
try{
104-
await keyRoom.add(contact)
105-
await keyRoom.say('微信每日说:欢迎新朋友 ', contact)
106-
}catch (e) {
107-
console.error(e)
98+
if(room){ // 如果是群消息
99+
const topic = await room.topic()
100+
console.log(`群名: ${topic} 发消息人: ${contact.name()} 内容: ${content}`)
101+
}else { // 如果非群消息
102+
console.log(`发消息人: ${contact.name()} 消息内容: ${content}`)
103+
let addRoomReg = eval(config.ADDROOMWORD)
104+
let roomReg = eval(config.ROOMNAME)
105+
if(addRoomReg.test(content)&&!room){
106+
let keyRoom = await this.Room.find({topic: roomReg})
107+
if(keyRoom){
108+
try{
109+
await contact.say(roomCodeLocal||roomCodeUrl)
110+
await keyRoom.say('微信每日说:欢迎新朋友', contact)
111+
}catch (e) {
112+
console.error(e)
113+
}
108114
}
109-
115+
}else {
116+
await contact.say('你好,不要轻易调戏我,我只会发群二维码,不会聊天的!')
117+
await contact.say('请回复暗号:加群 获取群二维码图片')
110118
}
111119
}
112120
}
@@ -126,14 +134,14 @@ index.js
126134
* and accept this request by `request.accept()`
127135
*/
128136
case Friendship.Type.Receive:
129-
if (/微信每日说|微信机器人|微信|每日说/i.test(friendship.hello())) {
137+
let addFriendReg = eval(config.ADDFRIENDWORD)
138+
if (addFriendReg.test(friendship.hello())) {
130139
logMsg = '自动添加好友,因为验证信息中带关键字‘每日说’'
131140
await friendship.accept()
132141
} else {
133142
logMsg = '没有通过验证 ' + friendship.hello()
134143
}
135144
break
136-
137145
/**
138146
*
139147
* 2. Friend Ship Confirmed
@@ -173,6 +181,7 @@ index.js
173181
.catch(e => console.error(e))
174182

175183

184+
176185
superagent/index.js
177186

178187
const superagent = require('../config/superagent')
@@ -237,18 +246,23 @@ yarn
237246

238247
wechatBot/config/index.js
239248

240-
// 配置文件
241249
// 配置文件
242250
module.exports ={
243-
ONE:'http://wufazhuce.com/',//ONE的web版网站
244-
MOJI_HOST:'https://tianqi.moji.com/weather/china/', //中国墨迹天气url
245-
CITY:'shanghai',//收信者所在城市
246-
LOCATION:'pudong-new-district',//收信者所在区
247-
MEMORIAL_DAY:'2015/04/18', //你和收信者的纪念日
248-
NAME:'Leo_chen',//微信备注姓名
249-
NICKNAME:'Leo_chen', //微信昵称
250-
SENDDATE:'30 * * * * *',//定时发送时间,规则见 /schedule/index.js
251+
ONE:'http://wufazhuce.com/',////ONE的web版网站
252+
MOJI_HOST:'https://tianqi.moji.com/weather/china/', //中国墨迹天气url
253+
CITY:'shanghai',//收信者所在城市
254+
LOCATION:'pudong-new-district',//收信者所在区 (可以访问墨迹天气网站后,查询区的英文拼写)
255+
MEMORIAL_DAY:'2015/04/18', //你和收信者的纪念日
256+
NAME:'Leo_chen',//备注姓名
257+
NICKNAME:'Leo_chen', //昵称
258+
SENDDATE:'30 15 8 * * *',//定时发送时间 每天8点15分30秒发送,规则见 /schedule/index.js
259+
ROOMNAME:'/^微信每日说/i', //群名(请只修改中文,不要删除符号,这是正则)
260+
ADDFRIENDWORD:'/微信每日说/i',//自动加好友触发的关键词(请只修改中文,不要删除符号,这是正则)
261+
ADDROOMWORD:'/加群/',//自动发送群图片触发关键词(请只修改中文,不要删除符号,这是正则)
262+
ROOMCODEURL:'http://image.bloggeng.com/qun.png',//群二维码url链接(与本地群二维码路径选填一个)
263+
ROOMLOCALPATH:'./static/qun.png',//本地群二维码图片路径(与群url选填一个)
251264
}
265+
252266
开始运行
253267

254268
npm run start

config/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports ={
33
ONE:'http://wufazhuce.com/',////ONE的web版网站
44
MOJI_HOST:'https://tianqi.moji.com/weather/china/', //中国墨迹天气url
55
CITY:'shanghai',//收信者所在城市
6-
LOCATION:'pudong-new-district',//收信者所在区
6+
LOCATION:'pudong-new-district',//收信者所在区 (可以访问墨迹天气网站后,查询区的英文拼写)
77
MEMORIAL_DAY:'2015/04/18', //你和收信者的纪念日
88
NAME:'Leo_chen',//备注姓名
99
NICKNAME:'Leo_chen', //昵称

0 commit comments

Comments
 (0)