@zhin.js/adapter-kook 3.0.0 → 4.0.0
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 +22 -0
- package/README.md +27 -27
- package/client/Dashboard.tsx +33 -33
- package/dist/index.js +1 -1
- package/lib/adapter.d.ts +10 -9
- package/lib/adapter.d.ts.map +1 -1
- package/lib/adapter.js +33 -32
- package/lib/adapter.js.map +1 -1
- package/lib/{bot.d.ts → endpoint.d.ts} +9 -9
- package/lib/endpoint.d.ts.map +1 -0
- package/lib/{bot.js → endpoint.js} +43 -40
- package/lib/endpoint.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +96 -88
- package/lib/index.js.map +1 -1
- package/lib/kook-side-events.d.ts +1 -1
- package/lib/kook-side-events.d.ts.map +1 -1
- package/lib/kook-side-events.js +3 -3
- package/lib/kook-side-events.js.map +1 -1
- package/lib/platform-permit.d.ts +14 -0
- package/lib/platform-permit.d.ts.map +1 -0
- package/lib/platform-permit.js +63 -0
- package/lib/platform-permit.js.map +1 -0
- package/lib/types.d.ts +4 -1
- package/lib/types.d.ts.map +1 -1
- package/package.json +12 -9
- package/skills/kook/PERMITS.md +23 -0
- package/src/adapter.ts +27 -25
- package/src/{bot.ts → endpoint.ts} +45 -42
- package/src/index.ts +87 -78
- package/src/kook-side-events.ts +3 -3
- package/src/platform-permit.ts +77 -0
- package/src/types.ts +4 -1
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js.map +0 -1
package/lib/types.d.ts
CHANGED
|
@@ -17,6 +17,9 @@ export interface KookSenderInfo {
|
|
|
17
17
|
roles?: number[];
|
|
18
18
|
isGuildOwner?: boolean;
|
|
19
19
|
isAdmin?: boolean;
|
|
20
|
+
/** 归一化平台身份(供 platform checker) */
|
|
21
|
+
role?: string;
|
|
22
|
+
permissions?: string[];
|
|
20
23
|
}
|
|
21
24
|
export interface KookTypingIndicatorConfig {
|
|
22
25
|
enabled?: boolean;
|
|
@@ -35,7 +38,7 @@ export interface KookTypingIndicatorConfig {
|
|
|
35
38
|
message?: string;
|
|
36
39
|
};
|
|
37
40
|
}
|
|
38
|
-
export interface
|
|
41
|
+
export interface KookEndpointConfig {
|
|
39
42
|
context: "kook";
|
|
40
43
|
name: string;
|
|
41
44
|
token: string;
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,YAAY,EAAE,QAAQ,EAAE,CAAC;AAEzB,oBAAY,cAAc;IACxB,MAAM,IAAI;IACV,KAAK,IAAI;IACT,KAAK,IAAI;IACT,YAAY,IAAI;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,YAAY,EAAE,QAAQ,EAAE,CAAC;AAEzB,oBAAY,cAAc;IACxB,MAAM,IAAI;IACV,KAAK,IAAI;IACT,KAAK,IAAI;IACT,YAAY,IAAI;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE;QACd,IAAI,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC;QAClD,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,6CAA6C;IAC7C,WAAW,CAAC,EAAE;QACZ,IAAI,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC;QAClD,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,kCAAkC;IAClC,eAAe,CAAC,EAAE,yBAAyB,CAAC;CAC7C;AAED,MAAM,MAAM,cAAc,GAAG,mBAAmB,GAAG,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-kook",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Zhin.js adapter for KOOK (开黑啦)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -40,18 +40,21 @@
|
|
|
40
40
|
"@types/react-dom": "^19.2.3",
|
|
41
41
|
"lucide-react": "^1.17.0",
|
|
42
42
|
"typescript": "^6.0.3",
|
|
43
|
-
"@zhin.js/cli": "1.0.
|
|
44
|
-
"@zhin.js/
|
|
43
|
+
"@zhin.js/cli": "1.0.89",
|
|
44
|
+
"@zhin.js/client": "2.0.3",
|
|
45
45
|
"@zhin.js/contract": "1.0.1",
|
|
46
|
-
"zhin.js": "2.0.0"
|
|
46
|
+
"@zhin.js/host-api": "2.0.0",
|
|
47
|
+
"@zhin.js/host-router": "2.0.0",
|
|
48
|
+
"@zhin.js/logger": "0.1.71",
|
|
49
|
+
"zhin.js": "3.0.0"
|
|
47
50
|
},
|
|
48
51
|
"peerDependencies": {
|
|
49
|
-
"@zhin.js/client": "2.0.
|
|
50
|
-
"@zhin.js/host-api": "
|
|
52
|
+
"@zhin.js/client": "2.0.3",
|
|
53
|
+
"@zhin.js/host-api": "2.0.0",
|
|
51
54
|
"@zhin.js/contract": "1.0.1",
|
|
52
|
-
"@zhin.js/host-router": "
|
|
53
|
-
"@zhin.js/logger": "0.1.
|
|
54
|
-
"zhin.js": "
|
|
55
|
+
"@zhin.js/host-router": "2.0.0",
|
|
56
|
+
"@zhin.js/logger": "0.1.71",
|
|
57
|
+
"zhin.js": "3.0.0"
|
|
55
58
|
},
|
|
56
59
|
"peerDependenciesMeta": {
|
|
57
60
|
"@zhin.js/client": {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# KOOK Platform Permits
|
|
2
|
+
|
|
3
|
+
## 入站字段
|
|
4
|
+
|
|
5
|
+
| 字段 | 来源 | 取值 |
|
|
6
|
+
|------|------|------|
|
|
7
|
+
| `$sender.role` | `permission` / `isAdmin` / `isGuildOwner` | `owner` · `admin` · `channel_admin` · `member` |
|
|
8
|
+
| `$sender.permissions` | 归一化 + `roles[]` | `guild_owner` · `guild_admin` · `channel_admin` · `manage_roles` · `role:{id}` |
|
|
9
|
+
|
|
10
|
+
KOOK `permission`:1=成员,2=管理员,4=频道主,5=频道管理员(子频道场景为 `channel_admin`)。
|
|
11
|
+
|
|
12
|
+
## Permit 词汇表
|
|
13
|
+
|
|
14
|
+
| `platform(kook,…)` | 含义 |
|
|
15
|
+
|--------------------|------|
|
|
16
|
+
| `guild_owner` | 服务器主 |
|
|
17
|
+
| `guild_admin` | 服务器/频道管理员 |
|
|
18
|
+
| `channel_admin` | 子频道管理员 |
|
|
19
|
+
| `manage_roles` | 可管理身份组 |
|
|
20
|
+
|
|
21
|
+
## 工厂映射
|
|
22
|
+
|
|
23
|
+
`group_admin` → `guild_admin` · `group_owner` → `guild_owner`
|
package/src/adapter.ts
CHANGED
|
@@ -2,48 +2,50 @@
|
|
|
2
2
|
* KOOK 适配器
|
|
3
3
|
*/
|
|
4
4
|
import { formatCompact, Adapter, Plugin } from 'zhin.js';
|
|
5
|
-
import {
|
|
6
|
-
import type {
|
|
5
|
+
import { KookEndpoint } from "./endpoint.js";
|
|
6
|
+
import type { KookEndpointConfig } from "./types.js";
|
|
7
|
+
|
|
8
|
+
export class KookAdapter extends Adapter<KookEndpoint> {
|
|
9
|
+
static override readonly capabilities = ['inbound', 'outbound'] as const;
|
|
7
10
|
|
|
8
|
-
export class KookAdapter extends Adapter<KookBot> {
|
|
9
11
|
constructor(plugin: Plugin) {
|
|
10
12
|
super(plugin, "kook", []);
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
return new
|
|
15
|
+
createEndpoint(config: KookEndpointConfig): KookEndpoint {
|
|
16
|
+
return new KookEndpoint(this, config);
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
// ── IGroupManagement 标准群管方法 ──────────────────────────────────
|
|
18
20
|
|
|
19
|
-
async kickMember(
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
22
|
-
return
|
|
21
|
+
async kickMember(endpointId: string, sceneId: string, userId: string) {
|
|
22
|
+
const endpoint = this.endpoints.get(endpointId);
|
|
23
|
+
if (!endpoint) throw new Error(`Endpoint ${endpointId} 不存在`);
|
|
24
|
+
return endpoint.kickUser(sceneId, userId);
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
async banMember(
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
28
|
-
return
|
|
27
|
+
async banMember(endpointId: string, sceneId: string, userId: string, reason?: string) {
|
|
28
|
+
const endpoint = this.endpoints.get(endpointId);
|
|
29
|
+
if (!endpoint) throw new Error(`Endpoint ${endpointId} 不存在`);
|
|
30
|
+
return endpoint.addToBlacklist(sceneId, userId, reason);
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
async unbanMember(
|
|
32
|
-
const
|
|
33
|
-
if (!
|
|
34
|
-
return
|
|
33
|
+
async unbanMember(endpointId: string, sceneId: string, userId: string) {
|
|
34
|
+
const endpoint = this.endpoints.get(endpointId);
|
|
35
|
+
if (!endpoint) throw new Error(`Endpoint ${endpointId} 不存在`);
|
|
36
|
+
return endpoint.removeFromBlacklist(sceneId, userId);
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
async setMemberNickname(
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
40
|
-
return
|
|
39
|
+
async setMemberNickname(endpointId: string, sceneId: string, userId: string, nickname: string) {
|
|
40
|
+
const endpoint = this.endpoints.get(endpointId);
|
|
41
|
+
if (!endpoint) throw new Error(`Endpoint ${endpointId} 不存在`);
|
|
42
|
+
return endpoint.setNickname(sceneId, userId, nickname);
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
async listMembers(
|
|
44
|
-
const
|
|
45
|
-
if (!
|
|
46
|
-
const members = await
|
|
45
|
+
async listMembers(endpointId: string, sceneId: string) {
|
|
46
|
+
const endpoint = this.endpoints.get(endpointId);
|
|
47
|
+
if (!endpoint) throw new Error(`Endpoint ${endpointId} 不存在`);
|
|
48
|
+
const members = await endpoint.getGuildMembers(sceneId);
|
|
47
49
|
return {
|
|
48
50
|
members: members.map(m => ({
|
|
49
51
|
id: m.id, username: m.username,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* KOOK
|
|
2
|
+
* KOOK Endpoint 实现
|
|
3
3
|
*/
|
|
4
4
|
import {
|
|
5
5
|
Client,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import { EventEmitter } from "node:events";
|
|
15
15
|
import path from "path";
|
|
16
16
|
import {
|
|
17
|
-
|
|
17
|
+
Endpoint,
|
|
18
18
|
Message,
|
|
19
19
|
SendOptions,
|
|
20
20
|
SendContent,
|
|
@@ -22,10 +22,11 @@ import {
|
|
|
22
22
|
segment,
|
|
23
23
|
MessageType,
|
|
24
24
|
} from "zhin.js";
|
|
25
|
-
import type {
|
|
25
|
+
import type { KookEndpointConfig, KookSenderInfo, KookRawMessage } from "./types.js";
|
|
26
26
|
import { KookPermission } from "./types.js";
|
|
27
27
|
import type { KookAdapter } from "./adapter.js";
|
|
28
28
|
import { InboundMessageDeduper } from "./kook-inbound.js";
|
|
29
|
+
import { normalizeKookSenderForPermit } from "./platform-permit.js";
|
|
29
30
|
import {
|
|
30
31
|
enrichKookGatewayForPlugins,
|
|
31
32
|
formatKookNotice,
|
|
@@ -55,9 +56,9 @@ import { materializeOutboundMedia } from "./outbound-media.js";
|
|
|
55
56
|
import { uploadKookAsset } from "./kook-asset-upload.js";
|
|
56
57
|
import { convertToKookSendable } from "./outbound-sendable.js";
|
|
57
58
|
|
|
58
|
-
export class
|
|
59
|
+
export class KookEndpoint extends Client implements Endpoint<KookEndpointConfig, KookRawMessage> {
|
|
59
60
|
$connected: boolean = false;
|
|
60
|
-
/** KOOK 平台 user_id,用于 @ 触发匹配(
|
|
61
|
+
/** KOOK 平台 user_id,用于 @ 触发匹配(resolveEndpointAtIds) */
|
|
61
62
|
$platformUserId?: string;
|
|
62
63
|
adapter: KookAdapter;
|
|
63
64
|
private readonly inboundDeduper = new InboundMessageDeduper();
|
|
@@ -73,7 +74,7 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
73
74
|
return this.adapter.plugin.logger;
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
constructor(adapter: KookAdapter, public $config:
|
|
77
|
+
constructor(adapter: KookAdapter, public $config: KookEndpointConfig) {
|
|
77
78
|
super({
|
|
78
79
|
token: $config.token,
|
|
79
80
|
mode: "websocket", // KOOK 默认使用 WebSocket 模式
|
|
@@ -119,7 +120,6 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
119
120
|
payload: unknown,
|
|
120
121
|
): void {
|
|
121
122
|
this.adapter.emit(event, payload as never);
|
|
122
|
-
void this.adapter.plugin.dispatch(event, payload as never);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
/**
|
|
@@ -160,18 +160,18 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
160
160
|
// 监听连接事件
|
|
161
161
|
this.on("connect" as any, () => {
|
|
162
162
|
this.$connected = true;
|
|
163
|
-
this.pluginLogger.info(`KOOK
|
|
163
|
+
this.pluginLogger.info(`KOOK Endpoint ${this.$id} 已连接`);
|
|
164
164
|
});
|
|
165
165
|
|
|
166
166
|
// 监听断开事件
|
|
167
167
|
this.on("disconnect" as any, () => {
|
|
168
168
|
this.$connected = false;
|
|
169
|
-
this.pluginLogger.warn(`KOOK
|
|
169
|
+
this.pluginLogger.warn(`KOOK Endpoint ${this.$id} 已断开`);
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
// 监听错误事件
|
|
173
173
|
this.on("error" as any, (error: Error) => {
|
|
174
|
-
this.pluginLogger.error(`KOOK
|
|
174
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 错误:`, error);
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
177
|
|
|
@@ -202,7 +202,7 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
202
202
|
const message: Message<KookRawMessage> = Message.from(msg, {
|
|
203
203
|
$id: msg.message_id.toString(),
|
|
204
204
|
$adapter: "kook" as const,
|
|
205
|
-
$
|
|
205
|
+
$endpoint: this.$id,
|
|
206
206
|
|
|
207
207
|
$sender: senderInfo,
|
|
208
208
|
|
|
@@ -243,7 +243,7 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
243
243
|
return await this.adapter.sendMessage({
|
|
244
244
|
...message.$channel,
|
|
245
245
|
context: "kook",
|
|
246
|
-
|
|
246
|
+
endpoint: this.$id,
|
|
247
247
|
content: finalContent,
|
|
248
248
|
});
|
|
249
249
|
},
|
|
@@ -297,6 +297,9 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
+
const normalized = normalizeKookSenderForPermit(senderInfo, msg.message_type === "channel");
|
|
301
|
+
senderInfo.role = normalized.role;
|
|
302
|
+
senderInfo.permissions = normalized.permissions;
|
|
300
303
|
return senderInfo;
|
|
301
304
|
}
|
|
302
305
|
|
|
@@ -311,10 +314,10 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
311
314
|
try {
|
|
312
315
|
const guild = this.pickGuild(guildId);
|
|
313
316
|
const result = await guild.kick(userId);
|
|
314
|
-
this.pluginLogger.info(`KOOK
|
|
317
|
+
this.pluginLogger.info(`KOOK Endpoint ${this.$id} 踢出用户 ${userId} 从服务器 ${guildId}`);
|
|
315
318
|
return result;
|
|
316
319
|
} catch (error) {
|
|
317
|
-
this.pluginLogger.error(`KOOK
|
|
320
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 踢出用户失败:`, error);
|
|
318
321
|
throw error;
|
|
319
322
|
}
|
|
320
323
|
}
|
|
@@ -330,10 +333,10 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
330
333
|
try {
|
|
331
334
|
const member = this.pickGuildMember(guildId, userId);
|
|
332
335
|
const result = await member.addToBlackList(remark, delMsgDays);
|
|
333
|
-
this.pluginLogger.info(`KOOK
|
|
336
|
+
this.pluginLogger.info(`KOOK Endpoint ${this.$id} 将用户 ${userId} 加入黑名单(服务器 ${guildId})`);
|
|
334
337
|
return result;
|
|
335
338
|
} catch (error) {
|
|
336
|
-
this.pluginLogger.error(`KOOK
|
|
339
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 加入黑名单失败:`, error);
|
|
337
340
|
throw error;
|
|
338
341
|
}
|
|
339
342
|
}
|
|
@@ -347,10 +350,10 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
347
350
|
try {
|
|
348
351
|
const member = this.pickGuildMember(guildId, userId);
|
|
349
352
|
const result = await member.removeFromBlackList();
|
|
350
|
-
this.pluginLogger.info(`KOOK
|
|
353
|
+
this.pluginLogger.info(`KOOK Endpoint ${this.$id} 将用户 ${userId} 从黑名单移除(服务器 ${guildId})`);
|
|
351
354
|
return result;
|
|
352
355
|
} catch (error) {
|
|
353
|
-
this.pluginLogger.error(`KOOK
|
|
356
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 移除黑名单失败:`, error);
|
|
354
357
|
throw error;
|
|
355
358
|
}
|
|
356
359
|
}
|
|
@@ -365,10 +368,10 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
365
368
|
try {
|
|
366
369
|
const member = this.pickGuildMember(guildId, userId);
|
|
367
370
|
const result = await member.grant(roleId);
|
|
368
|
-
this.pluginLogger.info(`KOOK
|
|
371
|
+
this.pluginLogger.info(`KOOK Endpoint ${this.$id} 授予用户 ${userId} 角色 ${roleId}(服务器 ${guildId})`);
|
|
369
372
|
return result;
|
|
370
373
|
} catch (error) {
|
|
371
|
-
this.pluginLogger.error(`KOOK
|
|
374
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 授予角色失败:`, error);
|
|
372
375
|
throw error;
|
|
373
376
|
}
|
|
374
377
|
}
|
|
@@ -383,10 +386,10 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
383
386
|
try {
|
|
384
387
|
const member = this.pickGuildMember(guildId, userId);
|
|
385
388
|
const result = await member.revoke(roleId);
|
|
386
|
-
this.pluginLogger.info(`KOOK
|
|
389
|
+
this.pluginLogger.info(`KOOK Endpoint ${this.$id} 撤销用户 ${userId} 角色 ${roleId}(服务器 ${guildId})`);
|
|
387
390
|
return result;
|
|
388
391
|
} catch (error) {
|
|
389
|
-
this.pluginLogger.error(`KOOK
|
|
392
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 撤销角色失败:`, error);
|
|
390
393
|
throw error;
|
|
391
394
|
}
|
|
392
395
|
}
|
|
@@ -401,10 +404,10 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
401
404
|
try {
|
|
402
405
|
const member = this.pickGuildMember(guildId, userId);
|
|
403
406
|
const result = await member.setNickname(nickname);
|
|
404
|
-
this.pluginLogger.info(`KOOK
|
|
407
|
+
this.pluginLogger.info(`KOOK Endpoint ${this.$id} 设置用户 ${userId} 昵称为 "${nickname}"(服务器 ${guildId})`);
|
|
405
408
|
return result;
|
|
406
409
|
} catch (error) {
|
|
407
|
-
this.pluginLogger.error(`KOOK
|
|
410
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 设置昵称失败:`, error);
|
|
408
411
|
throw error;
|
|
409
412
|
}
|
|
410
413
|
}
|
|
@@ -418,7 +421,7 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
418
421
|
const guild = this.pickGuild(guildId);
|
|
419
422
|
return await guild.getRoleList();
|
|
420
423
|
} catch (error) {
|
|
421
|
-
this.pluginLogger.error(`KOOK
|
|
424
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 获取角色列表失败:`, error);
|
|
422
425
|
throw error;
|
|
423
426
|
}
|
|
424
427
|
}
|
|
@@ -432,10 +435,10 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
432
435
|
try {
|
|
433
436
|
const guild = this.pickGuild(guildId);
|
|
434
437
|
const role = await guild.createRole(name);
|
|
435
|
-
this.pluginLogger.info(`KOOK
|
|
438
|
+
this.pluginLogger.info(`KOOK Endpoint ${this.$id} 创建角色 "${name}"(服务器 ${guildId})`);
|
|
436
439
|
return role;
|
|
437
440
|
} catch (error) {
|
|
438
|
-
this.pluginLogger.error(`KOOK
|
|
441
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 创建角色失败:`, error);
|
|
439
442
|
throw error;
|
|
440
443
|
}
|
|
441
444
|
}
|
|
@@ -449,10 +452,10 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
449
452
|
try {
|
|
450
453
|
const guild = this.pickGuild(guildId);
|
|
451
454
|
const result = await guild.deleteRole(roleId);
|
|
452
|
-
this.pluginLogger.info(`KOOK
|
|
455
|
+
this.pluginLogger.info(`KOOK Endpoint ${this.$id} 删除角色 ${roleId}(服务器 ${guildId})`);
|
|
453
456
|
return result;
|
|
454
457
|
} catch (error) {
|
|
455
|
-
this.pluginLogger.error(`KOOK
|
|
458
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 删除角色失败:`, error);
|
|
456
459
|
throw error;
|
|
457
460
|
}
|
|
458
461
|
}
|
|
@@ -466,7 +469,7 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
466
469
|
try {
|
|
467
470
|
return await this.getGuildUserList(guildId, channelId);
|
|
468
471
|
} catch (error) {
|
|
469
|
-
this.pluginLogger.error(`KOOK
|
|
472
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 获取成员列表失败:`, error);
|
|
470
473
|
throw error;
|
|
471
474
|
}
|
|
472
475
|
}
|
|
@@ -650,11 +653,11 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
650
653
|
this.$platformUserId = String(selfId);
|
|
651
654
|
}
|
|
652
655
|
this.pluginLogger.info(
|
|
653
|
-
`KOOK
|
|
656
|
+
`KOOK Endpoint ${this.$id} 连接成功`
|
|
654
657
|
+ (this.$platformUserId ? ` (platform_user_id=${this.$platformUserId})` : ''),
|
|
655
658
|
);
|
|
656
659
|
} catch (error) {
|
|
657
|
-
this.pluginLogger.error(`KOOK
|
|
660
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 连接失败:`, error);
|
|
658
661
|
throw error;
|
|
659
662
|
}
|
|
660
663
|
}
|
|
@@ -670,9 +673,9 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
670
673
|
(this as unknown as import('node:events').EventEmitter).removeAllListeners();
|
|
671
674
|
await this.disconnect();
|
|
672
675
|
this.$connected = false;
|
|
673
|
-
this.pluginLogger.info(`KOOK
|
|
676
|
+
this.pluginLogger.info(`KOOK Endpoint ${this.$id} 已断开连接`);
|
|
674
677
|
} catch (error) {
|
|
675
|
-
this.pluginLogger.error(`KOOK
|
|
678
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 断开连接失败:`, error);
|
|
676
679
|
throw error;
|
|
677
680
|
}
|
|
678
681
|
}
|
|
@@ -708,7 +711,7 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
708
711
|
const route = routeFromSendType(type);
|
|
709
712
|
return encodeKookMsgRef(route, String(result?.msg_id ?? ''));
|
|
710
713
|
} catch (error) {
|
|
711
|
-
this.pluginLogger.error(`KOOK
|
|
714
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 发送消息失败:`, error);
|
|
712
715
|
throw error;
|
|
713
716
|
}
|
|
714
717
|
}
|
|
@@ -725,10 +728,10 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
725
728
|
try {
|
|
726
729
|
await this.deleteKookMsg(msgId, routeHint);
|
|
727
730
|
this.pluginLogger.debug(
|
|
728
|
-
`KOOK
|
|
731
|
+
`KOOK Endpoint ${this.$id} 撤回消息 (${routeHint ?? 'auto'}): ${msgId}`,
|
|
729
732
|
);
|
|
730
733
|
} catch (error) {
|
|
731
|
-
this.pluginLogger.error(`KOOK
|
|
734
|
+
this.pluginLogger.error(`KOOK Endpoint ${this.$id} 撤回消息失败:`, error);
|
|
732
735
|
throw error;
|
|
733
736
|
}
|
|
734
737
|
}
|
|
@@ -772,7 +775,7 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
772
775
|
return encodeKookReactionId(route, msgId, emoji);
|
|
773
776
|
}
|
|
774
777
|
|
|
775
|
-
/** 移除本
|
|
778
|
+
/** 移除本 Endpoint 在消息上的表情回应 */
|
|
776
779
|
async $removeReaction(messageId: string, reactionId: string): Promise<void> {
|
|
777
780
|
const { route, emoji } = parseKookReactionId(reactionId);
|
|
778
781
|
await this.mutateMsgReaction(plainKookMsgId(messageId), emoji, 'delete', route);
|
|
@@ -796,21 +799,21 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
796
799
|
) as { code?: number };
|
|
797
800
|
if (isKookApiSuccess(result)) {
|
|
798
801
|
this.pluginLogger.debug(
|
|
799
|
-
`KOOK
|
|
802
|
+
`KOOK Endpoint ${this.$id} ${action} reaction (${route}) on ${msgId}`,
|
|
800
803
|
);
|
|
801
804
|
return route;
|
|
802
805
|
}
|
|
803
806
|
if (action === 'delete' && shouldStopDeleteAfterResponse(result, routes.length)) {
|
|
804
807
|
const label = isKookApiGoneResult(result) ? 'already gone' : 'done';
|
|
805
808
|
this.pluginLogger.debug(
|
|
806
|
-
`KOOK
|
|
809
|
+
`KOOK Endpoint ${this.$id} delete reaction ${label} (${route}) on ${msgId}`,
|
|
807
810
|
);
|
|
808
811
|
return route;
|
|
809
812
|
}
|
|
810
813
|
} catch (err) {
|
|
811
814
|
if (action === 'delete' && isKookMsgGoneError(err)) {
|
|
812
815
|
this.pluginLogger.debug(
|
|
813
|
-
`KOOK
|
|
816
|
+
`KOOK Endpoint ${this.$id} delete reaction already gone (${route}) on ${msgId}`,
|
|
814
817
|
);
|
|
815
818
|
return route;
|
|
816
819
|
}
|
|
@@ -820,7 +823,7 @@ export class KookBot extends Client implements Bot<KookBotConfig, KookRawMessage
|
|
|
820
823
|
|
|
821
824
|
if (action === 'delete') {
|
|
822
825
|
this.pluginLogger.debug(
|
|
823
|
-
`KOOK
|
|
826
|
+
`KOOK Endpoint ${this.$id} delete reaction noop on ${msgId}`,
|
|
824
827
|
);
|
|
825
828
|
return routeHint ?? 'channel';
|
|
826
829
|
}
|