@zhin.js/adapter-napcat 3.0.1 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +43 -96
  3. package/adapters/napcat.ts +39 -0
  4. package/agent/tools/ai_tts.ts +21 -0
  5. package/agent/tools/del_group_notice.ts +22 -0
  6. package/agent/tools/delete_essence_msg.ts +21 -0
  7. package/agent/tools/delete_friend.ts +20 -0
  8. package/agent/tools/download_file.ts +19 -0
  9. package/agent/tools/forward_single_msg.ts +32 -0
  10. package/agent/tools/get_ai_characters.ts +19 -0
  11. package/agent/tools/get_essence_list.ts +19 -0
  12. package/agent/tools/get_friend_msg_history.ts +20 -0
  13. package/agent/tools/get_group_file_url.ts +21 -0
  14. package/agent/tools/get_group_info_ex.ts +19 -0
  15. package/agent/tools/get_group_msg_history.ts +21 -0
  16. package/agent/tools/get_group_notice.ts +19 -0
  17. package/agent/tools/get_group_root_files.ts +19 -0
  18. package/agent/tools/get_group_shut_list.ts +19 -0
  19. package/agent/tools/get_mini_app_ark.ts +22 -0
  20. package/agent/tools/get_user_status.ts +18 -0
  21. package/agent/tools/group_sign.ts +20 -0
  22. package/agent/tools/mark_msg_as_read.ts +19 -0
  23. package/agent/tools/ocr_image.ts +18 -0
  24. package/agent/tools/send_forward_msg.ts +31 -0
  25. package/agent/tools/send_group_notice.ts +23 -0
  26. package/agent/tools/send_like.ts +20 -0
  27. package/agent/tools/send_poke.ts +20 -0
  28. package/agent/tools/set_avatar.ts +19 -0
  29. package/agent/tools/set_emoji_reaction.ts +20 -0
  30. package/agent/tools/set_essence_msg.ts +21 -0
  31. package/agent/tools/set_group_portrait.ts +22 -0
  32. package/agent/tools/set_online_status.ts +20 -0
  33. package/agent/tools/set_profile.ts +23 -0
  34. package/agent/tools/set_signature.ts +19 -0
  35. package/agent/tools/set_title.ts +23 -0
  36. package/agent/tools/translate.ts +18 -0
  37. package/agent/tools/upload_group_file.ts +23 -0
  38. package/lib/http-endpoint.d.ts +26 -0
  39. package/lib/http-endpoint.js +147 -0
  40. package/lib/index.d.ts +11 -21
  41. package/lib/index.js +10 -59
  42. package/lib/napcat-agent-deps.d.ts +51 -0
  43. package/lib/napcat-agent-deps.js +33 -0
  44. package/lib/napcat-inbound.d.ts +12 -5
  45. package/lib/napcat-inbound.js +28 -13
  46. package/lib/onebot-get-msg.d.ts +13 -2
  47. package/lib/onebot-get-msg.js +0 -1
  48. package/lib/protocol.d.ts +151 -0
  49. package/lib/protocol.js +217 -0
  50. package/lib/webhook.d.ts +2 -0
  51. package/lib/webhook.js +14 -0
  52. package/lib/ws-endpoint.d.ts +61 -0
  53. package/lib/ws-endpoint.js +357 -0
  54. package/lib/ws-transport.d.ts +13 -0
  55. package/lib/ws-transport.js +75 -0
  56. package/lib/ws-types.d.ts +17 -0
  57. package/lib/ws-types.js +1 -0
  58. package/lib/wss-auth.d.ts +2 -0
  59. package/lib/wss-auth.js +16 -0
  60. package/lib/wss-endpoint.d.ts +25 -0
  61. package/lib/wss-endpoint.js +157 -0
  62. package/package.json +48 -32
  63. package/plugin.ts +13 -0
  64. package/schema.json +48 -0
  65. package/src/http-endpoint.ts +197 -0
  66. package/src/index.ts +66 -82
  67. package/src/napcat-agent-deps.ts +95 -0
  68. package/src/napcat-inbound.ts +34 -10
  69. package/src/onebot-get-msg.ts +8 -2
  70. package/src/protocol.ts +373 -0
  71. package/src/webhook.ts +16 -0
  72. package/src/ws-endpoint.ts +452 -0
  73. package/src/ws-transport.ts +105 -0
  74. package/src/ws-types.ts +20 -0
  75. package/src/wss-auth.ts +17 -0
  76. package/src/wss-endpoint.ts +205 -0
  77. package/client/NapCatManagement.tsx +0 -113
  78. package/client/index.tsx +0 -11
  79. package/client/tsconfig.json +0 -7
  80. package/client/utils/api.ts +0 -30
  81. package/dist/index.js +0 -27
  82. package/lib/adapter.d.ts +0 -36
  83. package/lib/adapter.d.ts.map +0 -1
  84. package/lib/adapter.js +0 -102
  85. package/lib/adapter.js.map +0 -1
  86. package/lib/agent-prompt.d.ts +0 -3
  87. package/lib/agent-prompt.d.ts.map +0 -1
  88. package/lib/agent-prompt.js +0 -106
  89. package/lib/agent-prompt.js.map +0 -1
  90. package/lib/endpoint-base.d.ts +0 -144
  91. package/lib/endpoint-base.d.ts.map +0 -1
  92. package/lib/endpoint-base.js +0 -341
  93. package/lib/endpoint-base.js.map +0 -1
  94. package/lib/endpoint-http.d.ts +0 -17
  95. package/lib/endpoint-http.d.ts.map +0 -1
  96. package/lib/endpoint-http.js +0 -106
  97. package/lib/endpoint-http.js.map +0 -1
  98. package/lib/endpoint-ws-client.d.ts +0 -20
  99. package/lib/endpoint-ws-client.d.ts.map +0 -1
  100. package/lib/endpoint-ws-client.js +0 -139
  101. package/lib/endpoint-ws-client.js.map +0 -1
  102. package/lib/endpoint-ws-server.d.ts +0 -20
  103. package/lib/endpoint-ws-server.d.ts.map +0 -1
  104. package/lib/endpoint-ws-server.js +0 -137
  105. package/lib/endpoint-ws-server.js.map +0 -1
  106. package/lib/index.d.ts.map +0 -1
  107. package/lib/index.js.map +0 -1
  108. package/lib/napcat-inbound.d.ts.map +0 -1
  109. package/lib/napcat-inbound.js.map +0 -1
  110. package/lib/onebot-get-msg.d.ts.map +0 -1
  111. package/lib/onebot-get-msg.js.map +0 -1
  112. package/lib/routes.d.ts +0 -4
  113. package/lib/routes.d.ts.map +0 -1
  114. package/lib/routes.js +0 -61
  115. package/lib/routes.js.map +0 -1
  116. package/lib/segment-mapper.d.ts +0 -2
  117. package/lib/segment-mapper.d.ts.map +0 -1
  118. package/lib/segment-mapper.js +0 -2
  119. package/lib/segment-mapper.js.map +0 -1
  120. package/lib/tools.d.ts +0 -8
  121. package/lib/tools.d.ts.map +0 -1
  122. package/lib/tools.js +0 -605
  123. package/lib/tools.js.map +0 -1
  124. package/lib/types.d.ts +0 -275
  125. package/lib/types.d.ts.map +0 -1
  126. package/lib/types.js +0 -6
  127. package/lib/types.js.map +0 -1
  128. package/plugin.yml +0 -3
  129. package/src/adapter.ts +0 -109
  130. package/src/agent-prompt.ts +0 -116
  131. package/src/endpoint-base.ts +0 -386
  132. package/src/endpoint-http.ts +0 -95
  133. package/src/endpoint-ws-client.ts +0 -137
  134. package/src/endpoint-ws-server.ts +0 -136
  135. package/src/routes.ts +0 -61
  136. package/src/segment-mapper.ts +0 -1
  137. package/src/tools.ts +0 -632
  138. package/src/types.ts +0 -266
  139. /package/{skills/napcat → agent}/PERMITS.md +0 -0
  140. /package/{skills/napcat/SKILL.md → agent/skills/napcat.md} +0 -0
