fix: #696 fallback

This commit is contained in:
手瓜一十雪
2025-01-07 18:51:04 +08:00
parent 1ae47fffb4
commit 3d16d52dd8
3 changed files with 8 additions and 7 deletions

View File

@@ -20,19 +20,19 @@ export class Fallback<T> {
for (const handler of this.handlers) { for (const handler of this.handlers) {
try { try {
const result = await handler(); const result = await handler();
try { let data = await this.checker(result);
return await this.checker(result); if (data) {
} catch (checkerError) { return data;
errors.push(checkerError instanceof Error ? checkerError : new Error(String(checkerError)));
} }
} catch (error) { } catch (error) {
console.log(error);
errors.push(error instanceof Error ? error : new Error(String(error))); errors.push(error instanceof Error ? error : new Error(String(error)));
} }
} }
throw new AggregateError(errors, 'All handlers failed'); throw new AggregateError(errors, 'All handlers failed');
} }
} }
export class FallbackUtil{ export class FallbackUtil {
static boolchecker<T>(value: T, condition: boolean): T { static boolchecker<T>(value: T, condition: boolean): T {
if (condition) { if (condition) {
return value; return value;

View File

@@ -193,7 +193,7 @@ export class NTQQUserApi {
.add(() => this.context.session.getGroupService().getUidByUins([uin]).then((data) => data.uids.get(uin))) .add(() => this.context.session.getGroupService().getUidByUins([uin]).then((data) => data.uids.get(uin)))
.add(() => this.getUserDetailInfoByUin(uin).then((data) => data.detail.uid)); .add(() => this.getUserDetailInfoByUin(uin).then((data) => data.detail.uid));
const uid = await fallback.run().catch(() => '0'); const uid = await fallback.run().catch(() => '');
return uid ?? ''; return uid ?? '';
} }

View File

@@ -13,12 +13,13 @@ type Payload = Static<typeof SchemaData>;
export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11User> { export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11User> {
actionName = ActionName.GoCQHTTP_GetStrangerInfo; actionName = ActionName.GoCQHTTP_GetStrangerInfo;
payloadSchema = SchemaData;
async _handle(payload: Payload): Promise<OB11User> { async _handle(payload: Payload): Promise<OB11User> {
const user_id = payload.user_id.toString(); const user_id = payload.user_id.toString();
const extendData = await this.core.apis.UserApi.getUserDetailInfoByUin(user_id); const extendData = await this.core.apis.UserApi.getUserDetailInfoByUin(user_id);
let uid = (await this.core.apis.UserApi.getUidByUinV2(user_id)); let uid = (await this.core.apis.UserApi.getUidByUinV2(user_id));
if (!uid) uid = extendData.detail.uid; if (!uid) uid = extendData.detail.uid;
console.log(uid);
const info = (await this.core.apis.UserApi.getUserDetailInfo(uid)); const info = (await this.core.apis.UserApi.getUserDetailInfo(uid));
return { return {
...extendData.detail.simpleInfo.coreInfo, ...extendData.detail.simpleInfo.coreInfo,