Session失效后自动重连
这个提交包含在:
107
CGI.js
107
CGI.js
@ -174,63 +174,74 @@ 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})
|
||||||
},(err,res)=>{
|
},(err,res)=>{
|
||||||
if(res == null){
|
if(res == null){
|
||||||
console.log("["+new Date().toString()+"][./Core.js]系统断线,十秒后重连");
|
console.log("["+new Date().toString()+"][./Core.js]系统断线,十秒后重连");
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
Active(true)
|
Active(true)
|
||||||
},10000)
|
},10000)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Session = JSON.parse(res.body).session;
|
Session = JSON.parse(res.body).session;
|
||||||
request.post({
|
request.post({
|
||||||
url:`http://127.0.0.1:${ServicePort}/bind`,
|
url:`http://127.0.0.1:${ServicePort}/bind`,
|
||||||
body:JSON.stringify({
|
body:JSON.stringify({
|
||||||
sessionKey:Session,
|
sessionKey:Session,
|
||||||
qq:2142562417
|
qq:2142562417
|
||||||
})
|
})
|
||||||
},(err2,res2)=>{
|
},(err2,res2)=>{
|
||||||
console.log("["+new Date().toString()+"][./Core.js]Session激活成功.");
|
console.log("["+new Date().toString()+"][./Core.js]Session激活成功.");
|
||||||
console.log(`得到Session[${Session}]`);
|
console.log(`得到Session[${Session}]`);
|
||||||
exports.HOOK = HOOK;
|
exports.HOOK = HOOK;
|
||||||
var STHandle = setInterval(()=>{
|
var STHandle = setInterval(()=>{
|
||||||
if(Session == ""){return}
|
if(Session == ""){return}
|
||||||
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(data == null || data == undefined){return}
|
if(err){
|
||||||
if(data.body.toString().substr(0,1)!="{"){return;}
|
console.error(err);
|
||||||
var MainData = JSON.parse(data.body);
|
}
|
||||||
if(MainData == null || MainData == undefined){return};
|
if(data == null || data == undefined){return}
|
||||||
if(MainData.data == null||MainData.data == undefined){return};
|
if(data.body.toString().substr(0,1)!="{"){return;}
|
||||||
var data_obj = MainData.data[0];
|
var MainData = JSON.parse(data.body);
|
||||||
if(data_obj == undefined){return};
|
if(MainData == null || MainData == undefined){return};
|
||||||
if(data_obj == last){
|
if(MainData.code != 0){
|
||||||
return
|
console.log(MainData);
|
||||||
}else{
|
|
||||||
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)
|
||||||
},10000)
|
},10000)
|
||||||
}
|
}
|
||||||
Core.frame.CGI("",data_obj);
|
if(MainData.data == null||MainData.data == undefined){return};
|
||||||
last = data_obj;
|
var data_obj = MainData.data[0];
|
||||||
}
|
if(data_obj == undefined){return};
|
||||||
});
|
if(data_obj == last){
|
||||||
},50);
|
return
|
||||||
});
|
}else{
|
||||||
});})
|
if(data_obj["type"]=="BotOfflineEventActive"){
|
||||||
|
Session = "";
|
||||||
|
console.log(`[${new Date().toString()}][CGI.JS]MIRAI端掉线,十秒后重连`)
|
||||||
|
clearInterval(STHandle);
|
||||||
|
setTimeout(()=>{
|
||||||
|
Active(true)
|
||||||
|
},10000)
|
||||||
|
}
|
||||||
|
Core.frame.CGI("",data_obj);
|
||||||
|
last = data_obj;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},50);
|
||||||
|
});
|
||||||
|
});}
|
||||||
|
)
|
||||||
|
|
||||||
global.Active = Active;
|
global.Active = Active;
|
||||||
Active();
|
Active();
|
||||||
在新工单中引用
屏蔽一个用户