fix: 修复无法查询别人

This commit is contained in:
Qian23333 2025-08-16 09:10:06 +08:00
parent e8d596b1c2
commit c0542f8688

View file

@ -181,13 +181,17 @@ export class Remind extends ZZZPlugin {
} }
async checkNow() { async checkNow() {
const userConfig = await this.getUserConfig(this.e.user_id); const uid = await this.getUID();
if (!uid) return false;
const targetUserId = this.e.user_id;
const userConfig = await this.getUserConfig(targetUserId);
if (!userConfig) { if (!userConfig) {
await this.reply('尚未设置任何提醒,请先设置阈值'); await this.reply('尚未设置任何提醒,请先设置阈值');
return false; return false;
} }
await this.reply('正在查询,请稍候...'); await this.reply('正在查询,请稍候...');
const messages = await this.checkUser(this.e.user_id, userConfig, true); // 主动查询,显示所有状态 const messages = await this.checkUser(targetUserId, userConfig, true); // 主动查询,显示所有状态
if (messages.length > 0) { if (messages.length > 0) {
await this.reply(messages.join('\n')); await this.reply(messages.join('\n'));
} else { } else {
@ -195,28 +199,30 @@ export class Remind extends ZZZPlugin {
} }
} }
async checkUser(userId, userConfig, showAll = false) { async checkUser(userId, userConfig, showAll = false, contextE = null) {
let messages = []; let messages = [];
// 创建一个模拟的 e 对象,用于获取 API
const mockE = {
user_id: userId,
game: 'zzz',
reply: (msg) => logger.info(`[Remind Mock Reply] ${msg}`)
};
// 临时设置 this.e 用于调用父类方法
const originalE = this.e; const originalE = this.e;
this.e = mockE; this.e = contextE || this.e;
let api, deviceFp;
try { try {
const { api, deviceFp } = await this.getAPI(); // 获取 API 和玩家信息
await this.getPlayerInfo(mockE); ({ api, deviceFp } = await this.getAPI());
await this.getPlayerInfo(this.e);
} catch (error) {
logger.error(`[ZZZ-Plugin] 为用户 ${userId} 获取API或玩家信息失败: ${error}`);
messages.push('查询失败,请稍后再试');
// 恢复原来的 this.e
this.e = originalE;
return messages;
}
// 检查式舆防卫战 // 检查式舆防卫战
const abyssRawData = await api.getFinalData('zzzChallenge', { deviceFp }).catch(() => ({})); try {
if (!abyssRawData.has_data) { const abyssRawData = await api.getFinalData('zzzChallenge', { deviceFp });
messages.push(`式舆防卫战S评级: 0/7`); if (!abyssRawData || !abyssRawData.has_data) {
messages.push('式舆防卫战S评级: 0/7');
} else { } else {
const abyssData = new ZZZChallenge(abyssRawData); const abyssData = new ZZZChallenge(abyssRawData);
const userThreshold = userConfig.abyssCheckLevel || 7; const userThreshold = userConfig.abyssCheckLevel || 7;
@ -226,11 +232,16 @@ export class Remind extends ZZZPlugin {
messages.push(`式舆防卫战S评级: ${sCount}/7${status}`); messages.push(`式舆防卫战S评级: ${sCount}/7${status}`);
} }
} }
} catch (error) {
logger.error(`[ZZZ-Plugin] 为用户 ${userId} 检查式舆防卫战失败: ${error}`);
messages.push('式舆防卫战查询失败');
}
// 检查危局强袭战 // 检查危局强袭战
const deadlyRawData = await api.getFinalData('zzzDeadly', { deviceFp }).catch(() => ({})); try {
if (!deadlyRawData.has_data) { const deadlyRawData = await api.getFinalData('zzzDeadly', { deviceFp });
messages.push(`危局强袭战星星: 0/9`); if (!deadlyRawData || !deadlyRawData.has_data) {
messages.push('危局强袭战星星: 0/9');
} else { } else {
const deadlyData = new Deadly(deadlyRawData); const deadlyData = new Deadly(deadlyRawData);
if (showAll || deadlyData.total_star < userConfig.deadlyStars) { if (showAll || deadlyData.total_star < userConfig.deadlyStars) {
@ -239,12 +250,12 @@ 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
this.e = originalE; this.e = originalE;
}
return messages; return messages;
} }
@ -266,7 +277,14 @@ export class Remind extends ZZZPlugin {
const remindTime = userConfig.remindTime || globalRemindTime; const remindTime = userConfig.remindTime || globalRemindTime;
if (this.isTimeMatch(remindTime, now)) { if (this.isTimeMatch(remindTime, now)) {
const messages = await this.checkUser(userId, userConfig); // 创建一个模拟的 e 对象,用于获取 API
const mockE = {
user_id: userId,
game: 'zzz',
reply: (msg) => logger.info(`[Remind Mock Reply] ${msg}`)
};
const messages = await this.checkUser(userId, userConfig, false, mockE);
if (messages.length > 0) { if (messages.length > 0) {
const user = Bot.pickUser(userId); const user = Bot.pickUser(userId);
await user.sendMsg(messages.join('\n')); await user.sendMsg(messages.join('\n'));