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).
140 lines
7.8 KiB
TypeScript
140 lines
7.8 KiB
TypeScript
import type { SendPacketResult } from '../protocol/packet-sender';
|
|
import type { ApiHub } from './apis';
|
|
import type { GroupFilesResult } from './actions/group-file';
|
|
import type { MediaIndexNode } from './actions/shared';
|
|
import type {
|
|
ClientKeyInfo,
|
|
DownloadRKeyInfo,
|
|
UploadedFileMeta,
|
|
} from './bridge';
|
|
import type { BridgeEventBus } from './event-bus';
|
|
import type { ForwardNodePayload } from './events';
|
|
import type { IdentityService } from './identity-service';
|
|
import type { WebHonorType } from './web/group-honor';
|
|
|
|
export interface BridgeInterface {
|
|
// ─── Shared state ───
|
|
readonly identity: IdentityService;
|
|
readonly events: BridgeEventBus;
|
|
readonly activePid: number | null;
|
|
/**
|
|
* Typed Api hub — `apis.message.sendGroup(...)`, `apis.message.recallGroup(...)`,
|
|
* etc. The shape of `ApiHub` grows commit-by-commit as the #6
|
|
* refactor moves the remaining areas (group-admin, group-file,
|
|
* profile, …) off Bridge and onto their dedicated Api classes.
|
|
*/
|
|
readonly apis: ApiHub;
|
|
|
|
// ─── Resolution ───
|
|
resolveUserUid(uin: number, groupId?: number): Promise<string>;
|
|
|
|
// ─── Raw packet (deliberate escape hatch for `send_packet` action) ───
|
|
// OneBot clients use this to debug or invoke commands SnowLuma has no
|
|
// typed wrapper for. Every other method on this interface eventually
|
|
// routes through here.
|
|
sendRawPacket(serviceCmd: string, body: Uint8Array, timeoutMs?: number): Promise<SendPacketResult>;
|
|
|
|
// ─── Send-side protocol helpers (used by Api classes) ───
|
|
nextMessageRandom(): number;
|
|
nextClientSequence(): number;
|
|
|
|
// ─── Send (messages) ───
|
|
// Moved to `apis.message.{sendGroup, sendPrivate, sendC2cFile,
|
|
// recallGroup, recallPrivate, markGroupRead, markPrivateRead}`.
|
|
|
|
// ─── Fetch (contacts / profile / system) — moved to apis.contacts ───
|
|
|
|
// ─── Group admin (moved to apis.groupAdmin) ───
|
|
setGroupReaction(groupId: number, sequence: number, code: string, isSet: boolean): Promise<void>;
|
|
setGroupEssence(groupId: number, sequence: number, random: number, enable: boolean): Promise<void>;
|
|
|
|
// ─── Friend ───
|
|
setFriendAddRequest(uidOrFlag: string, approve: boolean): Promise<void>;
|
|
deleteFriend(userId: number, block?: boolean): Promise<void>;
|
|
setFriendRemark(userId: number, remark: string): Promise<void>;
|
|
|
|
// ─── Files ───
|
|
uploadGroupFile(groupId: number, file: string, name?: string, folderId?: string, uploadFile?: boolean): Promise<{ fileId: string | null }>;
|
|
uploadPrivateFile(userId: number, file: string, name?: string, uploadFile?: boolean): Promise<{ fileId: string | null }>;
|
|
/**
|
|
* Publish a previously-uploaded group file as a chat message via
|
|
* `OidbSvcTrpcTcp.0x6d9_4`. The atomic upload+publish flow inside
|
|
* `uploadGroupFile` already does this, but the OneBot send-message
|
|
* path needs it too for {type:'file', file_id} segments.
|
|
*/
|
|
sendGroupFileMessage(groupId: number, fileId: string): Promise<void>;
|
|
/** Cache file metadata so a later send_msg with just `file_id` can rehydrate it. */
|
|
rememberUploadedFile(meta: UploadedFileMeta): void;
|
|
recallUploadedFile(fileId: string): UploadedFileMeta | undefined;
|
|
fetchGroupFiles(groupId: number, folderId?: string): Promise<GroupFilesResult>;
|
|
fetchGroupFileUrl(groupId: number, fileId: string, busId?: number): Promise<string>;
|
|
fetchPrivateFileUrl(userId: number, fileId: string, fileHash: string): Promise<string>;
|
|
fetchGroupPttUrlByNode(groupId: number, node: MediaIndexNode): Promise<string>;
|
|
fetchPrivatePttUrlByNode(node: MediaIndexNode): Promise<string>;
|
|
fetchGroupVideoUrlByNode(groupId: number, node: MediaIndexNode): Promise<string>;
|
|
fetchPrivateVideoUrlByNode(node: MediaIndexNode): Promise<string>;
|
|
deleteGroupFile(groupId: number, fileId: string): Promise<void>;
|
|
moveGroupFile(groupId: number, fileId: string, parentDirectory: string, targetDirectory: string): Promise<void>;
|
|
createGroupFileFolder(groupId: number, name: string, parentId?: string): Promise<void>;
|
|
deleteGroupFileFolder(groupId: number, folderId: string): Promise<void>;
|
|
renameGroupFileFolder(groupId: number, folderId: string, newFolderName: string): Promise<void>;
|
|
fetchGroupFileCount(groupId: number): Promise<{ fileCount: number; maxCount: number }>;
|
|
|
|
// ─── Group Album ───
|
|
getGroupAlbumList(groupId: number): Promise<any>;
|
|
uploadImageToGroupAlbum(groupId: number, albumId: string, albumName: string, filePath: string): Promise<void>;
|
|
getGroupAlbumMediaList(groupId: number, albumId: string, attachInfo?: string): Promise<any>;
|
|
commentGroupAlbumMedia(groupId: number, albumId: string, lloc: string, content: string): Promise<any>;
|
|
deleteGroupAlbumMedia(groupId: number, albumId: string, lloc: string): Promise<any>;
|
|
likeGroupAlbumMedia(groupId: number, albumId: string, batchId: string, lloc: string | undefined, isLike: boolean): Promise<any>;
|
|
|
|
// ─── Forward ───
|
|
uploadForwardNodes(nodes: ForwardNodePayload[], groupId?: number, userId?: number): Promise<string>;
|
|
fetchForwardNodes(resId: string): Promise<ForwardNodePayload[]>;
|
|
|
|
// ─── Message ops (moved to apis.message) ───
|
|
|
|
// ─── Interaction ───
|
|
sendPoke(isGroup: boolean, peerUin: number, targetUin?: number): Promise<void>;
|
|
sendLike(userId: number, count: number): Promise<void>;
|
|
getEmojiLikes(groupId: number, sequence: number, emojiId: string, emojiType?: number, count?: number, cookie?: string): Promise<{ users: Array<{ uin: number }>; cookie: string; isLast: boolean }>;
|
|
|
|
// ─── Web-backed ───
|
|
getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any>;
|
|
forceFetchClientKey(): Promise<ClientKeyInfo>;
|
|
getGroupEssence(groupId: number, pageStart?: number, pageLimit?: number): Promise<any>;
|
|
getGroupEssenceAll(groupId: number): Promise<any>;
|
|
sendGroupNotice(groupId: number, content: string, options?: any): Promise<any>;
|
|
getGroupNotice(groupId: number): Promise<any>;
|
|
deleteGroupNotice(groupId: number, fid: string): Promise<boolean>;
|
|
getCookiesStr(domain: string): Promise<string>;
|
|
getCsrfToken(): Promise<number>;
|
|
getCredentials(domain: string): Promise<any>;
|
|
|
|
// ─── Personal profile ───
|
|
setOnlineStatus(status: number, extStatus?: number, batteryStatus?: number): Promise<void>;
|
|
setDiyOnlineStatus(faceId: number, wording: string, faceType: number): Promise<void>;
|
|
setProfile(nickname?: string, personalNote?: string): Promise<void>;
|
|
setSelfLongNick(longNick: string): Promise<any>;
|
|
setInputStatus(userId: number, eventType: number): Promise<any>;
|
|
setAvatar(source: string): Promise<void>;
|
|
setGroupAvatar(groupId: number, source: string): Promise<void>;
|
|
fetchCustomFace(count?: number): Promise<string[]>;
|
|
getProfileLike(userId?: number, start?: number, limit?: number): Promise<any>;
|
|
getUnidirectionalFriendList(): Promise<any>;
|
|
|
|
// ─── Misc ───
|
|
translateEn2Zh(words: string[]): Promise<any>;
|
|
getMiniAppArk(type: string, title: string, desc: string, picUrl: string, jumpUrl: string): Promise<any>;
|
|
clickInlineKeyboardButton(groupId: number, botAppid: number, buttonId: string, callbackData: string, msgSeq: number): Promise<any>;
|
|
sendGroupSign(groupId: number): Promise<any>;
|
|
|
|
// ─── Tier-2 napcat parity extras ───
|
|
setGroupTodo(groupId: number, msgSeq: bigint | number | string): Promise<void>;
|
|
completeGroupTodo(groupId: number, msgSeq: bigint | number | string): Promise<void>;
|
|
cancelGroupTodo(groupId: number, msgSeq: bigint | number | string): Promise<void>;
|
|
getStrangerStatus(uin: number): Promise<{ status: number; ext_status: number } | null>;
|
|
fetchAiVoiceList(groupId: number, chatType: number): Promise<Array<{ category: string; voices: Array<{ voiceId: string; voiceDisplayName: string; voiceExampleUrl: string }> }>>;
|
|
fetchAiVoice(groupId: number, voiceId: string, text: string, chatType: number): Promise<MediaIndexNode>;
|
|
}
|