mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-14 02:31:24 +00:00
refactor: dedupe discord structured send context
This commit is contained in:
@@ -432,18 +432,10 @@ export async function sendStickerDiscord(
|
||||
stickerIds: string[],
|
||||
opts: DiscordSendOpts & { content?: string } = {},
|
||||
): Promise<DiscordSendResult> {
|
||||
const cfg = opts.cfg ?? loadConfig();
|
||||
const accountInfo = resolveDiscordAccount({
|
||||
cfg,
|
||||
accountId: opts.accountId,
|
||||
});
|
||||
const { rest, request, channelId } = await resolveDiscordSendTarget(to, opts);
|
||||
const content = opts.content?.trim();
|
||||
const rewrittenContent = content
|
||||
? rewriteDiscordKnownMentions(content, {
|
||||
accountId: accountInfo.accountId,
|
||||
})
|
||||
: undefined;
|
||||
const { rest, request, channelId, rewrittenContent } = await resolveDiscordStructuredSendContext(
|
||||
to,
|
||||
opts,
|
||||
);
|
||||
const stickers = normalizeStickerIds(stickerIds);
|
||||
const res = (await request(
|
||||
() =>
|
||||
@@ -463,18 +455,10 @@ export async function sendPollDiscord(
|
||||
poll: PollInput,
|
||||
opts: DiscordSendOpts & { content?: string } = {},
|
||||
): Promise<DiscordSendResult> {
|
||||
const cfg = opts.cfg ?? loadConfig();
|
||||
const accountInfo = resolveDiscordAccount({
|
||||
cfg,
|
||||
accountId: opts.accountId,
|
||||
});
|
||||
const { rest, request, channelId } = await resolveDiscordSendTarget(to, opts);
|
||||
const content = opts.content?.trim();
|
||||
const rewrittenContent = content
|
||||
? rewriteDiscordKnownMentions(content, {
|
||||
accountId: accountInfo.accountId,
|
||||
})
|
||||
: undefined;
|
||||
const { rest, request, channelId, rewrittenContent } = await resolveDiscordStructuredSendContext(
|
||||
to,
|
||||
opts,
|
||||
);
|
||||
if (poll.durationSeconds !== undefined) {
|
||||
throw new Error("Discord polls do not support durationSeconds; use durationHours");
|
||||
}
|
||||
@@ -494,6 +478,30 @@ export async function sendPollDiscord(
|
||||
return toDiscordSendResult(res, channelId);
|
||||
}
|
||||
|
||||
async function resolveDiscordStructuredSendContext(
|
||||
to: string,
|
||||
opts: DiscordSendOpts & { content?: string },
|
||||
): Promise<{
|
||||
rest: RequestClient;
|
||||
request: DiscordClientRequest;
|
||||
channelId: string;
|
||||
rewrittenContent?: string;
|
||||
}> {
|
||||
const cfg = opts.cfg ?? loadConfig();
|
||||
const accountInfo = resolveDiscordAccount({
|
||||
cfg,
|
||||
accountId: opts.accountId,
|
||||
});
|
||||
const { rest, request, channelId } = await resolveDiscordSendTarget(to, opts);
|
||||
const content = opts.content?.trim();
|
||||
const rewrittenContent = content
|
||||
? rewriteDiscordKnownMentions(content, {
|
||||
accountId: accountInfo.accountId,
|
||||
})
|
||||
: undefined;
|
||||
return { rest, request, channelId, rewrittenContent };
|
||||
}
|
||||
|
||||
type VoiceMessageOpts = {
|
||||
cfg?: OpenClawConfig;
|
||||
token?: string;
|
||||
|
||||
Reference in New Issue
Block a user