秉持开源精神,允许任意方式的魔改与使用,但请注明出处
【这不是插件!!!!】
没事不要乱下载,仅提供给插件开发人员自动检测插件版本与MineBBS版本的思路。
这个插件直接在LXL上执行没有任何功能,除了检测自己的版本。。。。
仅供大家分享与学习
【思路】
其实很简单粗暴,抓取MineBBS,然后分析出版本号,并与当前插件版本进行比较,并给予用户提示
他抓取的页面是更新页面,如图:
结果如下:
如果你是新插件刚刚发布的,你会发现你没有 ”更新” 这一栏,你需要随便更新一下。因为minebbs默认新发布的插件这个 ”更新“ 栏不存在,自检的时候会找这个栏目,如果发现不存在,会报 ”连接重置“。
因此你需要做的就是:
1、把下载的源码复制到你的插件代码最头部
2、修改插件相关信息
3、正常更新MineBBS
4、当插件运行时会去爬取更新页面的标题,版本,更新标题,更新信息
注:这里必须要有“更新”这一栏,因为如果没有这一栏,会导致连接被重定向,因此如果你是第一次发布插件,请随便填写一次更新
5、返回到用户服务端控制台
【用法】
【非常重要】
注:由于minebbs的url算法问题,每次你更新资源都不要修改大标题,就算要修改也不要添加字母和数字。因为minebbs的url算法是依据大标题动态生成的,所以如果你修改了大标题,你的url也会变化,会让插件爬取不到更新信息
例如我的大标题是:
VersionCheck - 插件版本与MineBBS最新版本比较的【源码】
现在的url是:
他会依据大标题的英文与数字进行组合生存url,如果我把大标题修改为 :
VersionCheck - 插件版本与MineBBS最新版本比较的【源码】abcd
那么我的url就会变成
"https://www.minebbs.com/resources/versioncheck-minebbs-abcd.随机数字/"
你需要修改的信息参考如下:
【注意】
它可能会修改你的日志路径,默认存储在作者名目录下,如果需要更改,自行修改源码头部的logger日志配置即可
有人会问,为什么不做成一个可导出接口的独立插件。其实最开始设计的就是想导出的,然后让别的插件导入接口即可。但是有一个问题,你怎么确保每一个服主他都有这个版本自检插件,最后还是回到了插件开发人员自己身上。因此直接在自己的插件头部插入一串自检代码不就好了吗。而且在1.8版本之后,再也不需要修改这串头部代码了,放心插入吧
底下代码是最新的自检代码,别问我为什么不放在GitHub,毕竟不是所有腐竹的服务器都可以访问
你假装没看见就好了
俗话说,羊毛出在羊身上
【这不是插件!!!!】
没事不要乱下载,仅提供给插件开发人员自动检测插件版本与MineBBS版本的思路。
这个插件直接在LXL上执行没有任何功能,除了检测自己的版本。。。。
仅供大家分享与学习
【思路】
其实很简单粗暴,抓取MineBBS,然后分析出版本号,并与当前插件版本进行比较,并给予用户提示
他抓取的页面是更新页面,如图:
结果如下:
如果你是新插件刚刚发布的,你会发现你没有 ”更新” 这一栏,你需要随便更新一下。因为minebbs默认新发布的插件这个 ”更新“ 栏不存在,自检的时候会找这个栏目,如果发现不存在,会报 ”连接重置“。
因此你需要做的就是:
1、把下载的源码复制到你的插件代码最头部
2、修改插件相关信息
3、正常更新MineBBS
4、当插件运行时会去爬取更新页面的标题,版本,更新标题,更新信息
注:这里必须要有“更新”这一栏,因为如果没有这一栏,会导致连接被重定向,因此如果你是第一次发布插件,请随便填写一次更新
5、返回到用户服务端控制台
【用法】
【非常重要】
注:由于minebbs的url算法问题,每次你更新资源都不要修改大标题,就算要修改也不要添加字母和数字。因为minebbs的url算法是依据大标题动态生成的,所以如果你修改了大标题,你的url也会变化,会让插件爬取不到更新信息
例如我的大标题是:
VersionCheck - 插件版本与MineBBS最新版本比较的【源码】
现在的url是:
他会依据大标题的英文与数字进行组合生存url,如果我把大标题修改为 :
VersionCheck - 插件版本与MineBBS最新版本比较的【源码】abcd
那么我的url就会变成
"https://www.minebbs.com/resources/versioncheck-minebbs-abcd.随机数字/"
你需要修改的信息参考如下:
JavaScript:
let pluginsInfo = {
//你的插件minebbs地址
minebbs_url:"https://www.minebbs.com/resources/versioncheck-minebbs.3362/",
//你的名称
author:"KING",
//首发平台(当然是minebbs啦,不是的话估计你也没法使用)
platform:"minebbs",
//现在这个插件名称
name:"VersionCheck",
//现在这个插件版本
version:"1.8",
//LXLQQ群,你可以修改为自己的
LiteXLoaderQQ:"850517473",
};
//默认日志路径(如果没有别的需求,别改)
let baseDir = "./plugins/"+pluginsInfo.author+"/"
let pluginsFolder = baseDir+pluginsInfo.name+"/";
//日志等级
let loggerLevel=5;
logger.setTitle(pluginsInfo.name);
logger.setFile(pluginsFolder+"/log/"+system.getTimeStr().split(" ")[0]+".log",loggerLevel);
//日志打印到控制台
logger.setConsole(true,loggerLevel)
//打印插件信息
function showPluginInfo(){
log("===============")
log("作者: "+pluginsInfo.author+" "+"首发平台: "+pluginsInfo.platform+" "+"当前版本: "+pluginsInfo.version);
log("author: "+pluginsInfo.author+" "+"publishing platform: "+pluginsInfo.platform+" "+"version: "+pluginsInfo.version);
//这里是你的私人信息,你可以自己修改这里
log("问题反馈请私信或请前往LiteXLoad群: " + pluginsInfo.LiteXLoaderQQ);
log("For feedback, please send a private letter or go to litexload QQ group: " + pluginsInfo.LiteXLoaderQQ);
log("===============");
}
它可能会修改你的日志路径,默认存储在作者名目录下,如果需要更改,自行修改源码头部的logger日志配置即可
有人会问,为什么不做成一个可导出接口的独立插件。其实最开始设计的就是想导出的,然后让别的插件导入接口即可。但是有一个问题,你怎么确保每一个服主他都有这个版本自检插件,最后还是回到了插件开发人员自己身上。因此直接在自己的插件头部插入一串自检代码不就好了吗。而且在1.8版本之后,再也不需要修改这串头部代码了,放心插入吧

