Session失效后自动重连
这个提交包含在:
19
CGI.js
19
CGI.js
@ -174,11 +174,9 @@ exports.frame={
|
|||||||
}
|
}
|
||||||
|
|
||||||
var Active = ((force=false)=>{
|
var Active = ((force=false)=>{
|
||||||
|
|
||||||
if(Session != "" && !force){
|
if(Session != "" && !force){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
request.post({
|
request.post({
|
||||||
url:`http://127.0.0.1:${ServicePort}/verify`,
|
url:`http://127.0.0.1:${ServicePort}/verify`,
|
||||||
body:JSON.stringify({verifyKey:Key})
|
body:JSON.stringify({verifyKey:Key})
|
||||||
@ -206,10 +204,22 @@ var Active = ((force=false)=>{
|
|||||||
request.get({
|
request.get({
|
||||||
url:`http://127.0.0.1:${ServicePort}/fetchLatestMessage?sessionKey=${Session}&count=1`
|
url:`http://127.0.0.1:${ServicePort}/fetchLatestMessage?sessionKey=${Session}&count=1`
|
||||||
},(err,data)=>{
|
},(err,data)=>{
|
||||||
|
if(err){
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
if(data == null || data == undefined){return}
|
if(data == null || data == undefined){return}
|
||||||
if(data.body.toString().substr(0,1)!="{"){return;}
|
if(data.body.toString().substr(0,1)!="{"){return;}
|
||||||
var MainData = JSON.parse(data.body);
|
var MainData = JSON.parse(data.body);
|
||||||
if(MainData == null || MainData == undefined){return};
|
if(MainData == null || MainData == undefined){return};
|
||||||
|
if(MainData.code != 0){
|
||||||
|
console.log(MainData);
|
||||||
|
Session = "";
|
||||||
|
console.log(`[${new Date().toString()}][CGI.JS]MIRAI端掉线,十秒后重连`)
|
||||||
|
clearInterval(STHandle);
|
||||||
|
setTimeout(()=>{
|
||||||
|
Active(true)
|
||||||
|
},10000)
|
||||||
|
}
|
||||||
if(MainData.data == null||MainData.data == undefined){return};
|
if(MainData.data == null||MainData.data == undefined){return};
|
||||||
var data_obj = MainData.data[0];
|
var data_obj = MainData.data[0];
|
||||||
if(data_obj == undefined){return};
|
if(data_obj == undefined){return};
|
||||||
@ -218,7 +228,7 @@ var Active = ((force=false)=>{
|
|||||||
}else{
|
}else{
|
||||||
if(data_obj["type"]=="BotOfflineEventActive"){
|
if(data_obj["type"]=="BotOfflineEventActive"){
|
||||||
Session = "";
|
Session = "";
|
||||||
console.log("[CGI.JS]MIRAI端掉线,十秒后重连")
|
console.log(`[${new Date().toString()}][CGI.JS]MIRAI端掉线,十秒后重连`)
|
||||||
clearInterval(STHandle);
|
clearInterval(STHandle);
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
Active(true)
|
Active(true)
|
||||||
@ -230,7 +240,8 @@ var Active = ((force=false)=>{
|
|||||||
});
|
});
|
||||||
},50);
|
},50);
|
||||||
});
|
});
|
||||||
});})
|
});}
|
||||||
|
)
|
||||||
|
|
||||||
global.Active = Active;
|
global.Active = Active;
|
||||||
Active();
|
Active();
|
||||||
在新工单中引用
屏蔽一个用户