@zhin.js/adapter-napcat 3.0.0 → 3.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.
- package/CHANGELOG.md +17 -0
- package/dist/index.js +2 -2
- package/lib/adapter.d.ts +12 -5
- package/lib/adapter.d.ts.map +1 -1
- package/lib/adapter.js +14 -7
- package/lib/adapter.js.map +1 -1
- package/lib/endpoint-base.d.ts +1 -0
- package/lib/endpoint-base.d.ts.map +1 -1
- package/lib/endpoint-base.js +12 -5
- package/lib/endpoint-base.js.map +1 -1
- package/lib/endpoint-http.d.ts +0 -1
- package/lib/endpoint-http.d.ts.map +1 -1
- package/lib/endpoint-http.js +0 -13
- package/lib/endpoint-http.js.map +1 -1
- package/lib/endpoint-ws-client.d.ts +0 -1
- package/lib/endpoint-ws-client.d.ts.map +1 -1
- package/lib/endpoint-ws-client.js +0 -26
- package/lib/endpoint-ws-client.js.map +1 -1
- package/lib/endpoint-ws-server.d.ts +0 -1
- package/lib/endpoint-ws-server.d.ts.map +1 -1
- package/lib/endpoint-ws-server.js +0 -13
- package/lib/endpoint-ws-server.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -5
- package/lib/index.js.map +1 -1
- package/lib/segment-mapper.d.ts +2 -0
- package/lib/segment-mapper.d.ts.map +1 -0
- package/lib/segment-mapper.js +2 -0
- package/lib/segment-mapper.js.map +1 -0
- package/lib/tools.js +7 -7
- package/lib/types.d.ts +0 -18
- package/lib/types.d.ts.map +1 -1
- package/package.json +14 -14
- package/skills/napcat/PERMITS.md +3 -3
- package/skills/napcat/SKILL.md +2 -2
- package/src/adapter.ts +14 -7
- package/src/endpoint-base.ts +15 -4
- package/src/endpoint-http.ts +0 -14
- package/src/endpoint-ws-client.ts +0 -27
- package/src/endpoint-ws-server.ts +0 -14
- package/src/index.ts +7 -12
- package/src/segment-mapper.ts +1 -0
- package/src/tools.ts +7 -7
- package/src/types.ts +0 -13
- package/lib/typing-indicator.d.ts +0 -45
- package/lib/typing-indicator.d.ts.map +0 -1
- package/lib/typing-indicator.js +0 -132
- package/lib/typing-indicator.js.map +0 -1
- package/src/typing-indicator.ts +0 -184
package/src/tools.ts
CHANGED
|
@@ -122,7 +122,7 @@ const NAPCAT_TOOL_SPECS: ToolSpec[] = [
|
|
|
122
122
|
},
|
|
123
123
|
required: ['endpoint_id', 'message_id'],
|
|
124
124
|
keywords: ['精华', 'essence', '设精', '加精'],
|
|
125
|
-
permit: 'platform(napcat,
|
|
125
|
+
permit: 'platform(napcat,scene_admin)',
|
|
126
126
|
scopes: ['group'],
|
|
127
127
|
execute: async (adapter, args) => {
|
|
128
128
|
const endpoint = getEndpoint(adapter, args.endpoint_id);
|
|
@@ -139,7 +139,7 @@ const NAPCAT_TOOL_SPECS: ToolSpec[] = [
|
|
|
139
139
|
},
|
|
140
140
|
required: ['endpoint_id', 'message_id'],
|
|
141
141
|
keywords: ['取消精华', '移除精华', 'delete essence'],
|
|
142
|
-
permit: 'platform(napcat,
|
|
142
|
+
permit: 'platform(napcat,scene_admin)',
|
|
143
143
|
scopes: ['group'],
|
|
144
144
|
execute: async (adapter, args) => {
|
|
145
145
|
const endpoint = getEndpoint(adapter, args.endpoint_id);
|
|
@@ -176,7 +176,7 @@ const NAPCAT_TOOL_SPECS: ToolSpec[] = [
|
|
|
176
176
|
},
|
|
177
177
|
required: ['endpoint_id', 'group_id', 'content'],
|
|
178
178
|
keywords: ['群公告', 'notice', '公告', '发公告'],
|
|
179
|
-
permit: 'platform(napcat,
|
|
179
|
+
permit: 'platform(napcat,scene_admin)',
|
|
180
180
|
scopes: ['group'],
|
|
181
181
|
execute: async (adapter, args) => {
|
|
182
182
|
const endpoint = getEndpoint(adapter, args.endpoint_id);
|
|
@@ -210,7 +210,7 @@ const NAPCAT_TOOL_SPECS: ToolSpec[] = [
|
|
|
210
210
|
},
|
|
211
211
|
required: ['endpoint_id', 'group_id', 'notice_id'],
|
|
212
212
|
keywords: ['删除公告', 'delete notice'],
|
|
213
|
-
permit: 'platform(napcat,
|
|
213
|
+
permit: 'platform(napcat,scene_admin)',
|
|
214
214
|
scopes: ['group'],
|
|
215
215
|
execute: async (adapter, args) => {
|
|
216
216
|
const endpoint = getEndpoint(adapter, args.endpoint_id);
|
|
@@ -301,7 +301,7 @@ const NAPCAT_TOOL_SPECS: ToolSpec[] = [
|
|
|
301
301
|
},
|
|
302
302
|
required: ['endpoint_id', 'group_id', 'file'],
|
|
303
303
|
keywords: ['群头像', 'group portrait', '设置群头像'],
|
|
304
|
-
permit: 'platform(napcat,
|
|
304
|
+
permit: 'platform(napcat,scene_admin)',
|
|
305
305
|
scopes: ['group'],
|
|
306
306
|
execute: async (adapter, args) => {
|
|
307
307
|
const endpoint = getEndpoint(adapter, args.endpoint_id);
|
|
@@ -320,7 +320,7 @@ const NAPCAT_TOOL_SPECS: ToolSpec[] = [
|
|
|
320
320
|
},
|
|
321
321
|
required: ['endpoint_id', 'group_id', 'user_id', 'title'],
|
|
322
322
|
keywords: ['头衔', 'title', '专属头衔', '设置头衔'],
|
|
323
|
-
permit: 'platform(napcat,
|
|
323
|
+
permit: 'platform(napcat,scene_owner)',
|
|
324
324
|
scopes: ['group'],
|
|
325
325
|
execute: async (adapter, args) => {
|
|
326
326
|
const endpoint = getEndpoint(adapter, args.endpoint_id);
|
|
@@ -603,7 +603,7 @@ const NAPCAT_TOOL_SPECS: ToolSpec[] = [
|
|
|
603
603
|
},
|
|
604
604
|
required: ['endpoint_id', 'user_id'],
|
|
605
605
|
keywords: ['删除好友', 'delete friend', '删好友'],
|
|
606
|
-
permit: 'platform(napcat,
|
|
606
|
+
permit: 'platform(napcat,scene_admin)',
|
|
607
607
|
execute: async (adapter, args) => {
|
|
608
608
|
const endpoint = getEndpoint(adapter, args.endpoint_id);
|
|
609
609
|
await endpoint.deleteFriend(args.user_id);
|
package/src/types.ts
CHANGED
|
@@ -5,23 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
// ── 配置 ─────────────────────────────────────────────────────────────
|
|
7
7
|
|
|
8
|
-
export interface TypingIndicatorConfig {
|
|
9
|
-
/** 是否启用(默认 true) */
|
|
10
|
-
enabled?: boolean;
|
|
11
|
-
/** 默认表情 ID */
|
|
12
|
-
defaultEmoji?: string;
|
|
13
|
-
/** 私聊配置 */
|
|
14
|
-
privateConfig?: { type?: 'message' | 'typing'; message?: string };
|
|
15
|
-
/** 群聊配置 */
|
|
16
|
-
groupConfig?: { type?: 'reaction'; emoji?: string };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
8
|
export interface NapCatConfigBase {
|
|
20
9
|
context: 'napcat';
|
|
21
10
|
name: string;
|
|
22
11
|
access_token?: string;
|
|
23
|
-
/** Typing Indicator 配置 */
|
|
24
|
-
typingIndicator?: TypingIndicatorConfig;
|
|
25
12
|
}
|
|
26
13
|
|
|
27
14
|
/** 正向 WebSocket */
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NapCat Typing Indicator 集成
|
|
3
|
-
*
|
|
4
|
-
* 群聊:set_msg_emoji_like(表情回应)
|
|
5
|
-
* 私聊:set_input_status(输入状态)或短暂提示消息
|
|
6
|
-
*/
|
|
7
|
-
import type { NapCatEndpointBase } from './endpoint-base.js';
|
|
8
|
-
import { type TypingIndicatorConfig, type TypingIndicator } from '@zhin.js/agent';
|
|
9
|
-
export interface NapCatTypingIndicatorConfig {
|
|
10
|
-
enabled: boolean;
|
|
11
|
-
defaultEmoji: string;
|
|
12
|
-
autoRemove: boolean;
|
|
13
|
-
removeDelay: number;
|
|
14
|
-
privateConfig?: Partial<TypingIndicatorConfig>;
|
|
15
|
-
groupConfig?: Partial<TypingIndicatorConfig>;
|
|
16
|
-
}
|
|
17
|
-
export declare class NapCatTypingIndicatorManager {
|
|
18
|
-
private manager;
|
|
19
|
-
private config;
|
|
20
|
-
private endpoint;
|
|
21
|
-
constructor(endpoint: NapCatEndpointBase, config?: Partial<NapCatTypingIndicatorConfig>);
|
|
22
|
-
private registerAdapter;
|
|
23
|
-
start(options: {
|
|
24
|
-
messageId?: string;
|
|
25
|
-
sessionId: string;
|
|
26
|
-
userId?: string;
|
|
27
|
-
groupId?: string;
|
|
28
|
-
sceneType: 'private' | 'group';
|
|
29
|
-
}): Promise<TypingIndicator>;
|
|
30
|
-
stop(options: {
|
|
31
|
-
sessionId: string;
|
|
32
|
-
userId?: string;
|
|
33
|
-
groupId?: string;
|
|
34
|
-
}): Promise<void>;
|
|
35
|
-
stopAll(): Promise<void>;
|
|
36
|
-
updateConfig(config: Partial<NapCatTypingIndicatorConfig>): void;
|
|
37
|
-
getConfig(): NapCatTypingIndicatorConfig;
|
|
38
|
-
}
|
|
39
|
-
declare module './endpoint-base.js' {
|
|
40
|
-
interface NapCatEndpointBase {
|
|
41
|
-
$typingIndicator?: NapCatTypingIndicatorManager;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export declare function enableTypingIndicator(endpoint: NapCatEndpointBase, config?: Partial<NapCatTypingIndicatorConfig>): NapCatTypingIndicatorManager;
|
|
45
|
-
//# sourceMappingURL=typing-indicator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typing-indicator.d.ts","sourceRoot":"","sources":["../src/typing-indicator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAIL,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC/C,WAAW,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAC9C;AAqBD,qBAAa,4BAA4B;IACvC,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,QAAQ,CAAqB;gBAEzB,QAAQ,EAAE,kBAAkB,EAAE,MAAM,GAAE,OAAO,CAAC,2BAA2B,CAAM;IAY3F,OAAO,CAAC,eAAe;IA0CjB,KAAK,CAAC,OAAO,EAAE;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC;KAChC,GAAG,OAAO,CAAC,eAAe,CAAC;IA+BtB,IAAI,CAAC,OAAO,EAAE;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,IAAI,CAAC;IAYX,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,2BAA2B,CAAC,GAAG,IAAI;IAIhE,SAAS,IAAI,2BAA2B;CAGzC;AAED,OAAO,QAAQ,oBAAoB,CAAC;IAClC,UAAU,kBAAkB;QAC1B,gBAAgB,CAAC,EAAE,4BAA4B,CAAC;KACjD;CACF;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,kBAAkB,EAC5B,MAAM,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,GAC5C,4BAA4B,CAK9B"}
|
package/lib/typing-indicator.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NapCat Typing Indicator 集成
|
|
3
|
-
*
|
|
4
|
-
* 群聊:set_msg_emoji_like(表情回应)
|
|
5
|
-
* 私聊:set_input_status(输入状态)或短暂提示消息
|
|
6
|
-
*/
|
|
7
|
-
import { TypingIndicatorManager, ReactionTypingIndicatorAdapter, } from '@zhin.js/agent';
|
|
8
|
-
const DEFAULT_CONFIG = {
|
|
9
|
-
enabled: true,
|
|
10
|
-
defaultEmoji: '128516',
|
|
11
|
-
autoRemove: true,
|
|
12
|
-
removeDelay: 5000,
|
|
13
|
-
privateConfig: {
|
|
14
|
-
type: 'message',
|
|
15
|
-
message: '正在思考中...',
|
|
16
|
-
autoRemove: true,
|
|
17
|
-
removeDelay: 3000,
|
|
18
|
-
},
|
|
19
|
-
groupConfig: {
|
|
20
|
-
type: 'reaction',
|
|
21
|
-
emoji: '128516',
|
|
22
|
-
autoRemove: true,
|
|
23
|
-
removeDelay: 5000,
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
export class NapCatTypingIndicatorManager {
|
|
27
|
-
manager;
|
|
28
|
-
config;
|
|
29
|
-
endpoint;
|
|
30
|
-
constructor(endpoint, config = {}) {
|
|
31
|
-
this.endpoint = endpoint;
|
|
32
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
33
|
-
this.manager = new TypingIndicatorManager({
|
|
34
|
-
type: 'reaction',
|
|
35
|
-
emoji: this.config.defaultEmoji,
|
|
36
|
-
autoRemove: this.config.autoRemove,
|
|
37
|
-
removeDelay: this.config.removeDelay,
|
|
38
|
-
});
|
|
39
|
-
this.registerAdapter();
|
|
40
|
-
}
|
|
41
|
-
registerAdapter() {
|
|
42
|
-
const adapter = new ReactionTypingIndicatorAdapter('napcat', async (messageId, emoji, _options) => {
|
|
43
|
-
return await this.endpoint.$addReaction(messageId, emoji);
|
|
44
|
-
}, async (messageId, reactionId) => {
|
|
45
|
-
await this.endpoint.$removeReaction(messageId, reactionId);
|
|
46
|
-
}, async (options, content) => {
|
|
47
|
-
try {
|
|
48
|
-
if (options.sceneType === 'group' && options.groupId) {
|
|
49
|
-
return await this.endpoint.$sendMessage({
|
|
50
|
-
type: 'group',
|
|
51
|
-
id: options.groupId,
|
|
52
|
-
context: 'napcat',
|
|
53
|
-
endpoint: this.endpoint.$id,
|
|
54
|
-
content: [{ type: 'text', data: { text: content } }],
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
else if (options.userId) {
|
|
58
|
-
return await this.endpoint.$sendMessage({
|
|
59
|
-
type: 'private',
|
|
60
|
-
id: options.userId,
|
|
61
|
-
context: 'napcat',
|
|
62
|
-
endpoint: this.endpoint.$id,
|
|
63
|
-
content: [{ type: 'text', data: { text: content } }],
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
}, async (messageId) => {
|
|
72
|
-
try {
|
|
73
|
-
await this.endpoint.$recallMessage(messageId);
|
|
74
|
-
}
|
|
75
|
-
catch { /* ignore */ }
|
|
76
|
-
});
|
|
77
|
-
this.manager.registerAdapter(adapter);
|
|
78
|
-
}
|
|
79
|
-
async start(options) {
|
|
80
|
-
this.endpoint.logger.debug('[NapCat:TypingIndicator] start called', {
|
|
81
|
-
enabled: this.config.enabled,
|
|
82
|
-
sceneType: options.sceneType,
|
|
83
|
-
});
|
|
84
|
-
if (!this.config.enabled) {
|
|
85
|
-
return {
|
|
86
|
-
start: async () => { },
|
|
87
|
-
stop: async () => { },
|
|
88
|
-
isActive: () => false,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
const config = options.sceneType === 'group'
|
|
92
|
-
? this.config.groupConfig
|
|
93
|
-
: this.config.privateConfig;
|
|
94
|
-
const typingOptions = {
|
|
95
|
-
messageId: options.messageId,
|
|
96
|
-
sessionId: options.sessionId,
|
|
97
|
-
userId: options.userId,
|
|
98
|
-
groupId: options.groupId,
|
|
99
|
-
platform: 'napcat',
|
|
100
|
-
endpointId: this.endpoint.$id,
|
|
101
|
-
sceneType: options.sceneType,
|
|
102
|
-
};
|
|
103
|
-
return await this.manager.start(typingOptions, config);
|
|
104
|
-
}
|
|
105
|
-
async stop(options) {
|
|
106
|
-
const typingOptions = {
|
|
107
|
-
sessionId: options.sessionId,
|
|
108
|
-
userId: options.userId,
|
|
109
|
-
groupId: options.groupId,
|
|
110
|
-
platform: 'napcat',
|
|
111
|
-
endpointId: this.endpoint.$id,
|
|
112
|
-
sceneType: 'private',
|
|
113
|
-
};
|
|
114
|
-
await this.manager.stop(typingOptions);
|
|
115
|
-
}
|
|
116
|
-
async stopAll() {
|
|
117
|
-
await this.manager.stopAll();
|
|
118
|
-
}
|
|
119
|
-
updateConfig(config) {
|
|
120
|
-
this.config = { ...this.config, ...config };
|
|
121
|
-
}
|
|
122
|
-
getConfig() {
|
|
123
|
-
return { ...this.config };
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
export function enableTypingIndicator(endpoint, config) {
|
|
127
|
-
if (!endpoint.$typingIndicator) {
|
|
128
|
-
endpoint.$typingIndicator = new NapCatTypingIndicatorManager(endpoint, config);
|
|
129
|
-
}
|
|
130
|
-
return endpoint.$typingIndicator;
|
|
131
|
-
}
|
|
132
|
-
//# sourceMappingURL=typing-indicator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typing-indicator.js","sourceRoot":"","sources":["../src/typing-indicator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,sBAAsB,EACtB,8BAA8B,GAI/B,MAAM,gBAAgB,CAAC;AAWxB,MAAM,cAAc,GAAgC;IAClD,OAAO,EAAE,IAAI;IACb,YAAY,EAAE,QAAQ;IACtB,UAAU,EAAE,IAAI;IAChB,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE;QACb,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,UAAU;QACnB,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,IAAI;KAClB;IACD,WAAW,EAAE;QACX,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,QAAQ;QACf,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,IAAI;KAClB;CACF,CAA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CAAC;IAC9C,CAAC;IAED,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF;AAQD,MAAM,UAAU,qBAAqB,CACnC,QAA4B,EAC5B,MAA6C;IAE7C,IAAI,CAAE,QAAgB,CAAC,gBAAgB,EAAE,CAAC;QACvC,QAAgB,CAAC,gBAAgB,GAAG,IAAI,4BAA4B,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC1F,CAAC;IACD,OAAQ,QAAgB,CAAC,gBAAgB,CAAC;AAC5C,CAAC"}
|
package/src/typing-indicator.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NapCat Typing Indicator 集成
|
|
3
|
-
*
|
|
4
|
-
* 群聊:set_msg_emoji_like(表情回应)
|
|
5
|
-
* 私聊:set_input_status(输入状态)或短暂提示消息
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { NapCatEndpointBase } from './endpoint-base.js';
|
|
9
|
-
import {
|
|
10
|
-
TypingIndicatorManager,
|
|
11
|
-
ReactionTypingIndicatorAdapter,
|
|
12
|
-
type TypingIndicatorOptions,
|
|
13
|
-
type TypingIndicatorConfig,
|
|
14
|
-
type TypingIndicator,
|
|
15
|
-
} from '@zhin.js/agent';
|
|
16
|
-
|
|
17
|
-
export interface NapCatTypingIndicatorConfig {
|
|
18
|
-
enabled: boolean;
|
|
19
|
-
defaultEmoji: string;
|
|
20
|
-
autoRemove: boolean;
|
|
21
|
-
removeDelay: number;
|
|
22
|
-
privateConfig?: Partial<TypingIndicatorConfig>;
|
|
23
|
-
groupConfig?: Partial<TypingIndicatorConfig>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const DEFAULT_CONFIG: NapCatTypingIndicatorConfig = {
|
|
27
|
-
enabled: true,
|
|
28
|
-
defaultEmoji: '128516',
|
|
29
|
-
autoRemove: true,
|
|
30
|
-
removeDelay: 5000,
|
|
31
|
-
privateConfig: {
|
|
32
|
-
type: 'message',
|
|
33
|
-
message: '正在思考中...',
|
|
34
|
-
autoRemove: true,
|
|
35
|
-
removeDelay: 3000,
|
|
36
|
-
},
|
|
37
|
-
groupConfig: {
|
|
38
|
-
type: 'reaction',
|
|
39
|
-
emoji: '128516',
|
|
40
|
-
autoRemove: true,
|
|
41
|
-
removeDelay: 5000,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export class NapCatTypingIndicatorManager {
|
|
46
|
-
private manager: TypingIndicatorManager;
|
|
47
|
-
private config: NapCatTypingIndicatorConfig;
|
|
48
|
-
private endpoint: NapCatEndpointBase;
|
|
49
|
-
|
|
50
|
-
constructor(endpoint: NapCatEndpointBase, config: Partial<NapCatTypingIndicatorConfig> = {}) {
|
|
51
|
-
this.endpoint = endpoint;
|
|
52
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
53
|
-
this.manager = new TypingIndicatorManager({
|
|
54
|
-
type: 'reaction',
|
|
55
|
-
emoji: this.config.defaultEmoji,
|
|
56
|
-
autoRemove: this.config.autoRemove,
|
|
57
|
-
removeDelay: this.config.removeDelay,
|
|
58
|
-
});
|
|
59
|
-
this.registerAdapter();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private registerAdapter(): void {
|
|
63
|
-
const adapter = new ReactionTypingIndicatorAdapter(
|
|
64
|
-
'napcat',
|
|
65
|
-
async (messageId: string, emoji: string, _options) => {
|
|
66
|
-
return await this.endpoint.$addReaction(messageId, emoji);
|
|
67
|
-
},
|
|
68
|
-
async (messageId: string, reactionId: string) => {
|
|
69
|
-
await this.endpoint.$removeReaction(messageId, reactionId);
|
|
70
|
-
},
|
|
71
|
-
async (options: TypingIndicatorOptions, content: string) => {
|
|
72
|
-
try {
|
|
73
|
-
if (options.sceneType === 'group' && options.groupId) {
|
|
74
|
-
return await this.endpoint.$sendMessage({
|
|
75
|
-
type: 'group',
|
|
76
|
-
id: options.groupId,
|
|
77
|
-
context: 'napcat',
|
|
78
|
-
endpoint: this.endpoint.$id,
|
|
79
|
-
content: [{ type: 'text', data: { text: content } }],
|
|
80
|
-
});
|
|
81
|
-
} else if (options.userId) {
|
|
82
|
-
return await this.endpoint.$sendMessage({
|
|
83
|
-
type: 'private',
|
|
84
|
-
id: options.userId,
|
|
85
|
-
context: 'napcat',
|
|
86
|
-
endpoint: this.endpoint.$id,
|
|
87
|
-
content: [{ type: 'text', data: { text: content } }],
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return null;
|
|
91
|
-
} catch {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
async (messageId: string) => {
|
|
96
|
-
try {
|
|
97
|
-
await this.endpoint.$recallMessage(messageId);
|
|
98
|
-
} catch { /* ignore */ }
|
|
99
|
-
},
|
|
100
|
-
);
|
|
101
|
-
this.manager.registerAdapter(adapter);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async start(options: {
|
|
105
|
-
messageId?: string;
|
|
106
|
-
sessionId: string;
|
|
107
|
-
userId?: string;
|
|
108
|
-
groupId?: string;
|
|
109
|
-
sceneType: 'private' | 'group';
|
|
110
|
-
}): Promise<TypingIndicator> {
|
|
111
|
-
this.endpoint.logger.debug('[NapCat:TypingIndicator] start called', {
|
|
112
|
-
enabled: this.config.enabled,
|
|
113
|
-
sceneType: options.sceneType,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
if (!this.config.enabled) {
|
|
117
|
-
return {
|
|
118
|
-
start: async () => {},
|
|
119
|
-
stop: async () => {},
|
|
120
|
-
isActive: () => false,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const config = options.sceneType === 'group'
|
|
125
|
-
? this.config.groupConfig
|
|
126
|
-
: this.config.privateConfig;
|
|
127
|
-
|
|
128
|
-
const typingOptions: TypingIndicatorOptions = {
|
|
129
|
-
messageId: options.messageId,
|
|
130
|
-
sessionId: options.sessionId,
|
|
131
|
-
userId: options.userId,
|
|
132
|
-
groupId: options.groupId,
|
|
133
|
-
platform: 'napcat',
|
|
134
|
-
endpointId: this.endpoint.$id,
|
|
135
|
-
sceneType: options.sceneType,
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
return await this.manager.start(typingOptions, config);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async stop(options: {
|
|
142
|
-
sessionId: string;
|
|
143
|
-
userId?: string;
|
|
144
|
-
groupId?: string;
|
|
145
|
-
}): Promise<void> {
|
|
146
|
-
const typingOptions: TypingIndicatorOptions = {
|
|
147
|
-
sessionId: options.sessionId,
|
|
148
|
-
userId: options.userId,
|
|
149
|
-
groupId: options.groupId,
|
|
150
|
-
platform: 'napcat',
|
|
151
|
-
endpointId: this.endpoint.$id,
|
|
152
|
-
sceneType: 'private',
|
|
153
|
-
};
|
|
154
|
-
await this.manager.stop(typingOptions);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async stopAll(): Promise<void> {
|
|
158
|
-
await this.manager.stopAll();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
updateConfig(config: Partial<NapCatTypingIndicatorConfig>): void {
|
|
162
|
-
this.config = { ...this.config, ...config };
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
getConfig(): NapCatTypingIndicatorConfig {
|
|
166
|
-
return { ...this.config };
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
declare module './endpoint-base.js' {
|
|
171
|
-
interface NapCatEndpointBase {
|
|
172
|
-
$typingIndicator?: NapCatTypingIndicatorManager;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function enableTypingIndicator(
|
|
177
|
-
endpoint: NapCatEndpointBase,
|
|
178
|
-
config?: Partial<NapCatTypingIndicatorConfig>,
|
|
179
|
-
): NapCatTypingIndicatorManager {
|
|
180
|
-
if (!(endpoint as any).$typingIndicator) {
|
|
181
|
-
(endpoint as any).$typingIndicator = new NapCatTypingIndicatorManager(endpoint, config);
|
|
182
|
-
}
|
|
183
|
-
return (endpoint as any).$typingIndicator;
|
|
184
|
-
}
|