mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:30:57 +00:00
fix(discord): preserve option localizations
This commit is contained in:
committed by
clawsweeper
parent
bd427ea1a8
commit
e6925886d4
@@ -204,6 +204,63 @@ describe("Client.deployCommands", () => {
|
||||
expect(deleteRequest).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("patches changed option localization maps", async () => {
|
||||
const client = createInternalTestClient([
|
||||
createTestCommand({
|
||||
name: "one",
|
||||
options: [
|
||||
{
|
||||
type: 3,
|
||||
name: "value",
|
||||
name_localizations: { de: "wert" },
|
||||
description: "Value",
|
||||
description_localizations: { de: "Wert" },
|
||||
},
|
||||
],
|
||||
}),
|
||||
]);
|
||||
const get = vi.fn(async () => [
|
||||
{
|
||||
id: "cmd1",
|
||||
application_id: "app1",
|
||||
type: ApplicationCommandType.ChatInput,
|
||||
name: "one",
|
||||
description: "one command",
|
||||
options: [
|
||||
{
|
||||
type: 3,
|
||||
name: "value",
|
||||
name_localizations: { de: "alter-wert" },
|
||||
description: "Value",
|
||||
description_localizations: { de: "Alter Wert" },
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
const patch = vi.fn(async () => undefined);
|
||||
const post = vi.fn(async () => undefined);
|
||||
const deleteRequest = vi.fn(async () => undefined);
|
||||
attachRestMock(client, { get, patch, post, delete: deleteRequest });
|
||||
|
||||
await client.deployCommands({ mode: "reconcile" });
|
||||
|
||||
expect(patch).toHaveBeenCalledWith(
|
||||
Routes.applicationCommand("app1", "cmd1"),
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
options: [
|
||||
expect.objectContaining({
|
||||
name_localizations: { de: "wert" },
|
||||
description_localizations: { de: "Wert" },
|
||||
}),
|
||||
],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(post).not.toHaveBeenCalled();
|
||||
expect(deleteRequest).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("skips command deploy when the serialized command set is unchanged", async () => {
|
||||
const client = createInternalTestClient([createTestCommand({ name: "one" })]);
|
||||
const get = vi.fn(async () => []);
|
||||
|
||||
@@ -175,14 +175,12 @@ function comparableCommand(value: unknown): unknown {
|
||||
}
|
||||
|
||||
const unorderedCommandArrayFields = new Set(["channel_types", "contexts", "integration_types"]);
|
||||
const subcommandOptionOnlyFields = new Set([
|
||||
const optionComparisonOmittedFields = new Set([
|
||||
"contexts",
|
||||
"default_member_permissions",
|
||||
"description_localized",
|
||||
"description_localizations",
|
||||
"integration_types",
|
||||
"name_localized",
|
||||
"name_localizations",
|
||||
]);
|
||||
|
||||
function stableComparableObject(value: unknown, path: string[] = []): unknown {
|
||||
@@ -210,7 +208,7 @@ function stableComparableObject(value: unknown, path: string[] = []): unknown {
|
||||
if (entry === undefined) {
|
||||
return false;
|
||||
}
|
||||
if (path.includes("options") && subcommandOptionOnlyFields.has(key)) {
|
||||
if (path.includes("options") && optionComparisonOmittedFields.has(key)) {
|
||||
return false;
|
||||
}
|
||||
if ((key === "required" || key === "autocomplete") && entry === false) {
|
||||
|
||||
Reference in New Issue
Block a user