mirai-js 2.8.0-3 → 2.8.2

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/demo.ts ADDED
@@ -0,0 +1,53 @@
1
+ import { Bot, Message, Middleware } from './src';
2
+
3
+ (async () => {
4
+ try {
5
+ const baseUrl = 'http://localhost:8080';
6
+ const verifyKey = '123456789';
7
+ const qq = 3070539027;
8
+ const bot = new Bot();
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+ bot.on('FriendMessage', new Middleware()
20
+ .messageProcessor(['AtAll', 'App'])
21
+ .textProcessor()
22
+ .done(ctx => {
23
+ ctx.
24
+
25
+ }));
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ bot.on('NewFriendRequestEvent', new Middleware()
44
+ .friendRequestProcessor()
45
+ .done(ctx => {
46
+ d
47
+ }))
48
+ // 在 mirai-console 登录你的 bot
49
+
50
+ } catch (err) {
51
+ console.log(err);
52
+ }
53
+ })();
@@ -87,7 +87,7 @@ type MessageId = number;
87
87
  * @see https://github.com/project-mirai/mirai-api-http/blob/master/docs/EventType.md
88
88
  */
89
89
 
90
- type MessageChainElementTypes =
90
+ export type MessageChainElementTypes =
91
91
  | 'Source'
92
92
  | 'Quote'
93
93
  | 'At'
@@ -113,26 +113,6 @@ interface EventBaseType {
113
113
  }
114
114
 
115
115
  // Middleware
116
- interface MessageExtendType {
117
- text?: string;
118
- classified?: {
119
- [key in MessageChainElementTypes]?: any[];
120
- };
121
- messageId?: number;
122
- waitFor?: any
123
- unlock?: () => void;
124
- }
125
- type RequestEventMethods =
126
- | 'agree'
127
- | 'refuse'
128
- | 'ignore'
129
- | 'refuseAndAddBlacklist'
130
- | 'ignoreAndAddBlacklist';
131
-
132
- type RequestEventExtendType = {
133
- [key in RequestEventMethods]?: () => void;
134
- };
135
-
136
116
  interface Member {
137
117
  id: number;
138
118
  memberName: string;
@@ -169,14 +149,12 @@ interface EventEntityMap {
169
149
  type: 'GroupMessage';
170
150
  sender: Member & { group: GroupSenderType },
171
151
  messageChain: MessageType[];
172
- } & EventBaseType &
173
- MessageExtendType,
152
+ } & EventBaseType,
174
153
  FriendMessage: {
175
154
  type: 'FriendMessage';
176
155
  messageChain: MessageType[];
177
156
  sender: Friend
178
- } & EventBaseType &
179
- MessageExtendType,
157
+ } & EventBaseType,
180
158
  BotOnlineEvent: {
181
159
  type: 'BotOnlineEvent',
182
160
  qq: number
@@ -334,7 +312,7 @@ interface EventEntityMap {
334
312
  groupId: number,
335
313
  nick: string,
336
314
  message: string
337
- } & RequestEventExtendType & EventBaseType;
315
+ } & EventBaseType;
338
316
  MemberJoinRequestEvent: {
339
317
  type: 'MemberJoinRequestEvent',
340
318
  eventId: number,
@@ -343,7 +321,7 @@ interface EventEntityMap {
343
321
  groupName: string,
344
322
  nick: string,
345
323
  message: string
346
- } & RequestEventExtendType & EventBaseType;
324
+ } & EventBaseType;
347
325
  BotInvitedJoinGroupRequestEvent: {
348
326
  type: 'MemberJoinRequestEvent',
349
327
  eventId: number,
@@ -352,7 +330,7 @@ interface EventEntityMap {
352
330
  groupName: string,
353
331
  nick: string,
354
332
  message: string
355
- } & RequestEventExtendType & EventBaseType;
333
+ } & EventBaseType;
356
334
  }
357
335
 
358
336
  type EventType = keyof EventEntityMap;
@@ -366,8 +344,7 @@ type GroupPermission = 'OWNER' | 'ADMINISTRATOR' | 'MEMBER';
366
344
  type SEX = 'UNKNOWN' | 'MALE' | 'FEMALE';
