























@@ -1,6 +1,5 @@
11import type { AgentToolResult } from "@mariozechner/pi-agent-core";
22import {
3-parseAvailableTags,
43readNumberParam,
54readStringArrayParam,
65readStringParam,
@@ -12,6 +11,11 @@ import {
1211isDiscordModerationAction,
1312readDiscordModerationCommand,
1413} from "./runtime.moderation-shared.js";
14+import {
15+readDiscordChannelCreateParams,
16+readDiscordChannelEditParams,
17+readDiscordChannelMoveParams,
18+} from "./runtime.shared.js";
15191620type Ctx = Pick<
1721ChannelMessageActionContext,
@@ -21,9 +25,8 @@ type Ctx = Pick<
2125export async function tryHandleDiscordMessageActionGuildAdmin(params: {
2226ctx: Ctx;
2327resolveChannelId: () => string;
24-readParentIdParam: (params: Record<string, unknown>) => string | null | undefined;
2528}): Promise<AgentToolResult<unknown> | undefined> {
26-const { ctx, resolveChannelId, readParentIdParam } = params;
29+const { ctx, resolveChannelId } = params;
2730const { action, params: actionParams, cfg } = ctx;
2831const accountId = ctx.accountId ?? readStringParam(actionParams, "accountId");
2932@@ -154,25 +157,11 @@ export async function tryHandleDiscordMessageActionGuildAdmin(params: {
154157const guildId = readStringParam(actionParams, "guildId", {
155158required: true,
156159});
157-const name = readStringParam(actionParams, "name", { required: true });
158-const type = readNumberParam(actionParams, "type", { integer: true });
159-const parentId = readParentIdParam(actionParams);
160-const topic = readStringParam(actionParams, "topic");
161-const position = readNumberParam(actionParams, "position", {
162-integer: true,
163-});
164-const nsfw = typeof actionParams.nsfw === "boolean" ? actionParams.nsfw : undefined;
165160return await handleDiscordAction(
166161{
167162action: "channelCreate",
168163accountId: accountId ?? undefined,
169- guildId,
170- name,
171-type: type ?? undefined,
172-parentId: parentId ?? undefined,
173-topic: topic ?? undefined,
174-position: position ?? undefined,
175- nsfw,
164+ ...readDiscordChannelCreateParams({ ...actionParams, guildId }),
176165},
177166cfg,
178167);
@@ -182,37 +171,11 @@ export async function tryHandleDiscordMessageActionGuildAdmin(params: {
182171const channelId = readStringParam(actionParams, "channelId", {
183172required: true,
184173});
185-const name = readStringParam(actionParams, "name");
186-const topic = readStringParam(actionParams, "topic");
187-const position = readNumberParam(actionParams, "position", {
188-integer: true,
189-});
190-const parentId = readParentIdParam(actionParams);
191-const nsfw = typeof actionParams.nsfw === "boolean" ? actionParams.nsfw : undefined;
192-const rateLimitPerUser = readNumberParam(actionParams, "rateLimitPerUser", {
193-integer: true,
194-});
195-const archived = typeof actionParams.archived === "boolean" ? actionParams.archived : undefined;
196-const locked = typeof actionParams.locked === "boolean" ? actionParams.locked : undefined;
197-const autoArchiveDuration = readNumberParam(actionParams, "autoArchiveDuration", {
198-integer: true,
199-});
200-const availableTags = parseAvailableTags(actionParams.availableTags);
201174return await handleDiscordAction(
202175{
203176action: "channelEdit",
204177accountId: accountId ?? undefined,
205- channelId,
206-name: name ?? undefined,
207-topic: topic ?? undefined,
208-position: position ?? undefined,
209-parentId: parentId === undefined ? undefined : parentId,
210- nsfw,
211-rateLimitPerUser: rateLimitPerUser ?? undefined,
212- archived,
213- locked,
214-autoArchiveDuration: autoArchiveDuration ?? undefined,
215- availableTags,
178+ ...readDiscordChannelEditParams({ ...actionParams, channelId }),
216179},
217180cfg,
218181);
@@ -235,18 +198,11 @@ export async function tryHandleDiscordMessageActionGuildAdmin(params: {
235198const channelId = readStringParam(actionParams, "channelId", {
236199required: true,
237200});
238-const parentId = readParentIdParam(actionParams);
239-const position = readNumberParam(actionParams, "position", {
240-integer: true,
241-});
242201return await handleDiscordAction(
243202{
244203action: "channelMove",
245204accountId: accountId ?? undefined,
246- guildId,
247- channelId,
248-parentId: parentId === undefined ? undefined : parentId,
249-position: position ?? undefined,
205+ ...readDiscordChannelMoveParams({ ...actionParams, guildId, channelId }),
250206},
251207cfg,
252208);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。