@zhin.js/adapter-discord 1.0.87 → 1.1.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/CHANGELOG.md +949 -66
- package/PERMITS.md +25 -0
- package/README.md +60 -67
- package/adapters/discord/index.js +41 -0
- package/adapters/discord/index.ts +57 -0
- package/agents/discord/agent.json +20 -0
- package/agents/discord/boundaries.md +3 -0
- package/agents/discord/conventions.md +3 -0
- package/agents/discord/skills/discord/SKILL.md +21 -0
- package/agents/discord/skills/discord/tools/add_role/index.js +24 -0
- package/agents/discord/skills/discord/tools/add_role/index.ts +26 -0
- package/agents/discord/skills/discord/tools/create_thread/index.js +29 -0
- package/agents/discord/skills/discord/tools/create_thread/index.ts +28 -0
- package/agents/discord/skills/discord/tools/forum_post/index.js +33 -0
- package/agents/discord/skills/discord/tools/forum_post/index.ts +33 -0
- package/agents/discord/skills/discord/tools/list_roles/index.js +28 -0
- package/agents/discord/skills/discord/tools/list_roles/index.ts +34 -0
- package/agents/discord/skills/discord/tools/react/index.js +24 -0
- package/agents/discord/skills/discord/tools/react/index.ts +24 -0
- package/agents/discord/skills/discord/tools/remove_role/index.js +24 -0
- package/agents/discord/skills/discord/tools/remove_role/index.ts +26 -0
- package/agents/discord/skills/discord/tools/send_embed/index.js +43 -0
- package/agents/discord/skills/discord/tools/send_embed/index.ts +38 -0
- package/agents/discord/system.md +3 -0
- package/commands/discord/endpoint/add/[id]/index.js +3 -0
- package/commands/discord/endpoint/add/[id]/index.ts +3 -0
- package/commands/discord/endpoint/definition.js +19 -0
- package/commands/discord/endpoint/definition.ts +19 -0
- package/commands/discord/endpoint/list/index.js +3 -0
- package/commands/discord/endpoint/list/index.ts +3 -0
- package/commands/discord/endpoint/remove/[id]/index.js +3 -0
- package/commands/discord/endpoint/remove/[id]/index.ts +3 -0
- package/lib/client.d.ts +16 -0
- package/lib/client.js +8 -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 +145 -0
- package/lib/protocol.js +320 -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 +74 -30
- package/plugin.js +19 -0
- package/schema.json +205 -0
- package/src/client.ts +24 -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 +57 -323
- package/src/platform-permit.ts +57 -0
- package/src/protocol.ts +475 -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/skills/discord/SKILL.md +0 -104
- 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/PERMITS.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Discord Platform Permits
|
|
2
|
+
|
|
3
|
+
## 入站字段
|
|
4
|
+
|
|
5
|
+
Guild 频道消息从 `msg.member.permissions` bitfield 解析:
|
|
6
|
+
|
|
7
|
+
| 字段 | 取值 |
|
|
8
|
+
|------|------|
|
|
9
|
+
| `$sender.role` | `owner`(`guild.ownerId === author.id`)· `member` |
|
|
10
|
+
| `$sender.permissions` | `guild_owner` · `ADMINISTRATOR` · `MANAGE_ROLES` · `MODERATE_MEMBERS` · `MANAGE_CHANNELS` · … |
|
|
11
|
+
|
|
12
|
+
需 `GuildMembers` intent;缺失时 checker 保守拒绝。
|
|
13
|
+
|
|
14
|
+
## Permit 词汇表
|
|
15
|
+
|
|
16
|
+
| `platform(discord,…)` | 含义 |
|
|
17
|
+
|-----------------------|------|
|
|
18
|
+
| `guild_owner` | 服务器主 |
|
|
19
|
+
| `moderate_members` | 踢人/禁言 |
|
|
20
|
+
| `manage_roles` | 管理身份组 |
|
|
21
|
+
| `manage_channels` | 管理频道/线程 |
|
|
22
|
+
|
|
23
|
+
## 工厂映射
|
|
24
|
+
|
|
25
|
+
`scene_admin` → `moderate_members` · `scene_owner` → `guild_owner`
|
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# @zhin.js/adapter-discord
|
|
2
2
|
|
|
3
|
-
Zhin.js Discord
|
|
3
|
+
Zhin.js Discord 适配器(Plugin Runtime),默认通过 **Gateway WebSocket**(discord.js)收发消息(无需 host-router / host-http)。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 功能
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
7
|
+
- Gateway WebSocket 入站(默认;无需公网 HTTPS / host)
|
|
8
|
+
- 解析 text / mention / attachment / embed / sticker / button
|
|
9
|
+
- 支持私聊、群组与服务器频道
|
|
10
|
+
- 出站 `send({ conversation, payload })` → Discord channel message(Markdown content / media / embed / keyboard)
|
|
11
|
+
- 约定式 `defineAdapter` / `definePlugin`(无需 `usePlugin`)
|
|
12
|
+
- Interactions HTTP webhook 延期(需 `httpHostToken`);配置 `connection: interactions` 会明确报错
|
|
13
13
|
|
|
14
14
|
## 安装
|
|
15
15
|
|
|
@@ -17,89 +17,82 @@ Zhin.js Discord 适配器,支持 Discord 机器人的消息收发和服务器
|
|
|
17
17
|
pnpm add @zhin.js/adapter-discord discord.js
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
## Plugin Runtime
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
- `@zhin.js/adapter` — 约定式 `adapters/discord/index.ts`(`defineAdapter`)
|
|
23
|
+
- `@zhin.js/core` — `Endpoint.emit(...)` 入站、`outboundMessageToken` 出站
|
|
24
|
+
- `zhin.js` — `plugin.ts`(`definePlugin`)
|
|
25
|
+
- 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`
|
|
26
|
+
- **无需** `@zhin.js/host-http` / `@zhin.js/host-router`(Gateway 路径)
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
入站:`gateway.receive({ conversation, message, content: text, sender, metadata })`(`conversation` 为 `ConversationRef`,guild 频道带 `parent` guild 容器)
|
|
29
|
+
出站:`send({ conversation, payload })` → discord.js channel.send
|
|
25
30
|
|
|
26
|
-
###
|
|
31
|
+
### 平台权限(platform permit)
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- "@zhin.js/adapter-discord"
|
|
31
|
-
|
|
32
|
-
bots:
|
|
33
|
-
- context: discord
|
|
34
|
-
connection: gateway
|
|
35
|
-
name: my-discord-bot
|
|
36
|
-
token: "${DISCORD_BOT_TOKEN}"
|
|
37
|
-
# 可选: intents, enableSlashCommands, defaultActivity, slashCommands
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### Interactions(connection: interactions)
|
|
41
|
-
|
|
42
|
-
```yaml
|
|
43
|
-
plugins:
|
|
44
|
-
- "@zhin.js/http"
|
|
45
|
-
- "@zhin.js/adapter-discord"
|
|
46
|
-
|
|
47
|
-
bots:
|
|
48
|
-
- context: discord
|
|
49
|
-
connection: interactions
|
|
50
|
-
name: my-discord-bot
|
|
51
|
-
token: "${DISCORD_BOT_TOKEN}"
|
|
52
|
-
applicationId: "${DISCORD_APP_ID}"
|
|
53
|
-
publicKey: "${DISCORD_PUBLIC_KEY}"
|
|
54
|
-
interactionsPath: "/discord/interactions"
|
|
55
|
-
```
|
|
33
|
+
- sender role 已恢复:Gateway 入站 `metadata.role` / `metadata.permissions`(来自 member 权限位与 guild owner 判定,见 `src/gateway.ts` `resolveSenderRole`)。
|
|
34
|
+
- `plugin.ts` 在 generation setup 注册 checker,并在 dispose 注销;Plugin Runtime CapabilityIngress 与 ToolSystem 统一经 Core `canAccessTool()` 消费 `permissions`。
|
|
56
35
|
|
|
57
|
-
|
|
36
|
+
## 前置条件
|
|
58
37
|
|
|
59
|
-
|
|
38
|
+
| 要求 | 说明 |
|
|
39
|
+
|------|------|
|
|
40
|
+
| **Bot Token** | [Discord Developer Portal](https://discord.com/developers/applications) 创建应用并获取 Token |
|
|
41
|
+
| **MESSAGE CONTENT INTENT** | 需开启才能读取消息正文 |
|
|
42
|
+
| **Gateway(默认)** | 本地/生产均可;discord.js 连接 Gateway,无需公网 HTTPS |
|
|
43
|
+
| **host-http** | Gateway **不需要**;Interactions webhook 延期至下一棒 |
|
|
60
44
|
|
|
61
|
-
|
|
45
|
+
必填字段(`endpoints[i]`):`id`、`token`。
|
|
62
46
|
|
|
63
|
-
|
|
64
|
-
import { usePlugin, MessageCommand } from 'zhin.js'
|
|
47
|
+
## 最小配置
|
|
65
48
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
49
|
+
```yaml
|
|
50
|
+
# zhin.config.yml(Plugin Runtime)
|
|
51
|
+
plugins:
|
|
52
|
+
discord:
|
|
53
|
+
# connection: gateway # 默认
|
|
54
|
+
endpoints:
|
|
55
|
+
- id: my-discord-bot
|
|
56
|
+
token: ${DISCORD_BOT_TOKEN}
|
|
73
57
|
```
|
|
74
58
|
|
|
75
|
-
|
|
59
|
+
根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-discord`(`instanceKey: discord`)。
|
|
76
60
|
|
|
77
|
-
|
|
78
|
-
import { usePlugin } from 'zhin.js'
|
|
61
|
+
## 环境变量
|
|
79
62
|
|
|
80
|
-
|
|
63
|
+
| 变量 | 说明 |
|
|
64
|
+
|------|------|
|
|
65
|
+
| `DISCORD_BOT_TOKEN` | YAML 示例中 `token` 引用的 Bot Token |
|
|
81
66
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
await next()
|
|
87
|
-
})
|
|
88
|
-
```
|
|
67
|
+
## Interactions(HTTP)
|
|
68
|
+
|
|
69
|
+
`connection: interactions` 经 `httpHostToken` 注册 POST 路由(默认 `/discord/interactions`),Ed25519 验签后处理 PING 与 slash command;出站走 Discord REST `channels/.../messages`。需配置 `applicationId` 与 `publicKey`。
|
|
89
70
|
|
|
90
71
|
## AI 工具(Skill)
|
|
91
72
|
|
|
92
|
-
|
|
73
|
+
| 类别 | 路径 |
|
|
74
|
+
|------|------|
|
|
75
|
+
| Permit 词汇 | `PERMITS.md` |
|
|
76
|
+
| 平台工具(7 个) | `agents/discord/skills/discord/tools/`(Skill 激活后披露 `discord_*`:角色、Embed、反应等) |
|
|
77
|
+
| 技能说明 | `agents/discord/skills/discord/SKILL.md` |
|
|
93
78
|
|
|
94
|
-
|
|
79
|
+
工具使用 Discord Snowflake ID 标识 `guild_id`、`user_id`、`channel_id`。
|
|
95
80
|
|
|
96
81
|
## Discord 开发者配置
|
|
97
82
|
|
|
98
83
|
1. 前往 [Discord Developer Portal](https://discord.com/developers/applications)
|
|
99
84
|
2. 创建应用并获取 Bot Token
|
|
100
|
-
3. 开启 **MESSAGE CONTENT INTENT
|
|
85
|
+
3. 开启 **MESSAGE CONTENT INTENT**
|
|
101
86
|
4. 通过 OAuth2 URL 邀请 Bot 加入服务器
|
|
102
|
-
|
|
87
|
+
|
|
88
|
+
## 故障排查
|
|
89
|
+
|
|
90
|
+
| 现象 | 排查 |
|
|
91
|
+
| --- | --- |
|
|
92
|
+
| Gateway 反复断线 | 检查 Token、网络代理、Gateway Intents 与应用后台配置 |
|
|
93
|
+
| 能上线但收不到正文 | 启用 Message Content Intent,并给 Bot 频道读取权限 |
|
|
94
|
+
| 能收不能发 | 检查 Send Messages、Embed Links 与附件权限 |
|
|
95
|
+
| `connection: interactions` 启动失败 | 当前生产路径使用 Gateway;改回 `gateway` |
|
|
103
96
|
|
|
104
97
|
## 许可证
|
|
105
98
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
/**
|
|
3
|
+
* Convention entry: discover `adapters/discord/index.ts` → defineAdapter.
|
|
4
|
+
*/
|
|
5
|
+
import { defineAdapter } from 'zhin.js/adapter';
|
|
6
|
+
import { httpHostToken } from '@zhin.js/host-http';
|
|
7
|
+
import { DiscordGatewayEndpoint, DiscordInteractionsEndpoint, } from "../../lib/endpoint.js";
|
|
8
|
+
import { resolveDiscordConfig, } from "../../lib/protocol.js";
|
|
9
|
+
import { discordRuntimeStateToken } from "../../lib/discord-runtime-state.js";
|
|
10
|
+
export { DiscordGatewayEndpoint, DiscordInteractionsEndpoint, } from "../../lib/endpoint.js";
|
|
11
|
+
export default defineAdapter({
|
|
12
|
+
capabilities: ['inbound', 'outbound'],
|
|
13
|
+
operations: (context) => context.config.connection === 'interactions'
|
|
14
|
+
? ['recall']
|
|
15
|
+
: ['recall', 'reaction'],
|
|
16
|
+
// 媒体 url 直发或由 AttachmentBuilder 物化本地文件上传;message components 原生按钮承载交互段。
|
|
17
|
+
segments: {
|
|
18
|
+
outboundMedia: ['url', 'upload'],
|
|
19
|
+
interactive: 'native',
|
|
20
|
+
markdown: 'native',
|
|
21
|
+
},
|
|
22
|
+
create(context) {
|
|
23
|
+
const config = resolveDiscordConfig(context.config);
|
|
24
|
+
// 注册到插件运行时状态(discord endpoint list 的"运行中"数据源)
|
|
25
|
+
context.use(discordRuntimeStateToken).endpoints.set(config.id, {
|
|
26
|
+
id: config.id,
|
|
27
|
+
mode: config.connection,
|
|
28
|
+
});
|
|
29
|
+
if (config.connection === 'interactions') {
|
|
30
|
+
return new DiscordInteractionsEndpoint({
|
|
31
|
+
id: context.id,
|
|
32
|
+
http: context.use(httpHostToken),
|
|
33
|
+
config,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return new DiscordGatewayEndpoint({
|
|
37
|
+
id: context.id,
|
|
38
|
+
config,
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convention entry: discover `adapters/discord/index.ts` → defineAdapter.
|
|
3
|
+
*/
|
|
4
|
+
import { defineAdapter } from 'zhin.js/adapter';
|
|
5
|
+
import { httpHostToken } from '@zhin.js/host-http';
|
|
6
|
+
import {
|
|
7
|
+
DiscordGatewayEndpoint,
|
|
8
|
+
DiscordInteractionsEndpoint,
|
|
9
|
+
} from '../../src/endpoint.js';
|
|
10
|
+
import {
|
|
11
|
+
resolveDiscordConfig,
|
|
12
|
+
type DiscordEndpointConfig,
|
|
13
|
+
} from '../../src/protocol.js';
|
|
14
|
+
import { discordRuntimeStateToken } from '../../src/discord-runtime-state.js';
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
DiscordGatewayEndpoint,
|
|
18
|
+
DiscordInteractionsEndpoint,
|
|
19
|
+
} from '../../src/endpoint.js';
|
|
20
|
+
export type {
|
|
21
|
+
CreateDiscordClient,
|
|
22
|
+
DiscordClientTransport,
|
|
23
|
+
DiscordEndpointOptions,
|
|
24
|
+
DiscordInteractionsEndpointOptions,
|
|
25
|
+
} from '../../src/endpoint.js';
|
|
26
|
+
|
|
27
|
+
export default defineAdapter<DiscordEndpointConfig>({
|
|
28
|
+
capabilities: ['inbound', 'outbound'],
|
|
29
|
+
operations: (context) => context.config.connection === 'interactions'
|
|
30
|
+
? ['recall']
|
|
31
|
+
: ['recall', 'reaction'],
|
|
32
|
+
// 媒体 url 直发或由 AttachmentBuilder 物化本地文件上传;message components 原生按钮承载交互段。
|
|
33
|
+
segments: {
|
|
34
|
+
outboundMedia: ['url', 'upload'],
|
|
35
|
+
interactive: 'native',
|
|
36
|
+
markdown: 'native',
|
|
37
|
+
},
|
|
38
|
+
create(context) {
|
|
39
|
+
const config = resolveDiscordConfig(context.config);
|
|
40
|
+
// 注册到插件运行时状态(discord endpoint list 的"运行中"数据源)
|
|
41
|
+
context.use(discordRuntimeStateToken).endpoints.set(config.id, {
|
|
42
|
+
id: config.id,
|
|
43
|
+
mode: config.connection,
|
|
44
|
+
});
|
|
45
|
+
if (config.connection === 'interactions') {
|
|
46
|
+
return new DiscordInteractionsEndpoint({
|
|
47
|
+
id: context.id,
|
|
48
|
+
http: context.use(httpHostToken),
|
|
49
|
+
config,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return new DiscordGatewayEndpoint({
|
|
53
|
+
id: context.id,
|
|
54
|
+
config,
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "DISCORD Platform Agent",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Handles discord platform-specific operations and progressively loads only the required platform Skill.",
|
|
5
|
+
"trigger_rules": {
|
|
6
|
+
"file_patterns": [],
|
|
7
|
+
"keywords": [
|
|
8
|
+
"discord",
|
|
9
|
+
"adapter:discord"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"entry_points": [
|
|
13
|
+
"system.md",
|
|
14
|
+
"boundaries.md",
|
|
15
|
+
"conventions.md"
|
|
16
|
+
],
|
|
17
|
+
"platforms": [
|
|
18
|
+
"discord"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: discord
|
|
3
|
+
platforms: [discord]
|
|
4
|
+
description: Discord 角色、线程、论坛帖子、反应和 Embed 操作能力。
|
|
5
|
+
keywords: [discord, role, thread, forum, reaction, embed]
|
|
6
|
+
tags: [adapter, community]
|
|
7
|
+
tools:
|
|
8
|
+
- add_role
|
|
9
|
+
- remove_role
|
|
10
|
+
- list_roles
|
|
11
|
+
- create_thread
|
|
12
|
+
- react
|
|
13
|
+
- send_embed
|
|
14
|
+
- forum_post
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Discord
|
|
18
|
+
|
|
19
|
+
按“先查询、后修改”执行:授予或移除角色前先用 `list_roles` 找到角色 ID;创建线程或论坛帖子时使用当前频道上下文;发送结构化内容时使用 `send_embed`;表情回应使用 `react`。
|
|
20
|
+
|
|
21
|
+
当前 Agent Tool 不提供踢人、封禁、禁言、改昵称或成员列表操作,不要声称已经执行这些动作。
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
5
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
6
|
+
export default defineAgentTool({
|
|
7
|
+
description: '给成员添加 Discord 角色',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
guild_id: z.string().describe('服务器 ID'),
|
|
10
|
+
user_id: z.string().describe('用户 ID'),
|
|
11
|
+
role_id: z.string().describe('角色 ID'),
|
|
12
|
+
}),
|
|
13
|
+
adapter: 'discord',
|
|
14
|
+
tags: ['discord'],
|
|
15
|
+
permissions: [platformPermission('discord', 'manage_roles')],
|
|
16
|
+
async execute({ guild_id, user_id, role_id }, context) {
|
|
17
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
18
|
+
const guild = await client.guilds.fetch(guild_id);
|
|
19
|
+
const member = await guild.members.fetch(user_id);
|
|
20
|
+
await member.roles.add(role_id);
|
|
21
|
+
const success = true;
|
|
22
|
+
return { success, message: success ? `已给用户 ${user_id} 添加角色` : '操作失败' };
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
|
+
|
|
6
|
+
export default defineAgentTool<{ guild_id: string; user_id: string; role_id: string }>({
|
|
7
|
+
description: '给成员添加 Discord 角色',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
guild_id: z.string().describe('服务器 ID'),
|
|
10
|
+
user_id: z.string().describe('用户 ID'),
|
|
11
|
+
role_id: z.string().describe('角色 ID'),
|
|
12
|
+
}),
|
|
13
|
+
adapter: 'discord',
|
|
14
|
+
tags: ['discord'],
|
|
15
|
+
permissions: [platformPermission('discord', 'manage_roles')],
|
|
16
|
+
async execute({ guild_id, user_id, role_id }: { guild_id: string; user_id: string; role_id: string }, context) {
|
|
17
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
18
|
+
const guild = await client.guilds.fetch(guild_id);
|
|
19
|
+
const member = await guild.members.fetch(user_id) as {
|
|
20
|
+
roles: { add(id: string): Promise<unknown> };
|
|
21
|
+
};
|
|
22
|
+
await member.roles.add(role_id);
|
|
23
|
+
const success = true;
|
|
24
|
+
return { success, message: success ? `已给用户 ${user_id} 添加角色` : '操作失败' };
|
|
25
|
+
},
|
|
26
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
5
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
6
|
+
export default defineAgentTool({
|
|
7
|
+
description: '在 Discord 频道中创建帖子/子线程',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
channel_id: z.string().describe('频道 ID'),
|
|
10
|
+
name: z.string().describe('帖子标题'),
|
|
11
|
+
message_id: z.string().optional().describe('基于某条消息创建(可选)'),
|
|
12
|
+
auto_archive_duration: z.number().optional().describe('自动归档时间(分钟:60/1440/4320/10080)'),
|
|
13
|
+
}),
|
|
14
|
+
adapter: 'discord',
|
|
15
|
+
tags: ['discord'],
|
|
16
|
+
permissions: [platformPermission('discord', 'manage_channels')],
|
|
17
|
+
async execute({ channel_id, name, message_id, auto_archive_duration }, context) {
|
|
18
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
19
|
+
const channel = await client.channels.fetch(channel_id);
|
|
20
|
+
if (!channel?.threads)
|
|
21
|
+
throw new Error(`Channel ${channel_id} 不支持创建帖子`);
|
|
22
|
+
const thread = await channel.threads.create({
|
|
23
|
+
name,
|
|
24
|
+
autoArchiveDuration: auto_archive_duration || 1440,
|
|
25
|
+
...(message_id ? { startMessage: message_id } : {}),
|
|
26
|
+
});
|
|
27
|
+
return { success: true, thread_id: thread.id, message: `帖子 "${name}" 已创建` };
|
|
28
|
+
},
|
|
29
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
|
+
|
|
6
|
+
export default defineAgentTool<{ channel_id: string; name: string; message_id?: string; auto_archive_duration?: number }>({
|
|
7
|
+
description: '在 Discord 频道中创建帖子/子线程',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
channel_id: z.string().describe('频道 ID'),
|
|
10
|
+
name: z.string().describe('帖子标题'),
|
|
11
|
+
message_id: z.string().optional().describe('基于某条消息创建(可选)'),
|
|
12
|
+
auto_archive_duration: z.number().optional().describe('自动归档时间(分钟:60/1440/4320/10080)'),
|
|
13
|
+
}),
|
|
14
|
+
adapter: 'discord',
|
|
15
|
+
tags: ['discord'],
|
|
16
|
+
permissions: [platformPermission('discord', 'manage_channels')],
|
|
17
|
+
async execute({ channel_id, name, message_id, auto_archive_duration }: { channel_id: string; name: string; message_id?: string; auto_archive_duration?: number }, context) {
|
|
18
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
19
|
+
const channel = await client.channels.fetch(channel_id);
|
|
20
|
+
if (!channel?.threads) throw new Error(`Channel ${channel_id} 不支持创建帖子`);
|
|
21
|
+
const thread = await channel.threads.create({
|
|
22
|
+
name,
|
|
23
|
+
autoArchiveDuration: auto_archive_duration || 1440,
|
|
24
|
+
...(message_id ? { startMessage: message_id } : {}),
|
|
25
|
+
});
|
|
26
|
+
return { success: true, thread_id: thread.id, message: `帖子 "${name}" 已创建` };
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
5
|
+
import { ChannelType } from 'discord.js';
|
|
6
|
+
export default defineAgentTool({
|
|
7
|
+
description: '在 Discord 论坛频道中创建帖子',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
channel_id: z.string().describe('论坛频道 ID'),
|
|
10
|
+
name: z.string().describe('帖子标题'),
|
|
11
|
+
content: z.string().describe('帖子内容'),
|
|
12
|
+
tags: z.string().optional().describe('标签名,逗号分隔(可选)'),
|
|
13
|
+
}),
|
|
14
|
+
adapter: 'discord',
|
|
15
|
+
tags: ['discord'],
|
|
16
|
+
async execute({ channel_id, name, content, tags }, context) {
|
|
17
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
18
|
+
const tagList = tags ? tags.split(',').map((t) => t.trim()) : undefined;
|
|
19
|
+
const channel = await client.channels.fetch(channel_id);
|
|
20
|
+
if (!channel?.threads || channel.type !== ChannelType.GuildForum) {
|
|
21
|
+
throw new Error(`Channel ${channel_id} 不是论坛频道`);
|
|
22
|
+
}
|
|
23
|
+
const tagIds = tagList?.length
|
|
24
|
+
? channel.availableTags?.filter((tag) => tagList.includes(tag.name)).map((tag) => tag.id)
|
|
25
|
+
: undefined;
|
|
26
|
+
const thread = await channel.threads.create({
|
|
27
|
+
name,
|
|
28
|
+
message: { content },
|
|
29
|
+
...(tagIds?.length ? { appliedTags: tagIds } : {}),
|
|
30
|
+
});
|
|
31
|
+
return { success: true, thread_id: thread.id, message: `论坛帖 "${name}" 已创建` };
|
|
32
|
+
},
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
4
|
+
import { ChannelType } from 'discord.js';
|
|
5
|
+
|
|
6
|
+
export default defineAgentTool<{ channel_id: string; name: string; content: string; tags?: string }>({
|
|
7
|
+
description: '在 Discord 论坛频道中创建帖子',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
channel_id: z.string().describe('论坛频道 ID'),
|
|
10
|
+
name: z.string().describe('帖子标题'),
|
|
11
|
+
content: z.string().describe('帖子内容'),
|
|
12
|
+
tags: z.string().optional().describe('标签名,逗号分隔(可选)'),
|
|
13
|
+
}),
|
|
14
|
+
adapter: 'discord',
|
|
15
|
+
tags: ['discord'],
|
|
16
|
+
async execute({ channel_id, name, content, tags }: { channel_id: string; name: string; content: string; tags?: string }, context) {
|
|
17
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
18
|
+
const tagList = tags ? tags.split(',').map((t: string) => t.trim()) : undefined;
|
|
19
|
+
const channel = await client.channels.fetch(channel_id);
|
|
20
|
+
if (!channel?.threads || channel.type !== ChannelType.GuildForum) {
|
|
21
|
+
throw new Error(`Channel ${channel_id} 不是论坛频道`);
|
|
22
|
+
}
|
|
23
|
+
const tagIds = tagList?.length
|
|
24
|
+
? channel.availableTags?.filter((tag) => tagList.includes(tag.name)).map((tag) => tag.id)
|
|
25
|
+
: undefined;
|
|
26
|
+
const thread = await channel.threads.create({
|
|
27
|
+
name,
|
|
28
|
+
message: { content },
|
|
29
|
+
...(tagIds?.length ? { appliedTags: tagIds } : {}),
|
|
30
|
+
});
|
|
31
|
+
return { success: true, thread_id: thread.id, message: `论坛帖 "${name}" 已创建` };
|
|
32
|
+
},
|
|
33
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
5
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
6
|
+
export default defineAgentTool({
|
|
7
|
+
description: '获取 Discord 服务器角色列表',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
guild_id: z.string().describe('服务器 ID'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'discord',
|
|
12
|
+
tags: ['discord'],
|
|
13
|
+
permissions: [platformPermission('discord', 'manage_roles')],
|
|
14
|
+
async execute({ guild_id }, context) {
|
|
15
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
16
|
+
const guild = await client.guilds.fetch(guild_id);
|
|
17
|
+
await guild.roles.fetch();
|
|
18
|
+
const cache = guild.roles.cache;
|
|
19
|
+
const roles = [...cache.values()].map((role) => ({
|
|
20
|
+
id: role.id,
|
|
21
|
+
name: role.name,
|
|
22
|
+
color: role.hexColor,
|
|
23
|
+
position: role.position,
|
|
24
|
+
permissions: role.permissions.bitfield.toString(),
|
|
25
|
+
}));
|
|
26
|
+
return { roles, count: roles.length };
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
|
+
|
|
6
|
+
export default defineAgentTool<{ guild_id: string }>({
|
|
7
|
+
description: '获取 Discord 服务器角色列表',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
guild_id: z.string().describe('服务器 ID'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'discord',
|
|
12
|
+
tags: ['discord'],
|
|
13
|
+
permissions: [platformPermission('discord', 'manage_roles')],
|
|
14
|
+
async execute({ guild_id }: { guild_id: string }, context) {
|
|
15
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
16
|
+
const guild = await client.guilds.fetch(guild_id);
|
|
17
|
+
await guild.roles.fetch();
|
|
18
|
+
const cache = guild.roles.cache as Map<string, {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
hexColor: string;
|
|
22
|
+
position: number;
|
|
23
|
+
permissions: { bitfield: bigint };
|
|
24
|
+
}>;
|
|
25
|
+
const roles = [...cache.values()].map((role) => ({
|
|
26
|
+
id: role.id,
|
|
27
|
+
name: role.name,
|
|
28
|
+
color: role.hexColor,
|
|
29
|
+
position: role.position,
|
|
30
|
+
permissions: role.permissions.bitfield.toString(),
|
|
31
|
+
}));
|
|
32
|
+
return { roles, count: roles.length };
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
5
|
+
export default defineAgentTool({
|
|
6
|
+
description: '对 Discord 消息添加表情反应',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
channel_id: z.string().describe('频道 ID'),
|
|
9
|
+
message_id: z.string().describe('消息 ID'),
|
|
10
|
+
emoji: z.string().describe('表情(Unicode 表情或自定义表情如 <:name:id>)'),
|
|
11
|
+
}),
|
|
12
|
+
adapter: 'discord',
|
|
13
|
+
tags: ['discord'],
|
|
14
|
+
async execute({ channel_id, message_id, emoji }, context) {
|
|
15
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
16
|
+
const channel = await client.channels.fetch(channel_id);
|
|
17
|
+
if (!channel?.isTextBased() || !channel.messages) {
|
|
18
|
+
throw new Error(`Channel ${channel_id} 不是文本频道`);
|
|
19
|
+
}
|
|
20
|
+
const message = await channel.messages.fetch(message_id);
|
|
21
|
+
await message.react(emoji);
|
|
22
|
+
return { success: true, message: `已添加反应 ${emoji}` };
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
4
|
+
|
|
5
|
+
export default defineAgentTool<{ channel_id: string; message_id: string; emoji: string }>({
|
|
6
|
+
description: '对 Discord 消息添加表情反应',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
channel_id: z.string().describe('频道 ID'),
|
|
9
|
+
message_id: z.string().describe('消息 ID'),
|
|
10
|
+
emoji: z.string().describe('表情(Unicode 表情或自定义表情如 <:name:id>)'),
|
|
11
|
+
}),
|
|
12
|
+
adapter: 'discord',
|
|
13
|
+
tags: ['discord'],
|
|
14
|
+
async execute({ channel_id, message_id, emoji }: { channel_id: string; message_id: string; emoji: string }, context) {
|
|
15
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
16
|
+
const channel = await client.channels.fetch(channel_id);
|
|
17
|
+
if (!channel?.isTextBased() || !channel.messages) {
|
|
18
|
+
throw new Error(`Channel ${channel_id} 不是文本频道`);
|
|
19
|
+
}
|
|
20
|
+
const message = await channel.messages.fetch(message_id);
|
|
21
|
+
await message.react(emoji);
|
|
22
|
+
return { success: true, message: `已添加反应 ${emoji}` };
|
|
23
|
+
},
|
|
24
|
+
});
|