#角色详情 支持从外部API进行查询

This commit is contained in:
yoimiya-kokomi 2022-04-16 17:40:30 +08:00
parent 8002b7a916
commit 4d3146004d
7 changed files with 41 additions and 20 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
/components/cfg.json
/resources/miao-res-plus/
/components/setting.json
/config.js

View File

@ -416,8 +416,10 @@ export async function getProfile(e) {
return true;
}
let data = await Profile.request(selfUser.uid, e);
if (!data || !data.chars) {
if(!data){
return true;
}
if (!data.chars) {
e.reply("请求游戏信息失败请确认角色已在游戏内橱窗展示并开放了查看详情。设置完毕后请5分钟后再进行请求~");
} else {
let ret = [];

View File

@ -4,10 +4,6 @@ import lodash from "lodash";
const _path = process.cwd();
const _cfgPath = `${_path}/plugins/miao-plugin/components/`;
let cfg = {};
console.log(cfg);
if (!fs.existsSync(_cfgPath)) {
fs.mkdirSync(_cfgPath);
}
try {
if (fs.existsSync(_cfgPath + "cfg.json")) {

View File

@ -5,15 +5,18 @@ import Format from "./Format.js";
import Character from "./models/Character.js";
const _path = process.cwd();
const cfgPath = `${_path}/plugins/miao-plugin/components/setting.json`;
let cfg = {};
try {
if (fs.existsSync(cfgPath)) {
cfg = JSON.parse(fs.readFileSync(cfgPath, "utf8")) || {};
const cfgPath = `${_path}/plugins/miao-plugin/config.js`;
let config = {};
//try {
if (fs.existsSync(cfgPath)) {
let fileData = await import (`file://${cfgPath}`);
if (fileData && fileData.config) {
config = fileData.config;
}
} catch (e) {
// do nth
}
//} catch (e) {
// do nth
//}
const userPath = `${_path}/data/UserData/`;
@ -207,17 +210,27 @@ let Data = {
let Profile = {
async request(uid, e) {
let cfg = config.miaoApi || {};
if (!cfg.api) {
e.reply("尚未配置更新Api无法更新数据~");
return false;
}
if (!cfg.qq || !cfg.token || cfg.token.length !== 32) {
e.reply("Token错误无法请求数据~");
return false;
}
e.reply("开始获取角色展柜中展示的角色详情,请确认已经打开显示角色详情开关,数据获取可能会需要一定时间~");
const api = cfg.api + uid;
const api = `${cfg.api}?uid=${uid}&qq=${cfg.qq}&token=${cfg.token}`;
console.log(api);
let req = await fetch(api);
let data = await req.text();
data = data.replace(/\x00/g, '');
fs.writeFileSync(userPath + "/test.json", data);
data = JSON.parse(data);
let data = await req.json();
//fs.writeFileSync(userPath + "/test.json", data);
if (data.status !== 0 || !data.data) {
e.reply(`请求错误:${data.msg || "未知错误"}`);
return false;
}
data = data.data;
let userData = {};
if (data && data["角色名称"]) {
userData = Profile.save(uid, data)

7
config_default.js Normal file
View File

@ -0,0 +1,7 @@
export default {
miaoApi: {
api: "http://49.232.91.210:88/miaoPlugin/GetRoleAll", // Miao APi 地址
qq: "", // 申请的主人qq
token: "" // 申请的token
}
}

View File

@ -47,4 +47,6 @@ lodash.forEach(rule, (r) => {
r.hashMark = true;
});
export { rule };
export { rule };
console.log("喵喵插件初始化~");

View File

@ -40,7 +40,7 @@
<div class="char-cons">
{{each cons con idx}}
<div class="cons-item">
<div class="talent-icon {{idx*1>data.cons*1 ? 'off':''}}">
<div class="talent-icon {{idx*1>avatar.actived_constellation_num*1 ? 'off':''}}">
<img src="{{_res_path}}/meta/character/{{name}}/cons_{{idx}}.png"/>
</div>
</div>