From 606109f4b3300d17e8a4491b2000dd8fe9537620 Mon Sep 17 00:00:00 2001 From: bietiaop <1527109126@qq.com> Date: Mon, 15 Jul 2024 12:44:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9F=A5=E8=AF=A2=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E4=BA=BA&=E8=AE=BE=E7=BD=AE=E5=85=81=E8=AE=B8/=E7=A6=81?= =?UTF-8?q?=E6=AD=A2=E6=9F=A5=E8=AF=A2=E5=85=B6=E4=BB=96=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/gachalog.js | 16 +++++++++------- apps/panel.js | 3 ++- defSet/config.yaml | 2 ++ guoba.support.js | 6 ++++++ lib/plugin.js | 14 ++++++++------ lib/render.js | 1 - resources/common/layout/playerinfo.html | 4 ++-- 7 files changed, 29 insertions(+), 17 deletions(-) diff --git a/apps/gachalog.js b/apps/gachalog.js index be5e2ce..01e26bb 100644 --- a/apps/gachalog.js +++ b/apps/gachalog.js @@ -3,6 +3,7 @@ import render from '../lib/render.js'; import { rulePrefix } from '../lib/common.js'; import { getAuthKey } from '../lib/authkey.js'; import settings from '../lib/settings.js'; +import _ from 'lodash'; import { anaylizeGachaLog, updateGachaLog, @@ -81,6 +82,14 @@ export class GachaLog extends ZZZPlugin { async refreshGachaLog() { const uid = await this.getUID(); if (!uid) return false; + const lastQueryTime = await redis.get(`ZZZ:GACHA:${uid}:LASTTIME`); + const gachaConfig = settings.getConfig('gacha'); + const coldTime = _.get(gachaConfig, 'interval', 300); + if (lastQueryTime && Date.now() - lastQueryTime < 1000 * coldTime) { + await this.reply(`${coldTime}秒内只能刷新一次,请稍后再试`); + return false; + } + await redis.set(`ZZZ:GACHA:${uid}:LASTTIME`, Date.now()); try { const key = await getAuthKey(this.e, this.User, uid); if (!key) { @@ -97,13 +106,6 @@ export class GachaLog extends ZZZPlugin { if (!uid) { return false; } - const lastQueryTime = await redis.get(`ZZZ:GACHA:${uid}:LASTTIME`); - const coldTime = settings.getConfig('gacha').interval || 300; - if (lastQueryTime && Date.now() - lastQueryTime < 1000 * coldTime) { - await this.reply(`${coldTime}秒内只能刷新一次,请稍后再试`); - return false; - } - await redis.set(`ZZZ:GACHA:${uid}:LASTTIME`, Date.now()); this.reply('正在更新抽卡记录,可能需要一段时间,请耐心等待'); const { data, count } = await updateGachaLog(key, uid); let msg = `抽卡记录更新成功,共${Object.keys(data).length}个卡池`; diff --git a/apps/panel.js b/apps/panel.js index 7b50ff8..5934adf 100644 --- a/apps/panel.js +++ b/apps/panel.js @@ -31,7 +31,8 @@ export class Panel extends ZZZPlugin { const uid = await this.getUID(); if (!uid) return; const lastQueryTime = await redis.get(`ZZZ:PANEL:${uid}:LASTTIME`); - const coldTime = settings.getConfig('panel').interval || 300; + const panelSettings = settings.getConfig('panel'); + const coldTime = _.get(panelSettings, 'interval', 300); if (lastQueryTime && Date.now() - lastQueryTime < 1000 * coldTime) { await this.reply(`${coldTime}秒内只能刷新一次,请稍后再试`); return; diff --git a/defSet/config.yaml b/defSet/config.yaml index 9cbe634..e67cc30 100644 --- a/defSet/config.yaml +++ b/defSet/config.yaml @@ -1,2 +1,4 @@ render: scale: 100 +query: + others: true diff --git a/guoba.support.js b/guoba.support.js index 3399a2d..d180618 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -44,6 +44,12 @@ export function supportGuoba() { placeholder: '请输入数字', }, }, + { + field: 'config.query.others', + label: '允许查询他人信息', + bottomHelpMessage: '是否允许查询他人信息', + component: 'Switch', + }, { component: 'Divider', label: '抽卡设置', diff --git a/lib/plugin.js b/lib/plugin.js index 2010b66..8330e85 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -2,6 +2,7 @@ import MysZZZApi from './mysapi.js'; import { getCk } from './common.js'; import _ from 'lodash'; import NoteUser from '../../genshin/model/mys/NoteUser.js'; +import settings from '../lib/settings.js'; export class ZZZPlugin extends plugin { /** @@ -10,7 +11,10 @@ export class ZZZPlugin extends plugin { */ async getUID() { let user = this.e; - if (this.e.at) { + const query = settings.getConfig('config').query; + const allow = _.get(query, 'others', true); + if (this.e.at && allow) { + this.e.user_id = this.e.at; user = this.e.at; } this.User = await NoteUser.create(user); @@ -29,9 +33,6 @@ export class ZZZPlugin extends plugin { async getAPI() { let uid = await this.getUID(); if (!uid) return false; - if (this.e.at) { - this.e.user_id = this.e.at; - } const ck = await getCk(this.e); if (!ck || Object.keys(ck).filter(k => ck[k].ck).length === 0) { await this.reply('尚未绑定cookie,请先绑定cookie'); @@ -69,8 +70,9 @@ export class ZZZPlugin extends plugin { if (!userData) return false; userData = userData?.list[0]; let avatar = this.e.bot.avatar; - // 头像 - if (this.e.member?.getAvatarUrl) { + if (this.e?.user_id) { + avatar = `https://q1.qlogo.cn/g?b=qq&s=0&nk=${this.e.user_id}`; + } else if (this.e.member?.getAvatarUrl) { avatar = await this.e.member.getAvatarUrl(); } else if (this.e.friend?.getAvatarUrl) { avatar = await this.e.friend.getAvatarUrl(); diff --git a/lib/render.js b/lib/render.js index 6e7b6e2..7441fa7 100644 --- a/lib/render.js +++ b/lib/render.js @@ -38,7 +38,6 @@ function render(e, renderPath, renderData = {}, cfg = {}) { return { player: e?.playerCard?.player, avatar: e?.playerCard?.avatar, - qqId: e?.at || e.user_id, ...data, _res_path: resPath, _layout_path: layoutPath, diff --git a/resources/common/layout/playerinfo.html b/resources/common/layout/playerinfo.html index fb30609..0779e5d 100644 --- a/resources/common/layout/playerinfo.html +++ b/resources/common/layout/playerinfo.html @@ -1,7 +1,7 @@
+ \ No newline at end of file