refactor(api): move 14 group-admin methods to GroupAdminApi (#6 commit 3/13)
Third of 13 commits. Folds the previous `actions/group-admin.ts`
plus the matching Bridge facade methods into a typed `apis.groupAdmin`
hub.
Methods (14, all renamed to drop the redundant `Group` prefix once
the `apis.groupAdmin` namespace makes it implicit):
muteGroupMember → apis.groupAdmin.muteMember
muteGroupAll → apis.groupAdmin.muteAll
setGroupAddOption → apis.groupAdmin.setAddOption
setGroupSearch → apis.groupAdmin.setSearch
setGroupAddRequest → apis.groupAdmin.setAddRequest
kickGroupMember → apis.groupAdmin.kickMember
kickGroupMembers → apis.groupAdmin.kickMembers
leaveGroup → apis.groupAdmin.leave
setGroupAdmin → apis.groupAdmin.setAdmin
setGroupCard → apis.groupAdmin.setCard
setGroupName → apis.groupAdmin.setName
setGroupSpecialTitle→ apis.groupAdmin.setSpecialTitle
setGroupRemark → apis.groupAdmin.setRemark
getGroupAtAllRemain → apis.groupAdmin.getAtAllRemain
actions/group-admin.ts deleted. The corresponding `*_` alias imports
and `async xxx() { return xxx_(this, …); }` delegate methods on
Bridge are gone.
Caller updates
--------------
* onebot/instance-context.ts — 6 sites (the multi-method binding for
the OneBot action layer).
* onebot/actions/extended.ts — 8 sites including `getAtAllRemain`.
* onebot/actions/group-admin.ts — all 6 onebot action handlers.
* onebot/modules/request-actions.ts — `setGroupAddRequest`.
Test updates
------------
* tests/actions/group-admin.test.ts — was importing the deleted
`* as admin` module and calling `admin.muteGroupMember(bridge, ...)`.
Switched to `new GroupAdminApi(bridge as any).muteMember(...)` —
same wire validation, just constructs the real Api class once per
call (the Api is stateless so it's effectively free).
* tests/onebot/request-actions.test.ts — was stubbing
`setGroupAddRequest` flat on bridge. Updated to
`apis: { groupAdmin: { setAddRequest } } as any`.
Tests: 587/587 pass (network-manager native-addon failure unchanged).
This commit is contained in:
1 parent
6bf53890dc
commit
0b91e4db8d
11 files changed
+228
-253
No files matched your search
@@ -550,7 +550,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (params.remark === undefined) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'remark is required (pass an empty string to clear)');
|
||||
}
|
||||
await ctx.bridge.setGroupRemark(groupId, asString(params.remark));
|
||||
await ctx.bridge.apis.groupAdmin.setRemark(groupId, asString(params.remark));
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -888,7 +888,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
const data = await ctx.bridge.getGroupAtAllRemain(groupId);
|
||||
const data = await ctx.bridge.apis.groupAdmin.getAtAllRemain(groupId);
|
||||
return okResponse(data);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
|
||||
@@ -42,14 +42,14 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const addType = asNumber(params.add_type);
|
||||
if (!groupId || addType === undefined) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and add_type are required');
|
||||
await ctx.bridge.setGroupAddOption(groupId, addType);
|
||||
await ctx.bridge.apis.groupAdmin.setAddOption(groupId, addType);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
h.registerAction('set_group_search', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
await ctx.bridge.setGroupSearch(groupId);
|
||||
await ctx.bridge.apis.groupAdmin.setSearch(groupId);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -58,7 +58,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const enable = asBoolean(params.enable, true);
|
||||
if (!groupId || !userId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id are required');
|
||||
await ctx.bridge.setGroupAdmin(groupId, userId, enable);
|
||||
await ctx.bridge.apis.groupAdmin.setAdmin(groupId, userId, enable);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -67,7 +67,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const card = asString(params.card);
|
||||
if (!groupId || !userId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id are required');
|
||||
await ctx.bridge.setGroupCard(groupId, userId, card);
|
||||
await ctx.bridge.apis.groupAdmin.setCard(groupId, userId, card);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -75,7 +75,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const name = asString(params.group_name);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
await ctx.bridge.setGroupName(groupId, name);
|
||||
await ctx.bridge.apis.groupAdmin.setName(groupId, name);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -91,7 +91,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const title = asString(params.special_title);
|
||||
if (!groupId || !userId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id are required');
|
||||
await ctx.bridge.setGroupSpecialTitle(groupId, userId, title);
|
||||
await ctx.bridge.apis.groupAdmin.setSpecialTitle(groupId, userId, title);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
|
||||
@@ -112,11 +112,11 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
getStrangerInfo: (userId) => getStrangerInfo(bridge, userId),
|
||||
|
||||
// Group admin — names translate to OneBot vocabulary.
|
||||
setGroupKick: (groupId, userId, reject) => bridge.kickGroupMember(groupId, userId, reject),
|
||||
setGroupKickMembers: (groupId, userIds, reject) => bridge.kickGroupMembers(groupId, userIds, reject),
|
||||
setGroupBan: (groupId, userId, duration) => bridge.muteGroupMember(groupId, userId, duration),
|
||||
setGroupWholeBan: (groupId, enable) => bridge.muteGroupAll(groupId, enable),
|
||||
setGroupLeave: (groupId) => bridge.leaveGroup(groupId),
|
||||
setGroupKick: (groupId, userId, reject) => bridge.apis.groupAdmin.kickMember(groupId, userId, reject),
|
||||
setGroupKickMembers: (groupId, userIds, reject) => bridge.apis.groupAdmin.kickMembers(groupId, userIds, reject),
|
||||
setGroupBan: (groupId, userId, duration) => bridge.apis.groupAdmin.muteMember(groupId, userId, duration),
|
||||
setGroupWholeBan: (groupId, enable) => bridge.apis.groupAdmin.muteAll(groupId, enable),
|
||||
setGroupLeave: (groupId) => bridge.apis.groupAdmin.leave(groupId),
|
||||
|
||||
// Group file — fileId field extraction + defaults.
|
||||
uploadGroupFile: async (groupId, file, name, folderId, uploadFile) => {
|
||||
@@ -164,7 +164,7 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
handleDeleteFriend: (userId, block) => bridge.deleteFriend(userId, !!block),
|
||||
forceFetchClientKey: () => bridge.forceFetchClientKey(),
|
||||
setFriendRemark: (userId, remark) => bridge.setFriendRemark(userId, remark),
|
||||
setGroupRemark: (groupId, remark) => bridge.setGroupRemark(groupId, remark),
|
||||
setGroupRemark: (groupId, remark) => bridge.apis.groupAdmin.setRemark(groupId, remark),
|
||||
setGroupAvatar: (groupId, source) => bridge.setGroupAvatar(groupId, source),
|
||||
getGroupFileCount: (groupId) => bridge.fetchGroupFileCount(groupId),
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ export async function handleGroupAddRequest(
|
||||
throw new Error('matching group request not found');
|
||||
}
|
||||
|
||||
await bridge.setGroupAddRequest(
|
||||
await bridge.apis.groupAdmin.setAddRequest(
|
||||
groupId,
|
||||
matching.sequence,
|
||||
matching.eventType,
|
||||
|
||||
Reference in new issue
Block a user