refactor(onebot): drop redundant per-action try/catch in qzone/album/admin
阶段 2a:删除 qzone(7)、group-album(8)、group-admin(1) 共 16 个「纯兜底再包一层」 的 try/catch,让抛错自然落到唯一 seam runAction(阶段 1 已统一为 ACTION_FAILED 100 + error.message)。qzone/album 原返回 1200 → 归一 100(本任务有意);group-admin 原本就是 100,仅去冗余包装。 - 保留:qzone helper uploadQzoneImages 的带前缀 re-throw catch、group-info 的 honor-info 前缀 catch、message 的吞值 catch(best-effort 保留旧 URL)——均未动。 - 清理三文件不再使用的 RETCODE/failedResponse import。 - qzone-actions 测试断言 1200 → 100(wording 前缀经 seam 仍保留)。 - onebot 全量 516 全绿、typecheck 干净;对抗性 Agent 逐个对比 HEAD 确认纯兜底、 无其它漂移、无误删漏改。
This commit is contained in:
4 files changed
+51
-130
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { defineAction, registerActions, f } from '../action-kit';
|
||||
import type { ApiActionContext, ApiHandler } from '../api-handler';
|
||||
import type { JsonValue } from '../types';
|
||||
import { RETCODE, failedResponse, okResponse } from '../types';
|
||||
import { okResponse } from '../types';
|
||||
|
||||
async function uploadQzoneImages(
|
||||
ctx: ApiActionContext,
|
||||
@@ -61,13 +61,8 @@ export const actions = [
|
||||
num: f.int({ min: 1, max: 100 }).describe('本页数量').default(20),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
const res = await ctx.bridge.apis.qzone.getMsgList(p.target_uin, p.pos, p.num);
|
||||
return okResponse(res as unknown as JsonValue);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'failed to get qzone msg list';
|
||||
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||
}
|
||||
const res = await ctx.bridge.apis.qzone.getMsgList(p.target_uin, p.pos, p.num);
|
||||
return okResponse(res as unknown as JsonValue);
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -106,13 +101,8 @@ export const actions = [
|
||||
count: f.int({ min: 1, max: 50 }).describe('本页数量').default(10),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
const res = await ctx.bridge.apis.qzone.getFeeds(p.page_num, p.count);
|
||||
return okResponse(res as unknown as JsonValue);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'failed to get qzone feeds';
|
||||
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||
}
|
||||
const res = await ctx.bridge.apis.qzone.getFeeds(p.page_num, p.count);
|
||||
return okResponse(res as unknown as JsonValue);
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -134,18 +124,13 @@ export const actions = [
|
||||
r.rule('target_uins is required when ugc_right is 16 or 128', (p) => (p.ugc_right !== 16 && p.ugc_right !== 128) || !!p.target_uins?.length),
|
||||
],
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
if (p.images && p.images.length > 0) {
|
||||
const richval = await uploadQzoneImages(ctx, p.images, (upload) => upload.richval);
|
||||
const res = await ctx.bridge.apis.qzone.publish(p.content, 1, richval, p.ugc_right, p.target_uins?.join('|'));
|
||||
return okResponse(res as unknown as JsonValue);
|
||||
}
|
||||
const res = await ctx.bridge.apis.qzone.publish(p.content, undefined, undefined, p.ugc_right, p.target_uins?.join('|'));
|
||||
if (p.images && p.images.length > 0) {
|
||||
const richval = await uploadQzoneImages(ctx, p.images, (upload) => upload.richval);
|
||||
const res = await ctx.bridge.apis.qzone.publish(p.content, 1, richval, p.ugc_right, p.target_uins?.join('|'));
|
||||
return okResponse(res as unknown as JsonValue);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'failed to publish qzone msg';
|
||||
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||
}
|
||||
const res = await ctx.bridge.apis.qzone.publish(p.content, undefined, undefined, p.ugc_right, p.target_uins?.join('|'));
|
||||
return okResponse(res as unknown as JsonValue);
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -157,13 +142,8 @@ export const actions = [
|
||||
tid: f.string({ allowEmpty: false }).describe('说说 tid(来自 get_qzone_msg_list / send_qzone_msg)'),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
await ctx.bridge.apis.qzone.delete(p.tid);
|
||||
return okResponse(null);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'failed to delete qzone msg';
|
||||
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||
}
|
||||
await ctx.bridge.apis.qzone.delete(p.tid);
|
||||
return okResponse(null);
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -179,13 +159,8 @@ export const actions = [
|
||||
abstime: f.int({ min: 0 }).describe('说说发表时间(unix 秒),传真实值更可靠').default(0).role('timestamp'),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
await ctx.bridge.apis.qzone.like(p.tid, p.target_uin, true, p.abstime);
|
||||
return okResponse(null);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'failed to like qzone msg';
|
||||
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||
}
|
||||
await ctx.bridge.apis.qzone.like(p.tid, p.target_uin, true, p.abstime);
|
||||
return okResponse(null);
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -200,13 +175,8 @@ export const actions = [
|
||||
abstime: f.int({ min: 0 }).describe('说说发表时间(unix 秒),传真实值更可靠').default(0).role('timestamp'),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
await ctx.bridge.apis.qzone.like(p.tid, p.target_uin, false, p.abstime);
|
||||
return okResponse(null);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'failed to unlike qzone msg';
|
||||
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||
}
|
||||
await ctx.bridge.apis.qzone.like(p.tid, p.target_uin, false, p.abstime);
|
||||
return okResponse(null);
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -223,18 +193,13 @@ export const actions = [
|
||||
images: f.array(f.string({ allowEmpty: false })).describe('图片数组(可选),支持 file:// http:// base64://;自动上传').optional(),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
if (p.images && p.images.length > 0) {
|
||||
const richval = await uploadQzoneImages(ctx, p.images, (upload) => upload.url);
|
||||
const res = await ctx.bridge.apis.qzone.comment(p.tid, p.content, p.target_uin, 1, richval);
|
||||
return okResponse(res as unknown as JsonValue);
|
||||
}
|
||||
const res = await ctx.bridge.apis.qzone.comment(p.tid, p.content, p.target_uin);
|
||||
if (p.images && p.images.length > 0) {
|
||||
const richval = await uploadQzoneImages(ctx, p.images, (upload) => upload.url);
|
||||
const res = await ctx.bridge.apis.qzone.comment(p.tid, p.content, p.target_uin, 1, richval);
|
||||
return okResponse(res as unknown as JsonValue);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'failed to comment qzone msg';
|
||||
return failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||
}
|
||||
const res = await ctx.bridge.apis.qzone.comment(p.tid, p.content, p.target_uin);
|
||||
return okResponse(res as unknown as JsonValue);
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user