@zhin.js/adapter-discord 1.0.87 → 1.1.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 +855 -66
- package/README.md +61 -67
- package/adapters/discord.js +41 -0
- package/adapters/discord.ts +57 -0
- package/agent/PERMITS.md +25 -0
- package/{skills/discord/SKILL.md → agent/skills/discord.md} +1 -1
- package/agent/tools/add_role.ts +26 -0
- package/agent/tools/create_thread.ts +28 -0
- package/agent/tools/forum_post.ts +33 -0
- package/agent/tools/list_roles.ts +34 -0
- package/agent/tools/react.ts +24 -0
- package/agent/tools/remove_role.ts +26 -0
- package/agent/tools/send_embed.ts +38 -0
- package/commands/endpoint/add/[id].js +3 -0
- package/commands/endpoint/add/[id].ts +3 -0
- package/commands/endpoint/list.js +3 -0
- package/commands/endpoint/list.ts +3 -0
- package/commands/endpoint/remove/[id].js +3 -0
- package/commands/endpoint/remove/[id].ts +3 -0
- package/lib/client.d.ts +16 -0
- package/lib/client.js +8 -0
- package/lib/discord-endpoint-commands.d.ts +1 -0
- package/lib/discord-endpoint-commands.js +18 -0
- package/lib/discord-runtime-state.d.ts +1 -0
- package/lib/discord-runtime-state.js +6 -0
- package/lib/endpoint.d.ts +72 -0
- package/lib/endpoint.js +458 -0
- package/lib/gateway.d.ts +144 -0
- package/lib/gateway.js +303 -0
- package/lib/index.d.ts +6 -18
- package/lib/index.js +6 -323
- package/lib/platform-permit.d.ts +14 -0
- package/lib/platform-permit.js +42 -0
- package/lib/protocol.d.ts +162 -0
- package/lib/protocol.js +333 -0
- package/lib/side-event-dispatch.d.ts +8 -0
- package/lib/side-event-dispatch.js +24 -0
- package/lib/webhook.d.ts +14 -0
- package/lib/webhook.js +88 -0
- package/package.json +62 -29
- package/plugin.js +19 -0
- package/schema.json +141 -0
- package/src/client.ts +24 -0
- package/src/discord-endpoint-commands.ts +19 -0
- package/src/discord-runtime-state.ts +7 -0
- package/src/endpoint.ts +562 -0
- package/src/gateway.ts +426 -0
- package/src/index.ts +55 -323
- package/src/platform-permit.ts +57 -0
- package/src/protocol.ts +502 -0
- package/src/side-event-dispatch.ts +37 -0
- package/src/webhook.ts +123 -0
- package/client/Dashboard.tsx +0 -195
- package/client/index.tsx +0 -11
- package/client/tsconfig.json +0 -7
- package/client/utils/api.ts +0 -17
- package/dist/index.js +0 -29
- package/lib/adapter.d.ts +0 -19
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -90
- package/lib/adapter.js.map +0 -1
- package/lib/bot-interactions.d.ts +0 -33
- package/lib/bot-interactions.d.ts.map +0 -1
- package/lib/bot-interactions.js +0 -278
- package/lib/bot-interactions.js.map +0 -1
- package/lib/bot.d.ts +0 -117
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js +0 -904
- package/lib/bot.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types.d.ts +0 -49
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/plugin.yml +0 -3
- package/src/adapter.ts +0 -107
- package/src/bot-interactions.ts +0 -348
- package/src/bot.ts +0 -1037
- package/src/types.ts +0 -60
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-discord",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "Zhin.js adapter for
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Zhin.js Discord adapter for Plugin Runtime (Gateway WebSocket)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
@@ -32,52 +32,85 @@
|
|
|
32
32
|
"directory": "plugins/adapters/discord"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"discord.js": "^14.
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"lucide-react": "^1.16.0",
|
|
44
|
-
"typescript": "^6.0.3",
|
|
45
|
-
"@zhin.js/cli": "1.0.77",
|
|
46
|
-
"@zhin.js/console": "2.0.24",
|
|
47
|
-
"zhin.js": "1.0.81"
|
|
35
|
+
"discord.js": "^14.27.0",
|
|
36
|
+
"@zhin.js/adapter": "1.1.12",
|
|
37
|
+
"@zhin.js/core": "1.1.35",
|
|
38
|
+
"@zhin.js/feature-kit": "1.1.0",
|
|
39
|
+
"@zhin.js/host-http": "1.1.0",
|
|
40
|
+
"@zhin.js/im-contract": "1.1.0",
|
|
41
|
+
"@zhin.js/logger": "1.1.0",
|
|
42
|
+
"@zhin.js/permission": "1.1.0"
|
|
48
43
|
},
|
|
49
44
|
"peerDependencies": {
|
|
50
|
-
"
|
|
51
|
-
"@zhin.js/
|
|
52
|
-
"@zhin.js/
|
|
53
|
-
"zhin.js": "1.0
|
|
45
|
+
"zod": "^4.0.0",
|
|
46
|
+
"@zhin.js/adapter": "^1.1.12",
|
|
47
|
+
"@zhin.js/agent": "^1.1.23",
|
|
48
|
+
"@zhin.js/command": "^1.1.0",
|
|
49
|
+
"@zhin.js/core": "^1.1.35",
|
|
50
|
+
"zhin.js": "^1.1.0"
|
|
54
51
|
},
|
|
55
52
|
"peerDependenciesMeta": {
|
|
56
|
-
"@zhin.js/
|
|
53
|
+
"@zhin.js/agent": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"@zhin.js/command": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"zhin.js": {
|
|
57
60
|
"optional": true
|
|
58
61
|
},
|
|
59
|
-
"
|
|
62
|
+
"zod": {
|
|
60
63
|
"optional": true
|
|
61
64
|
}
|
|
62
65
|
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@types/node": "^26.1.2",
|
|
68
|
+
"typescript": "^6.0.3",
|
|
69
|
+
"vitest": "^4.1.10",
|
|
70
|
+
"zod": "^4.4.3",
|
|
71
|
+
"@zhin.js/agent": "1.1.23",
|
|
72
|
+
"@zhin.js/host-http": "1.1.0",
|
|
73
|
+
"zhin.js": "1.1.0"
|
|
74
|
+
},
|
|
63
75
|
"files": [
|
|
76
|
+
"adapters",
|
|
77
|
+
"commands",
|
|
78
|
+
"plugin.js",
|
|
79
|
+
"schema.json",
|
|
64
80
|
"src",
|
|
65
81
|
"lib",
|
|
66
|
-
"
|
|
67
|
-
"dist",
|
|
68
|
-
"skills",
|
|
69
|
-
"plugin.yml",
|
|
82
|
+
"agent",
|
|
70
83
|
"README.md",
|
|
71
|
-
"node",
|
|
72
84
|
"CHANGELOG.md"
|
|
73
85
|
],
|
|
74
86
|
"publishConfig": {
|
|
75
87
|
"access": "public",
|
|
76
88
|
"registry": "https://registry.npmjs.org"
|
|
77
89
|
},
|
|
90
|
+
"engines": {
|
|
91
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
92
|
+
},
|
|
93
|
+
"zhin": {
|
|
94
|
+
"protocol": 1,
|
|
95
|
+
"type": "plugin",
|
|
96
|
+
"entry": "./plugin.js",
|
|
97
|
+
"engine": "^1.0.0",
|
|
98
|
+
"runtime": "trusted",
|
|
99
|
+
"features": [
|
|
100
|
+
{
|
|
101
|
+
"package": "@zhin.js/adapter",
|
|
102
|
+
"api": "^1.0.0"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"package": "@zhin.js/command",
|
|
106
|
+
"api": "^1.0.0"
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"plugins": []
|
|
110
|
+
},
|
|
78
111
|
"scripts": {
|
|
79
|
-
"build": "
|
|
80
|
-
"clean": "rimraf lib
|
|
81
|
-
"
|
|
112
|
+
"build": "tsc",
|
|
113
|
+
"clean": "rimraf lib",
|
|
114
|
+
"test": "NODE_OPTIONS=--experimental-strip-types vitest run --root ../../.. plugins/adapters/discord/tests"
|
|
82
115
|
}
|
|
83
116
|
}
|
package/plugin.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { createEndpointRuntimeState } from 'zhin.js/adapter';
|
|
3
|
+
import { definePlugin } from 'zhin.js';
|
|
4
|
+
import { permissionHostToken } from '@zhin.js/permission';
|
|
5
|
+
import { checkDiscordPlatformPermit } from "./lib/platform-permit.js";
|
|
6
|
+
import { discordRuntimeStateToken } from "./lib/discord-runtime-state.js";
|
|
7
|
+
export default definePlugin({
|
|
8
|
+
name: 'discord',
|
|
9
|
+
metadata: {
|
|
10
|
+
displayName: 'Discord Gateway Adapter',
|
|
11
|
+
},
|
|
12
|
+
setup(context) {
|
|
13
|
+
context.resources.provide(discordRuntimeStateToken, createEndpointRuntimeState());
|
|
14
|
+
if (context.resources.has(permissionHostToken)) {
|
|
15
|
+
const host = context.resources.use(permissionHostToken);
|
|
16
|
+
return host.registerPlatform('discord', checkDiscordPlatformPermit);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
});
|
package/schema.json
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"additionalProperties": false,
|
|
5
|
+
"properties": {
|
|
6
|
+
"connection": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"enum": [
|
|
9
|
+
"gateway",
|
|
10
|
+
"interactions"
|
|
11
|
+
],
|
|
12
|
+
"default": "gateway",
|
|
13
|
+
"description": "Gateway WebSocket (default). interactions uses httpHostToken POST + Ed25519 verify."
|
|
14
|
+
},
|
|
15
|
+
"intents": {
|
|
16
|
+
"type": "array",
|
|
17
|
+
"items": {
|
|
18
|
+
"type": "number"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"enableSlashCommands": {
|
|
22
|
+
"type": "boolean",
|
|
23
|
+
"default": false
|
|
24
|
+
},
|
|
25
|
+
"globalCommands": {
|
|
26
|
+
"type": "boolean",
|
|
27
|
+
"default": false
|
|
28
|
+
},
|
|
29
|
+
"defaultActivity": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"additionalProperties": false,
|
|
32
|
+
"properties": {
|
|
33
|
+
"name": {
|
|
34
|
+
"type": "string"
|
|
35
|
+
},
|
|
36
|
+
"type": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"enum": [
|
|
39
|
+
"PLAYING",
|
|
40
|
+
"STREAMING",
|
|
41
|
+
"LISTENING",
|
|
42
|
+
"WATCHING",
|
|
43
|
+
"COMPETING"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"url": {
|
|
47
|
+
"type": "string"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"required": [
|
|
51
|
+
"name",
|
|
52
|
+
"type"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"slashCommands": {
|
|
56
|
+
"type": "array",
|
|
57
|
+
"items": {
|
|
58
|
+
"type": "object"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"applicationId": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"description": "Required when connection is interactions."
|
|
64
|
+
},
|
|
65
|
+
"publicKey": {
|
|
66
|
+
"type": "string",
|
|
67
|
+
"description": "Required when connection is interactions (hex Ed25519 public key)."
|
|
68
|
+
},
|
|
69
|
+
"interactionsPath": {
|
|
70
|
+
"type": "string",
|
|
71
|
+
"default": "/discord/interactions",
|
|
72
|
+
"description": "POST path on httpHostToken when connection is interactions."
|
|
73
|
+
},
|
|
74
|
+
"master": {
|
|
75
|
+
"type": [
|
|
76
|
+
"string",
|
|
77
|
+
"number"
|
|
78
|
+
],
|
|
79
|
+
"description": "框架 master(Discord user snowflake;AI/工具权限、endpoint 管理)。endpoints[i].master 可逐项覆盖"
|
|
80
|
+
},
|
|
81
|
+
"trusted": {
|
|
82
|
+
"type": "array",
|
|
83
|
+
"items": {
|
|
84
|
+
"type": [
|
|
85
|
+
"string",
|
|
86
|
+
"number"
|
|
87
|
+
],
|
|
88
|
+
"description": "Trusted Discord user snowflake"
|
|
89
|
+
},
|
|
90
|
+
"description": "框架 trusted 用户列表(弱于 master)。endpoints[i].trusted 可逐项追加"
|
|
91
|
+
},
|
|
92
|
+
"endpoints": {
|
|
93
|
+
"type": "array",
|
|
94
|
+
"description": "多账号:一个插件实例挂多个 endpoint。每项与顶层字段同构(id 必填,其余覆盖顶层)",
|
|
95
|
+
"items": {
|
|
96
|
+
"type": "object",
|
|
97
|
+
"additionalProperties": true,
|
|
98
|
+
"properties": {
|
|
99
|
+
"master": {
|
|
100
|
+
"type": [
|
|
101
|
+
"string",
|
|
102
|
+
"number"
|
|
103
|
+
],
|
|
104
|
+
"description": "本 endpoint 的框架 master(Discord user snowflake);覆盖顶层 master"
|
|
105
|
+
},
|
|
106
|
+
"trusted": {
|
|
107
|
+
"type": "array",
|
|
108
|
+
"items": {
|
|
109
|
+
"type": [
|
|
110
|
+
"string",
|
|
111
|
+
"number"
|
|
112
|
+
],
|
|
113
|
+
"description": "Trusted Discord user snowflake"
|
|
114
|
+
},
|
|
115
|
+
"description": "本 endpoint 的 trusted 列表"
|
|
116
|
+
},
|
|
117
|
+
"token": {
|
|
118
|
+
"type": "string",
|
|
119
|
+
"description": "Discord bot token"
|
|
120
|
+
},
|
|
121
|
+
"id": {
|
|
122
|
+
"type": "string",
|
|
123
|
+
"description": "Discord bot name"
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"required": [
|
|
127
|
+
"id",
|
|
128
|
+
"token"
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
"commandPrefix": {
|
|
133
|
+
"type": "string",
|
|
134
|
+
"default": "",
|
|
135
|
+
"description": "命令前缀(默认 '' 无前缀,任意文本按命令匹配;如 '/' 要求 / 开头)。endpoints[i] 可逐项覆盖"
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
"required": [
|
|
139
|
+
"endpoints"
|
|
140
|
+
]
|
|
141
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineEndpointClient } from 'zhin.js/adapter';
|
|
2
|
+
import type { DiscordRestClient } from './endpoint.js';
|
|
3
|
+
import type { DiscordClientTransport } from './gateway.js';
|
|
4
|
+
|
|
5
|
+
/** Exact Client variants produced by the Gateway and Interactions Endpoints. */
|
|
6
|
+
export type DiscordClient = DiscordClientTransport | DiscordRestClient;
|
|
7
|
+
export type DiscordClientEventMap = Record<string, unknown>;
|
|
8
|
+
|
|
9
|
+
/** Narrow an adapter Client for Gateway-only SDK operations. */
|
|
10
|
+
export function requireDiscordGatewayClient(client: DiscordClient): DiscordClientTransport {
|
|
11
|
+
if ('guilds' in client && 'channels' in client) return client;
|
|
12
|
+
throw new Error('This Discord tool requires a Gateway Endpoint Client');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare module '@zhin.js/feature-kit' {
|
|
16
|
+
interface AdapterClientRegistry {
|
|
17
|
+
readonly discord: {
|
|
18
|
+
readonly client: DiscordClient;
|
|
19
|
+
readonly events: DiscordClientEventMap;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const discordClient = defineEndpointClient<DiscordClient, DiscordClientEventMap>('discord');
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `discord.endpoint` 命令族:由 @zhin.js/adapter 的 createEndpointCommands 套件生成。
|
|
3
|
+
* commands/endpoint/ 下的 list / add / remove 直接默认导出这三项。
|
|
4
|
+
* 注:applicationId / publicKey 为顶层共享字段(slash commands / interactions 用),
|
|
5
|
+
* endpoints[i] 仅需 name + token(见 schema.json),故 add 只录入 token。
|
|
6
|
+
*/
|
|
7
|
+
import { createEndpointCommands } from 'zhin.js/adapter';
|
|
8
|
+
import { defineCommand } from 'zhin.js/command';
|
|
9
|
+
import { discordRuntimeStateToken } from './discord-runtime-state.js';
|
|
10
|
+
|
|
11
|
+
export const discordEndpointCommands = createEndpointCommands({
|
|
12
|
+
adapterKey: 'discord',
|
|
13
|
+
adapterDisplayName: 'Discord',
|
|
14
|
+
fields: [
|
|
15
|
+
{ key: 'token', required: true, env: true, description: 'Discord bot token' },
|
|
16
|
+
],
|
|
17
|
+
running: (use) => use(discordRuntimeStateToken).endpoints.values(),
|
|
18
|
+
describeEntry: (entry) => `token: ${String(entry.token)}`,
|
|
19
|
+
}, defineCommand);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord 插件实例的运行时状态:adapter create() 注册的 endpoint 列表。
|
|
3
|
+
* 由 plugin.ts setup() provide,adapter create 与 `discord.endpoint` 命令共享(同一 owner generation)。
|
|
4
|
+
*/
|
|
5
|
+
import { defineEndpointRuntimeStateToken } from 'zhin.js/adapter';
|
|
6
|
+
|
|
7
|
+
export const discordRuntimeStateToken = defineEndpointRuntimeStateToken('discord');
|