367
345
 
368
346
  // 消息处理器
369
- type Processor<U extends EventType[] | 'UnknownEventType' = 'UnknownEventType'> =
370
- (data: U extends 'UnknownEventType' ? EventBaseType : EventEntityMap[ArrayToValuesUnion<U extends 'UnknownEventType' ? never : U>]) => Awaitable<void | any>;
347
+ type Processor<U extends EventType[] = [], Extend = { [key: string]: any }> = (data: EventEntityMap[ArrayToValuesUnion<U>] & Extend) => Awaitable<void | any>;
371
348
 
372
349
  // QQ 自带表情
373
350
  type FaceType =
@@ -93,8 +93,8 @@ export class Bot implements BotConfigGetable {
93
93
  * @param callback 必选,回调函数
94
94
  * @returns handle 事件处理器的标识,用于移除该处理器
95
95
  */
96
- on<U extends EventType>(eventType: U, callback: Processor<[U]>): number;
97
- on<U extends EventType[]>(eventType: U, callback: Processor<U>): number[];
96
+ on<U extends EventType, E>(eventType: U, callback: Processor<[U], E>): number;
97
+ on<U extends EventType[], E>(eventType: U, callback: Processor<U, E>): number[];
98
98
 
99
99
  /**
100
100
  * @description 添加一个一次性事件处理器,回调一次后自动移除
@@ -1,7 +1,8 @@
1
- import { Processor, EventType } from './BaseType';
1
+ import { Processor, EventType, MessageChainElementTypes, MessageType } from './BaseType';
2
2
  import { Bot } from './Bot';
3
+ import { ArrayToValuesUnion } from './typeHelpers';
3
4
 
4
- export class Middleware {
5
+ export class Middleware<CTX = { [key: string]: any }> {
5
6
  private middleware: ((data: any, next: Middleware.NextMiddlewareCaller) => any)[];
6
7
  private catcher: (error: any) => any;
7
8
 
@@ -12,44 +13,44 @@ export class Middleware {
12
13
  * @param verifyKey mirai-api-http server 设置的 verifyKey
13
14
  * @param password 欲重新登陆的 qq 密码
14
15
  */
15
- autoReLogin({ bot, baseUrl, verifyKey, password }: Middleware.AutoReLoginOptions): Middleware;
16
+ autoReLogin({ bot, baseUrl, verifyKey, password }: Middleware.AutoReLoginOptions): Middleware<CTX>;
16
17
 
17
18
  /**
18
19
  * @description 自动重建 ws 连接
19
20
  * @param bot 欲重连的 Bot 实例
20
21
  */
21
- autoReconnection(bot: Bot): Middleware;
22
+ autoReconnection(bot: Bot): Middleware<CTX>;
22
23
 
23
24
  /**
24
25
  * @description 过滤出指定类型的消息,消息类型为 key,对应类型的
25
26
  * message 数组为 value,置于 data.classified
26
27
  * @param typeArr message 的类型,例如 Plain Image Voice
27
28
  */
28
- messageProcessor(typeArr: string[]): Middleware;
29
+ messageProcessor<U extends MessageChainElementTypes[]>(typeArr: U): Middleware<CTX & { classified: { [type in ArrayToValuesUnion<U>]: any[] } }>;
29
30
 
30
31
  /**
31
32
  * @description 过滤出字符串类型的 message,并拼接在一起,置于 data.text
32
33
  */
33
- textProcessor(): Middleware;
34
+ textProcessor(): Middleware<CTX & { text: string }>;
34
35
 
35
36
  /**
36
37
  * @description 过滤出消息 id,置于 data.messageId
37
38
  */
38
- messageIdProcessor(): Middleware;
39
+ messageIdProcessor(): Middleware<CTX & { messageId: string }>;
39
40
 
40
41
  /**
41
42
  * @description 过滤指定的群消息
42
43
  * @param groupArr 允许通过的群号数组
43
44
  * @param allow 允许通过还是禁止通过
44
45
  */
45
- groupFilter(groupArr: number[], allow?: boolean): Middleware;
46
+ groupFilter(groupArr: number[], allow?: boolean): Middleware<CTX>;
46
47
 
47
48
  /**
48
49
  * @description 过滤指定的好友消息
49
50
  * @param friendArr 好友 qq 号数组
50
51
  * @param allow 允许通过还是禁止通过
51
52
  */
52
- friendFilter(friendArr: number[], allow?: boolean): Middleware;
53
+ friendFilter(friendArr: number[], allow?: boolean): Middleware<CTX>;
53
54
 
54
55
  /**
55
56
  * @description 过滤指定群的群成员的消息
@@ -57,32 +58,32 @@ export class Middleware {
57
58
  * @param allow 允许通过还是禁止通过
58
59
  * 结构 { number => number[], } key 为允许通过的群号,value 为该群允许通过的成员 qq
59
60
  */
60
- groupMemberFilter(groupMemberMap: Middleware.GroupMemberMap, allow?: boolean): Middleware;
61
+ groupMemberFilter(groupMemberMap: Middleware.GroupMemberMap, allow?: boolean): Middleware<CTX>;
61
62
 
62
63
  /**
63
64
  * @description 这是一个对话锁,保证群中同一成员不能在中途触发处理器
64
65
  * @use 在你需要保护的过程结束后调用 data.unlock 即可
65
66
  */
66
- memberLock({ autoUnlock }?: Middleware.LockOptions): Middleware;
67
+ memberLock({ autoUnlock }?: Middleware.LockOptions): Middleware<CTX & { unlock: () => void }>;
67
68
 
68
69
  /**
69
70
  * @description 这是一个对话锁,保证同一好友不能在中途触发处理器
70
71
  * @use 在你需要保护的过程结束后调用 data.unlock 即可
71
72
  */
72
- friendLock({ autoUnlock }?: Middleware.LockOptions): Middleware;
73
+ friendLock({ autoUnlock }?: Middleware.LockOptions): Middleware<CTX & { unlock: () => void }>;
73
74
 
74
75
  /**
75
76
  * @description 过滤包含指定 @ 信息的消息
76
77
  * @param atArr 必选,qq 号数组
77
78
  * @param allow 可选,允许通过还是禁止通过
78
79
  */
79
- atFilter(friendArr: number[], allow?: boolean): Middleware;
80
+ atFilter(friendArr: number[], allow?: boolean): Middleware<CTX>;
80
81
 
81
82
  /**
82
83
  * @description 用于 NewFriendRequestEvent 的中间件,经过该中间件后,将在 data 下放置三个方法
83
84
  * agree、refuse、refuseAndAddBlacklist,调用后将分别进行好友请求的 同意、拒绝和拒绝并加入黑名单
84
85
  */
85
- friendRequestProcessor(): Middleware;
86
+ friendRequestProcessor(): Middleware<CTX & { agree: () => void, refuse: () => void, refuseAndAddBlacklist: () => void }>;
86
87
 
87
88
  /**
88
89
  * ! mirai-core 的问题,有时候收不到 MemberJoinRequestEvent 事件
@@ -93,9 +94,11 @@ export class Middleware {
93
94
  * ignore 忽略
94
95
  * refuseAndAddBlacklist 拒绝并移入黑名单
95
96
  * ignoreAndAddBlacklist 忽略并移入黑名单
96
- * @param bot 必选,Bot 实例
97
97
  */
98
- memberJoinRequestProcessor(): Middleware;
98
+ memberJoinRequestProcessor(): Middleware<CTX & {
99
+ agree: () => void, refuse: () => void, ignore: () => void,
100
+ refuseAndAddBlacklist: () => void, ignoreAndAddBlacklist: () => void,
101
+ }>;
99
102
 
100
103
  /**
101
104
  * ! 目前被邀请入群不会触发 BotInvitedJoinGroupRequestEvent 事件
@@ -103,32 +106,47 @@ export class Middleware {
103
106
  * @description 用于 BotInvitedJoinGroupRequestEvent 的中间件,经过该中间件后,将在 data 下放置两个方法
104
107
  * agree 同意
105
108
  * refuse 拒绝
106
- * @param bot 必选,Bot 实例
107
109
  */
108
- invitedJoinGroupRequestProcessor(): Middleware;
110
+ invitedJoinGroupRequestProcessor(): Middleware<CTX & { agree: () => void, refuse: () => void }>;
109
111
 
110
112
  /**
111
113
  * @description Waiter 的包装器,提供方便的同步 IO 方式
112
114
  */
113
- syncWrapper(): Middleware;
115
+ syncWrapper(): Middleware<CTX & {
116
+ waitFor: {
117
+ groupMember: (qq: number) => {
118
+ messageChain: () => Promise<MessageType[]>,
119
+ text: () => Promise<string>,
120
+ custom: <R>(processor: () => R) => Promise<R>,
121
+ },
122
+ friend: (qq) => {
123
+ messageChain: () => Promise<MessageType[]>,
124
+ text: () => Promise<string>,
125
+ custom: <R>(processor: () => R) => Promise<R>,
126
+ },
127
+ messageChain: () => Promise<MessageType[]>,
128
+ text: Promise<string>,
129
+ custom: <R>(processor: () => R) => Promise<R>,
130
+ }
131
+ }>;
114
132
 
115
133
  /**
116
134
  * @description 添加一个自定义中间件
117
135
  * @param callback (data, next) => void
118
136
  */
119
- use(callback: (data: any, next: Middleware.NextMiddlewareCaller) => any): Middleware;
137
+ use(callback: (data: CTX, next: Middleware.NextMiddlewareCaller) => any): Middleware<CTX>;
120
138
 
121
139
  /**
122
140
  * @description 使用错误处理器
123
141
  * @param catcher 错误处理器 (err) => void
124
142
  */
125
- catch(catcher: (error: any) => any): Middleware;
143
+ catch(catcher: (error: any) => any): Middleware<CTX>;
126
144
 
127
145
  /**
128
146
  * @description 生成一个带有中间件的事件处理器
129
147
  * @param callback 事件处理器
130
148
  */
131
- done<E extends EventType[] | EventType>(callback: Processor<E extends EventType ? [E] : E>): Processor<E extends EventType ? [E] : E>;
149
+ done<E extends EventType[]>(callback: Processor<E, CTX>): Processor<E, CTX>;
132
150
 
133
151
  }
