Skip to content

Commit

Permalink
fix: #696 fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
MliKiowa committed Jan 7, 2025
1 parent 1ae47ff commit 3d16d52
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/common/fall-back.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ export class Fallback<T> {
for (const handler of this.handlers) {
try {
const result = await handler();
try {
return await this.checker(result);
} catch (checkerError) {
errors.push(checkerError instanceof Error ? checkerError : new Error(String(checkerError)));
let data = await this.checker(result);
if (data) {
return data;
}
} catch (error) {
console.log(error);
errors.push(error instanceof Error ? error : new Error(String(error)));
}
}
throw new AggregateError(errors, 'All handlers failed');
}
}
export class FallbackUtil{
export class FallbackUtil {
static boolchecker<T>(value: T, condition: boolean): T {
if (condition) {
return value;
Expand Down
2 changes: 1 addition & 1 deletion src/core/apis/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class NTQQUserApi {
.add(() => this.context.session.getGroupService().getUidByUins([uin]).then((data) => data.uids.get(uin)))
.add(() => this.getUserDetailInfoByUin(uin).then((data) => data.detail.uid));

const uid = await fallback.run().catch(() => '0');
const uid = await fallback.run().catch(() => '');
return uid ?? '';
}

Expand Down
3 changes: 2 additions & 1 deletion src/onebot/action/go-cqhttp/GetStrangerInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ type Payload = Static<typeof SchemaData>;

export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11User> {
actionName = ActionName.GoCQHTTP_GetStrangerInfo;

payloadSchema = SchemaData;
async _handle(payload: Payload): Promise<OB11User> {
const user_id = payload.user_id.toString();
const extendData = await this.core.apis.UserApi.getUserDetailInfoByUin(user_id);
let uid = (await this.core.apis.UserApi.getUidByUinV2(user_id));
if (!uid) uid = extendData.detail.uid;
console.log(uid);
const info = (await this.core.apis.UserApi.getUserDetailInfo(uid));
return {
...extendData.detail.simpleInfo.coreInfo,
Expand Down

0 comments on commit 3d16d52

Please sign in to comment.