@zhin.js/adapter-discord 1.0.53 → 1.0.55
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 +14 -0
- package/README.md +26 -44
- package/lib/adapter.d.ts +20 -0
- package/lib/adapter.d.ts.map +1 -0
- package/lib/adapter.js +320 -0
- package/lib/adapter.js.map +1 -0
- package/lib/bot-interactions.d.ts +33 -0
- package/lib/bot-interactions.d.ts.map +1 -0
- package/lib/bot-interactions.js +278 -0
- package/lib/bot-interactions.js.map +1 -0
- package/lib/bot.d.ts +117 -0
- package/lib/bot.d.ts.map +1 -0
- package/lib/bot.js +904 -0
- package/lib/bot.js.map +1 -0
- package/lib/index.d.ts +5 -195
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +11 -1471
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +49 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -4,10 +4,11 @@ Zhin.js Discord 适配器,支持 Discord 机器人的消息收发和服务器
|
|
|
4
4
|
|
|
5
5
|
## 功能特性
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
7
|
+
- 📦 **单一适配器**:`context: discord`,通过 `connection` 选择连接方式
|
|
8
|
+
- 🌐 **Gateway**(`connection: gateway`):WebSocket 网关,支持群管、消息、斜杠命令等
|
|
9
|
+
- 📮 **Interactions**(`connection: interactions`):HTTP 交互端点,斜杠命令等
|
|
9
10
|
- 可配置 Intents 和默认活动状态
|
|
10
|
-
- 服务器管理 AI
|
|
11
|
+
- 服务器管理 AI 工具(仅 Gateway 支持)
|
|
11
12
|
- 基于 discord.js 库
|
|
12
13
|
|
|
13
14
|
## 安装
|
|
@@ -16,63 +17,44 @@ Zhin.js Discord 适配器,支持 Discord 机器人的消息收发和服务器
|
|
|
16
17
|
pnpm add @zhin.js/adapter-discord discord.js
|
|
17
18
|
```
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
- `@zhin.js/http` — HTTP 服务(Interactions 模式需要)
|
|
20
|
+
Interactions 模式需同时启用 `@zhin.js/http`。
|
|
22
21
|
|
|
23
22
|
## 配置
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
所有 Bot 使用 **同一 context:`discord`**,通过 **`connection`** 区分连接方式。
|
|
25
|
+
|
|
26
|
+
### Gateway(connection: gateway,默认)
|
|
26
27
|
|
|
27
28
|
```yaml
|
|
28
|
-
|
|
29
|
+
plugins:
|
|
30
|
+
- "@zhin.js/adapter-discord"
|
|
31
|
+
|
|
29
32
|
bots:
|
|
30
33
|
- context: discord
|
|
34
|
+
connection: gateway
|
|
31
35
|
name: my-discord-bot
|
|
32
|
-
token: ${DISCORD_BOT_TOKEN}
|
|
33
|
-
#
|
|
34
|
-
# intents:
|
|
35
|
-
# - Guilds
|
|
36
|
-
# - GuildMessages
|
|
37
|
-
# - MessageContent
|
|
38
|
-
# enableSlashCommands: true
|
|
39
|
-
# defaultActivity:
|
|
40
|
-
# name: Zhin.js
|
|
41
|
-
# type: Playing
|
|
42
|
-
|
|
43
|
-
plugins:
|
|
44
|
-
- adapter-discord
|
|
45
|
-
- http
|
|
36
|
+
token: "${DISCORD_BOT_TOKEN}"
|
|
37
|
+
# 可选: intents, enableSlashCommands, defaultActivity, slashCommands
|
|
46
38
|
```
|
|
47
39
|
|
|
48
|
-
### Interactions
|
|
40
|
+
### Interactions(connection: interactions)
|
|
49
41
|
|
|
50
42
|
```yaml
|
|
43
|
+
plugins:
|
|
44
|
+
- "@zhin.js/http"
|
|
45
|
+
- "@zhin.js/adapter-discord"
|
|
46
|
+
|
|
51
47
|
bots:
|
|
52
|
-
- context: discord
|
|
48
|
+
- context: discord
|
|
49
|
+
connection: interactions
|
|
53
50
|
name: my-discord-bot
|
|
54
|
-
token: ${DISCORD_BOT_TOKEN}
|
|
55
|
-
applicationId: ${DISCORD_APP_ID}
|
|
56
|
-
publicKey: ${DISCORD_PUBLIC_KEY}
|
|
57
|
-
interactionsPath: /discord/interactions
|
|
51
|
+
token: "${DISCORD_BOT_TOKEN}"
|
|
52
|
+
applicationId: "${DISCORD_APP_ID}"
|
|
53
|
+
publicKey: "${DISCORD_PUBLIC_KEY}"
|
|
54
|
+
interactionsPath: "/discord/interactions"
|
|
58
55
|
```
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
```typescript
|
|
63
|
-
import { defineConfig } from 'zhin.js'
|
|
64
|
-
|
|
65
|
-
export default defineConfig({
|
|
66
|
-
bots: [
|
|
67
|
-
{
|
|
68
|
-
context: 'discord',
|
|
69
|
-
name: 'my-discord-bot',
|
|
70
|
-
token: process.env.DISCORD_BOT_TOKEN!,
|
|
71
|
-
}
|
|
72
|
-
],
|
|
73
|
-
plugins: ['adapter-discord', 'http']
|
|
74
|
-
})
|
|
75
|
-
```
|
|
57
|
+
未写 `connection` 时默认为 `gateway`。
|
|
76
58
|
|
|
77
59
|
## 使用示例
|
|
78
60
|
|
package/lib/adapter.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Adapter, Plugin } from "zhin.js";
|
|
2
|
+
import { DiscordBot } from "./bot.js";
|
|
3
|
+
import { DiscordInteractionsBot } from "./bot-interactions.js";
|
|
4
|
+
import type { DiscordBotConfig } from "./types.js";
|
|
5
|
+
export type DiscordBotLike = DiscordBot | DiscordInteractionsBot;
|
|
6
|
+
export declare class DiscordAdapter extends Adapter<DiscordBotLike> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(plugin: Plugin);
|
|
9
|
+
createBot(config: DiscordBotConfig): DiscordBotLike;
|
|
10
|
+
kickMember(botId: string, sceneId: string, userId: string): Promise<boolean>;
|
|
11
|
+
banMember(botId: string, sceneId: string, userId: string, reason?: string): Promise<boolean>;
|
|
12
|
+
unbanMember(botId: string, sceneId: string, userId: string): Promise<boolean>;
|
|
13
|
+
muteMember(botId: string, sceneId: string, userId: string, duration?: number): Promise<boolean>;
|
|
14
|
+
setMemberNickname(botId: string, sceneId: string, userId: string, nickname: string): Promise<boolean>;
|
|
15
|
+
listMembers(botId: string, sceneId: string): Promise<any[]>;
|
|
16
|
+
getGroupInfo(botId: string, sceneId: string): Promise<any>;
|
|
17
|
+
start(): Promise<void>;
|
|
18
|
+
private registerDiscordPlatformTools;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,OAAO,EACP,MAAM,EAKP,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EACV,gBAAgB,EAGjB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,sBAAsB,CAAC;AAMjE,qBAAa,cAAe,SAAQ,OAAO,CAAC,cAAc,CAAC;;gBAG7C,MAAM,EAAE,MAAM;IAI1B,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,cAAc;IAiB7C,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAOzD,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAOzE,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAO1D,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAM;IAOzE,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAOlF,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAO1C,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAO3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB5B,OAAO,CAAC,4BAA4B;CAkNrC"}
|
package/lib/adapter.js
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { Adapter, createGroupManagementTools, GROUP_MANAGEMENT_SKILL_KEYWORDS, GROUP_MANAGEMENT_SKILL_TAGS, } from "zhin.js";
|
|
2
|
+
import { DiscordBot } from "./bot.js";
|
|
3
|
+
import { DiscordInteractionsBot } from "./bot-interactions.js";
|
|
4
|
+
function isGatewayBot(bot) {
|
|
5
|
+
return bot.$config.connection === "gateway";
|
|
6
|
+
}
|
|
7
|
+
export class DiscordAdapter extends Adapter {
|
|
8
|
+
#router;
|
|
9
|
+
constructor(plugin) {
|
|
10
|
+
super(plugin, "discord", []);
|
|
11
|
+
}
|
|
12
|
+
createBot(config) {
|
|
13
|
+
const connection = config.connection ?? "gateway";
|
|
14
|
+
switch (connection) {
|
|
15
|
+
case "gateway":
|
|
16
|
+
return new DiscordBot(this, config);
|
|
17
|
+
case "interactions":
|
|
18
|
+
if (!this.#router) {
|
|
19
|
+
throw new Error("Discord connection: interactions 需要 router,请安装并在配置中启用 @zhin.js/http");
|
|
20
|
+
}
|
|
21
|
+
return new DiscordInteractionsBot(this, this.#router, config);
|
|
22
|
+
default:
|
|
23
|
+
throw new Error(`Unknown Discord connection: ${config.connection}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async kickMember(botId, sceneId, userId) {
|
|
27
|
+
const bot = this.bots.get(botId);
|
|
28
|
+
if (!bot)
|
|
29
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
30
|
+
if (!isGatewayBot(bot))
|
|
31
|
+
throw new Error("群管仅支持 connection: gateway");
|
|
32
|
+
return bot.kickMember(sceneId, userId);
|
|
33
|
+
}
|
|
34
|
+
async banMember(botId, sceneId, userId, reason) {
|
|
35
|
+
const bot = this.bots.get(botId);
|
|
36
|
+
if (!bot)
|
|
37
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
38
|
+
if (!isGatewayBot(bot))
|
|
39
|
+
throw new Error("群管仅支持 connection: gateway");
|
|
40
|
+
return bot.banMember(sceneId, userId, reason);
|
|
41
|
+
}
|
|
42
|
+
async unbanMember(botId, sceneId, userId) {
|
|
43
|
+
const bot = this.bots.get(botId);
|
|
44
|
+
if (!bot)
|
|
45
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
46
|
+
if (!isGatewayBot(bot))
|
|
47
|
+
throw new Error("群管仅支持 connection: gateway");
|
|
48
|
+
return bot.unbanMember(sceneId, userId);
|
|
49
|
+
}
|
|
50
|
+
async muteMember(botId, sceneId, userId, duration = 600) {
|
|
51
|
+
const bot = this.bots.get(botId);
|
|
52
|
+
if (!bot)
|
|
53
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
54
|
+
if (!isGatewayBot(bot))
|
|
55
|
+
throw new Error("群管仅支持 connection: gateway");
|
|
56
|
+
return bot.timeoutMember(sceneId, userId, duration);
|
|
57
|
+
}
|
|
58
|
+
async setMemberNickname(botId, sceneId, userId, nickname) {
|
|
59
|
+
const bot = this.bots.get(botId);
|
|
60
|
+
if (!bot)
|
|
61
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
62
|
+
if (!isGatewayBot(bot))
|
|
63
|
+
throw new Error("群管仅支持 connection: gateway");
|
|
64
|
+
return bot.setNickname(sceneId, userId, nickname);
|
|
65
|
+
}
|
|
66
|
+
async listMembers(botId, sceneId) {
|
|
67
|
+
const bot = this.bots.get(botId);
|
|
68
|
+
if (!bot)
|
|
69
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
70
|
+
if (!isGatewayBot(bot))
|
|
71
|
+
throw new Error("群管仅支持 connection: gateway");
|
|
72
|
+
return bot.getMembers(sceneId);
|
|
73
|
+
}
|
|
74
|
+
async getGroupInfo(botId, sceneId) {
|
|
75
|
+
const bot = this.bots.get(botId);
|
|
76
|
+
if (!bot)
|
|
77
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
78
|
+
if (!isGatewayBot(bot))
|
|
79
|
+
throw new Error("群管仅支持 connection: gateway");
|
|
80
|
+
return bot.getGuildInfo(sceneId);
|
|
81
|
+
}
|
|
82
|
+
async start() {
|
|
83
|
+
this.#router = this.plugin.inject("router");
|
|
84
|
+
this.plugin.useContext("router", (router) => {
|
|
85
|
+
this.#router = router;
|
|
86
|
+
});
|
|
87
|
+
this.registerDiscordPlatformTools();
|
|
88
|
+
const groupTools = createGroupManagementTools(this, this.name);
|
|
89
|
+
groupTools.forEach((t) => this.addTool(t));
|
|
90
|
+
this.declareSkill({
|
|
91
|
+
description: "Discord 服务器/频道管理:踢人、禁言、封禁、改频道名、查成员等。需先 list_members 获取用户 ID 再执行管理操作。仅 Gateway 连接支持。",
|
|
92
|
+
keywords: GROUP_MANAGEMENT_SKILL_KEYWORDS,
|
|
93
|
+
tags: GROUP_MANAGEMENT_SKILL_TAGS,
|
|
94
|
+
});
|
|
95
|
+
await super.start();
|
|
96
|
+
}
|
|
97
|
+
registerDiscordPlatformTools() {
|
|
98
|
+
this.addTool({
|
|
99
|
+
name: "discord_add_role",
|
|
100
|
+
description: "给成员添加 Discord 角色",
|
|
101
|
+
parameters: {
|
|
102
|
+
type: "object",
|
|
103
|
+
properties: {
|
|
104
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
105
|
+
guild_id: { type: "string", description: "服务器 ID" },
|
|
106
|
+
user_id: { type: "string", description: "用户 ID" },
|
|
107
|
+
role_id: { type: "string", description: "角色 ID" },
|
|
108
|
+
},
|
|
109
|
+
required: ["bot", "guild_id", "user_id", "role_id"],
|
|
110
|
+
},
|
|
111
|
+
platforms: ["discord"],
|
|
112
|
+
scopes: ["channel"],
|
|
113
|
+
permissionLevel: "group_admin",
|
|
114
|
+
execute: async (args) => {
|
|
115
|
+
const { bot: botId, guild_id, user_id, role_id } = args;
|
|
116
|
+
const bot = this.bots.get(botId);
|
|
117
|
+
if (!bot)
|
|
118
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
119
|
+
if (!isGatewayBot(bot))
|
|
120
|
+
throw new Error("此工具仅支持 connection: gateway");
|
|
121
|
+
const success = await bot.addRole(guild_id, user_id, role_id);
|
|
122
|
+
return { success, message: success ? `已给用户 ${user_id} 添加角色` : "操作失败" };
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
this.addTool({
|
|
126
|
+
name: "discord_remove_role",
|
|
127
|
+
description: "移除成员的 Discord 角色",
|
|
128
|
+
parameters: {
|
|
129
|
+
type: "object",
|
|
130
|
+
properties: {
|
|
131
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
132
|
+
guild_id: { type: "string", description: "服务器 ID" },
|
|
133
|
+
user_id: { type: "string", description: "用户 ID" },
|
|
134
|
+
role_id: { type: "string", description: "角色 ID" },
|
|
135
|
+
},
|
|
136
|
+
required: ["bot", "guild_id", "user_id", "role_id"],
|
|
137
|
+
},
|
|
138
|
+
platforms: ["discord"],
|
|
139
|
+
scopes: ["channel"],
|
|
140
|
+
permissionLevel: "group_admin",
|
|
141
|
+
execute: async (args) => {
|
|
142
|
+
const { bot: botId, guild_id, user_id, role_id } = args;
|
|
143
|
+
const bot = this.bots.get(botId);
|
|
144
|
+
if (!bot)
|
|
145
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
146
|
+
if (!isGatewayBot(bot))
|
|
147
|
+
throw new Error("此工具仅支持 connection: gateway");
|
|
148
|
+
const success = await bot.removeRole(guild_id, user_id, role_id);
|
|
149
|
+
return { success, message: success ? `已移除用户 ${user_id} 的角色` : "操作失败" };
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
this.addTool({
|
|
153
|
+
name: "discord_list_roles",
|
|
154
|
+
description: "获取 Discord 服务器角色列表",
|
|
155
|
+
parameters: {
|
|
156
|
+
type: "object",
|
|
157
|
+
properties: {
|
|
158
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
159
|
+
guild_id: { type: "string", description: "服务器 ID" },
|
|
160
|
+
},
|
|
161
|
+
required: ["bot", "guild_id"],
|
|
162
|
+
},
|
|
163
|
+
platforms: ["discord"],
|
|
164
|
+
scopes: ["channel"],
|
|
165
|
+
permissionLevel: "user",
|
|
166
|
+
execute: async (args) => {
|
|
167
|
+
const { bot: botId, guild_id } = args;
|
|
168
|
+
const bot = this.bots.get(botId);
|
|
169
|
+
if (!bot)
|
|
170
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
171
|
+
if (!isGatewayBot(bot))
|
|
172
|
+
throw new Error("此工具仅支持 connection: gateway");
|
|
173
|
+
const roles = await bot.getRoles(guild_id);
|
|
174
|
+
return { roles, count: roles.length };
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
this.addTool({
|
|
178
|
+
name: "discord_create_thread",
|
|
179
|
+
description: "在 Discord 频道中创建帖子/子线程",
|
|
180
|
+
parameters: {
|
|
181
|
+
type: "object",
|
|
182
|
+
properties: {
|
|
183
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
184
|
+
channel_id: { type: "string", description: "频道 ID" },
|
|
185
|
+
name: { type: "string", description: "帖子标题" },
|
|
186
|
+
message_id: { type: "string", description: "基于某条消息创建(可选)" },
|
|
187
|
+
auto_archive_duration: {
|
|
188
|
+
type: "number",
|
|
189
|
+
description: "自动归档时间(分钟:60/1440/4320/10080)",
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
required: ["bot", "channel_id", "name"],
|
|
193
|
+
},
|
|
194
|
+
platforms: ["discord"],
|
|
195
|
+
scopes: ["channel"],
|
|
196
|
+
permissionLevel: "user",
|
|
197
|
+
execute: async (args) => {
|
|
198
|
+
const { bot: botId, channel_id, name, message_id, auto_archive_duration } = args;
|
|
199
|
+
const bot = this.bots.get(botId);
|
|
200
|
+
if (!bot)
|
|
201
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
202
|
+
if (!isGatewayBot(bot))
|
|
203
|
+
throw new Error("此工具仅支持 connection: gateway");
|
|
204
|
+
const thread = await bot.createThread(channel_id, name, message_id, auto_archive_duration);
|
|
205
|
+
return { success: true, thread_id: thread.id, message: `帖子 "${name}" 已创建` };
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
this.addTool({
|
|
209
|
+
name: "discord_react",
|
|
210
|
+
description: "对 Discord 消息添加表情反应",
|
|
211
|
+
parameters: {
|
|
212
|
+
type: "object",
|
|
213
|
+
properties: {
|
|
214
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
215
|
+
channel_id: { type: "string", description: "频道 ID" },
|
|
216
|
+
message_id: { type: "string", description: "消息 ID" },
|
|
217
|
+
emoji: {
|
|
218
|
+
type: "string",
|
|
219
|
+
description: "表情(Unicode 表情或自定义表情如 <:name:id>)",
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
required: ["bot", "channel_id", "message_id", "emoji"],
|
|
223
|
+
},
|
|
224
|
+
platforms: ["discord"],
|
|
225
|
+
scopes: ["channel", "private"],
|
|
226
|
+
permissionLevel: "user",
|
|
227
|
+
execute: async (args) => {
|
|
228
|
+
const { bot: botId, channel_id, message_id, emoji } = args;
|
|
229
|
+
const bot = this.bots.get(botId);
|
|
230
|
+
if (!bot)
|
|
231
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
232
|
+
if (!isGatewayBot(bot))
|
|
233
|
+
throw new Error("此工具仅支持 connection: gateway");
|
|
234
|
+
await bot.addReaction(channel_id, message_id, emoji);
|
|
235
|
+
return { success: true, message: `已添加反应 ${emoji}` };
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
this.addTool({
|
|
239
|
+
name: "discord_send_embed",
|
|
240
|
+
description: "发送 Discord 富文本嵌入消息(Embed)",
|
|
241
|
+
parameters: {
|
|
242
|
+
type: "object",
|
|
243
|
+
properties: {
|
|
244
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
245
|
+
channel_id: { type: "string", description: "频道 ID" },
|
|
246
|
+
title: { type: "string", description: "Embed 标题" },
|
|
247
|
+
description: { type: "string", description: "Embed 描述" },
|
|
248
|
+
color: { type: "number", description: "颜色值(十进制,如 0x00ff00 = 65280)" },
|
|
249
|
+
url: { type: "string", description: "标题链接(可选)" },
|
|
250
|
+
fields: {
|
|
251
|
+
type: "string",
|
|
252
|
+
description: '字段,JSON 格式: [{"name":"k","value":"v","inline":false}]',
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
required: ["bot", "channel_id"],
|
|
256
|
+
},
|
|
257
|
+
platforms: ["discord"],
|
|
258
|
+
scopes: ["channel", "private"],
|
|
259
|
+
permissionLevel: "user",
|
|
260
|
+
execute: async (args) => {
|
|
261
|
+
const { bot: botId, channel_id, title, description, color, url, fields } = args;
|
|
262
|
+
const bot = this.bots.get(botId);
|
|
263
|
+
if (!bot)
|
|
264
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
265
|
+
if (!isGatewayBot(bot))
|
|
266
|
+
throw new Error("此工具仅支持 connection: gateway");
|
|
267
|
+
const embedData = {};
|
|
268
|
+
if (title)
|
|
269
|
+
embedData.title = title;
|
|
270
|
+
if (description)
|
|
271
|
+
embedData.description = description;
|
|
272
|
+
if (color)
|
|
273
|
+
embedData.color = color;
|
|
274
|
+
if (url)
|
|
275
|
+
embedData.url = url;
|
|
276
|
+
if (fields) {
|
|
277
|
+
try {
|
|
278
|
+
embedData.fields = JSON.parse(fields);
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
return { success: false, message: "fields 格式错误,应为 JSON 数组" };
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const msg = await bot.sendEmbed(channel_id, embedData);
|
|
285
|
+
return { success: true, message_id: msg.id, message: "Embed 已发送" };
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
this.addTool({
|
|
289
|
+
name: "discord_forum_post",
|
|
290
|
+
description: "在 Discord 论坛频道中创建帖子",
|
|
291
|
+
parameters: {
|
|
292
|
+
type: "object",
|
|
293
|
+
properties: {
|
|
294
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
295
|
+
channel_id: { type: "string", description: "论坛频道 ID" },
|
|
296
|
+
name: { type: "string", description: "帖子标题" },
|
|
297
|
+
content: { type: "string", description: "帖子内容" },
|
|
298
|
+
tags: { type: "string", description: "标签名,逗号分隔(可选)" },
|
|
299
|
+
},
|
|
300
|
+
required: ["bot", "channel_id", "name", "content"],
|
|
301
|
+
},
|
|
302
|
+
platforms: ["discord"],
|
|
303
|
+
scopes: ["channel"],
|
|
304
|
+
permissionLevel: "user",
|
|
305
|
+
execute: async (args) => {
|
|
306
|
+
const { bot: botId, channel_id, name, content, tags } = args;
|
|
307
|
+
const bot = this.bots.get(botId);
|
|
308
|
+
if (!bot)
|
|
309
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
310
|
+
if (!isGatewayBot(bot))
|
|
311
|
+
throw new Error("此工具仅支持 connection: gateway");
|
|
312
|
+
const tagList = tags ? tags.split(",").map((t) => t.trim()) : undefined;
|
|
313
|
+
const thread = await bot.createForumPost(channel_id, name, content, tagList);
|
|
314
|
+
return { success: true, thread_id: thread.id, message: `论坛帖 "${name}" 已创建` };
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
this.plugin.logger.debug("已注册 Discord 平台服务器管理工具");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,OAAO,EAEP,0BAA0B,EAC1B,+BAA+B,EAC/B,2BAA2B,GAE5B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,UAAU,EAAE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AC;gBACjC,IAAI,CAAC,GAAG;oBAAE,MAAM,IAAI,KAAK,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC;gBAC9C,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;oBAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;gBACtE,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;gBAChF,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,CAAC;YAC/E,CAAC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord Interactions Bot 实现
|
|
3
|
+
*/
|
|
4
|
+
import { Client } from "discord.js";
|
|
5
|
+
import { Bot, Message, SendOptions } from "zhin.js";
|
|
6
|
+
import type { DiscordInteractionsConfig } from "./types.js";
|
|
7
|
+
import type { DiscordAdapter } from "./adapter.js";
|
|
8
|
+
export declare class DiscordInteractionsBot extends Client implements Bot<DiscordInteractionsConfig, any> {
|
|
9
|
+
adapter: DiscordAdapter;
|
|
10
|
+
$config: DiscordInteractionsConfig;
|
|
11
|
+
$connected: boolean;
|
|
12
|
+
private router;
|
|
13
|
+
private slashCommandHandlers;
|
|
14
|
+
get pluginLogger(): import("zhin.js").Logger;
|
|
15
|
+
get $id(): string;
|
|
16
|
+
constructor(adapter: DiscordAdapter, router: import("@zhin.js/http").Router, $config: DiscordInteractionsConfig);
|
|
17
|
+
private setupInteractionsEndpoint;
|
|
18
|
+
private handleInteraction;
|
|
19
|
+
private verifyDiscordSignature;
|
|
20
|
+
private handleApplicationCommand;
|
|
21
|
+
private formatInteractionAsMessage;
|
|
22
|
+
private formatSendContent;
|
|
23
|
+
$connect(): Promise<void>;
|
|
24
|
+
$disconnect(): Promise<void>;
|
|
25
|
+
private registerSlashCommands;
|
|
26
|
+
addSlashCommandHandler(commandName: string, handler: (interaction: any) => Promise<void>): void;
|
|
27
|
+
removeSlashCommandHandler(commandName: string): boolean;
|
|
28
|
+
private getActivityType;
|
|
29
|
+
$formatMessage(msg: any): Message<any>;
|
|
30
|
+
$sendMessage(options: SendOptions): Promise<string>;
|
|
31
|
+
$recallMessage(id: string): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=bot-interactions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot-interactions.d.ts","sourceRoot":"","sources":["../src/bot-interactions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,MAAM,EAiBP,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,EAAwC,MAAM,SAAS,CAAC;AAE1F,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,qBAAa,sBACX,SAAQ,MACR,YAAW,GAAG,CAAC,yBAAyB,EAAE,GAAG,CAAC;IAgB3B,OAAO,EAAE,cAAc;IAAiD,OAAO,EAAE,yBAAyB;IAf7H,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,oBAAoB,CAGd;IAEd,IAAI,YAAY,6BAEf;IAED,IAAI,GAAG,WAEN;gBAEkB,O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