mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-17 05:37:46 +00:00
fix: 修复定时任务无法获取api
This commit is contained in:
parent
534ef0765e
commit
09df0ace00
1 changed files with 30 additions and 20 deletions
|
|
@ -162,28 +162,35 @@ 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 })
|
if (!abyssRawData.has_data) {
|
||||||
.catch(() => ({}));
|
messages.push(`式舆防卫战S评级: 0/7`);
|
||||||
if (!abyssRawData.has_data) {
|
} else {
|
||||||
messages.push(`式舆防卫战S评级: 0/7`);
|
const abyssData = new ZZZChallenge(abyssRawData);
|
||||||
} else {
|
const userThreshold = userConfig.abyssCheckLevel || 7;
|
||||||
const abyssData = new ZZZChallenge(abyssRawData);
|
if (showAll || !abyssData.areAllSUpTo(userThreshold)) {
|
||||||
const userThreshold = userConfig.abyssCheckLevel || 7;
|
const sCount = abyssData.getSRankCountUpTo(7);
|
||||||
if (showAll || !abyssData.areAllSUpTo(userThreshold)) {
|
const status = abyssData.areAllSUpTo(userThreshold) ? ' ✓' : '';
|
||||||
const sCount = abyssData.getSRankCountUpTo(7);
|
messages.push(`式舆防卫战S评级: ${sCount}/7${status}`);
|
||||||
const status = abyssData.areAllSUpTo(userThreshold) ? ' ✓' : '';
|
}
|
||||||
messages.push(`式舆防卫战S评级: ${sCount}/7${status}`);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查危局强袭战
|
// 检查危局强袭战
|
||||||
const deadlyRawData = await api.getFinalData('zzzDeadly', { deviceFp }).catch(() => ({}));
|
const deadlyRawData = await api.getFinalData('zzzDeadly', { deviceFp }).catch(() => ({}));
|
||||||
|
|
@ -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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue