hotcat-bot-qq 0.1.4 → 0.1.5
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.
- package/dist/botEvent.d.ts +36 -111
- package/dist/botEvent.js +356 -171
- package/package.json +1 -1
- package/plugins/hotCatPlugin/index.ts +4 -4
package/dist/botEvent.d.ts
CHANGED
|
@@ -3,176 +3,101 @@ import { PrivateMessage, PrivateMessageSelf, RequestGroup } from './botConsole';
|
|
|
3
3
|
import type { BotClient } from './botClient';
|
|
4
4
|
import type { BotApi } from './botApi';
|
|
5
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
|
-
* ```
|
|
6
|
+
* 接收到的事件处理(别人发的消息)。
|
|
14
7
|
*/
|
|
15
8
|
export declare class MessageEvent {
|
|
16
9
|
private napcat;
|
|
17
10
|
private client;
|
|
11
|
+
private wrappers;
|
|
18
12
|
constructor(napcat: NCWebsocket, client: BotClient);
|
|
19
|
-
/**
|
|
20
|
-
* 注册群消息事件回调
|
|
21
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
22
|
-
*/
|
|
23
13
|
onGroupMessage(fn: (bot: BotClient, event: GroupMessage) => any): void;
|
|
24
|
-
|
|
25
|
-
* 注册群消息普通事件回调
|
|
26
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
27
|
-
*/
|
|
14
|
+
offGroupMessage(fn: Function): void;
|
|
28
15
|
onGroupNormal(fn: (bot: BotClient, event: GroupMessage) => any): void;
|
|
29
|
-
|
|
30
|
-
* 注册私聊消息事件回调
|
|
31
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
32
|
-
*/
|
|
16
|
+
offGroupNormal(fn: Function): void;
|
|
33
17
|
onPrivateMessage(fn: (bot: BotClient, event: PrivateMessage) => any): void;
|
|
34
|
-
|
|
35
|
-
* 注册私聊消息好友事件回调
|
|
36
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
37
|
-
*/
|
|
18
|
+
offPrivateMessage(fn: Function): void;
|
|
38
19
|
onPrivateFriend(fn: (bot: BotClient, event: PrivateMessage) => any): void;
|
|
39
|
-
|
|
40
|
-
* 注册私聊消息群临时事件回调
|
|
41
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
42
|
-
*/
|
|
20
|
+
offPrivateFriend(fn: Function): void;
|
|
43
21
|
onPrivateGroup(fn: (bot: BotClient, event: PrivateMessage) => any): void;
|
|
22
|
+
offPrivateGroup(fn: Function): void;
|
|
44
23
|
}
|
|
45
24
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* bot.event.messageSent.onGroupSent(async (bot, event) => {
|
|
51
|
-
* console.log('群消息已发送:', event.message_id);
|
|
52
|
-
* });
|
|
53
|
-
* ```
|
|
25
|
+
* bot 自身发出的消息事件(发送成功后的回执)。
|
|
54
26
|
*/
|
|
55
27
|
export declare class MessageSent {
|
|
56
28
|
private napcat;
|
|
57
29
|
private client;
|
|
30
|
+
private wrappers;
|
|
58
31
|
constructor(napcat: NCWebsocket, client: BotClient);
|
|
59
|
-
/**
|
|
60
|
-
* 注册群消息发送回执
|
|
61
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
62
|
-
*/
|
|
63
32
|
onGroupSent(fn: (bot: BotClient, event: GroupMessageSelf) => any): void;
|
|
64
|
-
|
|
65
|
-
* 注册群消息发送回执(仅普通消息)
|
|
66
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
67
|
-
*/
|
|
33
|
+
offGroupSent(fn: Function): void;
|
|
68
34
|
onGroupNormal(fn: (bot: BotClient, event: GroupMessageSelf) => any): void;
|
|
69
|
-
|
|
70
|
-
* 注册私聊消息发送回执
|
|
71
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
72
|
-
*/
|
|
35
|
+
offGroupNormal(fn: Function): void;
|
|
73
36
|
onPrivateSent(fn: (bot: BotClient, event: PrivateMessageSelf) => any): void;
|
|
74
|
-
|
|
75
|
-
* 注册私聊好友消息发送回执
|
|
76
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
77
|
-
*/
|
|
37
|
+
offPrivateSent(fn: Function): void;
|
|
78
38
|
onPrivateFriend(fn: (bot: BotClient, event: PrivateFriendMessageSelf) => any): void;
|
|
79
|
-
|
|
80
|
-
* 注册私聊群临时消息发送回执
|
|
81
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
82
|
-
*/
|
|
39
|
+
offPrivateFriend(fn: Function): void;
|
|
83
40
|
onPrivateGroup(fn: (bot: BotClient, event: PrivateGroupMessageSelf) => any): void;
|
|
41
|
+
offPrivateGroup(fn: Function): void;
|
|
84
42
|
}
|
|
85
43
|
/**
|
|
86
44
|
* 请求事件监听(加好友、加群、邀请入群)。
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```ts
|
|
90
|
-
* bot.event.request.onFriend(async (bot, event) => {
|
|
91
|
-
* await bot.api.handleFriendAddRequest(event.flag, true);
|
|
92
|
-
* });
|
|
93
|
-
* ```
|
|
94
45
|
*/
|
|
95
46
|
export declare class RequestEvent {
|
|
96
47
|
private napcat;
|
|
97
48
|
private client;
|
|
49
|
+
private wrappers;
|
|
98
50
|
constructor(napcat: NCWebsocket, client: BotClient);
|
|
99
|
-
/**
|
|
100
|
-
* 注册加好友请求回调
|
|
101
|
-
* @param fn - 回调 `(bot, event) => any`,event.flag 可传给 handleFriendAddRequest
|
|
102
|
-
*/
|
|
103
51
|
onFriend(fn: (bot: BotClient, event: RequestFriend) => any): void;
|
|
104
|
-
|
|
105
|
-
* 注册加群请求回调
|
|
106
|
-
* @param fn - 回调 `(bot, event) => any`,event.flag 可传给 handleGroupAddRequest
|
|
107
|
-
*/
|
|
52
|
+
offFriend(fn: Function): void;
|
|
108
53
|
onGroupAdd(fn: (bot: BotClient, event: RequestGroupAdd) => any): void;
|
|
109
|
-
|
|
110
|
-
* 注册邀请入群回调
|
|
111
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
112
|
-
*/
|
|
54
|
+
offGroupAdd(fn: Function): void;
|
|
113
55
|
onGroupInvite(fn: (bot: BotClient, event: RequestGroupInvite) => any): void;
|
|
114
|
-
|
|
115
|
-
* 注册所有群请求回调(加群 + 邀请)
|
|
116
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
117
|
-
*/
|
|
56
|
+
offGroupInvite(fn: Function): void;
|
|
118
57
|
onGroupRequest(fn: (bot: BotClient, event: RequestGroup) => any): void;
|
|
58
|
+
offGroupRequest(fn: Function): void;
|
|
119
59
|
}
|
|
120
60
|
/**
|
|
121
61
|
* 通知事件监听(好友添加、群成员变动、禁言、撤回等)。
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```ts
|
|
125
|
-
* bot.event.notice.onFriendAdd(async (bot, event) => { ... });
|
|
126
|
-
* bot.event.notice.onGroupIncrease(async (bot, event) => { ... });
|
|
127
|
-
* ```
|
|
128
62
|
*/
|
|
129
63
|
export declare class NoticeEvent {
|
|
130
64
|
private napcat;
|
|
131
65
|
private client;
|
|
66
|
+
private wrappers;
|
|
132
67
|
constructor(napcat: NCWebsocket, client: BotClient);
|
|
133
|
-
/** 好友添加 */
|
|
134
68
|
onFriendAdd(fn: (bot: BotClient, event: FriendAdd) => any): void;
|
|
135
|
-
|
|
69
|
+
offFriendAdd(fn: Function): void;
|
|
136
70
|
onFriendRecall(fn: (bot: BotClient, event: FriendRecall) => any): void;
|
|
137
|
-
|
|
71
|
+
offFriendRecall(fn: Function): void;
|
|
138
72
|
onGroupAdmin(fn: (bot: BotClient, event: GroupAdminSet | GroupAdminUnset) => any): void;
|
|
139
|
-
|
|
73
|
+
offGroupAdmin(fn: Function): void;
|
|
140
74
|
onGroupBan(fn: (bot: BotClient, event: GroupBanBan | GroupBanLiftBan) => any): void;
|
|
141
|
-
|
|
75
|
+
offGroupBan(fn: Function): void;
|
|
142
76
|
onGroupCard(fn: (bot: BotClient, event: GroupCard) => any): void;
|
|
143
|
-
|
|
77
|
+
offGroupCard(fn: Function): void;
|
|
144
78
|
onGroupDecrease(fn: (bot: BotClient, event: GroupDecreaseLeave | GroupDecreaseKick | GroupDecreaseKickMe) => any): void;
|
|
145
|
-
|
|
79
|
+
offGroupDecrease(fn: Function): void;
|
|
146
80
|
onGroupIncrease(fn: (bot: BotClient, event: GroupIncreaseApprove | GroupIncreaseInvite) => any): void;
|
|
147
|
-
|
|
81
|
+
offGroupIncrease(fn: Function): void;
|
|
148
82
|
onGroupRecall(fn: (bot: BotClient, event: GroupRecall) => any): void;
|
|
149
|
-
|
|
83
|
+
offGroupRecall(fn: Function): void;
|
|
150
84
|
onGroupUpload(fn: (bot: BotClient, event: GroupUpload) => any): void;
|
|
151
|
-
|
|
85
|
+
offGroupUpload(fn: Function): void;
|
|
152
86
|
onGroupEmojiLike(fn: (bot: BotClient, event: GroupMsgEmojiLike) => any): void;
|
|
153
|
-
|
|
87
|
+
offGroupEmojiLike(fn: Function): void;
|
|
154
88
|
onGroupEssence(fn: (bot: BotClient, event: GroupEssenceAdd | GroupEssenceDelete) => any): void;
|
|
155
|
-
|
|
89
|
+
offGroupEssence(fn: Function): void;
|
|
156
90
|
onPoke(fn: (bot: BotClient, event: NotifyPokeFriend | NotifyPokeGroup) => any): void;
|
|
157
|
-
|
|
91
|
+
offPoke(fn: Function): void;
|
|
158
92
|
onGroupNameChange(fn: (bot: BotClient, event: NotifyGroupName) => any): void;
|
|
159
|
-
|
|
93
|
+
offGroupNameChange(fn: Function): void;
|
|
160
94
|
onTitleChange(fn: (bot: BotClient, event: NotifyTitle) => any): void;
|
|
161
|
-
|
|
95
|
+
offTitleChange(fn: Function): void;
|
|
162
96
|
onProfileLike(fn: (bot: BotClient, event: NotifyProfileLike) => any): void;
|
|
163
|
-
|
|
97
|
+
offProfileLike(fn: Function): void;
|
|
164
98
|
onBotOffline(fn: (bot: BotClient, event: BotOffline) => any): void;
|
|
99
|
+
offBotOffline(fn: Function): void;
|
|
165
100
|
}
|
|
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
101
|
export declare class BotEvent {
|
|
177
102
|
message: MessageEvent;
|
|
178
103
|
messageSent: MessageSent;
|
package/dist/botEvent.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { BotConsole } from './botConsole';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* bot.event.message.onGroupMessage(async (bot, event) => {
|
|
8
|
-
* await bot.api.sendGroupMessage(event.group_id, Message.text('收到'));
|
|
9
|
-
* });
|
|
10
|
-
* ```
|
|
3
|
+
* 接收到的事件处理(别人发的消息)。
|
|
11
4
|
*/
|
|
12
5
|
export class MessageEvent {
|
|
13
6
|
constructor(napcat, client) {
|
|
@@ -23,15 +16,17 @@ export class MessageEvent {
|
|
|
23
16
|
writable: true,
|
|
24
17
|
value: void 0
|
|
25
18
|
});
|
|
19
|
+
Object.defineProperty(this, "wrappers", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: new Map()
|
|
24
|
+
});
|
|
26
25
|
this.napcat = napcat;
|
|
27
26
|
this.client = client;
|
|
28
27
|
}
|
|
29
|
-
/**
|
|
30
|
-
* 注册群消息事件回调
|
|
31
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
32
|
-
*/
|
|
33
28
|
onGroupMessage(fn) {
|
|
34
|
-
|
|
29
|
+
const w = async (event) => {
|
|
35
30
|
try {
|
|
36
31
|
new BotConsole('groupMessage', event).log();
|
|
37
32
|
await fn(this.client, event);
|
|
@@ -39,14 +34,19 @@ export class MessageEvent {
|
|
|
39
34
|
catch (e) {
|
|
40
35
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
41
36
|
}
|
|
42
|
-
}
|
|
37
|
+
};
|
|
38
|
+
this.wrappers.set(fn, w);
|
|
39
|
+
this.napcat.on('message.group', w);
|
|
40
|
+
}
|
|
41
|
+
offGroupMessage(fn) {
|
|
42
|
+
const w = this.wrappers.get(fn);
|
|
43
|
+
if (w) {
|
|
44
|
+
this.napcat.off('message.group', w);
|
|
45
|
+
this.wrappers.delete(fn);
|
|
46
|
+
}
|
|
43
47
|
}
|
|
44
|
-
/**
|
|
45
|
-
* 注册群消息普通事件回调
|
|
46
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
47
|
-
*/
|
|
48
48
|
onGroupNormal(fn) {
|
|
49
|
-
|
|
49
|
+
const w = async (event) => {
|
|
50
50
|
try {
|
|
51
51
|
new BotConsole('groupMessage', event).log();
|
|
52
52
|
await fn(this.client, event);
|
|
@@ -54,14 +54,19 @@ export class MessageEvent {
|
|
|
54
54
|
catch (e) {
|
|
55
55
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
56
56
|
}
|
|
57
|
-
}
|
|
57
|
+
};
|
|
58
|
+
this.wrappers.set(fn, w);
|
|
59
|
+
this.napcat.on('message.group.normal', w);
|
|
60
|
+
}
|
|
61
|
+
offGroupNormal(fn) {
|
|
62
|
+
const w = this.wrappers.get(fn);
|
|
63
|
+
if (w) {
|
|
64
|
+
this.napcat.off('message.group.normal', w);
|
|
65
|
+
this.wrappers.delete(fn);
|
|
66
|
+
}
|
|
58
67
|
}
|
|
59
|
-
/**
|
|
60
|
-
* 注册私聊消息事件回调
|
|
61
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
62
|
-
*/
|
|
63
68
|
onPrivateMessage(fn) {
|
|
64
|
-
|
|
69
|
+
const w = async (event) => {
|
|
65
70
|
try {
|
|
66
71
|
new BotConsole('privateMessage', event).log();
|
|
67
72
|
await fn(this.client, event);
|
|
@@ -69,14 +74,19 @@ export class MessageEvent {
|
|
|
69
74
|
catch (e) {
|
|
70
75
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
71
76
|
}
|
|
72
|
-
}
|
|
77
|
+
};
|
|
78
|
+
this.wrappers.set(fn, w);
|
|
79
|
+
this.napcat.on('message.private', w);
|
|
80
|
+
}
|
|
81
|
+
offPrivateMessage(fn) {
|
|
82
|
+
const w = this.wrappers.get(fn);
|
|
83
|
+
if (w) {
|
|
84
|
+
this.napcat.off('message.private', w);
|
|
85
|
+
this.wrappers.delete(fn);
|
|
86
|
+
}
|
|
73
87
|
}
|
|
74
|
-
/**
|
|
75
|
-
* 注册私聊消息好友事件回调
|
|
76
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
77
|
-
*/
|
|
78
88
|
onPrivateFriend(fn) {
|
|
79
|
-
|
|
89
|
+
const w = async (event) => {
|
|
80
90
|
try {
|
|
81
91
|
new BotConsole('privateMessage', event).log();
|
|
82
92
|
await fn(this.client, event);
|
|
@@ -84,14 +94,19 @@ export class MessageEvent {
|
|
|
84
94
|
catch (e) {
|
|
85
95
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
86
96
|
}
|
|
87
|
-
}
|
|
97
|
+
};
|
|
98
|
+
this.wrappers.set(fn, w);
|
|
99
|
+
this.napcat.on('message.private.friend', w);
|
|
100
|
+
}
|
|
101
|
+
offPrivateFriend(fn) {
|
|
102
|
+
const w = this.wrappers.get(fn);
|
|
103
|
+
if (w) {
|
|
104
|
+
this.napcat.off('message.private.friend', w);
|
|
105
|
+
this.wrappers.delete(fn);
|
|
106
|
+
}
|
|
88
107
|
}
|
|
89
|
-
/**
|
|
90
|
-
* 注册私聊消息群临时事件回调
|
|
91
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
92
|
-
*/
|
|
93
108
|
onPrivateGroup(fn) {
|
|
94
|
-
|
|
109
|
+
const w = async (event) => {
|
|
95
110
|
try {
|
|
96
111
|
new BotConsole('privateMessage', event).log();
|
|
97
112
|
await fn(this.client, event);
|
|
@@ -99,18 +114,20 @@ export class MessageEvent {
|
|
|
99
114
|
catch (e) {
|
|
100
115
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
101
116
|
}
|
|
102
|
-
}
|
|
117
|
+
};
|
|
118
|
+
this.wrappers.set(fn, w);
|
|
119
|
+
this.napcat.on('message.private.group', w);
|
|
120
|
+
}
|
|
121
|
+
offPrivateGroup(fn) {
|
|
122
|
+
const w = this.wrappers.get(fn);
|
|
123
|
+
if (w) {
|
|
124
|
+
this.napcat.off('message.private.group', w);
|
|
125
|
+
this.wrappers.delete(fn);
|
|
126
|
+
}
|
|
103
127
|
}
|
|
104
128
|
}
|
|
105
129
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```ts
|
|
110
|
-
* bot.event.messageSent.onGroupSent(async (bot, event) => {
|
|
111
|
-
* console.log('群消息已发送:', event.message_id);
|
|
112
|
-
* });
|
|
113
|
-
* ```
|
|
130
|
+
* bot 自身发出的消息事件(发送成功后的回执)。
|
|
114
131
|
*/
|
|
115
132
|
export class MessageSent {
|
|
116
133
|
constructor(napcat, client) {
|
|
@@ -126,15 +143,17 @@ export class MessageSent {
|
|
|
126
143
|
writable: true,
|
|
127
144
|
value: void 0
|
|
128
145
|
});
|
|
146
|
+
Object.defineProperty(this, "wrappers", {
|
|
147
|
+
enumerable: true,
|
|
148
|
+
configurable: true,
|
|
149
|
+
writable: true,
|
|
150
|
+
value: new Map()
|
|
151
|
+
});
|
|
129
152
|
this.napcat = napcat;
|
|
130
153
|
this.client = client;
|
|
131
154
|
}
|
|
132
|
-
/**
|
|
133
|
-
* 注册群消息发送回执
|
|
134
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
135
|
-
*/
|
|
136
155
|
onGroupSent(fn) {
|
|
137
|
-
|
|
156
|
+
const w = async (event) => {
|
|
138
157
|
try {
|
|
139
158
|
new BotConsole('groupMessageSelf', event).log();
|
|
140
159
|
await fn(this.client, event);
|
|
@@ -142,14 +161,19 @@ export class MessageSent {
|
|
|
142
161
|
catch (e) {
|
|
143
162
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
144
163
|
}
|
|
145
|
-
}
|
|
164
|
+
};
|
|
165
|
+
this.wrappers.set(fn, w);
|
|
166
|
+
this.napcat.on('message_sent.group', w);
|
|
167
|
+
}
|
|
168
|
+
offGroupSent(fn) {
|
|
169
|
+
const w = this.wrappers.get(fn);
|
|
170
|
+
if (w) {
|
|
171
|
+
this.napcat.off('message_sent.group', w);
|
|
172
|
+
this.wrappers.delete(fn);
|
|
173
|
+
}
|
|
146
174
|
}
|
|
147
|
-
/**
|
|
148
|
-
* 注册群消息发送回执(仅普通消息)
|
|
149
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
150
|
-
*/
|
|
151
175
|
onGroupNormal(fn) {
|
|
152
|
-
|
|
176
|
+
const w = async (event) => {
|
|
153
177
|
try {
|
|
154
178
|
new BotConsole('groupMessageSelf', event).log();
|
|
155
179
|
await fn(this.client, event);
|
|
@@ -157,14 +181,19 @@ export class MessageSent {
|
|
|
157
181
|
catch (e) {
|
|
158
182
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
159
183
|
}
|
|
160
|
-
}
|
|
184
|
+
};
|
|
185
|
+
this.wrappers.set(fn, w);
|
|
186
|
+
this.napcat.on('message_sent.group.normal', w);
|
|
187
|
+
}
|
|
188
|
+
offGroupNormal(fn) {
|
|
189
|
+
const w = this.wrappers.get(fn);
|
|
190
|
+
if (w) {
|
|
191
|
+
this.napcat.off('message_sent.group.normal', w);
|
|
192
|
+
this.wrappers.delete(fn);
|
|
193
|
+
}
|
|
161
194
|
}
|
|
162
|
-
/**
|
|
163
|
-
* 注册私聊消息发送回执
|
|
164
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
165
|
-
*/
|
|
166
195
|
onPrivateSent(fn) {
|
|
167
|
-
|
|
196
|
+
const w = async (event) => {
|
|
168
197
|
try {
|
|
169
198
|
new BotConsole('privateMessageSelf', event).log();
|
|
170
199
|
await fn(this.client, event);
|
|
@@ -172,14 +201,19 @@ export class MessageSent {
|
|
|
172
201
|
catch (e) {
|
|
173
202
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
174
203
|
}
|
|
175
|
-
}
|
|
204
|
+
};
|
|
205
|
+
this.wrappers.set(fn, w);
|
|
206
|
+
this.napcat.on('message_sent.private', w);
|
|
207
|
+
}
|
|
208
|
+
offPrivateSent(fn) {
|
|
209
|
+
const w = this.wrappers.get(fn);
|
|
210
|
+
if (w) {
|
|
211
|
+
this.napcat.off('message_sent.private', w);
|
|
212
|
+
this.wrappers.delete(fn);
|
|
213
|
+
}
|
|
176
214
|
}
|
|
177
|
-
/**
|
|
178
|
-
* 注册私聊好友消息发送回执
|
|
179
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
180
|
-
*/
|
|
181
215
|
onPrivateFriend(fn) {
|
|
182
|
-
|
|
216
|
+
const w = async (event) => {
|
|
183
217
|
try {
|
|
184
218
|
new BotConsole('privateMessageSelf', event).log();
|
|
185
219
|
await fn(this.client, event);
|
|
@@ -187,14 +221,19 @@ export class MessageSent {
|
|
|
187
221
|
catch (e) {
|
|
188
222
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
189
223
|
}
|
|
190
|
-
}
|
|
224
|
+
};
|
|
225
|
+
this.wrappers.set(fn, w);
|
|
226
|
+
this.napcat.on('message_sent.private.friend', w);
|
|
227
|
+
}
|
|
228
|
+
offPrivateFriend(fn) {
|
|
229
|
+
const w = this.wrappers.get(fn);
|
|
230
|
+
if (w) {
|
|
231
|
+
this.napcat.off('message_sent.private.friend', w);
|
|
232
|
+
this.wrappers.delete(fn);
|
|
233
|
+
}
|
|
191
234
|
}
|
|
192
|
-
/**
|
|
193
|
-
* 注册私聊群临时消息发送回执
|
|
194
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
195
|
-
*/
|
|
196
235
|
onPrivateGroup(fn) {
|
|
197
|
-
|
|
236
|
+
const w = async (event) => {
|
|
198
237
|
try {
|
|
199
238
|
new BotConsole('privateMessageSelf', event).log();
|
|
200
239
|
await fn(this.client, event);
|
|
@@ -202,18 +241,20 @@ export class MessageSent {
|
|
|
202
241
|
catch (e) {
|
|
203
242
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
204
243
|
}
|
|
205
|
-
}
|
|
244
|
+
};
|
|
245
|
+
this.wrappers.set(fn, w);
|
|
246
|
+
this.napcat.on('message_sent.private.group', w);
|
|
247
|
+
}
|
|
248
|
+
offPrivateGroup(fn) {
|
|
249
|
+
const w = this.wrappers.get(fn);
|
|
250
|
+
if (w) {
|
|
251
|
+
this.napcat.off('message_sent.private.group', w);
|
|
252
|
+
this.wrappers.delete(fn);
|
|
253
|
+
}
|
|
206
254
|
}
|
|
207
255
|
}
|
|
208
256
|
/**
|
|
209
257
|
* 请求事件监听(加好友、加群、邀请入群)。
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```ts
|
|
213
|
-
* bot.event.request.onFriend(async (bot, event) => {
|
|
214
|
-
* await bot.api.handleFriendAddRequest(event.flag, true);
|
|
215
|
-
* });
|
|
216
|
-
* ```
|
|
217
258
|
*/
|
|
218
259
|
export class RequestEvent {
|
|
219
260
|
constructor(napcat, client) {
|
|
@@ -229,15 +270,17 @@ export class RequestEvent {
|
|
|
229
270
|
writable: true,
|
|
230
271
|
value: void 0
|
|
231
272
|
});
|
|
273
|
+
Object.defineProperty(this, "wrappers", {
|
|
274
|
+
enumerable: true,
|
|
275
|
+
configurable: true,
|
|
276
|
+
writable: true,
|
|
277
|
+
value: new Map()
|
|
278
|
+
});
|
|
232
279
|
this.napcat = napcat;
|
|
233
280
|
this.client = client;
|
|
234
281
|
}
|
|
235
|
-
/**
|
|
236
|
-
* 注册加好友请求回调
|
|
237
|
-
* @param fn - 回调 `(bot, event) => any`,event.flag 可传给 handleFriendAddRequest
|
|
238
|
-
*/
|
|
239
282
|
onFriend(fn) {
|
|
240
|
-
|
|
283
|
+
const w = async (event) => {
|
|
241
284
|
try {
|
|
242
285
|
new BotConsole('requestFriend', event).log();
|
|
243
286
|
await fn(this.client, event);
|
|
@@ -245,14 +288,19 @@ export class RequestEvent {
|
|
|
245
288
|
catch (e) {
|
|
246
289
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
247
290
|
}
|
|
248
|
-
}
|
|
291
|
+
};
|
|
292
|
+
this.wrappers.set(fn, w);
|
|
293
|
+
this.napcat.on('request.friend', w);
|
|
294
|
+
}
|
|
295
|
+
offFriend(fn) {
|
|
296
|
+
const w = this.wrappers.get(fn);
|
|
297
|
+
if (w) {
|
|
298
|
+
this.napcat.off('request.friend', w);
|
|
299
|
+
this.wrappers.delete(fn);
|
|
300
|
+
}
|
|
249
301
|
}
|
|
250
|
-
/**
|
|
251
|
-
* 注册加群请求回调
|
|
252
|
-
* @param fn - 回调 `(bot, event) => any`,event.flag 可传给 handleGroupAddRequest
|
|
253
|
-
*/
|
|
254
302
|
onGroupAdd(fn) {
|
|
255
|
-
|
|
303
|
+
const w = async (event) => {
|
|
256
304
|
try {
|
|
257
305
|
new BotConsole('requestGroupAdd', event).log();
|
|
258
306
|
await fn(this.client, event);
|
|
@@ -260,14 +308,19 @@ export class RequestEvent {
|
|
|
260
308
|
catch (e) {
|
|
261
309
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
262
310
|
}
|
|
263
|
-
}
|
|
311
|
+
};
|
|
312
|
+
this.wrappers.set(fn, w);
|
|
313
|
+
this.napcat.on('request.group.add', w);
|
|
314
|
+
}
|
|
315
|
+
offGroupAdd(fn) {
|
|
316
|
+
const w = this.wrappers.get(fn);
|
|
317
|
+
if (w) {
|
|
318
|
+
this.napcat.off('request.group.add', w);
|
|
319
|
+
this.wrappers.delete(fn);
|
|
320
|
+
}
|
|
264
321
|
}
|
|
265
|
-
/**
|
|
266
|
-
* 注册邀请入群回调
|
|
267
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
268
|
-
*/
|
|
269
322
|
onGroupInvite(fn) {
|
|
270
|
-
|
|
323
|
+
const w = async (event) => {
|
|
271
324
|
try {
|
|
272
325
|
new BotConsole('requestGroupInvite', event).log();
|
|
273
326
|
await fn(this.client, event);
|
|
@@ -275,14 +328,19 @@ export class RequestEvent {
|
|
|
275
328
|
catch (e) {
|
|
276
329
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
277
330
|
}
|
|
278
|
-
}
|
|
331
|
+
};
|
|
332
|
+
this.wrappers.set(fn, w);
|
|
333
|
+
this.napcat.on('request.group.invite', w);
|
|
334
|
+
}
|
|
335
|
+
offGroupInvite(fn) {
|
|
336
|
+
const w = this.wrappers.get(fn);
|
|
337
|
+
if (w) {
|
|
338
|
+
this.napcat.off('request.group.invite', w);
|
|
339
|
+
this.wrappers.delete(fn);
|
|
340
|
+
}
|
|
279
341
|
}
|
|
280
|
-
/**
|
|
281
|
-
* 注册所有群请求回调(加群 + 邀请)
|
|
282
|
-
* @param fn - 回调 `(bot, event) => any`
|
|
283
|
-
*/
|
|
284
342
|
onGroupRequest(fn) {
|
|
285
|
-
|
|
343
|
+
const w = async (event) => {
|
|
286
344
|
try {
|
|
287
345
|
const type = event.sub_type === 'add' ? 'requestGroupAdd' : 'requestGroupInvite';
|
|
288
346
|
new BotConsole(type, event).log();
|
|
@@ -291,17 +349,20 @@ export class RequestEvent {
|
|
|
291
349
|
catch (e) {
|
|
292
350
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
293
351
|
}
|
|
294
|
-
}
|
|
352
|
+
};
|
|
353
|
+
this.wrappers.set(fn, w);
|
|
354
|
+
this.napcat.on('request.group', w);
|
|
355
|
+
}
|
|
356
|
+
offGroupRequest(fn) {
|
|
357
|
+
const w = this.wrappers.get(fn);
|
|
358
|
+
if (w) {
|
|
359
|
+
this.napcat.off('request.group', w);
|
|
360
|
+
this.wrappers.delete(fn);
|
|
361
|
+
}
|
|
295
362
|
}
|
|
296
363
|
}
|
|
297
364
|
/**
|
|
298
365
|
* 通知事件监听(好友添加、群成员变动、禁言、撤回等)。
|
|
299
|
-
*
|
|
300
|
-
* @example
|
|
301
|
-
* ```ts
|
|
302
|
-
* bot.event.notice.onFriendAdd(async (bot, event) => { ... });
|
|
303
|
-
* bot.event.notice.onGroupIncrease(async (bot, event) => { ... });
|
|
304
|
-
* ```
|
|
305
366
|
*/
|
|
306
367
|
export class NoticeEvent {
|
|
307
368
|
constructor(napcat, client) {
|
|
@@ -317,12 +378,17 @@ export class NoticeEvent {
|
|
|
317
378
|
writable: true,
|
|
318
379
|
value: void 0
|
|
319
380
|
});
|
|
381
|
+
Object.defineProperty(this, "wrappers", {
|
|
382
|
+
enumerable: true,
|
|
383
|
+
configurable: true,
|
|
384
|
+
writable: true,
|
|
385
|
+
value: new Map()
|
|
386
|
+
});
|
|
320
387
|
this.napcat = napcat;
|
|
321
388
|
this.client = client;
|
|
322
389
|
}
|
|
323
|
-
/** 好友添加 */
|
|
324
390
|
onFriendAdd(fn) {
|
|
325
|
-
|
|
391
|
+
const w = async (event) => {
|
|
326
392
|
try {
|
|
327
393
|
new BotConsole('notice', event).log();
|
|
328
394
|
await fn(this.client, event);
|
|
@@ -330,11 +396,19 @@ export class NoticeEvent {
|
|
|
330
396
|
catch (e) {
|
|
331
397
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
332
398
|
}
|
|
333
|
-
}
|
|
399
|
+
};
|
|
400
|
+
this.wrappers.set(fn, w);
|
|
401
|
+
this.napcat.on('notice.friend_add', w);
|
|
402
|
+
}
|
|
403
|
+
offFriendAdd(fn) {
|
|
404
|
+
const w = this.wrappers.get(fn);
|
|
405
|
+
if (w) {
|
|
406
|
+
this.napcat.off('notice.friend_add', w);
|
|
407
|
+
this.wrappers.delete(fn);
|
|
408
|
+
}
|
|
334
409
|
}
|
|
335
|
-
/** 私聊消息撤回 */
|
|
336
410
|
onFriendRecall(fn) {
|
|
337
|
-
|
|
411
|
+
const w = async (event) => {
|
|
338
412
|
try {
|
|
339
413
|
new BotConsole('notice', event).log();
|
|
340
414
|
await fn(this.client, event);
|
|
@@ -342,11 +416,19 @@ export class NoticeEvent {
|
|
|
342
416
|
catch (e) {
|
|
343
417
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
344
418
|
}
|
|
345
|
-
}
|
|
419
|
+
};
|
|
420
|
+
this.wrappers.set(fn, w);
|
|
421
|
+
this.napcat.on('notice.friend_recall', w);
|
|
422
|
+
}
|
|
423
|
+
offFriendRecall(fn) {
|
|
424
|
+
const w = this.wrappers.get(fn);
|
|
425
|
+
if (w) {
|
|
426
|
+
this.napcat.off('notice.friend_recall', w);
|
|
427
|
+
this.wrappers.delete(fn);
|
|
428
|
+
}
|
|
346
429
|
}
|
|
347
|
-
/** 群管理员变动(设置/取消) */
|
|
348
430
|
onGroupAdmin(fn) {
|
|
349
|
-
|
|
431
|
+
const w = async (event) => {
|
|
350
432
|
try {
|
|
351
433
|
new BotConsole('notice', event).log();
|
|
352
434
|
await fn(this.client, event);
|
|
@@ -354,11 +436,19 @@ export class NoticeEvent {
|
|
|
354
436
|
catch (e) {
|
|
355
437
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
356
438
|
}
|
|
357
|
-
}
|
|
439
|
+
};
|
|
440
|
+
this.wrappers.set(fn, w);
|
|
441
|
+
this.napcat.on('notice.group_admin', w);
|
|
442
|
+
}
|
|
443
|
+
offGroupAdmin(fn) {
|
|
444
|
+
const w = this.wrappers.get(fn);
|
|
445
|
+
if (w) {
|
|
446
|
+
this.napcat.off('notice.group_admin', w);
|
|
447
|
+
this.wrappers.delete(fn);
|
|
448
|
+
}
|
|
358
449
|
}
|
|
359
|
-
/** 群禁言变动(禁言/解除) */
|
|
360
450
|
onGroupBan(fn) {
|
|
361
|
-
|
|
451
|
+
const w = async (event) => {
|
|
362
452
|
try {
|
|
363
453
|
new BotConsole('notice', event).log();
|
|
364
454
|
await fn(this.client, event);
|
|
@@ -366,11 +456,19 @@ export class NoticeEvent {
|
|
|
366
456
|
catch (e) {
|
|
367
457
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
368
458
|
}
|
|
369
|
-
}
|
|
459
|
+
};
|
|
460
|
+
this.wrappers.set(fn, w);
|
|
461
|
+
this.napcat.on('notice.group_ban', w);
|
|
462
|
+
}
|
|
463
|
+
offGroupBan(fn) {
|
|
464
|
+
const w = this.wrappers.get(fn);
|
|
465
|
+
if (w) {
|
|
466
|
+
this.napcat.off('notice.group_ban', w);
|
|
467
|
+
this.wrappers.delete(fn);
|
|
468
|
+
}
|
|
370
469
|
}
|
|
371
|
-
/** 群名片变更 */
|
|
372
470
|
onGroupCard(fn) {
|
|
373
|
-
|
|
471
|
+
const w = async (event) => {
|
|
374
472
|
try {
|
|
375
473
|
new BotConsole('notice', event).log();
|
|
376
474
|
await fn(this.client, event);
|
|
@@ -378,11 +476,19 @@ export class NoticeEvent {
|
|
|
378
476
|
catch (e) {
|
|
379
477
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
380
478
|
}
|
|
381
|
-
}
|
|
479
|
+
};
|
|
480
|
+
this.wrappers.set(fn, w);
|
|
481
|
+
this.napcat.on('notice.group_card', w);
|
|
482
|
+
}
|
|
483
|
+
offGroupCard(fn) {
|
|
484
|
+
const w = this.wrappers.get(fn);
|
|
485
|
+
if (w) {
|
|
486
|
+
this.napcat.off('notice.group_card', w);
|
|
487
|
+
this.wrappers.delete(fn);
|
|
488
|
+
}
|
|
382
489
|
}
|
|
383
|
-
/** 群成员减少(退群/被踢/bot被踢) */
|
|
384
490
|
onGroupDecrease(fn) {
|
|
385
|
-
|
|
491
|
+
const w = async (event) => {
|
|
386
492
|
try {
|
|
387
493
|
new BotConsole('notice', event).log();
|
|
388
494
|
await fn(this.client, event);
|
|
@@ -390,11 +496,19 @@ export class NoticeEvent {
|
|
|
390
496
|
catch (e) {
|
|
391
497
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
392
498
|
}
|
|
393
|
-
}
|
|
499
|
+
};
|
|
500
|
+
this.wrappers.set(fn, w);
|
|
501
|
+
this.napcat.on('notice.group_decrease', w);
|
|
502
|
+
}
|
|
503
|
+
offGroupDecrease(fn) {
|
|
504
|
+
const w = this.wrappers.get(fn);
|
|
505
|
+
if (w) {
|
|
506
|
+
this.napcat.off('notice.group_decrease', w);
|
|
507
|
+
this.wrappers.delete(fn);
|
|
508
|
+
}
|
|
394
509
|
}
|
|
395
|
-
/** 群成员增加(审批/邀请) */
|
|
396
510
|
onGroupIncrease(fn) {
|
|
397
|
-
|
|
511
|
+
const w = async (event) => {
|
|
398
512
|
try {
|
|
399
513
|
new BotConsole('notice', event).log();
|
|
400
514
|
await fn(this.client, event);
|
|
@@ -402,11 +516,19 @@ export class NoticeEvent {
|
|
|
402
516
|
catch (e) {
|
|
403
517
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
404
518
|
}
|
|
405
|
-
}
|
|
519
|
+
};
|
|
520
|
+
this.wrappers.set(fn, w);
|
|
521
|
+
this.napcat.on('notice.group_increase', w);
|
|
522
|
+
}
|
|
523
|
+
offGroupIncrease(fn) {
|
|
524
|
+
const w = this.wrappers.get(fn);
|
|
525
|
+
if (w) {
|
|
526
|
+
this.napcat.off('notice.group_increase', w);
|
|
527
|
+
this.wrappers.delete(fn);
|
|
528
|
+
}
|
|
406
529
|
}
|
|
407
|
-
/** 群消息撤回 */
|
|
408
530
|
onGroupRecall(fn) {
|
|
409
|
-
|
|
531
|
+
const w = async (event) => {
|
|
410
532
|
try {
|
|
411
533
|
new BotConsole('notice', event).log();
|
|
412
534
|
await fn(this.client, event);
|
|
@@ -414,11 +536,19 @@ export class NoticeEvent {
|
|
|
414
536
|
catch (e) {
|
|
415
537
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
416
538
|
}
|
|
417
|
-
}
|
|
539
|
+
};
|
|
540
|
+
this.wrappers.set(fn, w);
|
|
541
|
+
this.napcat.on('notice.group_recall', w);
|
|
542
|
+
}
|
|
543
|
+
offGroupRecall(fn) {
|
|
544
|
+
const w = this.wrappers.get(fn);
|
|
545
|
+
if (w) {
|
|
546
|
+
this.napcat.off('notice.group_recall', w);
|
|
547
|
+
this.wrappers.delete(fn);
|
|
548
|
+
}
|
|
418
549
|
}
|
|
419
|
-
/** 群文件上传 */
|
|
420
550
|
onGroupUpload(fn) {
|
|
421
|
-
|
|
551
|
+
const w = async (event) => {
|
|
422
552
|
try {
|
|
423
553
|
new BotConsole('notice', event).log();
|
|
424
554
|
await fn(this.client, event);
|
|
@@ -426,11 +556,19 @@ export class NoticeEvent {
|
|
|
426
556
|
catch (e) {
|
|
427
557
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
428
558
|
}
|
|
429
|
-
}
|
|
559
|
+
};
|
|
560
|
+
this.wrappers.set(fn, w);
|
|
561
|
+
this.napcat.on('notice.group_upload', w);
|
|
562
|
+
}
|
|
563
|
+
offGroupUpload(fn) {
|
|
564
|
+
const w = this.wrappers.get(fn);
|
|
565
|
+
if (w) {
|
|
566
|
+
this.napcat.off('notice.group_upload', w);
|
|
567
|
+
this.wrappers.delete(fn);
|
|
568
|
+
}
|
|
430
569
|
}
|
|
431
|
-
/** 群表情回应 */
|
|
432
570
|
onGroupEmojiLike(fn) {
|
|
433
|
-
|
|
571
|
+
const w = async (event) => {
|
|
434
572
|
try {
|
|
435
573
|
new BotConsole('notice', event).log();
|
|
436
574
|
await fn(this.client, event);
|
|
@@ -438,11 +576,19 @@ export class NoticeEvent {
|
|
|
438
576
|
catch (e) {
|
|
439
577
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
440
578
|
}
|
|
441
|
-
}
|
|
579
|
+
};
|
|
580
|
+
this.wrappers.set(fn, w);
|
|
581
|
+
this.napcat.on('notice.group_msg_emoji_like', w);
|
|
582
|
+
}
|
|
583
|
+
offGroupEmojiLike(fn) {
|
|
584
|
+
const w = this.wrappers.get(fn);
|
|
585
|
+
if (w) {
|
|
586
|
+
this.napcat.off('notice.group_msg_emoji_like', w);
|
|
587
|
+
this.wrappers.delete(fn);
|
|
588
|
+
}
|
|
442
589
|
}
|
|
443
|
-
/** 群设精(添加/删除) */
|
|
444
590
|
onGroupEssence(fn) {
|
|
445
|
-
|
|
591
|
+
const w = async (event) => {
|
|
446
592
|
try {
|
|
447
593
|
new BotConsole('notice', event).log();
|
|
448
594
|
await fn(this.client, event);
|
|
@@ -450,11 +596,19 @@ export class NoticeEvent {
|
|
|
450
596
|
catch (e) {
|
|
451
597
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
452
598
|
}
|
|
453
|
-
}
|
|
599
|
+
};
|
|
600
|
+
this.wrappers.set(fn, w);
|
|
601
|
+
this.napcat.on('notice.essence', w);
|
|
602
|
+
}
|
|
603
|
+
offGroupEssence(fn) {
|
|
604
|
+
const w = this.wrappers.get(fn);
|
|
605
|
+
if (w) {
|
|
606
|
+
this.napcat.off('notice.essence', w);
|
|
607
|
+
this.wrappers.delete(fn);
|
|
608
|
+
}
|
|
454
609
|
}
|
|
455
|
-
/** 戳一戳(好友/群) */
|
|
456
610
|
onPoke(fn) {
|
|
457
|
-
|
|
611
|
+
const w = async (event) => {
|
|
458
612
|
try {
|
|
459
613
|
new BotConsole('notice', event).log();
|
|
460
614
|
await fn(this.client, event);
|
|
@@ -462,11 +616,19 @@ export class NoticeEvent {
|
|
|
462
616
|
catch (e) {
|
|
463
617
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
464
618
|
}
|
|
465
|
-
}
|
|
619
|
+
};
|
|
620
|
+
this.wrappers.set(fn, w);
|
|
621
|
+
this.napcat.on('notice.notify.poke', w);
|
|
622
|
+
}
|
|
623
|
+
offPoke(fn) {
|
|
624
|
+
const w = this.wrappers.get(fn);
|
|
625
|
+
if (w) {
|
|
626
|
+
this.napcat.off('notice.notify.poke', w);
|
|
627
|
+
this.wrappers.delete(fn);
|
|
628
|
+
}
|
|
466
629
|
}
|
|
467
|
-
/** 群名称变更 */
|
|
468
630
|
onGroupNameChange(fn) {
|
|
469
|
-
|
|
631
|
+
const w = async (event) => {
|
|
470
632
|
try {
|
|
471
633
|
new BotConsole('notice', event).log();
|
|
472
634
|
await fn(this.client, event);
|
|
@@ -474,11 +636,19 @@ export class NoticeEvent {
|
|
|
474
636
|
catch (e) {
|
|
475
637
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
476
638
|
}
|
|
477
|
-
}
|
|
639
|
+
};
|
|
640
|
+
this.wrappers.set(fn, w);
|
|
641
|
+
this.napcat.on('notice.notify.group_name', w);
|
|
642
|
+
}
|
|
643
|
+
offGroupNameChange(fn) {
|
|
644
|
+
const w = this.wrappers.get(fn);
|
|
645
|
+
if (w) {
|
|
646
|
+
this.napcat.off('notice.notify.group_name', w);
|
|
647
|
+
this.wrappers.delete(fn);
|
|
648
|
+
}
|
|
478
649
|
}
|
|
479
|
-
/** 群头衔变更 */
|
|
480
650
|
onTitleChange(fn) {
|
|
481
|
-
|
|
651
|
+
const w = async (event) => {
|
|
482
652
|
try {
|
|
483
653
|
new BotConsole('notice', event).log();
|
|
484
654
|
await fn(this.client, event);
|
|
@@ -486,11 +656,19 @@ export class NoticeEvent {
|
|
|
486
656
|
catch (e) {
|
|
487
657
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
488
658
|
}
|
|
489
|
-
}
|
|
659
|
+
};
|
|
660
|
+
this.wrappers.set(fn, w);
|
|
661
|
+
this.napcat.on('notice.notify.title', w);
|
|
662
|
+
}
|
|
663
|
+
offTitleChange(fn) {
|
|
664
|
+
const w = this.wrappers.get(fn);
|
|
665
|
+
if (w) {
|
|
666
|
+
this.napcat.off('notice.notify.title', w);
|
|
667
|
+
this.wrappers.delete(fn);
|
|
668
|
+
}
|
|
490
669
|
}
|
|
491
|
-
/** 个人资料点赞 */
|
|
492
670
|
onProfileLike(fn) {
|
|
493
|
-
|
|
671
|
+
const w = async (event) => {
|
|
494
672
|
try {
|
|
495
673
|
new BotConsole('notice', event).log();
|
|
496
674
|
await fn(this.client, event);
|
|
@@ -498,11 +676,19 @@ export class NoticeEvent {
|
|
|
498
676
|
catch (e) {
|
|
499
677
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
500
678
|
}
|
|
501
|
-
}
|
|
679
|
+
};
|
|
680
|
+
this.wrappers.set(fn, w);
|
|
681
|
+
this.napcat.on('notice.notify.profile_like', w);
|
|
682
|
+
}
|
|
683
|
+
offProfileLike(fn) {
|
|
684
|
+
const w = this.wrappers.get(fn);
|
|
685
|
+
if (w) {
|
|
686
|
+
this.napcat.off('notice.notify.profile_like', w);
|
|
687
|
+
this.wrappers.delete(fn);
|
|
688
|
+
}
|
|
502
689
|
}
|
|
503
|
-
/** bot 离线 */
|
|
504
690
|
onBotOffline(fn) {
|
|
505
|
-
|
|
691
|
+
const w = async (event) => {
|
|
506
692
|
try {
|
|
507
693
|
new BotConsole('notice', event).log();
|
|
508
694
|
await fn(this.client, event);
|
|
@@ -510,19 +696,18 @@ export class NoticeEvent {
|
|
|
510
696
|
catch (e) {
|
|
511
697
|
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
512
698
|
}
|
|
513
|
-
}
|
|
699
|
+
};
|
|
700
|
+
this.wrappers.set(fn, w);
|
|
701
|
+
this.napcat.on('notice.bot_offline', w);
|
|
702
|
+
}
|
|
703
|
+
offBotOffline(fn) {
|
|
704
|
+
const w = this.wrappers.get(fn);
|
|
705
|
+
if (w) {
|
|
706
|
+
this.napcat.off('notice.bot_offline', w);
|
|
707
|
+
this.wrappers.delete(fn);
|
|
708
|
+
}
|
|
514
709
|
}
|
|
515
710
|
}
|
|
516
|
-
/**
|
|
517
|
-
* 事件监听入口,按类别分组暴露监听器。
|
|
518
|
-
*
|
|
519
|
-
* @example
|
|
520
|
-
* ```ts
|
|
521
|
-
* bot.event.message.onGroupMessage(...);
|
|
522
|
-
* bot.event.messageSent.onGroupSent(...);
|
|
523
|
-
* bot.event.request.onFriend(...);
|
|
524
|
-
* ```
|
|
525
|
-
*/
|
|
526
711
|
export class BotEvent {
|
|
527
712
|
constructor(api, client) {
|
|
528
713
|
Object.defineProperty(this, "message", {
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@ import * as os from 'os'
|
|
|
7
7
|
export class HotCatPlugin extends PluginBase {
|
|
8
8
|
static meta = {
|
|
9
9
|
name: 'hotCatPlugin',
|
|
10
|
-
version: '0.1.
|
|
10
|
+
version: '0.1.5',
|
|
11
11
|
description: 'HotCat 默认插件(#hotCat 指令查询 bot 状态)',
|
|
12
12
|
author: 'CHCAT1320',
|
|
13
13
|
}
|
|
@@ -20,14 +20,14 @@ export class HotCatPlugin extends PluginBase {
|
|
|
20
20
|
|
|
21
21
|
async load() {
|
|
22
22
|
this.startTime = Date.now()
|
|
23
|
-
this.
|
|
23
|
+
this.bot.event.message.onGroupMessage(this.onGroupMsg)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
async unload() {
|
|
27
|
-
this.
|
|
27
|
+
this.bot.event.message.offGroupMessage(this.onGroupMsg)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
private onGroupMsg = async (event: any) => {
|
|
30
|
+
private onGroupMsg = async (_bot: BotClient, event: any) => {
|
|
31
31
|
const msg = event.raw_message.trim()
|
|
32
32
|
|
|
33
33
|
if (msg === '#hotCat' || msg === '#hotcat') {
|