@zhin.js/adapter-discord 8.0.0 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +10 -1
- package/adapters/discord.js +0 -7
- package/adapters/discord.ts +0 -7
- package/agent/tools/add_role.ts +10 -8
- package/agent/tools/create_thread.ts +12 -9
- package/agent/tools/forum_post.ts +18 -9
- package/agent/tools/list_roles.ts +21 -9
- package/agent/tools/react.ts +11 -9
- package/agent/tools/remove_role.ts +10 -8
- package/agent/tools/send_embed.ts +10 -9
- package/lib/client.d.ts +16 -0
- package/lib/client.js +8 -0
- package/lib/discord-endpoint-commands.d.ts +1 -1
- package/lib/endpoint.d.ts +20 -32
- package/lib/endpoint.js +88 -157
- package/lib/gateway.d.ts +1 -0
- package/lib/gateway.js +5 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/protocol.d.ts +1 -1
- package/lib/protocol.js +1 -1
- package/lib/side-event-dispatch.d.ts +2 -2
- package/lib/side-event-dispatch.js +3 -3
- package/lib/webhook.d.ts +1 -0
- package/lib/webhook.js +2 -0
- package/package.json +15 -14
- package/src/client.ts +24 -0
- package/src/endpoint.ts +105 -212
- package/src/gateway.ts +6 -0
- package/src/index.ts +4 -6
- package/src/protocol.ts +1 -1
- package/src/side-event-dispatch.ts +4 -4
- package/src/webhook.ts +2 -0
- package/lib/discord-agent-deps.d.ts +0 -35
- package/lib/discord-agent-deps.js +0 -32
- package/src/discord-agent-deps.ts +0 -79
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent tool deps for discord.
|
|
3
|
-
* Endpoints register themselves on start; tools look up by config name / endpoint id.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export interface DiscordAgentEndpoint {
|
|
7
|
-
addRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
|
|
8
|
-
removeRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
|
|
9
|
-
getRoles(guildId: string): Promise<unknown[]>;
|
|
10
|
-
createThread(
|
|
11
|
-
channelId: string,
|
|
12
|
-
name: string,
|
|
13
|
-
messageId?: string,
|
|
14
|
-
autoArchiveDuration?: number,
|
|
15
|
-
): Promise<{ id: string }>;
|
|
16
|
-
addReaction(channelId: string, messageId: string, emoji: string): Promise<void>;
|
|
17
|
-
sendEmbed(
|
|
18
|
-
channelId: string,
|
|
19
|
-
embedData: Record<string, unknown>,
|
|
20
|
-
): Promise<{ id: string }>;
|
|
21
|
-
createForumPost(
|
|
22
|
-
channelId: string,
|
|
23
|
-
name: string,
|
|
24
|
-
content: string,
|
|
25
|
-
tags?: string[],
|
|
26
|
-
): Promise<{ id: string }>;
|
|
27
|
-
kickMember(guildId: string, userId: string, reason?: string): Promise<boolean>;
|
|
28
|
-
banMember(guildId: string, userId: string, reason?: string): Promise<boolean>;
|
|
29
|
-
unbanMember(guildId: string, userId: string, reason?: string): Promise<boolean>;
|
|
30
|
-
timeoutMember(
|
|
31
|
-
guildId: string,
|
|
32
|
-
userId: string,
|
|
33
|
-
duration?: number,
|
|
34
|
-
reason?: string,
|
|
35
|
-
): Promise<boolean>;
|
|
36
|
-
setNickname(guildId: string, userId: string, nickname: string): Promise<boolean>;
|
|
37
|
-
getMembers(guildId: string, limit?: number): Promise<unknown[]>;
|
|
38
|
-
getGuildInfo(guildId: string): Promise<unknown>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface DiscordAgentDeps {
|
|
42
|
-
getEndpoint: (endpointKey: string) => DiscordAgentEndpoint;
|
|
43
|
-
/** Alias kept for existing agent/tools that call getGatewayEndpoint. */
|
|
44
|
-
getGatewayEndpoint: (endpointKey: string) => DiscordAgentEndpoint;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const endpoints = new Map<string, DiscordAgentEndpoint>();
|
|
48
|
-
let override: DiscordAgentDeps | null = null;
|
|
49
|
-
|
|
50
|
-
export function registerDiscordAgentEndpoint(
|
|
51
|
-
endpointKey: string,
|
|
52
|
-
endpoint: DiscordAgentEndpoint,
|
|
53
|
-
): () => void {
|
|
54
|
-
endpoints.set(endpointKey, endpoint);
|
|
55
|
-
return () => {
|
|
56
|
-
if (endpoints.get(endpointKey) === endpoint) {
|
|
57
|
-
endpoints.delete(endpointKey);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Optional override used by tests / transitional callers. Pass `null` to clear. */
|
|
63
|
-
export function setDiscordAgentDeps(deps: DiscordAgentDeps | null): void {
|
|
64
|
-
override = deps;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function lookup(endpointKey: string): DiscordAgentEndpoint {
|
|
68
|
-
const registered = endpoints.get(endpointKey);
|
|
69
|
-
if (!registered) throw new Error(`Endpoint ${endpointKey} 不存在`);
|
|
70
|
-
return registered;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function getDiscordAgentDeps(): DiscordAgentDeps {
|
|
74
|
-
if (override) return override;
|
|
75
|
-
return {
|
|
76
|
-
getEndpoint: lookup,
|
|
77
|
-
getGatewayEndpoint: lookup,
|
|
78
|
-
};
|
|
79
|
-
}
|