Skip to content

Commit 7f1d864

Browse files
committed
修复找图后再发送图片会复读的情况,添加debug模式
1 parent 89c1e1f commit 7f1d864

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

config.default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"PerQQLimit": 50,
1616
"needAt": true,
1717
"greet": "哈喽,我准备聊天了!",
18-
"refuse": "今天聊得太多了,明天再聊吧~"
18+
"refuse": "今天聊得太多了,明天再聊吧~",
19+
"debug": false
1920
},
2021
"message": {
2122
"reqType": 0,

docs/config.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"PerQQLimit": 50,
2121
"needAt": true,
2222
"greet": "哈喽,我准备聊天了!",
23-
"refuse": "今天聊得太多了,明天再聊吧~"
23+
"refuse": "今天聊得太多了,明天再聊吧~",
24+
"debug": false
2425
},
2526
"message": {
2627
"reqType": 0,
@@ -73,6 +74,8 @@
7374

7475
- refuse——达到聊天次数上限后触发的回复
7576

77+
- debug——是否开启 debug 模式,此选项会在控制台内显示每次聊天发送和接受具体消息
78+
7679
## message 分支
7780

7881
不要修改,这是机器人发送请求所用的格式,我只是省力保存在这了 ( = v =)ok

index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bot.on('socket.connecting', function (wsType, attempts) {
4646
console.log(new Date().toLocaleString() + ' 第%d次连接[%s]成功! ( = v =)b', attempts, wsType);
4747
if (config.bot.admin > 0 && wsType === '/api') {
4848
setTimeout(() => {
49-
console.log(`APIKey: ${config.bot.Apikey}\n聊天限制次数: ${config.bot.PerQQLimit}/QQ\n是否需要@: ${config.bot.needAt ? '是' : '否'}`);
49+
console.log(`APIKey: ${config.bot.Apikey}\n聊天限制次数: ${config.bot.PerQQLimit}/QQ\n是否需要@: ${config.bot.needAt ? '是' : '否'}\ndebug模式: ${config.bot.debug ? '是' : '否'}`);
5050
bot('send_private_msg', {
5151
user_id: config.bot.admin,
5252
message: `${config.bot.greet}`
@@ -88,6 +88,8 @@ function GetMsg(e, context) {
8888
Msg.userInfo.groupId = context.group_id;
8989
} else if (context.discuss_id) {
9090
Msg.userInfo.groupId = context.discuss_id;
91+
} else {
92+
Msg.userInfo.groupId = "";
9193
}
9294

9395
Msg.userInfo.userId = context.user_id;
@@ -96,21 +98,29 @@ function GetMsg(e, context) {
9698
//判断消息类型
9799
if (isImg(message)) {
98100
Msg.reqType = 1;
101+
Msg.perception.inputText.text = "";
99102
Msg.perception.inputImage.url = message.substring(58, message.length - 1);
100103
} else {
101104
Msg.reqType = 0;
102105
Msg.perception.inputText.text = message;
106+
Msg.perception.inputImage.url = "";
103107
}
104108

105109
//调用API
106110
Axios.post(url, Msg
107111
).then(function HandleMsg(response) {
108112
var GotMsg;
113+
//debug模式
114+
if (config.bot.debug) {
115+
console.log(`\n发送消息:`);
116+
console.log(Msg);
117+
console.log(`接收消息:`);
118+
console.log(response.data.results);
119+
}
109120
if (response.data.results.length == 1) {
110121
GotMsg = response.data.results[0].values.text;
111122
} else {
112123
GotMsg = `${response.data.results[1].values.text}\n${response.data.results[0].values.url}`;
113-
Msg.perception.inputImage = ''; //清空图片URL
114124
}
115125
SendMsg(context, GotMsg);
116126
});
@@ -134,7 +144,6 @@ function SendMsg(context, SendMsg) {
134144
message: msg,
135145
});
136146
console.log(`${new Date().toLocaleString()} 回复${gd}群, ${user}者:\n${SendMsg}`);
137-
Msg.userInfo.groupId = ''; //清空群组信息
138147
} else if (context.discuss_id) {
139148
var msg = `[CQ:at,qq=${id}]${SendMsg}`;
140149
var gd = context.discuss_id;
@@ -143,7 +152,6 @@ function SendMsg(context, SendMsg) {
143152
message: msg,
144153
});
145154
console.log(`${new Date().toLocaleString()} 回复${gd}讨论组, ${user}者:\n${SendMsg}`);
146-
Msg.userInfo.groupId = ''; //清空群组信息
147155
} else {
148156
bot('send_private_msg', {
149157
user_id: context.user_id,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-tuling-bot",
3-
"version": "1.3.1",
3+
"version": "1.4.0",
44
"description": "使用图灵API来让你的机器人谈笑风生",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)