134
152
 
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ const a = ['a', 'b', 'c'];
2
+
3
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mirai-js",
3
- "version": "2.8.0-3",
3
+ "version": "2.8.2",
4
4
  "description": "QQ robot development framework based on Mirai-api-http.",
5
5
  "main": "dist/node/index.js",
6
6
  "scripts": {
package/src/BaseType.d.ts CHANGED
@@ -87,7 +87,7 @@ type MessageId = number;
87
87
  * @see https://github.com/project-mirai/mirai-api-http/blob/master/docs/EventType.md
88
88
  */
89
89
 
90
- type MessageChainElementTypes =
90
+ export type MessageChainElementTypes =
91
91
  | 'Source'
92
92
  | 'Quote'
93
93
  | 'At'
@@ -113,26 +113,6 @@ interface EventBaseType {
113
113
  }
114
114
 
115
115
  // Middleware
116
- interface MessageExtendType {
117
- text?: string;
118
- classified?: {
119
- [key in MessageChainElementTypes]?: any[];
120
- };
121
- messageId?: number;
122
- waitFor?: any
123
- unlock?: () => void;
124
- }
125
- type RequestEventMethods =
126
- | 'agree'
127
- | 'refuse'
128
- | 'ignore'
129
- | 'refuseAndAddBlacklist'
130
- | 'ignoreAndAddBlacklist';
131
-
132
- type RequestEventExtendType = {
133
- [key in RequestEventMethods]?: () => void;
134
- };
135
-
136
116
  interface Member {
137
117
  id: number;
138
118
  memberName: string;
@@ -169,14 +149,12 @@ interface EventEntityMap {
169
149
  type: 'GroupMessage';
170
150
  sender: Member & { group: GroupSenderType },
171
151
  messageChain: MessageType[];
172
- } & EventBaseType &
173
- MessageExtendType,
152
+ } & EventBaseType,
174
153
  FriendMessage: {
175
154
  type: 'FriendMessage';
176
155
  messageChain: MessageType[];
177
156
  sender: Friend
178
- } & EventBaseType &
179
- MessageExtendType,
157
+ } & EventBaseType,
180
158
  BotOnlineEvent: {
181
159
  type: 'BotOnlineEvent',
182
160
  qq: number
@@ -334,7 +312,7 @@ interface EventEntityMap {
334
312
  groupId: number,
335
313
  nick: string,
336
314
  message: string
337
- } & RequestEventExtendType & EventBaseType;
315
+ } & EventBaseType;
338
316
  MemberJoinRequestEvent: {
339
317
  type: 'MemberJoinRequestEvent',
340
318
  eventId: number,
@@ -343,7 +321,7 @@ interface EventEntityMap {
343
321
  groupName: string,
344
322
  nick: string,
345
323
  message: string
346
- } & RequestEventExtendType & EventBaseType;
324
+ } & EventBaseType;
347
325
  BotInvitedJoinGroupRequestEvent: {
348
326
  type: 'MemberJoinRequestEvent',
349
327
  eventId: number,
@@ -352,7 +330,7 @@ interface EventEntityMap {
352
330
  groupName: string,
353
331
  nick: string,
354
332
  message: string
355
- } & RequestEventExtendType & EventBaseType;
333
+ } & EventBaseType;
356
334
  }
