feat: coldtime

This commit is contained in:
bietiaop 2024-07-13 19:31:57 +08:00
parent 59b40d600d
commit f09ad4b421
6 changed files with 24 additions and 7 deletions

View file

@ -2,6 +2,7 @@ import { ZZZPlugin } from '../lib/plugin.js';
import render from '../lib/render.js'; import render from '../lib/render.js';
import { rulePrefix } from '../lib/common.js'; import { rulePrefix } from '../lib/common.js';
import { getAuthKey } from '../lib/authkey.js'; import { getAuthKey } from '../lib/authkey.js';
import settings from '../lib/settings.js';
import { import {
anaylizeGachaLog, anaylizeGachaLog,
updateGachaLog, updateGachaLog,
@ -97,8 +98,9 @@ export class GachaLog extends ZZZPlugin {
return false; return false;
} }
const lastQueryTime = await redis.get(`ZZZ:GACHA:${uid}:LASTTIME`); const lastQueryTime = await redis.get(`ZZZ:GACHA:${uid}:LASTTIME`);
if (lastQueryTime && Date.now() - lastQueryTime < 1000 * 60 * 5) { const coldTime = settings.getConfig('panel').interval || 300;
await this.reply('1分钟内只能刷新一次请稍后重试'); if (lastQueryTime && Date.now() - lastQueryTime < 1000 * coldTime) {
await this.reply(`${coldTime}秒内只能刷新一次,请稍后再试`);
return false; return false;
} }
await redis.set(`ZZZ:GACHA:${uid}:LASTTIME`, Date.now()); await redis.set(`ZZZ:GACHA:${uid}:LASTTIME`, Date.now());

View file

@ -2,6 +2,7 @@ import { ZZZPlugin } from '../lib/plugin.js';
import render from '../lib/render.js'; import render from '../lib/render.js';
import { rulePrefix } from '../lib/common.js'; import { rulePrefix } from '../lib/common.js';
import { getPanelList, refreshPanel, getPanel } from '../lib/avatar.js'; import { getPanelList, refreshPanel, getPanel } from '../lib/avatar.js';
import settings from '../lib/settings.js';
export class Panel extends ZZZPlugin { export class Panel extends ZZZPlugin {
constructor() { constructor() {
@ -27,8 +28,18 @@ export class Panel extends ZZZPlugin {
}); });
} }
async refreshPanel() { async refreshPanel() {
const { api, deviceFp, uid } = await this.getAPI(); const uid = await this.getUID();
if (!api || !uid) return false; if (!uid) return;
const lastQueryTime = await redis.get(`ZZZ:PANEL:${uid}:LASTTIME`);
const coldTime = settings.getConfig('gacha').interval || 300;
if (lastQueryTime && Date.now() - lastQueryTime < 1000 * coldTime) {
await this.reply(`${coldTime}秒内只能刷新一次,请稍后再试`);
return;
}
const { api, deviceFp } = await this.getAPI();
if (!api) return false;
await redis.set(`ZZZ:PANEL:${uid}:LASTTIME`, Date.now());
await this.reply('正在刷新面板列表,请稍后...');
await this.getPlayerInfo(); await this.getPlayerInfo();
const result = await refreshPanel(this.e, api, uid, deviceFp); const result = await refreshPanel(this.e, api, uid, deviceFp);
const newChar = result.filter(item => item.isNew); const newChar = result.filter(item => item.isNew);
@ -66,11 +77,13 @@ export class Panel extends ZZZPlugin {
if (!uid) return false; if (!uid) return false;
const reg = new RegExp(`${rulePrefix}(.+)面板$`); const reg = new RegExp(`${rulePrefix}(.+)面板$`);
const name = this.e.msg.match(reg)[4]; const name = this.e.msg.match(reg)[4];
if (['刷新', '更新'].includes(name)) return this.getCharPanelList();
const data = getPanel(uid, name); const data = getPanel(uid, name);
if (!data) { if (!data) {
await this.reply(`未找到角色${name}的面板信息`); await this.reply(`未找到角色${name}的面板信息`);
return false; return;
} }
await this.reply('正在下载面板图片资源,请稍后...');
await data.get_detail_assets(); await data.get_detail_assets();
const finalData = { const finalData = {
charData: data, charData: data,

1
defSet/gacha.yaml Normal file
View file

@ -0,0 +1 @@
interval: 60

1
defSet/panel.yaml Normal file
View file

@ -0,0 +1 @@
interval: 60

View file

@ -1,7 +1,7 @@
import User from '../../genshin/model/user.js'; import User from '../../genshin/model/user.js';
import { getStoken } from './authkey.js'; import { getStoken } from './authkey.js';
export const rulePrefix = '((#|\\%)?(zzz|ZZZ|绝区零)|\\*|)'; export const rulePrefix = '^((#|\\%)?(zzz|ZZZ|绝区零))';
export async function getCk(e, s = false) { export async function getCk(e, s = false) {
e.isSr = true; e.isSr = true;

View file

@ -294,7 +294,7 @@ export class ZZZAvatarInfo {
async get_detail_assets() { async get_detail_assets() {
const role_icon = await getRoleImage(this.id); const role_icon = await getRoleImage(this.id);
this.role_icon = role_icon; this.role_icon = role_icon;
await this.weapon.get_assets(); await this?.weapon?.get_assets?.();
for (const equip of this.equip) { for (const equip of this.equip) {
await equip.get_assets(); await equip.get_assets();
} }