Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

feat(avatar): give one bot's body to every other bot from the avatar editor

mantrandev34105a787413
diff --git a/src/components/bot-panel/AvatarEditorCard.tsx b/src/components/bot-panel/AvatarEditorCard.tsx
index 124d48dec9..f0530d9d75 100644
--- a/src/components/bot-panel/AvatarEditorCard.tsx
+++ b/src/components/bot-panel/AvatarEditorCard.tsx
@@ -6,7 +6,7 @@ import { t } from "@/lib/i18n";
import { bodyName, colorName, festivalName } from "@/lib/mascot-names";
import type { LocaleKey } from "@/locales";
import { colorSwatch, MAUS_COLOR_LABEL, MAUS_COLOR_NAMES, PICKABLE_STATES, type MausState } from "@/lib/mascot";
-import type { Bot } from "@/state/store";
+import { useStore, type Bot } from "@/state/store";
import { MASCOT_BODY_IDS } from "../../../shared/mascot-bodies";
import { FESTIVAL_IDS, FESTIVALS, isCarvedBody, type BotBodyId } from "../../../shared/bot-body";
import { useFestivalDress, wornBody } from "@/lib/festival-dress";
@@ -66,6 +66,8 @@ export function AvatarEditorCard({ bot, activeState, onPatch, onClose }: {
}, []);
const pickMascot = (patch: AvatarPatch) => onPatch(crop === "mascot" ? patch : { ...patch, avatarCrop: "mascot" });
const body = bot.mascotBody ?? "cursor";
+ const { state, dispatch } = useStore();
+ const othersToMatch = state.bots.filter((other) => other.id !== bot.id && (other.mascotBody ?? "cursor") !== body);
const festival = useFestivalDress();
const costume = wornBody(bot.mascotBody, bot.color, festival);
const [moreLooks, setMoreLooks] = useState(() => Boolean(festival) || isCarvedBody(body) || Boolean(bot.mascotExpression && bot.mascotExpression !== "idle"));
@@ -137,6 +139,19 @@ export function AvatarEditorCard({ bot, activeState, onPatch, onClose }: {
<div className="grid grid-cols-5 gap-1.5">
{MASCOT_BODY_IDS.map((id) => bodyButton(id, bodyName(id)))}
</div>
+ {!showsImage && othersToMatch.length > 0 && (
+ <button
+ type="button"
+ data-avatar-body-everywhere
+ disabled={busy}
+ onClick={() => {
+ for (const other of othersToMatch) dispatch({ type: "updateBot", botId: other.id, patch: { mascotBody: body } });
+ }}
+ className="mx-auto mt-2 flex rounded-full px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-ink/[0.04] hover:text-ink disabled:opacity-50"
+ >
+ {t("botPanel.avatar.bodyEverywhere", { count: othersToMatch.length })}
+ </button>
+ )}
<div className="flex flex-wrap justify-center gap-2 px-1 pb-1 pt-3.5">
{MAUS_COLOR_NAMES.map((color) => (
<button
diff --git a/src/components/bot-panel/PanelShell.dom.test.ts b/src/components/bot-panel/PanelShell.dom.test.ts
index 5d39a33961..4dfd076574 100644
--- a/src/components/bot-panel/PanelShell.dom.test.ts
+++ b/src/components/bot-panel/PanelShell.dom.test.ts
@@ -7,12 +7,12 @@ import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { Bot, BotSettingsSection } from "@/state/store";
-const fixture = vi.hoisted(() => ({ dispatch: vi.fn(), settingsOpen: false }));
+const fixture = vi.hoisted(() => ({ dispatch: vi.fn(), settingsOpen: false, bots: [] as Bot[] }));
vi.mock("@/state/store", async (importOriginal) => {
const original = await importOriginal<typeof import("@/state/store")>();
return {
...original,
- useStore: () => ({ state: { ...original.initialState, settingsOpen: fixture.settingsOpen }, dispatch: fixture.dispatch, flushBotPatches: () => Promise.resolve(null) }),
+ useStore: () => ({ state: { ...original.initialState, settingsOpen: fixture.settingsOpen, bots: fixture.bots }, dispatch: fixture.dispatch, flushBotPatches: () => Promise.resolve(null) }),
};
});
vi.mock("@/lib/interface-mode", () => ({ useAdvancedMode: () => false, readAdvancedMode: () => false, setAdvancedMode: vi.fn() }));
@@ -78,6 +78,7 @@ const onWindowKey = (event: KeyboardEvent) => {
beforeEach(() => {
fixture.dispatch.mockReset();
+ fixture.bots = [];
onClose.mockReset();
dialogCloses.mockReset();
window.addEventListener("keydown", onWindowKey);
@@ -386,3 +387,36 @@ describe("focus around the hero", () => {
},
);
});
+
+describe("one body for every bot", () => {
+ const roundBot: Bot = { ...bot, mascotBody: "circle" };
+ const everywhere = () => host.querySelector("[data-avatar-body-everywhere]");
+ const openEditor = async (shown: Bot) => {
+ flushSync(() => root.render(createElement("aside", { role: "dialog" }, createElement(BotPanel, { bot: shown, derived, linkedSection: null, onClose }))));
+ await settle();
+ click(host.querySelector("[data-panel-avatar]"));
+ await settle();
+ };
+
+ it("gives this bot's body to every other bot that wears another one", async () => {
+ fixture.bots = [roundBot, { ...bot, id: "ada", mascotBody: "cursor" }, { ...bot, id: "bob" }, { ...bot, id: "cara", mascotBody: "circle" }];
+ await openEditor(roundBot);
+ expect(everywhere()?.textContent).toBe("Give this body to the other bots (2)");
+ click(everywhere());
+ expect(fixture.dispatch.mock.calls.map(([action]) => action)).toEqual([
+ { type: "updateBot", botId: "ada", patch: { mascotBody: "circle" } },
+ { type: "updateBot", botId: "bob", patch: { mascotBody: "circle" } },
+ ]);
+ });
+
+ it("is not offered once every bot wears this body, or while the bot shows a picture", async () => {
+ fixture.bots = [roundBot, { ...bot, id: "cara", mascotBody: "circle" }];
+ await openEditor(roundBot);
+ expect(everywhere()).toBeNull();
+ flushSync(() => root.unmount());
+ root = createRoot(host);
+ fixture.bots = [roundBot, { ...bot, id: "ada" }];
+ await openEditor({ ...roundBot, avatarUrl: "/avatars/scout.png", avatarCrop: "circle" });
+ expect(everywhere()).toBeNull();
+ });
+});
diff --git a/src/locales/en.json b/src/locales/en.json
index bf963b7654..55ad4716ce 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -4401,6 +4401,7 @@
"botPanel.avatar.halloween": "Halloween",
"botPanel.avatar.diwali": "Diwali",
"botPanel.avatar.more": "More looks",
+ "botPanel.avatar.bodyEverywhere": "Give this body to the other bots ({count})",
"botPanel.avatar.costume": "Dressed as the {name} while the {skin} skin is on",
"botPanel.avatar.drop": "Drop a picture here, or choose one",
"botPanel.avatar.types": "PNG, JPEG, GIF, or WebP · up to 10 MB",
diff --git a/src/state/bot-patch-queue.ts b/src/state/bot-patch-queue.ts
index db30ec53ec..16ca92f362 100644
--- a/src/state/bot-patch-queue.ts
+++ b/src/state/bot-patch-queue.ts
@@ -12,6 +12,7 @@ export type BotUpdatePatch = Partial<
| "autoStartVps"
| "color"
| "mascotExpression"
+ | "mascotBody"
| "mascotFaceColor"
| "avatarUrl"
| "avatarCrop"