@@ -1,106 +0,0 @@
1
- import { filterTools } from 'zhin.js/ai';
2
- function isNapCatDelegatedTask(query, goal) {
3
- const text = `${query} ${goal}`;
4
- if (/\bnapcat\b|napcat_|mcp_napcat/i.test(text))
5
- return true;
6
- if (/戳一戳|poke|表情回应|emoji.*reaction/i.test(text))
7
- return true;
8
- if (/精华消息|essence|群公告|group.*notice/i.test(text))
9
- return true;
10
- if (/AI语音|ai.*record|tts|文字转语音/i.test(text))
11
- return true;
12
- if (/群文件|upload.*file|群签到|group.*sign/i.test(text))
13
- return true;
14
- if (/合并转发|forward.*msg|转发消息/i.test(text))
15
- return true;
16
- if (/点赞/.test(text) && /qq|好友|\d{5,}/i.test(text))
17
- return true;
18
- return false;
19
- }
20
- function selectNapCatDeferredTools(query, goal, deferredCatalog, maxTools) {
21
- const pool = deferredCatalog.filter(t => !t.name.startsWith('mcp_filesystem') && !t.name.startsWith('mcp_memory_'));
22
- const napcatTools = pool.filter(t => t.name.startsWith('napcat_'));
23
- const pinned = [];
24
- const preferOrder = [
25
- 'napcat_send_poke',
26
- 'napcat_set_emoji_reaction',
27
- 'napcat_send_like',
28
- 'napcat_set_essence_msg',
29
- 'napcat_send_group_notice',
30
- 'napcat_ai_tts',
31
- ];
32
- for (const name of preferOrder) {
33
- const t = napcatTools.find(x => x.name === name);
34
- if (t)
35
- pinned.push(t);
36
- }
37
- for (const t of napcatTools) {
38
- if (pinned.length >= maxTools)
39
- break;
40
- if (!pinned.some(p => p.name === t.name))
41
- pinned.push(t);
42
- }
43
- const extra = filterTools(query, pool, { maxTools, minScore: 0.08 })
44
- .map((t) => ({ name: t.name, description: t.description }))
45
- .filter(t => !pinned.some(p => p.name === t.name));
46
- const merged = [...pinned];
47
- for (const t of extra) {
48
- if (merged.length >= maxTools)
49
- break;
50
- merged.push(t);
51
- }
52
- return merged.slice(0, maxTools);
53
- }
54
- const ORCHESTRATOR_NAPCAT = [
55
- 'On napcat/QQ: use run_deferred_task with tool_query "napcat_send_poke" or "napcat_set_emoji_reaction".',
56
- 'NapCat supports: poke, emoji reaction, forward msg, essence, group notice, AI TTS, OCR, group files.',
57
- 'Skip tool_search when the user clearly asks for QQ-specific features like poke, reaction, or group management.',
58
- ].join('\n');
59
- const WORKER_NAPCAT = [
60
- '- Use `napcat_send_poke` for poke/戳一戳.',
61
- '- Use `napcat_set_emoji_reaction` for emoji reaction/表情回应.',
62
- '- Use `napcat_send_like` for friend like/点赞.',
63
- '- Use `napcat_ai_tts` for AI voice/AI语音.',
64
- '- Use `napcat_set_essence_msg` / `napcat_delete_essence_msg` for essence messages.',
65
- '- Use `napcat_send_group_notice` for group announcements.',
66
- '- Do NOT use mcp_filesystem_* or explore node_modules for QQ tasks.',
67
- ].join('\n');
68
- export function createNapCatAgentPromptContributor() {
69
- return {
70
- platform: 'napcat',
71
- async buildSections(ctx) {
72
- if (ctx.slot === 'orchestrator') {
73
- return [{
74
- id: 'platform.napcat.orchestrator',
75
- title: '## napcat / QQ',
76
- body: ORCHESTRATOR_NAPCAT,
77
- priority: 50,
78
- }];
79
- }
80
- if (ctx.slot === 'deferred_worker') {
81
- const query = ctx.deferred?.toolQuery ?? ctx.deferred?.goal ?? '';
82
- const goal = ctx.deferred?.goal ?? '';
83
- if (!isNapCatDelegatedTask(query, goal))
84
- return null;
85
- return [{
86
- id: 'platform.napcat.deferred_worker',
87
- title: '## napcat / QQ(本任务)',
88
- body: WORKER_NAPCAT,
89
- priority: 50,
90
- }];
91
- }
92
- return null;
93
- },
94
- matchesDeferredTask(ctx) {
95
- const query = ctx.deferred?.toolQuery ?? ctx.deferred?.goal ?? ctx.userMessagePreview ?? '';
96
- const goal = ctx.deferred?.goal ?? ctx.userMessagePreview ?? '';
97
- return isNapCatDelegatedTask(query, goal);
98
- },
99
- selectDeferredTools(query, goal, catalog, maxTools) {
100
- if (!isNapCatDelegatedTask(query, goal))
101
- return null;
102
- return selectNapCatDeferredTools(query, goal, catalog, maxTools);
103
- },
104
- };
105
- }
106
- //# sourceMappingURL=agent-prompt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-prompt.js","sourceRoot":"","sources":["../src/agent-prompt.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,SAAS,qBAAqB,CAAC,KAAa,EAAE,IAAY;IACxD,MAAM,IAAI,GAAG,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC;IAChC,IAAI,gCAAgC,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7D,IAAI,gCAAgC,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7D,IAAI,iCAAiC,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9D,IAAI,4BAA4B,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACzD,IAAI,mCAAmC,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAChE,IAAI,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACtD,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/D,OAAO,KAAK,CAAC;AACf,CAAC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AK,GAAG,GAAG,CAAC,QAAQ,EAAE,SAAS,IAAI,GAAG,CAAC,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC;gBAClE,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC;gBACtC,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC;oBAAE,OAAO,IAAI,CAAC;gBACrD,OAAO,CAAC;wBACN,EAAE,EAAE,iCAAiC;wBACrC,KAAK,EAAE,qBAAqB;wBAC5B,IAAI,EAAE,aAAa;wBACnB,QAAQ,EAAE,EAAE;qBACb,CAAC,CAAC;YACL,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,mBAAmB,CAAC,GAA4B;YAC9C,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,EAAE,SAAS,IAAI,GAAG,CAAC,QAAQ,EAAE,IAAI,IAAI,GAAG,CAAC,kBAAkB,IAAI,EAAE,CAAC;YAC5F,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,EAAE,IAAI,IAAI,GAAG,CAAC,kBAAkB,IAAI,EAAE,CAAC;YAChE,OAAO,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC5C,CAAC;QAED,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ;YAChD,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAC;YACrD,OAAO,yBAAyB,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QACnE,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,144 +0,0 @@
1
- /**
2
- * NapCat Endpoint 抽象基类
3
- * 子类只需实现 callApi / $connect / $disconnect,其余 API 方法和事件处理全部复用。
4
- */
5
- import { EventEmitter } from 'events';
6
- import { Endpoint, Message, SendOptions, type QuotedMessagePayload } from 'zhin.js';
7
- import type { NapCatEndpointConfig, NapCatMessageEvent, MessageSegment } from './types.js';
8
- import type { NapCatAdapter } from './adapter.js';
9
- import { InboundMessageDeduper } from './napcat-inbound.js';
10
- export declare abstract class NapCatEndpointBase extends EventEmitter implements Endpoint<NapCatEndpointConfig, NapCatMessageEvent> {
11
- adapter: NapCatAdapter;
12
- $config: NapCatEndpointConfig;
13
- $connected: boolean;
14
- protected readonly inboundDeduper: InboundMessageDeduper;
15
- get logger(): import("zhin.js").Logger;
16
- get $id(): string;
17
- constructor(adapter: NapCatAdapter, $config: NapCatEndpointConfig);
18
- abstract $connect(): Promise<void>;
19
- abstract $disconnect(): Promise<void>;
20
- abstract callApi<T = any>(action: string, params?: Record<string, any>): Promise<T>;
21
- private toWireSendContent;
22
- $formatMessage(ev: NapCatMessageEvent): Message<NapCatMessageEvent>;
23
- $sendMessage(options: SendOptions): Promise<string>;
24
- $recallMessage(id: string): Promise<void>;
25
- $addReaction(messageId: string, emojiId: string): Promise<string>;
26
- $removeReaction(messageId: string, _reactionId: string): Promise<void>;
27
- protected dispatchEvent(event: any): void;
28
- private handleMessage;
29
- private handleNotice;
30
- private resolveNotifyType;
31
- private handleRequest;
32
- protected handleMeta(event: any): void;
33
- sendMsg(messageType: 'private' | 'group', id: number, message: MessageSegment[]): Promise<{
34
- message_id: number;
35
- }>;
36
- deleteMsg(messageId: number): Promise<any>;
37
- getMsg(messageId: number): Promise<any>;
38
- $getMsg(messageId: string): Promise<QuotedMessagePayload>;
39
- getForwardMsg(id: string): Promise<any>;
40
- sendLike(userId: number, times?: number): Promise<any>;
41
- setGroupKick(groupId: number, userId: number, rejectAddRequest?: boolean): Promise<any>;
42
- setGroupBan(groupId: number, userId: number, duration?: number): Promise<any>;
43
- setGroupWholeBan(groupId: number, enable?: boolean): Promise<any>;
44
- setGroupAdmin(groupId: number, userId: number, enable?: boolean): Promise<any>;
45
- setGroupCard(groupId: number, userId: number, card: string): Promise<any>;
46
- setGroupName(groupId: number, groupName: string): Promise<any>;
47
- setGroupLeave(groupId: number, isDismiss?: boolean): Promise<any>;
48
- setGroupSpecialTitle(groupId: number, userId: number, specialTitle: string, duration?: number): Promise<any>;
49
- setFriendAddRequest(flag: string, approve?: boolean, remark?: string): Promise<any>;
50
- setGroupAddRequest(flag: string, subType: string, approve?: boolean, reason?: string): Promise<any>;
51
- getLoginInfo(): Promise<any>;
52
- getStrangerInfo(userId: number, noCache?: boolean): Promise<any>;
53
- getFriendList(): Promise<any>;
54
- getGroupInfo(groupId: number, noCache?: boolean): Promise<any>;
55
- getGroupList(): Promise<any>;
56
- getGroupMemberInfo(groupId: number, userId: number, noCache?: boolean): Promise<any>;
57
- getGroupMemberList(groupId: number): Promise<any>;
58
- getGroupHonorInfo(groupId: number, type: string): Promise<any>;
59
- getCookies(domain?: string): Promise<any>;
60
- getCsrfToken(): Promise<any>;
61
- getCredentials(domain?: string): Promise<any>;
62
- getRecord(file: string, outFormat: string): Promise<any>;
63
- getImage(file: string): Promise<any>;
64
- canSendImage(): Promise<any>;
65
- canSendRecord(): Promise<any>;
66
- getStatus(): Promise<any>;
67
- getVersionInfo(): Promise<any>;
68
- cleanCache(): Promise<any>;
69
- setQQProfile(nickname: string, company?: string, email?: string, college?: string, personalNote?: string): Promise<any>;
70
- getOnlineClients(noCache?: boolean): Promise<any>;
71
- deleteFriend(userId: number): Promise<any>;
72
- markMsgAsRead(messageId: number): Promise<any>;
73
- sendGroupForwardMsg(groupId: number, messages: any[]): Promise<any>;
74
- sendPrivateForwardMsg(userId: number, messages: any[]): Promise<any>;
75
- getGroupMsgHistory(groupId: number, messageSeq?: number, count?: number): Promise<any>;
76
- ocrImage(image: string): Promise<any>;
77
- getGroupSystemMsg(): Promise<any>;
78
- getEssenceMsgList(groupId: number): Promise<any>;
79
- getGroupAtAllRemain(groupId: number): Promise<any>;
80
- setGroupPortrait(groupId: number, file: string): Promise<any>;
81
- setEssenceMsg(messageId: number): Promise<any>;
82
- deleteEssenceMsg(messageId: number): Promise<any>;
83
- sendGroupSign(groupId: number): Promise<any>;
84
- sendGroupNotice(groupId: number, content: string, image?: string): Promise<any>;
85
- getGroupNotice(groupId: number): Promise<any>;
86
- deleteGroupNotice(groupId: number, noticeId: string): Promise<any>;
87
- uploadGroupFile(groupId: number, file: string, name: string, folder?: string): Promise<any>;
88
- deleteGroupFile(groupId: number, fileId: string, busid: number): Promise<any>;
89
- createGroupFileFolder(groupId: number, name: string, parentId?: string): Promise<any>;
90
- deleteGroupFolder(groupId: number, folderId: string): Promise<any>;
91
- getGroupFileSystemInfo(groupId: number): Promise<any>;
92
- getGroupRootFiles(groupId: number): Promise<any>;
93
- getGroupFilesByFolder(groupId: number, folderId: string): Promise<any>;
94
- getGroupFileUrl(groupId: number, fileId: string, busid: number): Promise<any>;
95
- uploadPrivateFile(userId: number, file: string, name: string): Promise<any>;
96
- downloadFile(url: string, threadCount?: number, headers?: string[]): Promise<any>;
97
- checkUrlSafely(url: string): Promise<any>;
98
- setGroupSign(groupId: number): Promise<any>;
99
- arkSharePeer(userId: number): Promise<any>;
100
- arkShareGroup(groupId: number): Promise<any>;
101
- getRobotUinRange(): Promise<any>;
102
- setOnlineStatus(status: number, extStatus: number): Promise<any>;
103
- getFriendsWithCategory(): Promise<any>;
104
- setQQAvatar(file: string): Promise<any>;
105
- getFile(fileId: string): Promise<any>;
106
- forwardFriendSingleMsg(userId: number, messageId: number): Promise<any>;
107
- forwardGroupSingleMsg(groupId: number, messageId: number): Promise<any>;
108
- translateEn2Zh(sourceText: string): Promise<any>;
109
- setMsgEmojiLike(messageId: number, emojiId: string): Promise<any>;
110
- sendForwardMsg(messageType: 'private' | 'group', id: number, messages: any[]): Promise<any>;
111
- markPrivateMsgAsRead(userId: number): Promise<any>;
112
- markGroupMsgAsRead(groupId: number): Promise<any>;
113
- getFriendMsgHistory(userId: number, messageSeq?: number, count?: number): Promise<any>;
114
- createCollection(briefContent: string, rawData: string): Promise<any>;
115
- getCollectionList(page?: number, limit?: number): Promise<any>;
116
- setSelfLongnick(longnick: string): Promise<any>;
117
- getRecentContact(count?: number): Promise<any>;
118
- markAllAsRead(): Promise<any>;
119
- getProfileLike(): Promise<any>;
120
- fetchCustomFace(): Promise<any>;
121
- fetchEmojiLike(messageId: number, emojiId: string, emojiType: string): Promise<any>;
122
- setInputStatus(userId: number, eventType: string): Promise<any>;
123
- getGroupInfoEx(groupId: number): Promise<any>;
124
- getGroupIgnoreAddRequest(groupId: number): Promise<any>;
125
- friendPoke(userId: number): Promise<any>;
126
- groupPoke(groupId: number, userId: number): Promise<any>;
127
- sendPoke(userId: number, groupId?: number): Promise<any>;
128
- ncGetPacketStatus(): Promise<any>;
129
- ncGetUserStatus(userId: number): Promise<any>;
130
- ncGetRkey(): Promise<any>;
131
- getGroupShutList(groupId: number): Promise<any>;
132
- getMiniAppArk(type: string, title: string, desc: string, picUrl: string, jumpUrl: string): Promise<any>;
133
- getAiRecord(groupId: number, characterId: string, text: string): Promise<any>;
134
- getAiCharacters(groupId: number): Promise<any>;
135
- sendGroupAiRecord(groupId: number, characterId: string, text: string): Promise<any>;
136
- kickMember(groupId: number, userId: number, reject?: boolean): Promise<boolean>;
137
- muteMember(groupId: number, userId: number, duration?: number): Promise<boolean>;
138
- muteAll(groupId: number, enable?: boolean): Promise<boolean>;
139
- setAdmin(groupId: number, userId: number, enable?: boolean): Promise<boolean>;
140
- setCard(groupId: number, userId: number, card: string): Promise<boolean>;
141
- setTitle(groupId: number, userId: number, title: string, duration?: number): Promise<boolean>;
142
- getMemberList(groupId: number): Promise<any>;
143
- }
144
- //# sourceMappingURL=endpoint-base.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"endpoint-base.d.ts","sourceRoot":"","sources":["../src/endpoint-base.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EACL,QAAQ,EACR,OAAO,EAEP,WAAW,EAKX,KAAK,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE7C,OA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法和事件处理全部复用。
4
- */
5
- import { EventEmitter } from 'events';
6
- import { Message, segment, expandInteractiveSegmentsInContent, Notice, Request, } from 'zhin.js';
7
- import { parseOneBotGetMsgResponse } from './onebot-get-msg.js';
8
- import { InboundMessageDeduper, isSelfMessage, normalizeMessage, resolveSideEventDedupeKey } from './napcat-inbound.js';
9
- import { fromCanonicalSegments, toCanonicalSegments } from './segment-mapper.js';
10
- export class NapCatEndpointBase extends EventEmitter {
11
- adapter;
12
- $config;
13
- $connected = false;
14
- inboundDeduper = new InboundMessageDeduper();
15
- get logger() { return this.adapter.plugin.logger; }
16
- get $id() { return this.$config.name; }
17
- constructor(adapter, $config) {
18
- super();
19
- this.adapter = adapter;
20
- this.$config = $config;
21
- }
22
- // ══════════════════════════════════════════════════════════════════
23
- // 消息格式化
24
- // ══════════════════════════════════════════════════════════════════
25
- toWireSendContent(content) {
26
- const items = (Array.isArray(content) ? content : [content]).map((item) => typeof item === 'string' ? { type: 'text', data: { text: item } } : item);
27
- return fromCanonicalSegments(toCanonicalSegments(items));
28
- }
29
- $formatMessage(ev) {
30
- const wire = normalizeMessage(ev.message);
31
- const quoteId = Message.quoteIdFromContent(wire);
32
- Message.alignReplySegments(wire, quoteId);
33
- const content = toCanonicalSegments(wire);
34
- const message = Message.from(ev, {
35
- $id: ev.message_id.toString(),
36
- $adapter: 'napcat',
37
- $endpoint: this.$config.name,
38
- $sender: {
39
- id: ev.user_id.toString(),
40
- name: ev.sender?.nickname || ev.user_id.toString(),
41
- role: ev.sender?.role,
42
- },
43
- $channel: {
44
- id: (ev.group_id || ev.user_id).toString(),
45
- type: ev.group_id ? 'group' : 'private',
46
- },
47
- $content: content,
48
- $quote_id: quoteId,
49
- $raw: ev.raw_message,
50
- $timestamp: ev.time,
51
- $recall: async () => { await this.deleteMsg(ev.message_id); },
52
- $reply: async (content, quote) => {
53
- if (!Array.isArray(content))
54
- content = [content];
55
- if (quote)
56
- content.unshift({ type: 'reply', data: { message_id: ev.message_id.toString() } });
57
- return await this.adapter.sendMessage({
58
- id: (ev.group_id || ev.user_id).toString(),
59
- type: ev.group_id ? 'group' : 'private',
60
- context: 'napcat',
61
- endpoint: this.$config.name,
62
- content,
63
- });
64
- },
65
- });
66
- return message;
67
- }
68
- async $sendMessage(options) {
69
- const content = this.toWireSendContent(expandInteractiveSegmentsInContent(options.content));
70
- const msg = { message: content };
71
- if (options.type === 'group') {
72
- const result = await this.callApi('send_group_msg', { group_id: parseInt(options.id), ...msg });
73
- this.logger.debug(`${this.$id} send group(${options.id}):${segment.raw(options.content)}`);
74
- return result.message_id.toString();
75
- }
76
- if (options.type === 'private') {
77
- const result = await this.callApi('send_private_msg', { user_id: parseInt(options.id), ...msg });
78
- this.logger.debug(`${this.$id} send private(${options.id}):${segment.raw(options.content)}`);
79
- return result.message_id.toString();
80
- }
81
- throw new Error('Either group_id or user_id must be provided');
82
- }
83
- async $recallMessage(id) {
84
- await this.deleteMsg(parseInt(id));
85
- }
86
- async $addReaction(messageId, emojiId) {
87
- await this.setMsgEmojiLike(parseInt(messageId), emojiId);
88
- return `reaction:${messageId}:${emojiId}`;
89
- }
90
- async $removeReaction(messageId, _reactionId) {
91
- // NapCat 的 set_msg_emoji_like 是 toggle 行为,再调一次即取消
92
- const parts = _reactionId.split(':');
93
- const emojiId = parts[2] || parts[0];
94
- await this.setMsgEmojiLike(parseInt(messageId), emojiId);
95
- }
96
- // ══════════════════════════════════════════════════════════════════
97
- // 事件分发
98
- // ══════════════════════════════════════════════════════════════════
99
- dispatchEvent(event) {
100
- switch (event.post_type) {
101
- case 'message':
102
- case 'message_sent':
103
- return this.handleMessage(event);
104
- case 'notice':
105
- return this.handleNotice(event);
106
- case 'request':
107
- return this.handleRequest(event);
108
- case 'meta_event':
109
- return this.handleMeta(event);
110
- }
111
- }
112
- handleMessage(ev) {
113
- if (isSelfMessage(ev))
114
- return;
115
- const msgId = ev.message_id.toString();
116
- if (!this.inboundDeduper.shouldProcess(msgId))
117
- return;
118
- ev.message = normalizeMessage(ev.message);
119
- const message = this.$formatMessage(ev);
120
- this.adapter.emit('message.receive', message);
121
- this.logger.debug(`${this.$id} recv ${message.$channel.type}(${message.$channel.id}):${segment.raw(message.$content)}`);
122
- }
123
- handleNotice(event) {
124
- const dedupeKey = resolveSideEventDedupeKey(event, 'notice');
125
- if (!this.inboundDeduper.shouldProcess(dedupeKey))
126
- return;
127
- const noticeTypeMap = {
128
- group_increase: 'group_member_increase',
129
- group_decrease: 'group_member_decrease',
130
- group_admin: 'group_admin_change',
131
- group_ban: 'group_ban',
132
- group_recall: 'group_recall',
133
- friend_recall: 'friend_recall',
134
- friend_add: 'friend_add',
135
- group_upload: 'group_upload',
136
- group_card: 'group_card_change',
137
- essence: event.sub_type === 'add' ? 'essence_add' : 'essence_delete',
138
- notify: this.resolveNotifyType(event),
139
- group_msg_emoji_like: 'group_emoji_reaction',
140
- };
141
- const $type = noticeTypeMap[event.notice_type] || event.notice_type;
142
- const isGroup = !!event.group_id;
143
- const notice = Notice.from(event, {
144
- $id: `${event.time}_${event.notice_type}_${event.group_id || event.user_id}`,
145
- $adapter: 'napcat',
146
- $endpoint: this.$config.name,
147
- $type,
148
- $subType: event.sub_type,
149
- $channel: {
150
- id: (event.group_id || event.user_id)?.toString() || '',
151
- type: isGroup ? 'group' : 'private',
152
- },
153
- $operator: event.operator_id ? { id: event.operator_id.toString(), name: event.operator_id.toString() } : undefined,
154
- $target: event.user_id ? { id: event.user_id.toString(), name: event.user_id.toString() } : undefined,
155
- $timestamp: event.time || Math.floor(Date.now() / 1000),
156
- });
157
- this.adapter.emit('notice.receive', notice);
158
- }
159
- resolveNotifyType(event) {
160
- switch (event.sub_type) {
161
- case 'poke': return event.group_id ? 'group_poke' : 'friend_poke';
162
- case 'input_status': return 'input_status';
163
- case 'title': return 'title_change';
164
- case 'profile_like': return 'profile_like';
165
- default: return `notify_${event.sub_type}`;
166
- }
167
- }
168
- handleRequest(event) {
169
- const dedupeKey = resolveSideEventDedupeKey(event, 'request');
170
- if (!this.inboundDeduper.shouldProcess(dedupeKey))
171
- return;
172
- const typeMap = {
173
- friend: 'friend_add',
174
- group: event.sub_type === 'invite' ? 'group_invite' : 'group_add',
175
- };
176
- const $type = typeMap[event.request_type] || event.request_type;
177
- const request = Request.from(event, {
178
- $id: event.flag || `${event.time}_${event.request_type}_${event.user_id}`,
179
- $adapter: 'napcat',
180
- $endpoint: this.$config.name,
181
- $type,
182
- $subType: event.sub_type,
183
- $channel: {
184
- id: (event.group_id || event.user_id)?.toString() || '',
185
- type: event.group_id ? 'group' : 'private',
186
- },
187
- $sender: { id: event.user_id?.toString() || '', name: event.user_id?.toString() || '' },
188
- $comment: event.comment,
189
- $timestamp: event.time || Math.floor(Date.now() / 1000),
190
- $approve: async (remark) => {
191
- await this.callApi(event.request_type === 'friend' ? 'set_friend_add_request' : 'set_group_add_request', { flag: event.flag, approve: true, remark });
192
- },
193
- $reject: async (reason) => {
194
- await this.callApi(event.request_type === 'friend' ? 'set_friend_add_request' : 'set_group_add_request', { flag: event.flag, approve: false, reason });
195
- },
196
- });
197
- this.adapter.emit('request.receive', request);
198
- }
199
- handleMeta(event) {
200
- // subclass may override for lifecycle handling
201
- }
202
- // ══════════════════════════════════════════════════════════════════
203
- // OneBot11 标准 API
204
- // ══════════════════════════════════════════════════════════════════
205
- async sendMsg(messageType, id, message) {
206
- return this.callApi('send_msg', { message_type: messageType, [messageType === 'group' ? 'group_id' : 'user_id']: id, message });
207
- }
208
- async deleteMsg(messageId) { return this.callApi('delete_msg', { message_id: messageId }); }
209
- async getMsg(messageId) { return this.callApi('get_msg', { message_id: messageId }); }
210
- async $getMsg(messageId) {
211
- const idParam = /^\d+$/.test(messageId) ? Number(messageId) : messageId;
212
- const data = await this.callApi('get_msg', { message_id: idParam });
213
- return parseOneBotGetMsgResponse(messageId, data);
214
- }
215
- async getForwardMsg(id) { return this.callApi('get_forward_msg', { id }); }
216
- async sendLike(userId, times = 1) { return this.callApi('send_like', { user_id: userId, times }); }
217
- // 群管理
218
- async setGroupKick(groupId, userId, rejectAddRequest = false) { return this.callApi('set_group_kick', { group_id: groupId, user_id: userId, reject_add_request: rejectAddRequest }); }
219
- async setGroupBan(groupId, userId, duration = 600) { return this.callApi('set_group_ban', { group_id: groupId, user_id: userId, duration }); }
220
- async setGroupWholeBan(groupId, enable = true) { return this.callApi('set_group_whole_ban', { group_id: groupId, enable }); }
221
- async setGroupAdmin(groupId, userId, enable = true) { return this.callApi('set_group_admin', { group_id: groupId, user_id: userId, enable }); }
222
- async setGroupCard(groupId, userId, card) { return this.callApi('set_group_card', { group_id: groupId, user_id: userId, card }); }
223
- async setGroupName(groupId, groupName) { return this.callApi('set_group_name', { group_id: groupId, group_name: groupName }); }
224
- async setGroupLeave(groupId, isDismiss = false) { return this.callApi('set_group_leave', { group_id: groupId, is_dismiss: isDismiss }); }
225
- async setGroupSpecialTitle(groupId, userId, specialTitle, duration = -1) { return this.callApi('set_group_special_title', { group_id: groupId, user_id: userId, special_title: specialTitle, duration }); }
226
- // 好友/群请求
227
- async setFriendAddRequest(flag, approve = true, remark) { return this.callApi('set_friend_add_request', { flag, approve, remark }); }
228
- async setGroupAddRequest(flag, subType, approve = true, reason) { return this.callApi('set_group_add_request', { flag, sub_type: subType, approve, reason }); }
229
- // 信息查询
230
- async getLoginInfo() { return this.callApi('get_login_info'); }
231
- async getStrangerInfo(userId, noCache = false) { return this.callApi('get_stranger_info', { user_id: userId, no_cache: noCache }); }
232
- async getFriendList() { return this.callApi('get_friend_list'); }
233
- async getGroupInfo(groupId, noCache = false) { return this.callApi('get_group_info', { group_id: groupId, no_cache: noCache }); }
234
- async getGroupList() { return this.callApi('get_group_list'); }
235
- async getGroupMemberInfo(groupId, userId, noCache = false) { return this.callApi('get_group_member_info', { group_id: groupId, user_id: userId, no_cache: noCache }); }
236
- async getGroupMemberList(groupId) { return this.callApi('get_group_member_list', { group_id: groupId }); }
237
- async getGroupHonorInfo(groupId, type) { return this.callApi('get_group_honor_info', { group_id: groupId, type }); }
238
- // 凭证
239
- async getCookies(domain) { return this.callApi('get_cookies', { domain }); }
240
- async getCsrfToken() { return this.callApi('get_csrf_token'); }
241
- async getCredentials(domain) { return this.callApi('get_credentials', { domain }); }
242
- // 媒体
243
- async getRecord(file, outFormat) { return this.callApi('get_record', { file, out_format: outFormat }); }
244
- async getImage(file) { return this.callApi('get_image', { file }); }
245
- async canSendImage() { return this.callApi('can_send_image'); }
246
- async canSendRecord() { return this.callApi('can_send_record'); }
247
- // 系统
248
- async getStatus() { return this.callApi('get_status'); }
249
- async getVersionInfo() { return this.callApi('get_version_info'); }
250
- async cleanCache() { return this.callApi('clean_cache'); }
251
- // ══════════════════════════════════════════════════════════════════
252
- // go-cqhttp 扩展 API
253
- // ══════════════════════════════════════════════════════════════════
254
- async setQQProfile(nickname, company, email, college, personalNote) {
255
- return this.callApi('set_qq_profile', { nickname, company, email, college, personal_note: personalNote });
256
- }
257
- async getOnlineClients(noCache = false) { return this.callApi('get_online_clients', { no_cache: noCache }); }
258
- async deleteFriend(userId) { return this.callApi('delete_friend', { user_id: userId }); }
259
- async markMsgAsRead(messageId) { return this.callApi('mark_msg_as_read', { message_id: messageId }); }
260
- async sendGroupForwardMsg(groupId, messages) { return this.callApi('send_group_forward_msg', { group_id: groupId, messages }); }
261
- async sendPrivateForwardMsg(userId, messages) { return this.callApi('send_private_forward_msg', { user_id: userId, messages }); }
262
- async getGroupMsgHistory(groupId, messageSeq, count) { return this.callApi('get_group_msg_history', { group_id: groupId, message_seq: messageSeq, count }); }
263
- async ocrImage(image) { return this.callApi('ocr_image', { image }); }
264
- async getGroupSystemMsg() { return this.callApi('get_group_system_msg'); }
265
- async getEssenceMsgList(groupId) { return this.callApi('get_essence_msg_list', { group_id: groupId }); }
266
- async getGroupAtAllRemain(groupId) { return this.callApi('get_group_at_all_remain', { group_id: groupId }); }
267
- async setGroupPortrait(groupId, file) { return this.callApi('set_group_portrait', { group_id: groupId, file }); }
268
- async setEssenceMsg(messageId) { return this.callApi('set_essence_msg', { message_id: messageId }); }
269
- async deleteEssenceMsg(messageId) { return this.callApi('delete_essence_msg', { message_id: messageId }); }
270
- async sendGroupSign(groupId) { return this.callApi('send_group_sign', { group_id: groupId }); }
271
- async sendGroupNotice(groupId, content, image) { return this.callApi('_send_group_notice', { group_id: groupId, content, image }); }
272
- async getGroupNotice(groupId) { return this.callApi('_get_group_notice', { group_id: groupId }); }
273
- async deleteGroupNotice(groupId, noticeId) { return this.callApi('_del_group_notice', { group_id: groupId, notice_id: noticeId }); }
274
- async uploadGroupFile(groupId, file, name, folder) { return this.callApi('upload_group_file', { group_id: groupId, file, name, folder }); }
275
- async deleteGroupFile(groupId, fileId, busid) { return this.callApi('delete_group_file', { group_id: groupId, file_id: fileId, busid }); }
276
- async createGroupFileFolder(groupId, name, parentId = '/') { return this.callApi('create_group_file_folder', { group_id: groupId, name, parent_id: parentId }); }
277
- async deleteGroupFolder(groupId, folderId) { return this.callApi('delete_group_folder', { group_id: groupId, folder_id: folderId }); }
278
- async getGroupFileSystemInfo(groupId) { return this.callApi('get_group_file_system_info', { group_id: groupId }); }
279
- async getGroupRootFiles(groupId) { return this.callApi('get_group_root_files', { group_id: groupId }); }
280
- async getGroupFilesByFolder(groupId, folderId) { return this.callApi('get_group_files_by_folder', { group_id: groupId, folder_id: folderId }); }
281
- async getGroupFileUrl(groupId, fileId, busid) { return this.callApi('get_group_file_url', { group_id: groupId, file_id: fileId, busid }); }
282
- async uploadPrivateFile(userId, file, name) { return this.callApi('upload_private_file', { user_id: userId, file, name }); }
283
- async downloadFile(url, threadCount = 1, headers) { return this.callApi('download_file', { url, thread_count: threadCount, headers }); }
284
- async checkUrlSafely(url) { return this.callApi('check_url_safely', { url }); }
285
- // ══════════════════════════════════════════════════════════════════
286
- // NapCat 独有 API
287
- // ══════════════════════════════════════════════════════════════════
288
- async setGroupSign(groupId) { return this.callApi('set_group_sign', { group_id: groupId }); }
289
- async arkSharePeer(userId) { return this.callApi('ArkSharePeer', { user_id: userId }); }
290
- async arkShareGroup(groupId) { return this.callApi('ArkShareGroup', { group_id: groupId }); }
291
- async getRobotUinRange() { return this.callApi('get_robot_uin_range'); }
292
- async setOnlineStatus(status, extStatus) { return this.callApi('set_online_status', { status, ext_status: extStatus }); }
293
- async getFriendsWithCategory() { return this.callApi('get_friends_with_category'); }
294
- async setQQAvatar(file) { return this.callApi('set_qq_avatar', { file }); }
295
- async getFile(fileId) { return this.callApi('get_file', { file_id: fileId }); }
296
- async forwardFriendSingleMsg(userId, messageId) { return this.callApi('forward_friend_single_msg', { user_id: userId, message_id: messageId }); }
297
- async forwardGroupSingleMsg(groupId, messageId) { return this.callApi('forward_group_single_msg', { group_id: groupId, message_id: messageId }); }
298
- async translateEn2Zh(sourceText) { return this.callApi('translate_en2zh', { source_text: sourceText }); }
299
- async setMsgEmojiLike(messageId, emojiId) { return this.callApi('set_msg_emoji_like', { message_id: messageId, emoji_id: emojiId }); }
300
- async sendForwardMsg(messageType, id, messages) {
301
- return this.callApi('send_forward_msg', { message_type: messageType, [messageType === 'group' ? 'group_id' : 'user_id']: id, messages });
302
- }
303
- async markPrivateMsgAsRead(userId) { return this.callApi('mark_private_msg_as_read', { user_id: userId }); }
304
- async markGroupMsgAsRead(groupId) { return this.callApi('mark_group_msg_as_read', { group_id: groupId }); }
305
- async getFriendMsgHistory(userId, messageSeq, count) { return this.callApi('get_friend_msg_history', { user_id: userId, message_seq: messageSeq, count }); }
306
- async createCollection(briefContent, rawData) { return this.callApi('create_collection', { brief: briefContent, rawData }); }
307
- async getCollectionList(page = 0, limit = 20) { return this.callApi('get_collection_list', { page, limit }); }
308
- async setSelfLongnick(longnick) { return this.callApi('set_self_longnick', { longNick: longnick }); }
309
- async getRecentContact(count = 10) { return this.callApi('get_recent_contact', { count }); }
310
- async markAllAsRead() { return this.callApi('_mark_all_as_read'); }
311
- async getProfileLike() { return this.callApi('get_profile_like'); }
312
- async fetchCustomFace() { return this.callApi('fetch_custom_face'); }
313
- async fetchEmojiLike(messageId, emojiId, emojiType) { return this.callApi('fetch_emoji_like', { message_id: messageId, emoji_id: emojiId, emoji_type: emojiType }); }
314
- async setInputStatus(userId, eventType) { return this.callApi('set_input_status', { user_id: userId, event_type: eventType }); }
315
- async getGroupInfoEx(groupId) { return this.callApi('get_group_info_ex', { group_id: groupId }); }
316
- async getGroupIgnoreAddRequest(groupId) { return this.callApi('get_group_ignore_add_request', { group_id: groupId }); }
317
- async friendPoke(userId) { return this.callApi('friend_poke', { user_id: userId }); }
318
- async groupPoke(groupId, userId) { return this.callApi('group_poke', { group_id: groupId, user_id: userId }); }
319
- async sendPoke(userId, groupId) { return this.callApi('send_poke', { user_id: userId, group_id: groupId }); }
320
- async ncGetPacketStatus() { return this.callApi('nc_get_packet_status'); }
321
- async ncGetUserStatus(userId) { return this.callApi('nc_get_user_status', { user_id: userId }); }
322
- async ncGetRkey() { return this.callApi('nc_get_rkey'); }
323
- async getGroupShutList(groupId) { return this.callApi('get_group_shut_list', { group_id: groupId }); }
324
- async getMiniAppArk(type, title, desc, picUrl, jumpUrl) {
325
- return this.callApi('get_mini_app_ark', { type, title, desc, picUrl, jumpUrl });
326
- }
327
- async getAiRecord(groupId, characterId, text) { return this.callApi('get_ai_record', { group_id: groupId, character: characterId, text }); }
328
- async getAiCharacters(groupId) { return this.callApi('get_ai_characters', { group_id: groupId }); }
329
- async sendGroupAiRecord(groupId, characterId, text) { return this.callApi('send_group_ai_record', { group_id: groupId, character: characterId, text }); }
330
- // ══════════════════════════════════════════════════════════════════
331
- // Adapter 群管理接口适配
332
- // ══════════════════════════════════════════════════════════════════
333
- async kickMember(groupId, userId, reject = false) { await this.setGroupKick(groupId, userId, reject); return true; }
334
- async muteMember(groupId, userId, duration = 600) { await this.setGroupBan(groupId, userId, duration); return true; }
335
- async muteAll(groupId, enable = true) { await this.setGroupWholeBan(groupId, enable); return true; }
336
- async setAdmin(groupId, userId, enable = true) { await this.setGroupAdmin(groupId, userId, enable); return true; }
337
- async setCard(groupId, userId, card) { await this.setGroupCard(groupId, userId, card); return true; }
338
- async setTitle(groupId, userId, title, duration = -1) { await this.setGroupSpecialTitle(groupId, userId, title, duration); return true; }
339
- async getMemberList(groupId) { return this.getGroupMemberList(groupId); }
340
- }
341
- //# sourceMappingURL=endpoint-base.js.map