hotcat-bot-qq 0.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.
@@ -0,0 +1,35 @@
1
+ import { NCWebsocketOptions } from 'node-napcat-ts';
2
+ import { BotApi } from './botApi';
3
+ import { BotEvent } from './botEvent';
4
+ /**
5
+ * Bot 客户端,封装连接、启动流程及 bot 自身信息。
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const bot = new BotClient({
10
+ baseUrl: 'ws://localhost:8082/onebot/v11/ws/',
11
+ accessToken: 'yourAccessToken',
12
+ reconnection: {
13
+ enable: true,
14
+ attempts: 10,
15
+ delay: 5000,
16
+ },
17
+ });
18
+ * await bot.start();
19
+ * ```
20
+ */
21
+ export declare class BotClient {
22
+ /** API 调用入口 */
23
+ api: BotApi;
24
+ /** 事件监听入口 */
25
+ event: BotEvent;
26
+ /** 登录后 bot 自身昵称 */
27
+ nickname: string | null;
28
+ /** 登录后 bot 自身 QQ 号 */
29
+ id: number | null;
30
+ constructor(config: NCWebsocketOptions);
31
+ /**
32
+ * 连接 napcat 并初始化事件监听,启动成功后自动填充 {@link nickname} 和 {@link id}。
33
+ */
34
+ start(): Promise<void>;
35
+ }
@@ -0,0 +1,75 @@
1
+ import { BotApi } from './botApi';
2
+ import { BotConsole } from './botConsole';
3
+ import { BotEvent } from './botEvent';
4
+ /**
5
+ * Bot 客户端,封装连接、启动流程及 bot 自身信息。
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const bot = new BotClient({
10
+ baseUrl: 'ws://localhost:8082/onebot/v11/ws/',
11
+ accessToken: 'yourAccessToken',
12
+ reconnection: {
13
+ enable: true,
14
+ attempts: 10,
15
+ delay: 5000,
16
+ },
17
+ });
18
+ * await bot.start();
19
+ * ```
20
+ */
21
+ export class BotClient {
22
+ constructor(config) {
23
+ /** API 调用入口 */
24
+ Object.defineProperty(this, "api", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ /** 事件监听入口 */
31
+ Object.defineProperty(this, "event", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: void 0
36
+ });
37
+ /** 登录后 bot 自身昵称 */
38
+ Object.defineProperty(this, "nickname", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: void 0
43
+ });
44
+ /** 登录后 bot 自身 QQ 号 */
45
+ Object.defineProperty(this, "id", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ this.api = new BotApi(config);
52
+ this.api.client = this;
53
+ this.event = new BotEvent(this.api, this);
54
+ this.nickname = null;
55
+ this.id = null;
56
+ }
57
+ /**
58
+ * 连接 napcat 并初始化事件监听,启动成功后自动填充 {@link nickname} 和 {@link id}。
59
+ */
60
+ async start() {
61
+ await this.api.connect();
62
+ this.api.napcat.on('meta_event.lifecycle.connect', () => {
63
+ new BotConsole('system', 'napcat服务器连接成功').log();
64
+ });
65
+ try {
66
+ const loginInfo = await this.api.getLoginInfo();
67
+ new BotConsole('system', `bot启动成功,昵称: ${loginInfo.nickname}, 用户ID: ${loginInfo.user_id}`).log();
68
+ this.nickname = loginInfo.nickname;
69
+ this.id = loginInfo.user_id;
70
+ }
71
+ catch (e) {
72
+ new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,72 @@
1
+ import { GroupMessage, GroupMessageSelf, PrivateFriendMessage, PrivateGroupMessage, PrivateFriendMessageSelf, PrivateGroupMessageSelf, RequestFriend, RequestGroupAdd, RequestGroupInvite } from 'node-napcat-ts';
2
+ import { Message } from './message';
3
+ /** 私聊消息联合类型 */
4
+ export type PrivateMessage = PrivateFriendMessage | PrivateGroupMessage;
5
+ /** 自发送私聊消息联合类型 */
6
+ export type PrivateMessageSelf = PrivateFriendMessageSelf | PrivateGroupMessageSelf;
7
+ /** 群请求联合类型 */
8
+ export type RequestGroup = RequestGroupAdd | RequestGroupInvite;
9
+ /** notice 事件通用类型 */
10
+ export type NoticeEvent = Record<string, any> & {
11
+ post_type: 'notice';
12
+ notice_type: string;
13
+ sub_type?: string;
14
+ };
15
+ /** BotConsole 日志分类 */
16
+ export type BotConsoleType = 'system' | 'groupMessage' | 'privateMessage' | 'error' | 'sendGroupMessage' | 'sendPrivateMessage' | 'groupMessageSelf' | 'privateMessageSelf' | 'requestFriend' | 'requestGroupAdd' | 'requestGroupInvite' | 'notice';
17
+ /** ANSI 颜色/样式码 */
18
+ export declare const colors: {
19
+ reset: string;
20
+ bold: string;
21
+ dim: string;
22
+ underline: string;
23
+ black: string;
24
+ red: string;
25
+ green: string;
26
+ yellow: string;
27
+ blue: string;
28
+ magenta: string;
29
+ cyan: string;
30
+ white: string;
31
+ gray: string;
32
+ brightRed: string;
33
+ brightGreen: string;
34
+ brightYellow: string;
35
+ brightBlue: string;
36
+ brightMagenta: string;
37
+ brightCyan: string;
38
+ brightWhite: string;
39
+ redBg: string;
40
+ greenBg: string;
41
+ yellowBg: string;
42
+ blueBg: string;
43
+ magentaBg: string;
44
+ cyanBg: string;
45
+ };
46
+ /**
47
+ * 解析 CQ 码字符串为可读中文
48
+ * @example
49
+ * parseCQ('[CQ:at,qq=123]') // '[@123]'
50
+ * parseCQ('[CQ:image,url=https://...]') // '[图片:https://...]'
51
+ */
52
+ export declare const parseCQ: (raw: string) => string;
53
+ /**
54
+ * 将 Message 段格式化为带 ANSI 颜色的控制台字符串
55
+ * @param m - 消息段
56
+ */
57
+ export declare const formatMessage: (m: Message) => string;
58
+ /**
59
+ * 控制台日志输出,按 type 分类带颜色格式化。
60
+ *
61
+ * - `system`:绿色 `[hotCatBotSystem]` 前缀
62
+ * - `groupMessage`:解析群消息事件,显示群号/身份/发送者/内容
63
+ * - `privateMessage`:解析私聊消息事件,显示来源/发送者/内容
64
+ * - `error`:红色错误输出
65
+ * - `sendGroupMessage` / `sendPrivateMessage`:解析发送的消息段并带颜色输出
66
+ */
67
+ export declare class BotConsole {
68
+ type: BotConsoleType;
69
+ content: string | GroupMessage | GroupMessageSelf | PrivateMessage | PrivateMessageSelf | Message[] | RequestFriend | RequestGroupAdd | RequestGroupInvite | NoticeEvent;
70
+ constructor(type: BotConsoleType, content: string | GroupMessage | GroupMessageSelf | PrivateMessage | PrivateMessageSelf | Message[] | RequestFriend | RequestGroupAdd | RequestGroupInvite | NoticeEvent);
71
+ log(): void;
72
+ }
@@ -0,0 +1,297 @@
1
+ /** ANSI 颜色/样式码 */
2
+ export const colors = {
3
+ reset: '\x1b[0m',
4
+ bold: '\x1b[1m',
5
+ dim: '\x1b[2m',
6
+ underline: '\x1b[4m',
7
+ black: '\x1b[30m',
8
+ red: '\x1b[31m',
9
+ green: '\x1b[32m',
10
+ yellow: '\x1b[33m',
11
+ blue: '\x1b[34m',
12
+ magenta: '\x1b[35m',
13
+ cyan: '\x1b[36m',
14
+ white: '\x1b[37m',
15
+ gray: '\x1b[90m',
16
+ brightRed: '\x1b[91m',
17
+ brightGreen: '\x1b[92m',
18
+ brightYellow: '\x1b[93m',
19
+ brightBlue: '\x1b[94m',
20
+ brightMagenta: '\x1b[95m',
21
+ brightCyan: '\x1b[96m',
22
+ brightWhite: '\x1b[97m',
23
+ redBg: '\x1b[41m',
24
+ greenBg: '\x1b[42m',
25
+ yellowBg: '\x1b[43m',
26
+ blueBg: '\x1b[44m',
27
+ magentaBg: '\x1b[45m',
28
+ cyanBg: '\x1b[46m',
29
+ };
30
+ const sanitize = (s) => s.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\u200B-\u200F\u202A-\u202E\u2060\uFEFF]/g, '');
31
+ /**
32
+ * 解析 CQ 码字符串为可读中文
33
+ * @example
34
+ * parseCQ('[CQ:at,qq=123]') // '[@123]'
35
+ * parseCQ('[CQ:image,url=https://...]') // '[图片:https://...]'
36
+ */
37
+ export const parseCQ = (raw) => {
38
+ let result = '';
39
+ let i = 0;
40
+ while (i < raw.length) {
41
+ if (raw.startsWith('[CQ:', i)) {
42
+ const start = i + 4;
43
+ const commaIdx = raw.indexOf(',', start);
44
+ if (commaIdx === -1) {
45
+ result += raw[i];
46
+ i++;
47
+ continue;
48
+ }
49
+ const type = raw.slice(start, commaIdx);
50
+ let depth = 1;
51
+ let j = commaIdx + 1;
52
+ while (j < raw.length) {
53
+ if (raw[j] === '[')
54
+ depth++;
55
+ else if (raw[j] === ']') {
56
+ depth--;
57
+ if (depth === 0)
58
+ break;
59
+ }
60
+ j++;
61
+ }
62
+ if (depth !== 0) {
63
+ result += raw[i];
64
+ i++;
65
+ continue;
66
+ }
67
+ const params = raw.slice(commaIdx + 1, j);
68
+ const kv = {};
69
+ params.split(',').forEach(p => {
70
+ const eq = p.indexOf('=');
71
+ if (eq > 0)
72
+ kv[p.slice(0, eq)] = p.slice(eq + 1);
73
+ });
74
+ switch (type) {
75
+ case 'image':
76
+ result += kv.url ? `[图片:${sanitize(kv.url)}]` : '[图片]';
77
+ break;
78
+ case 'face':
79
+ result += `[表情:${kv.id || '?'}]`;
80
+ break;
81
+ case 'at':
82
+ result += kv.qq === 'all' ? '[@全体]' : `[@${kv.qq || '?'}]`;
83
+ break;
84
+ case 'record':
85
+ result += kv.url ? `[语音:${sanitize(kv.url)}]` : '[语音]';
86
+ break;
87
+ case 'video':
88
+ result += kv.url ? `[视频:${sanitize(kv.url)}]` : '[视频]';
89
+ break;
90
+ case 'reply':
91
+ result += '[回复]';
92
+ break;
93
+ case 'file':
94
+ result += kv.url ? `[文件:${sanitize(kv.url)}]` : '[文件]';
95
+ break;
96
+ case 'dice':
97
+ result += '[骰子]';
98
+ break;
99
+ case 'rps':
100
+ result += '[猜拳]';
101
+ break;
102
+ case 'json':
103
+ result += '[json]';
104
+ break;
105
+ case 'forward':
106
+ result += '[转发]';
107
+ break;
108
+ case 'music':
109
+ result += '[音乐]';
110
+ break;
111
+ case 'mface':
112
+ result += '[商城表情]';
113
+ break;
114
+ case 'markdown':
115
+ result += '[markdown]';
116
+ break;
117
+ default:
118
+ result += `[${type}]`;
119
+ break;
120
+ }
121
+ i = j + 1;
122
+ }
123
+ else {
124
+ result += raw[i];
125
+ i++;
126
+ }
127
+ }
128
+ return result;
129
+ };
130
+ /**
131
+ * 将 Message 段格式化为带 ANSI 颜色的控制台字符串
132
+ * @param m - 消息段
133
+ */
134
+ export const formatMessage = (m) => {
135
+ switch (m.type) {
136
+ case 'text':
137
+ return `${colors.green}${parseCQ(sanitize(m.data.text))}${colors.reset}`;
138
+ case 'at':
139
+ return m.data.qq === 'all'
140
+ ? `${colors.blue}@全体成员${colors.reset}`
141
+ : `${colors.blue}@${sanitize(String(m.data.qq))}${colors.reset}`;
142
+ case 'reply':
143
+ return `${colors.gray}[回复]${colors.reset}`;
144
+ case 'image': {
145
+ const f = sanitize(String(m.data.file || ''));
146
+ const short = f.length > 60 ? f.slice(0, 57) + '...' : f;
147
+ return `${colors.magenta}[图片:${short}]${colors.reset}`;
148
+ }
149
+ case 'face':
150
+ return `${colors.yellow}[表情:${m.data.id}]${colors.reset}`;
151
+ case 'record': {
152
+ const f = sanitize(String(m.data.file || ''));
153
+ const short = f.length > 60 ? f.slice(0, 57) + '...' : f;
154
+ return `${colors.brightYellow}[语音:${short}]${colors.reset}`;
155
+ }
156
+ case 'video': {
157
+ const f = sanitize(String(m.data.file || ''));
158
+ const short = f.length > 60 ? f.slice(0, 57) + '...' : f;
159
+ return `${colors.brightMagenta}[视频:${short}]${colors.reset}`;
160
+ }
161
+ case 'file': {
162
+ const f = sanitize(String(m.data.name || m.data.file || ''));
163
+ const short = f.length > 60 ? f.slice(0, 57) + '...' : f;
164
+ return `${colors.brightCyan}[文件:${short}]${colors.reset}`;
165
+ }
166
+ case 'json':
167
+ return `${colors.gray}[json]${colors.reset}`;
168
+ case 'markdown':
169
+ return `${colors.cyan}[markdown]${colors.reset}`;
170
+ case 'music':
171
+ return `${colors.magenta}[音乐]${colors.reset}`;
172
+ case 'dice':
173
+ return `${colors.yellow}[骰子]${colors.reset}`;
174
+ case 'rps':
175
+ return `${colors.yellow}[猜拳]${colors.reset}`;
176
+ case 'node':
177
+ return `${colors.cyan}[转发节点]${colors.reset}`;
178
+ case 'forward':
179
+ return `${colors.cyan}[转发:${sanitize(String(m.data.id))}]${colors.reset}`;
180
+ case 'contact':
181
+ return `${colors.blue}[推荐:${sanitize(String(m.data.type))}/${sanitize(String(m.data.id))}]${colors.reset}`;
182
+ case 'mface':
183
+ return `${colors.yellow}[商城表情]${colors.reset}`;
184
+ default:
185
+ return `[${m.type}]`;
186
+ }
187
+ };
188
+ /**
189
+ * 控制台日志输出,按 type 分类带颜色格式化。
190
+ *
191
+ * - `system`:绿色 `[hotCatBotSystem]` 前缀
192
+ * - `groupMessage`:解析群消息事件,显示群号/身份/发送者/内容
193
+ * - `privateMessage`:解析私聊消息事件,显示来源/发送者/内容
194
+ * - `error`:红色错误输出
195
+ * - `sendGroupMessage` / `sendPrivateMessage`:解析发送的消息段并带颜色输出
196
+ */
197
+ export class BotConsole {
198
+ constructor(type, content) {
199
+ Object.defineProperty(this, "type", {
200
+ enumerable: true,
201
+ configurable: true,
202
+ writable: true,
203
+ value: void 0
204
+ });
205
+ Object.defineProperty(this, "content", {
206
+ enumerable: true,
207
+ configurable: true,
208
+ writable: true,
209
+ value: void 0
210
+ });
211
+ this.type = type;
212
+ this.content = content;
213
+ }
214
+ log() {
215
+ if (this.type === 'system') {
216
+ console.log(`${colors.green}[hotCatBotSystem]: ${colors.reset}`, this.content);
217
+ }
218
+ else if (this.type === 'groupMessage') {
219
+ const event = this.content;
220
+ const sender = sanitize(event.sender.card || event.sender.nickname);
221
+ const roleText = event.sender.role === 'owner' ? '群主' : event.sender.role === 'admin' ? '管理' : '';
222
+ console.log(`${colors.cyan}[groupMessage]:${colors.reset} ` +
223
+ `${colors.yellow}群${colors.reset}(${colors.cyan}${event.group_id}${colors.reset}) ` +
224
+ `${colors.red}${roleText}${colors.reset} ` +
225
+ `${colors.magenta}${sender}${colors.reset}(${colors.blue}${event.user_id}${colors.reset}): ` +
226
+ `${colors.green}${parseCQ(sanitize(event.raw_message))}${colors.reset}`);
227
+ }
228
+ else if (this.type === 'privateMessage') {
229
+ const event = this.content;
230
+ const sender = sanitize(event.sender.nickname);
231
+ const tag = event.sub_type === 'group' ? '群临时' : '好友';
232
+ console.log(`${colors.yellow}[privateMessage]:${colors.reset} ` +
233
+ `${colors.cyan}[${tag}]${colors.reset} ` +
234
+ `${colors.magenta}${sender}${colors.reset}(${colors.blue}${event.user_id}${colors.reset}): ` +
235
+ `${colors.green}${parseCQ(sanitize(event.raw_message))}${colors.reset}`);
236
+ }
237
+ else if (this.type === 'error') {
238
+ console.log(`${colors.red}[error]${colors.red}`, this.content);
239
+ }
240
+ else if (this.type === 'sendGroupMessage') {
241
+ const messages = this.content;
242
+ console.log(`${colors.green}[sendGroupMessage]:${colors.reset} ${messages.map(formatMessage).join('')}`);
243
+ }
244
+ else if (this.type === 'sendPrivateMessage') {
245
+ const messages = this.content;
246
+ console.log(`${colors.green}[sendPrivateMessage]:${colors.reset} ${messages.map(formatMessage).join('')}`);
247
+ }
248
+ else if (this.type === 'groupMessageSelf') {
249
+ const event = this.content;
250
+ console.log(`${colors.cyan}[groupMessageSelf]:${colors.reset} ` +
251
+ `${colors.yellow}群${colors.reset}(${colors.cyan}${event.group_id}${colors.reset}): ` +
252
+ `${colors.green}${parseCQ(sanitize(event.raw_message))}${colors.reset}`);
253
+ }
254
+ else if (this.type === 'privateMessageSelf') {
255
+ const event = this.content;
256
+ const tag = event.sub_type === 'group' ? '群临时' : '好友';
257
+ console.log(`${colors.yellow}[privateMessageSelf]:${colors.reset} ` +
258
+ `${colors.cyan}[${tag}]${colors.reset} ` +
259
+ `${colors.magenta}发送给${colors.reset}(${colors.blue}${event.user_id}${colors.reset}): ` +
260
+ `${colors.green}${parseCQ(sanitize(event.raw_message))}${colors.reset}`);
261
+ }
262
+ else if (this.type === 'requestFriend') {
263
+ const event = this.content;
264
+ console.log(`${colors.yellow}[requestFriend]:${colors.reset} ` +
265
+ `用户(${colors.blue}${event.user_id}${colors.reset}) 请求添加好友` +
266
+ (event.comment ? ` 留言: ${colors.green}${sanitize(event.comment)}${colors.reset}` : ''));
267
+ }
268
+ else if (this.type === 'requestGroupAdd') {
269
+ const event = this.content;
270
+ console.log(`${colors.yellow}[requestGroupAdd]:${colors.reset} ` +
271
+ `用户(${colors.blue}${event.user_id}${colors.reset}) 申请加入群(${colors.cyan}${event.group_id}${colors.reset})` +
272
+ (event.comment ? ` 留言: ${colors.green}${sanitize(event.comment)}${colors.reset}` : ''));
273
+ }
274
+ else if (this.type === 'requestGroupInvite') {
275
+ const event = this.content;
276
+ console.log(`${colors.yellow}[requestGroupInvite]:${colors.reset} ` +
277
+ `用户(${colors.blue}${event.user_id}${colors.reset}) 邀请 bot 加入群(${colors.cyan}${event.group_id}${colors.reset})` +
278
+ (event.comment ? ` 留言: ${colors.green}${sanitize(event.comment)}${colors.reset}` : ''));
279
+ }
280
+ else if (this.type === 'notice') {
281
+ const event = this.content;
282
+ const label = event.sub_type
283
+ ? `${event.notice_type}/${event.sub_type}`
284
+ : event.notice_type;
285
+ console.log(`${colors.cyan}[notice:${label}]:${colors.reset} ` +
286
+ (event.user_id != null ? `用户(${colors.blue}${event.user_id}${colors.reset}) ` : '') +
287
+ ('group_id' in event ? `群(${colors.cyan}${event.group_id}${colors.reset}) ` : '') +
288
+ ('operator_id' in event ? `操作者(${colors.magenta}${event.operator_id}${colors.reset}) ` : '') +
289
+ ('duration' in event ? `时长${event.duration}s ` : '') +
290
+ ('message_id' in event ? `消息(${colors.gray}${event.message_id}${colors.reset}) ` : '') +
291
+ ('card_new' in event ? `${sanitize(event.card_old)} → ${colors.green}${sanitize(event.card_new)}${colors.reset}` : '') +
292
+ ('title' in event ? `${colors.green}${sanitize(event.title)}${colors.reset}` : '') +
293
+ ('name_new' in event ? `${colors.green}${sanitize(event.name_new)}${colors.reset}` : '') +
294
+ ('file' in event ? `文件:${event.file.name}` : ''));
295
+ }
296
+ }
297
+ }
@@ -0,0 +1,182 @@
1
+ import { GroupMessage, GroupMessageSelf, PrivateFriendMessageSelf, PrivateGroupMessageSelf, NCWebsocket, RequestFriend, RequestGroupAdd, RequestGroupInvite, FriendAdd, FriendRecall, GroupAdminSet, GroupAdminUnset, GroupBanBan, GroupBanLiftBan, GroupCard, GroupDecreaseLeave, GroupDecreaseKick, GroupDecreaseKickMe, GroupIncreaseApprove, GroupIncreaseInvite, GroupRecall, GroupUpload, GroupMsgEmojiLike, GroupEssenceAdd, GroupEssenceDelete, BotOffline, NotifyPokeFriend, NotifyPokeGroup, NotifyGroupName, NotifyTitle, NotifyProfileLike } from 'node-napcat-ts';
2
+ import { PrivateMessage, PrivateMessageSelf, RequestGroup } from './botConsole';
3
+ import type { BotClient } from './botClient';
4
+ import type { BotApi } from './botApi';
5
+ /**
6
+ * 当接收到消息时触发的事件。
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * bot.event.message.onGroupMessage(async (bot, event) => {
11
+ * await bot.api.sendGroupMessage(event.group_id, Message.text('收到'));
12
+ * });
13
+ * ```
14
+ */
15
+ export declare class MessageEvent {
16
+ private napcat;
17
+ private client;
18
+ constructor(napcat: NCWebsocket, client: BotClient);
19
+ /**
20
+ * 注册群消息事件回调
21
+ * @param fn - 回调 `(bot, event) => any`
22
+ */
23
+ onGroupMessage(fn: (bot: BotClient, event: GroupMessage) => any): void;
24
+ /**
25
+ * 注册群消息普通事件回调
26
+ * @param fn - 回调 `(bot, event) => any`
27
+ */
28
+ onGroupNormal(fn: (bot: BotClient, event: GroupMessage) => any): void;
29
+ /**
30
+ * 注册私聊消息事件回调
31
+ * @param fn - 回调 `(bot, event) => any`
32
+ */
33
+ onPrivateMessage(fn: (bot: BotClient, event: PrivateMessage) => any): void;
34
+ /**
35
+ * 注册私聊消息好友事件回调
36
+ * @param fn - 回调 `(bot, event) => any`
37
+ */
38
+ onPrivateFriend(fn: (bot: BotClient, event: PrivateMessage) => any): void;
39
+ /**
40
+ * 注册私聊消息群临时事件回调
41
+ * @param fn - 回调 `(bot, event) => any`
42
+ */
43
+ onPrivateGroup(fn: (bot: BotClient, event: PrivateMessage) => any): void;
44
+ }
45
+ /**
46
+ * 当 bot 自身发出消息后的事件。
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * bot.event.messageSent.onGroupSent(async (bot, event) => {
51
+ * console.log('群消息已发送:', event.message_id);
52
+ * });
53
+ * ```
54
+ */
55
+ export declare class MessageSent {
56
+ private napcat;
57
+ private client;
58
+ constructor(napcat: NCWebsocket, client: BotClient);
59
+ /**
60
+ * 注册群消息发送回执
61
+ * @param fn - 回调 `(bot, event) => any`
62
+ */
63
+ onGroupSent(fn: (bot: BotClient, event: GroupMessageSelf) => any): void;
64
+ /**
65
+ * 注册群消息发送回执(仅普通消息)
66
+ * @param fn - 回调 `(bot, event) => any`
67
+ */
68
+ onGroupNormal(fn: (bot: BotClient, event: GroupMessageSelf) => any): void;
69
+ /**
70
+ * 注册私聊消息发送回执
71
+ * @param fn - 回调 `(bot, event) => any`
72
+ */
73
+ onPrivateSent(fn: (bot: BotClient, event: PrivateMessageSelf) => any): void;
74
+ /**
75
+ * 注册私聊好友消息发送回执
76
+ * @param fn - 回调 `(bot, event) => any`
77
+ */
78
+ onPrivateFriend(fn: (bot: BotClient, event: PrivateFriendMessageSelf) => any): void;
79
+ /**
80
+ * 注册私聊群临时消息发送回执
81
+ * @param fn - 回调 `(bot, event) => any`
82
+ */
83
+ onPrivateGroup(fn: (bot: BotClient, event: PrivateGroupMessageSelf) => any): void;
84
+ }
85
+ /**
86
+ * 请求事件监听(加好友、加群、邀请入群)。
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * bot.event.request.onFriend(async (bot, event) => {
91
+ * await bot.api.handleFriendAddRequest(event.flag, true);
92
+ * });
93
+ * ```
94
+ */
95
+ export declare class RequestEvent {
96
+ private napcat;
97
+ private client;
98
+ constructor(napcat: NCWebsocket, client: BotClient);
99
+ /**
100
+ * 注册加好友请求回调
101
+ * @param fn - 回调 `(bot, event) => any`,event.flag 可传给 handleFriendAddRequest
102
+ */
103
+ onFriend(fn: (bot: BotClient, event: RequestFriend) => any): void;
104
+ /**
105
+ * 注册加群请求回调
106
+ * @param fn - 回调 `(bot, event) => any`,event.flag 可传给 handleGroupAddRequest
107
+ */
108
+ onGroupAdd(fn: (bot: BotClient, event: RequestGroupAdd) => any): void;
109
+ /**
110
+ * 注册邀请入群回调
111
+ * @param fn - 回调 `(bot, event) => any`
112
+ */
113
+ onGroupInvite(fn: (bot: BotClient, event: RequestGroupInvite) => any): void;
114
+ /**
115
+ * 注册所有群请求回调(加群 + 邀请)
116
+ * @param fn - 回调 `(bot, event) => any`
117
+ */
118
+ onGroupRequest(fn: (bot: BotClient, event: RequestGroup) => any): void;
119
+ }
120
+ /**
121
+ * 通知事件监听(好友添加、群成员变动、禁言、撤回等)。
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * bot.event.notice.onFriendAdd(async (bot, event) => { ... });
126
+ * bot.event.notice.onGroupIncrease(async (bot, event) => { ... });
127
+ * ```
128
+ */
129
+ export declare class NoticeEvent {
130
+ private napcat;
131
+ private client;
132
+ constructor(napcat: NCWebsocket, client: BotClient);
133
+ /** 好友添加 */
134
+ onFriendAdd(fn: (bot: BotClient, event: FriendAdd) => any): void;
135
+ /** 私聊消息撤回 */
136
+ onFriendRecall(fn: (bot: BotClient, event: FriendRecall) => any): void;
137
+ /** 群管理员变动(设置/取消) */
138
+ onGroupAdmin(fn: (bot: BotClient, event: GroupAdminSet | GroupAdminUnset) => any): void;
139
+ /** 群禁言变动(禁言/解除) */
140
+ onGroupBan(fn: (bot: BotClient, event: GroupBanBan | GroupBanLiftBan) => any): void;
141
+ /** 群名片变更 */
142
+ onGroupCard(fn: (bot: BotClient, event: GroupCard) => any): void;
143
+ /** 群成员减少(退群/被踢/bot被踢) */
144
+ onGroupDecrease(fn: (bot: BotClient, event: GroupDecreaseLeave | GroupDecreaseKick | GroupDecreaseKickMe) => any): void;
145
+ /** 群成员增加(审批/邀请) */
146
+ onGroupIncrease(fn: (bot: BotClient, event: GroupIncreaseApprove | GroupIncreaseInvite) => any): void;
147
+ /** 群消息撤回 */
148
+ onGroupRecall(fn: (bot: BotClient, event: GroupRecall) => any): void;
149
+ /** 群文件上传 */
150
+ onGroupUpload(fn: (bot: BotClient, event: GroupUpload) => any): void;
151
+ /** 群表情回应 */
152
+ onGroupEmojiLike(fn: (bot: BotClient, event: GroupMsgEmojiLike) => any): void;
153
+ /** 群设精(添加/删除) */
154
+ onGroupEssence(fn: (bot: BotClient, event: GroupEssenceAdd | GroupEssenceDelete) => any): void;
155
+ /** 戳一戳(好友/群) */
156
+ onPoke(fn: (bot: BotClient, event: NotifyPokeFriend | NotifyPokeGroup) => any): void;
157
+ /** 群名称变更 */
158
+ onGroupNameChange(fn: (bot: BotClient, event: NotifyGroupName) => any): void;
159
+ /** 群头衔变更 */
160
+ onTitleChange(fn: (bot: BotClient, event: NotifyTitle) => any): void;
161
+ /** 个人资料点赞 */
162
+ onProfileLike(fn: (bot: BotClient, event: NotifyProfileLike) => any): void;
163
+ /** bot 离线 */
164
+ onBotOffline(fn: (bot: BotClient, event: BotOffline) => any): void;
165
+ }
166
+ /**
167
+ * 事件监听入口,按类别分组暴露监听器。
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * bot.event.message.onGroupMessage(...);
172
+ * bot.event.messageSent.onGroupSent(...);
173
+ * bot.event.request.onFriend(...);
174
+ * ```
175
+ */
176
+ export declare class BotEvent {
177
+ message: MessageEvent;
178
+ messageSent: MessageSent;
179
+ request: RequestEvent;
180
+ notice: NoticeEvent;
181
+ constructor(api: BotApi, client: BotClient);
182
+ }