Skip to content

Commit 07be218

Browse files
author
chengeng
committed
添加图灵机器人
1 parent 8bf7536 commit 07be218

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,11 @@ github:[https://github.com/gengchen528/wechatBot](https://github.com/gengchen528
298298

299299
## 更新日志
300300

301+
2019-03-06
302+
* 添加图灵机器人配置项,需要先去注册图灵机器人,[网址](http://www.tuling123.com)
301303
2019-03-04
302304
* 进群后播报欢迎词
305+
303306
2019-03-02:
304307
* 添加自动加好友,自动拉群可配置项
305308
* 重启后可维持登录状态

config/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
module.exports ={
33
AUTOADDFRIEND:false,//自动加好友功能 默认关闭
44
AUTOADDROOM:false,//自动拉群功能 默认关闭
5+
AUTOREPLY:false,//自动聊天功能 默认关闭
56
ONE:'http://wufazhuce.com/',////ONE的web版网站
67
MOJI_HOST:'https://tianqi.moji.com/weather/china/', //中国墨迹天气url
78
CITY:'shanghai',//收信者所在城市
89
LOCATION:'pudong-new-district',//收信者所在区 (可以访问墨迹天气网站后,查询区的英文拼写)
10+
AIBOTAPI:'http://www.tuling123.com/openapi/api',//图灵机器人API 注册地址http://www.turingapi.com/
11+
APIKEY:'你的图灵机器人apikey',//图灵机器人apikey
912
MEMORIAL_DAY:'2015/04/18', //你和收信者的纪念日
1013
NAME:'A兔子',//备注姓名
1114
NICKNAME:'嗯哼', //昵称

index.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,25 @@ async function onMessage (msg) {
6262
}
6363
}
6464
}else {
65-
await contact.say('你好,由于目前群里人数超过100,群主将会看到消息后,第一时间把你拉入群中!')
66-
await contact.say('谢谢理解^_^')
65+
if(config.AUTOREPLY){ // 如果开启自动聊天
66+
let reply = await superagent.getReply(content)
67+
console.log('图灵机器人回复:',reply)
68+
try{
69+
await contact.say(reply)
70+
}catch (e) {
71+
console.error(e)
72+
}
73+
}
74+
}
75+
}else {
76+
if(config.AUTOREPLY){ // 如果开启自动聊天
77+
let reply = await superagent.getReply(content)
78+
console.log('图灵机器人回复:',reply)
79+
try{
80+
await contact.say(reply)
81+
}catch (e) {
82+
console.error(e)
83+
}
6784
}
6885
}
6986
}

superagent/index.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ async function getWeather() { //获取墨迹天气
3131
}
3232
return obj
3333
}
34+
35+
async function getReply(word) { // 青云api,智能聊天机器人
36+
let url = config.AIBOTAPI
37+
let res = await superagent.req(url,'GET',{key:config.APIKEY,info:word})
38+
let content = JSON.parse(res.text)
39+
if(content.code===100000){
40+
return content.text
41+
}else {
42+
return '我好像迷失在无边的网络中了,你能找回我么'
43+
}
44+
}
3445
module.exports ={
35-
getOne,getWeather
46+
getOne,getWeather,getReply
3647
}

0 commit comments

Comments
 (0)