底下代码是最新的自检代码,别问我为什么不放在GitHub,毕竟不是所有腐竹的服务器都可以访问
你假装没看见就好了

俗话说,羊毛出在羊身上
JavaScript:
//+++++OpenSourceForPluginsToCheckUpdate+++++//
//统一控制台输出
const consoleLog={
title:pluginsInfo.name,
_log(msg,showdate,title,type){
msg = msg+"";
// msg = msg.replace(/\{/g,"<(").replace(/\}/g,")>")
if(title!=null){
this.title=title;
logger.setTitle(pluginsInfo.name+" <"+title+">");
}else{
if(this.title!=pluginsInfo.name){
this.title=pluginsInfo.name;
logger.setTitle(pluginsInfo.name);
}
}
let time = (showdate!=null&&showdate==true)?("["+system.getTimeStr()+"] "):"";
switch(type){
case "info":{
logger.info(time+msg)
}break;
case "warning":{
logger.warn(time+msg)
}break;
case "error":{
logger.error(time+msg)
}break;
case "debug":{
if(pluginsInfo.debug){
let time = (showdate!=null&&showdate==true)?("["+system.getTimeStr()+"] "):"";
// colorLog("yellow","["+time+"debug]["+pluginsInfo.name+"]"+msg)
logger.debug(time+msg)
}
}break;
default:{
throw new Error("Wrong logger type");
}
}
},
info(msg,showdate,title){
this._log(msg,showdate,title,"info")
},
warning(msg,showdate,title){
this._log(msg,showdate,title,"warning")
},
error(msg,showdate,title){
this._log(msg,showdate,title,"error")
},
/**
* 利用catch递归捕捉,替换\n为缩进,可以实现仿堆栈打印
* @param {错误信息} msg
* @param {是否打印时间} showdate
*/
fatal(msg,showdate){
msg = msg.replace(/\{/g,"<(").replace(/\}/g,")>")
let endStr = "\n\nLXL Error trace(Useless):";
let startStr = "\n\n\n"+pluginsInfo.name+" Error trace(Useful):";
let time = (showdate!=null&&showdate==true)?(system.getTimeStr()+" "):"";
msg = msg.replace(endStr,"");
msg = msg.replace(startStr,"");
msg = msg.replace(/\n/g,"\n ");
msg = msg.replace("\nError:","");
throw new Error(startStr+"\n["+time+"ERROR]["+pluginsInfo.name+"]"+msg+endStr);
},
debug(msg,showdate,title){
this._log(msg,showdate,title,"debug")
},
}
//统一版本控制
let versionControl={
/**
* 版本比较,v1,v2必须是字符串,例如 v1=“1.2.3” v2=“1.2.4” 两者格式必须统一,不能出现类似于 v1="1.1" v2="1.1.1"
* @param {版本1} v1
* @param {版本2} v2
* @returns -1:v1<v2 0:v1=v2 1:v1>v2
*/
versionCompare:function(v1,v2){
let v1array = v1.split(".");
let v2array = v2.split(".");
try{
//防止出现版本格式不一致
for(let i in v1array){
if(parseInt(v1array[i])>parseInt(v2array[i])) {
return 1;
}else if(parseInt(v1array[i])<parseInt(v2array[i])){
return -1;
}
}
}catch(error){
consoleLog.error(error)
}
return 0;
},
//从MineBBS抓取html
checkUpdata:function(url,pluginInfo){
if(url==null) return;
//结尾不能有多个斜杠,否则会被重定向
url = url.replace(/[\/]+$/,"")
let updateInterface = "/updates";
network.httpGet(url+updateInterface,(status,result)=>{
if(300<=status&&status<400){
consoleLog.warning("版本自检:插件已经更新,但是更新连接已经改变\n请前往 "+url+" 查看更新详情\n",true);
}else if(status==200){
let minebbsPluginInfo = this.getVersionFrom_MineBBS(result);
let compareResult = this.versionCompare(minebbsPluginInfo.version,pluginInfo.version)
if(compareResult == 1){
let title = minebbsPluginInfo.title;
let versionMsg="你当前版本: "+pluginInfo.version+" 最新版: "+minebbsPluginInfo.version;
let url = "你的版本已经落后,请立即前往MineBBS官网更新: "+pluginInfo.minebbs_url;
let updateTitle = "*更新标题: "+minebbsPluginInfo.updateTitle;
let headSpace=" ";
let updateMsg = "*更新信息: \n"+headSpace+minebbsPluginInfo.updateMsg.replace(/\n/g,"\n"+headSpace);
consoleLog.warning("\n《"+title+"》\n"+versionMsg+"\n"+url+"\n"+updateTitle+"\n"+updateMsg+"\n")
}else if(compareResult == 0){
consoleLog.info("当前为最新版")
}else{
consoleLog.warning("当前为测试版: " + pluginInfo.version + " 最新版是: "+minebbsPluginInfo.version)
}
}else{
consoleLog.warning("版本自检:无法连接至网络:请检查网络连接状态 或 网址是否正确",true);
}
})
},
//分析出插件标题与版本号
getVersionFrom_MineBBS:function(htmlCode){
htmlCode = htmlCode.replace(/<br \/>/g,"");
let info={
title:"",//爬取的标题
version:"",//爬取的版本
updateTitle:"",//更新标题
updateMsg:"",//更新信息
}
let posStr = `<span class="u-muted">`;
let pos = htmlCode.indexOf(posStr);//定位到版本号标签起始位置
if(pos>0){
let index = pos+posStr.length;//跳过版本号标签定位到版本号位置
let current = "";
while(current!="<"){ //搜索版本号
info.version = info.version + current;
current = htmlCode[index];
index++;
}
// =======================================================
index = pos-1;//回到标签上一个位置
let isJumpSuffixBlack=false;
current = "\t";
while(current!=">"){
if(current==" "||current=="\n"||current=="\t"){ //跳过后缀制表
if(isJumpSuffixBlack){
info.title = current+info.title;
}
}else{
isJumpSuffixBlack=true;
info.title = current + info.title;
}
current = htmlCode[index];
index--;
}
}
// =======================================================
let updateTitleTag = "\/\" rel=\"nofollow\">";
let updateTitlePos = htmlCode.indexOf(updateTitleTag);
if(updateTitlePos>=0){
let index = updateTitlePos+updateTitleTag.length//获取到定位位置后面
let current = "";
while(current!="<"){
info.updateTitle = info.updateTitle + current;
current = htmlCode[index];
index++;
if(current=="\n"||current=="\t") continue;
}
}
// =======================================================
let updateMsgTag = "<div class=\"bbWrapper\">";
let updateMsgPos = htmlCode.indexOf(updateMsgTag);
if(updateMsgPos>=0){
let index = updateMsgPos+updateMsgTag.length//获取到定位位置后面
let current = "";
while(current!="<"){
info.updateMsg = info.updateMsg + current;
current = htmlCode[index];
index++;
if(current=="\n"||current=="\t") continue;
}
}
info.updateMsg = info.updateMsg.replace(/</g,"<").replace(/>/g,">");
return info;
}
}
function _checkUpdate(pluginsInfo){
setTimeout(()=>{
versionControl.checkUpdata(pluginsInfo.minebbs_url,pluginsInfo);
},5000) //延迟5秒后启动更新检查
}_checkUpdate(pluginsInfo);
//+++++OpenSourceForPluginsToCheckUpdate+++++//