character.js 中使用新版cookie获取逻辑

This commit is contained in:
yoimiya-kokomi 2022-04-01 04:34:04 +08:00
parent db7c3de778
commit 6c026a7381
6 changed files with 18 additions and 86 deletions

View File

@ -1,9 +1,8 @@
export async function userStat(e) { export async function userStat(e) {
if (await e.checkAuth({
auth: "master"
})) return true;
if (!e.isMaster) {
// e.reply("暂无权限");
return;
}
let ret = /\d+/.exec(e.msg) let ret = /\d+/.exec(e.msg)
if (ret && ret[0]) { if (ret && ret[0]) {
@ -30,10 +29,10 @@ export async function userStat(e) {
} }
export async function rebuildCookie(e) { export async function rebuildCookie(e) {
let MysApi = await e.initMysApi({ if (await e.checkAuth({
auth: "master" auth: "master"
}); })) return true;
if (!MysApi) return true;
let count = 0; let count = 0;
for (let qq in NoteCookie) { for (let qq in NoteCookie) {
@ -49,10 +48,9 @@ export async function rebuildCookie(e) {
} }
export async function userStatus(e, { Models }) { export async function userStatus(e, { Models }) {
let MysApi = await e.initMysApi({ if (await e.checkAuth({
auth: "master" auth: "master"
}); })) return true;
if (!MysApi) return true;
let { MysUser } = Models; let { MysUser } = Models;
let userList = await MysUser.getAll(); let userList = await MysUser.getAll();
@ -68,10 +66,10 @@ export async function userStatus(e, { Models }) {
} }
export async function userCacheRebuild(e, { Models }) { export async function userCacheRebuild(e, { Models }) {
let MysApi = await e.initMysApi({ if (await e.checkAuth({
auth: "master" auth: "master"
}); })) return true;
if (!MysApi) return true;
let { MysUser } = Models; let { MysUser } = Models;
await MysUser._delCache(); await MysUser._delCache();
@ -80,10 +78,9 @@ export async function userCacheRebuild(e, { Models }) {
} }
export async function mysUserCk(e, { Models }) { export async function mysUserCk(e, { Models }) {
let MysApi = await e.initMysApi({ if (await e.checkAuth({
auth: "master" auth: "master"
}); })) return true;
if (!MysApi) return true;
let uid = e.msg.replace("#ck", ""); let uid = e.msg.replace("#ck", "");
@ -91,9 +88,9 @@ export async function mysUserCk(e, { Models }) {
let user = await MysUser.get(uid); let user = await MysUser.get(uid);
let ret = []; let ret = [];
console.log(user);
let cookie = await user.getCookie(); let cookie = await user.getCookie();
console.log(cookie)
e.reply("完成"); e.reply("完成");
return true; return true;
} }

View File

@ -45,7 +45,7 @@ export async function character(e, { render, User }) {
let roleId = char.id, uid = e.targetUser.uid; let roleId = char.id, uid = e.targetUser.uid;
let charData = await MysApi.getData('character'); let charData = await MysApi.getCharacter();
if (!charData) return true; if (!charData) return true;
@ -81,7 +81,6 @@ export async function character(e, { render, User }) {
return true; //事件结束不再往下 return true; //事件结束不再往下
} }
//#老婆 //#老婆
export async function wife(e, { render, User }) { export async function wife(e, { render, User }) {
let msg = e.msg; let msg = e.msg;
@ -112,7 +111,7 @@ export async function wife(e, { render, User }) {
return true; return true;
} }
let data = await MysApi.getData("character"); let data = await MysApi.getCharacter();
if (!data) return true; if (!data) return true;
let avatars = data.avatars; let avatars = data.avatars;
@ -179,9 +178,7 @@ async function getTalent(e, avatars, MysApi) {
let skill = {}; let skill = {};
let skillres = await MysApi.getData("detail", { let skillres = await MysApi.getAvatar(avatars.id);
avatar_id: avatars.id,
});
if (skillres.retcode == 0 && skillres.data && skillres.data.skill_list) { if (skillres.retcode == 0 && skillres.data && skillres.data.skill_list) {
skill.id = avatars.id; skill.id = avatars.id;
@ -220,7 +217,6 @@ async function getTalent(e, avatars, MysApi) {
return skill; return skill;
} }
// 获取角色数据 // 获取角色数据
function getCharacterData(avatars) { function getCharacterData(avatars) {
let list = []; let list = [];
@ -296,67 +292,6 @@ function getCharacterData(avatars) {
}; };
} }
export function roleIdToName(keyword, search_val = false) {
if (!keyword) {
return false;
}
if (search_val) {
return genshin.roleId[keyword][0] ? genshin.roleId[keyword][0] : "";
}
if (!nameID) {
nameID = new Map();
for (let i in genshin.roleId) {
for (let val of genshin.roleId[i]) {
nameID.set(val, i);
}
}
}
let name = nameID.get(keyword);
return name ? name : "";
}
async function limitGet(e) {
if (!e.isGroup) {
return true;
}
if (e.isMaster) {
return true;
}
let key = `genshin:limit:${e.user_id}`;
let num = await redis.get(key);
if (num && num >= e.groupConfig.mysDayLimit - 1) {
let name = lodash.truncate(e.sender.card, { length: 8 });
e.reply([segment.at(e.user_id, name), "\n今日查询已达上限"]);
return false;
}
return true;
}
async function limitSet(e) {
if (!e.isGroup) {
return true;
}
let key = `genshin:limit:${e.user_id}`;
let dayEnd = getDayEnd();
await redis.incr(key);
redis.expire(key, dayEnd);
}
function getDayEnd() {
let now = new Date();
let dayEnd = new Date(now.getFullYear(), now.getMonth(), now.getDate(), "23", "59", "59").getTime() / 1000;
return dayEnd - parseInt(now.getTime() / 1000);
}
function getCharacterImg(name) { function getCharacterImg(name) {
if (!fs.existsSync(`./plugins/miao-plugin/resources/characterImg/${name}/`)) { if (!fs.existsSync(`./plugins/miao-plugin/resources/characterImg/${name}/`)) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 577 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 888 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 577 KiB