2
0
mirror of https://github.com/ctrlcvs/xiaoyao-cvs-plugin.git synced 2024-12-23 11:40:51 +08:00
xiaoyao-cvs-plugin/apps/map.js

83 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-10-17 20:55:39 +08:00
import {
Cfg,
Data
} from "../components/index.js";
import fs from "fs";
import fetch from "node-fetch";
import utils from "../model/mys/utils.js";
import {
segment
} from "oicq";
let path = './data/map'
//mapId-地图别名
let getPath={
"&map_id=7":["渊下宫",'渊下'],
"&map_id=9":['璃月地下','层岩地下','层岩']
}
export const rule = {
genShenMap: {
reg: "^#(刷新|更新)?(.*)(在(哪|那)里*)$",
describe: "地图资源查询 #**在哪里",
},
delMapData: {
reg: "^#(清空|清除)地图(缓存)?数据$",
describe: "清空地图下载数据",
},
}
export async function delMapData(e){
let urlFile = fs.readdirSync(path);
let count=0;
for (const item of urlFile) {
try {
await fs.unlinkSync(`${path}/${item}`)
count++;
} catch (error) {
e.reply('清空地图数据异常~')
}
}
e.reply(`共清除${count}个地图数据~\n您后续可通过直接重新获取地图资源数据~`)
return true
}
2022-10-17 20:55:39 +08:00
export async function genShenMap(e){
let isBool=/刷新|更新/.test(e.msg)
let msg= e.msg.replace(/#|(哪|那)|里|在|刷新|更新/g,"")
let urlFile = fs.readdirSync(path);
2022-10-17 20:55:39 +08:00
let msgPath=`${path}/${msg}.jpg`
if(urlFile.includes(`${msg}.jpg`)&&!isBool){
2022-10-17 20:55:39 +08:00
await e.reply(segment.image(`file://${msgPath}`))
return true;
}
let data=await exReg(msg);
let url=`https://map.minigg.cn/map/get_map?resource_name=${data.msg}&is_cluster=false${data.item}`
2022-10-17 20:55:39 +08:00
let res=await fetch(url,{method:'get'})
try{
res=await res.json()
if(res.retcode==-1){
2022-10-19 07:05:20 +08:00
await e.reply(`${res.message}`)
2022-10-17 20:55:39 +08:00
return true;
}
}catch(ex){
await Data.downFile(url,msgPath)
await e.reply(segment.image(`file://${msgPath}`))
return true;
}
return false;
}
async function exReg(msg){
for (const item of Object.keys(getPath)) {
let reg =new RegExp(`${getPath[item].join('|')}`,'g')
if(reg.test(msg)){
return {item,msg:msg.replace(reg,'')}
}
}
return {item:'',msg}
}
2022-10-17 20:55:39 +08:00
init()
/** 初始化创建配置文件 */
function init () {
if (!fs.existsSync(path)) {
fs.mkdirSync(path)
}
}