357
335
 
358
336
  type EventType = keyof EventEntityMap;
@@ -366,8 +344,7 @@ type GroupPermission = 'OWNER' | 'ADMINISTRATOR' | 'MEMBER';
366
344
  type SEX = 'UNKNOWN' | 'MALE' | 'FEMALE';
367
345
 
368
346
  // 消息处理器
369
- type Processor<U extends EventType[] | 'UnknownEventType' = 'UnknownEventType'> =
370
- (data: U extends 'UnknownEventType' ? EventBaseType : EventEntityMap[ArrayToValuesUnion<U extends 'UnknownEventType' ? never : U>]) => Awaitable<void | any>;
347
+ type Processor<U extends EventType[] = [], Extend = { [key: string]: any }> = (data: EventEntityMap[ArrayToValuesUnion<U>] & Extend) => Awaitable<void | any>;
371
348
 
372
349
  // QQ 自带表情
373
350
  type FaceType =
package/src/Bot.d.ts CHANGED
@@ -93,8 +93,8 @@ export class Bot implements BotConfigGetable {
93
93
  * @param callback 必选,回调函数
94
94
  * @returns handle 事件处理器的标识,用于移除该处理器
95
95
  */
96
- on<U extends EventType>(eventType: U, callback: Processor<[U]>): number;
97
- on<U extends EventType[]>(eventType: U, callback: Processor<U>): number[];
96
+ on<U extends EventType, E>(eventType: U, callback: Processor<[U], E>): number;
97
+ on<U extends EventType[], E>(eventType: U, callback: Processor<U, E>): number[];
98
98
 
99
99
  /**
100
100
  * @description 添加一个一次性事件处理器,回调一次后自动移除
@@ -1,7 +1,8 @@
1
- import { Processor, EventType } from './BaseType';
1
+ import { Processor, EventType, MessageChainElementTypes, MessageType } from './BaseType';
2
2
  import { Bot } from './Bot';
3
+ import { ArrayToValuesUnion } from './typeHelpers';
3
4
 
4
- export class Middleware {
5
+ export class Middleware<CTX = { [key: string]: any }> {
5
6
  private middleware: ((data: any, next: Middleware.NextMiddlewareCaller) => any)[];
6
7
  private catcher: (error: any) => any;
7
8
 
@@ -12,44 +13,44 @@ export class Middleware {
12
13
  * @param verifyKey mirai-api-http server 设置的 verifyKey
13
14
  * @param password 欲重新登陆的 qq 密码
14
15
  */
15
- autoReLogin({ bot, baseUrl, verifyKey, password }: Middleware.AutoReLoginOptions): Middleware;
16
+ autoReLogin({ bot, baseUrl, verifyKey, password }: Middleware.AutoReLoginOptions): Middleware<CTX>;
16
17
 
17
18
  /**
18
19
  * @description 自动重建 ws 连接
19
20
  * @param bot 欲重连的 Bot 实例
20
21
  */
21
- autoReconnection(bot: Bot): Middleware;
22
+ autoReconnection(bot: Bot): Middleware<CTX>;
22
23
 
23
24
  /**
24
25
  * @description 过滤出指定类型的消息,消息类型为 key,对应类型的
25
26
  * message 数组为 value,置于 data.classified
26
27
  * @param typeArr message 的类型,例如 Plain Image Voice
27
28
  */
28
- messageProcessor(typeArr: string[]): Middleware;
29
+ messageProcessor<U extends MessageChainElementTypes[]>(typeArr: U): Middleware<CTX & { classified: { [type in ArrayToValuesUnion<U>]: any[] } }>;
29
30
 
30
31
  /**
31
32
  * @description 过滤出字符串类型的 message,并拼接在一起,置于 data.text
32
33
  */
33
- textProcessor(): Middleware;
34
+ textProcessor(): Middleware<CTX & { text: string }>;
34
35
 
35
36
  /**
36
37
  * @description 过滤出消息 id,置于 data.messageId
37
38
  */
38
- messageIdProcessor(): Middleware;
39
+ messageIdProcessor(): Middleware<CTX & { messageId: string }>;
39
40
 
40
41
  /**
41
42
  * @description 过滤指定的群消息
42
43
  * @param groupArr 允许通过的群号数组
43
44
  * @param allow 允许通过还是禁止通过
44
45
  */
45
- groupFilter(groupArr: number[], allow?: boolean): Middleware;
46
+ groupFilter(groupArr: number[], allow?: boolean): Middleware<CTX>;
46
47
 
47
48
  /**
48
49
  * @description 过滤指定的好友消息
49
50
  * @param friendArr 好友 qq 号数组
50
51
  * @param allow 允许通过还是禁止通过
51
52
  */
52
- friendFilter(friendArr: number[], allow?: boolean): Middleware;
53
+ friendFilter(friendArr: number[], allow?: boolean): Middleware<CTX>;
53
54
 
54
55
  /**
55
56
  * @description 过滤指定群的群成员的消息
@@ -57,32 +58,32 @@ export class Middleware {
57
58
  * @param allow 允许通过还是禁止通过
58
59
  * 结构 { number => number[], } key 为允许通过的群号,value 为该群允许通过的成员 qq
59
60
  */
60
- groupMemberFilter(groupMemberMap: Middleware.GroupMemberMap, allow?: boolean): Middleware;
61
+ groupMemberFilter(groupMemberMap: Middleware.GroupMemberMap, allow?: boolean): Middleware<CTX>;
61
62
 
62
63
  /**
63
64
  * @description 这是一个对话锁,保证群中同一成员不能在中途触发处理器
64
65
  * @use 在你需要保护的过程结束后调用 data.unlock 即可
65
66
  */
66
- memberLock({ autoUnlock }?: Middleware.LockOptions): Middleware;
67
+ memberLock({ autoUnlock }?: Middleware.LockOptions): Middleware<CTX & { unlock: () => void }>;
67
68
 
68
69
  /**
69
70
  * @description 这是一个对话锁,保证同一好友不能在中途触发处理器
70
71
  * @use 在你需要保护的过程结束后调用 data.unlock 即可
71
72
  */
72
- friendLock({ autoUnlock }?: Middleware.LockOptions): Middleware;
73
+ friendLock({ autoUnlock }?: Middleware.LockOptions): Middleware<CTX & { unlock: () => void }>;
73
74
 
74
75
  /**
75
76
  * @description 过滤包含指定 @ 信息的消息
76
77
  * @param atArr 必选,qq 号数组
77
78
  * @param allow 可选,允许通过还是禁止通过
78
79
  */
79
- atFilter(friendArr: number[], allow?: boolean): Middleware;
80
+ atFilter(friendArr: number[], allow?: boolean): Middleware<CTX>;
80
81
 
81
82
  /**
82
83
  * @description 用于 NewFriendRequestEvent 的中间件,经过该中间件后,将在 data 下放置三个方法
83
84
  * agree、refuse、refuseAndAddBlacklist,调用后将分别进行好友请求的 同意、拒绝和拒绝并加入黑名单
84
85
  */
85
- friendRequestProcessor(): Middleware;
86
+ friendRequestProcessor(): Middleware<CTX & { agree: () => void, refuse: () => void, refuseAndAddBlacklist: () => void }>;
86
87
 
87
88
  /**
88
89
  * ! mirai-core 的问题,有时候收不到 MemberJoinRequestEvent 事件
@@ -93,9 +94,11 @@ export class Middleware {
93
94
  * ignore 忽略
94
95
  * refuseAndAddBlacklist 拒绝并移入黑名单
95
96
  * ignoreAndAddBlacklist 忽略并移入黑名单
96
- * @param bot 必选,Bot 实例
97
97
  */
98
- memberJoinRequestProcessor(): Middleware;
98
+ memberJoinRequestProcessor(): Middleware<CTX & {
99
+ agree: () => void, refuse: () => void, ignore: () => void,
100
+ refuseAndAddBlacklist: () => void, ignoreAndAddBlacklist: () => void,
101
+ }>;
99
102
 
100
103
  /**
101
104
  * ! 目前被邀请入群不会触发 BotInvitedJoinGroupRequestEvent 事件
@@ -103,32 +106,47 @@ export class Middleware {
103
106
  * @description 用于 BotInvitedJoinGroupRequestEvent 的中间件,经过该中间件后,将在 data 下放置两个方法
104
107
  * agree 同意
105
108
  * refuse 拒绝
106
- * @param bot 必选,Bot 实例
107
109
  */
108
- invitedJoinGroupRequestProcessor(): Middleware;
110
+ invitedJoinGroupRequestProcessor(): Middleware<CTX & { agree: () => void, refuse: () => void }>;
109
111
 
110
112
  /**
111
113
  * @description Waiter 的包装器,提供方便的同步 IO 方式
112
114
  */
113
- syncWrapper(): Middleware;
115
+ syncWrapper(): Middleware<CTX & {
116
+ waitFor: {
117
+ groupMember: (qq: number) => {
118
+ messageChain: () => Promise<MessageType[]>,
119
+ text: () => Promise<string>,
120
+ custom: <R>(processor: () => R) => Promise<R>,
121
+ },
122
+ friend: (qq) => {
123
+ messageChain: () => Promise<MessageType[]>,
124
+ text: () => Promise<string>,
125
+ custom: <R>(processor: () => R) => Promise<R>,
126
+ },
127
+ messageChain: () => Promise<MessageType[]>,
128
+ text: Promise<string>,
129
+ custom: <R>(processor: () => R) => Promise<R>,
130
+ }
131
+ }>;
114
132
 
115
133
  /**
116
134
  * @description 添加一个自定义中间件
117
135
  * @param callback (data, next) => void
118
136
  */
119
- use(callback: (data: any, next: Middleware.NextMiddlewareCaller) => any): Middleware;
137
+ use(callback: (data: CTX, next: Middleware.NextMiddlewareCaller) => any): Middleware<CTX>;
120
138
 
121
139
  /**
122
140
  * @description 使用错误处理器
123
141
  * @param catcher 错误处理器 (err) => void
124
142
  */
125
- catch(catcher: (error: any) => any): Middleware;
143
+ catch(catcher: (error: any) => any): Middleware<CTX>;
126
144
 
127
145
  /**
128
146
  * @description 生成一个带有中间件的事件处理器
129
147
  * @param callback 事件处理器
130
148
  */
131
- done<E extends EventType[] | EventType>(callback: Processor<E extends EventType ? [E] : E>): Processor<E extends EventType ? [E] : E>;
149
+ done<E extends EventType[]>(callback: Processor<E, CTX>): Processor<E, CTX>;
132
150
 
133
151
  }
134
152