fix: 修复定时任务无法获取api

This commit is contained in:
Qian23333 2025-08-15 14:30:09 +08:00
parent 534ef0765e
commit 09df0ace00

View file

@ -162,17 +162,24 @@ export class Remind extends ZZZPlugin {
async checkUser(userId, userConfig, showAll = false) { async checkUser(userId, userConfig, showAll = false) {
let messages = []; let messages = [];
try {
const user = this.e.bot.pickUser(userId);
const tempE = { ...this.e, user_id: userId, reply: (msg) => user.sendMsg(msg) };
const { api, deviceFp } = await this.getAPI(tempE); // 创建一个模拟的 e 对象,用于获取 API
await this.getPlayerInfo(tempE); const mockE = {
user_id: userId,
game: 'zzz',
reply: (msg) => logger.info(`[Remind Mock Reply] ${msg}`)
};
// 临时设置 this.e 用于调用父类方法
const originalE = this.e;
this.e = mockE;
try {
const { api, deviceFp } = await this.getAPI();
await this.getPlayerInfo(mockE);
// 检查式舆防卫战 // 检查式舆防卫战
const abyssRawData = await api const abyssRawData = await api.getFinalData('zzzChallenge', { deviceFp }).catch(() => ({}));
.getFinalData('zzzChallenge', { deviceFp })
.catch(() => ({}));
if (!abyssRawData.has_data) { if (!abyssRawData.has_data) {
messages.push(`式舆防卫战S评级: 0/7`); messages.push(`式舆防卫战S评级: 0/7`);
} else { } else {
@ -199,6 +206,9 @@ export class Remind extends ZZZPlugin {
} catch (error) { } catch (error) {
logger.error(`[ZZZ-Plugin] 为用户 ${userId} 执行检查失败: ${error}`); logger.error(`[ZZZ-Plugin] 为用户 ${userId} 执行检查失败: ${error}`);
messages.push('查询失败,请稍后再试'); messages.push('查询失败,请稍后再试');
} finally {
// 恢复原来的 this.e
this.e = originalE;
} }
return messages; return messages;
} }
@ -218,7 +228,7 @@ export class Remind extends ZZZPlugin {
const messages = await this.checkUser(userId, userConfig); const messages = await this.checkUser(userId, userConfig);
if (messages.length > 0) { if (messages.length > 0) {
const user = this.e.bot.pickUser(userId); const user = Bot.pickUser(userId);
await user.sendMsg(messages.join('\n')); await user.sendMsg(messages.join('\n'));
} }
} }