fix(onebot): accept async quick-operation alias
NoneBot 1 request handlers call `.handle_quick_operation_async`. Treat that name as the existing quick-operation action so group invites are approved instead of ignored. Fixes #434
This commit is contained in:
4 files changed
+66
-9
No files matched your search
@@ -4,8 +4,9 @@
|
||||
// structured doc list + a Markdown view. The metadata is carried on the same
|
||||
// values that drive runtime validation, so docs cannot drift from behavior.
|
||||
//
|
||||
// The reserved `.handle_quick_operation` raw handler deliberately has no
|
||||
// ActionSpec/doc entry; every catalogued action comes from ACTION_REGISTRY.
|
||||
// The reserved `.handle_quick_operation` raw handler (and its `_async` alias)
|
||||
// deliberately has no ActionSpec/doc entry; every catalogued action comes
|
||||
// from ACTION_REGISTRY.
|
||||
//
|
||||
// The serving SURFACE (WebUI panel / OpenAPI export / static markdown) is a
|
||||
// deferred product decision; this module produces format-agnostic data plus a
|
||||
@@ -58,7 +59,7 @@ export function renderActionDocsMarkdown(docs: readonly ActionDoc[] = collectAct
|
||||
'# OneBot Actions',
|
||||
'',
|
||||
'> 由 `packages/onebot/src/action-docs.ts` 从各 `ActionSpec.describe()` 自动生成,请勿手改。',
|
||||
'> 覆盖完整声明式 Action registry;保留的 raw `.handle_quick_operation` handler 不生成文档。',
|
||||
'> 覆盖完整声明式 Action registry;保留的 raw `.handle_quick_operation` / `.handle_quick_operation_async` handler 不生成文档。',
|
||||
'',
|
||||
`共 ${docs.length} 个声明式 action。`,
|
||||
'',
|
||||
|
||||
@@ -211,14 +211,14 @@ function bindActionRegistry(
|
||||
|
||||
for (const claim of executableNames) {
|
||||
if (claim.kind === 'raw') {
|
||||
const factory = rawFactories[claim.name];
|
||||
const factory = rawFactories[claim.canonical];
|
||||
if (!factory) {
|
||||
throw new Error(
|
||||
`Action registry raw factory missing: canonical "${claim.canonical}" `
|
||||
+ `(name "${claim.name}", kind raw)`,
|
||||
);
|
||||
}
|
||||
factoryNames.delete(claim.name);
|
||||
factoryNames.delete(claim.canonical);
|
||||
handlers.set(claim.name, Object.freeze({
|
||||
handler: factory(api),
|
||||
canonical: claim.canonical,
|
||||
@@ -262,10 +262,12 @@ export const ACTION_GROUPS: readonly ActionGroup[] = [
|
||||
{ category: '流式接口', actions: [...streamFileActions, ...streamDownloadActions] },
|
||||
];
|
||||
|
||||
/** The sole non-ActionSpec handler; reserved in the same namespace up front. */
|
||||
/** Hidden OneBot v11 quick-operation handler; `_async` is the NoneBot 1 alias. */
|
||||
export const HANDLE_QUICK_OPERATION_ACTION = '.handle_quick_operation';
|
||||
export const HANDLE_QUICK_OPERATION_ASYNC_ACTION = '.handle_quick_operation_async';
|
||||
export const RAW_ACTION_RESERVATIONS: readonly RawActionReservation[] = [
|
||||
{ name: HANDLE_QUICK_OPERATION_ACTION, canonical: HANDLE_QUICK_OPERATION_ACTION },
|
||||
{ name: HANDLE_QUICK_OPERATION_ASYNC_ACTION, canonical: HANDLE_QUICK_OPERATION_ACTION },
|
||||
];
|
||||
|
||||
/** Complete, validated runtime/docs registry. Compilation happens on import. */
|
||||
|
||||
@@ -147,13 +147,13 @@ export class ApiHandler {
|
||||
this.log = typeof uin === 'number' && uin > 0 ? moduleLog.child({ uin }) : moduleLog;
|
||||
const rawFactories: Record<string, (api: ApiHandler) => ActionHandler> = {};
|
||||
for (const raw of registry.rawActions) {
|
||||
if (raw.name !== HANDLE_QUICK_OPERATION_ACTION) {
|
||||
if (raw.canonical !== HANDLE_QUICK_OPERATION_ACTION) {
|
||||
throw new Error(
|
||||
`Action registry has no factory for raw action canonical "${raw.canonical}" `
|
||||
+ `(name "${raw.name}", kind raw)`,
|
||||
);
|
||||
}
|
||||
rawFactories[raw.name] = (api) => async (params) => {
|
||||
rawFactories[raw.canonical] = (api) => async (params) => {
|
||||
const opContext = params.context as JsonObject | undefined;
|
||||
const operation = params.operation as Record<string, unknown> | undefined;
|
||||
if (!opContext || !operation) {
|
||||
|
||||
Reference in new issue
Block a user