A bot's identity was one of seven hues, and the hue picked both its colour and its stone shape. Now its colour is free and its stone is its own: - `bots.color` holds any `#rrggbb`, `bots.stone` the flat-cut shape it's drawn on. `bots.hue` stays as the palette column they replaced, read only as a fallback; `src/scripts/move-bot-colour-to-owners.ts` backfills an install from it (safe to rerun). - `src/utils/bot-color.ts` is the only place a colour is validated or resolved (`resolveBotColor`/`resolveBotStone` carry the old hue forward, `botColorNeedsPaperFace` flips the eyes to paper on a very dark body), and `src/utils/bot-stone-props.ts` gives every row its props, so a row saved before this still renders as it did. - `BotStone` takes the colour as the body's SVG `fill`, the one documented exception to the token rule: an arbitrary hex has no token to point at. `UnreadDot` follows it. - The picker keeps the palette tiles (still shape and colour together) and adds a native swatch and a hex field, so a custom colour keeps its stone. Same place as before: the header avatar's modal and Settings > Bots, for crew managers. The coordinator stays hue-less. - A recolour reaches other open tabs through `pushBotUpdated`.
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import BunSQLite from "@moduletrace/bun-sqlite";
|
|
import type { CronJobWithNames } from "@/src/types";
|
|
import botFaceSql from "@/src/utils/bot-face-sql";
|
|
|
|
type Params = {
|
|
user_id: number | string;
|
|
/**
|
|
* Only this bot's.
|
|
*/
|
|
bot_id?: number | string;
|
|
/**
|
|
* Only this one.
|
|
*/
|
|
cron_job_id?: number | string;
|
|
};
|
|
|
|
/**
|
|
* The user's schedules with their bot (its face as the user sees it) and
|
|
* workspace names, the next to
|
|
* run first and paused ones last.
|
|
*/
|
|
export default async function grabCronJobs({ user_id, bot_id, cron_job_id }: Params): Promise<CronJobWithNames[]> {
|
|
const face = botFaceSql({ user_id, prefix: "bot_" });
|
|
const where = [`c.user_id = ?`];
|
|
const values: (number | string)[] = [user_id];
|
|
|
|
if (bot_id) {
|
|
where.push(`c.bot_id = ?`);
|
|
values.push(bot_id);
|
|
}
|
|
|
|
if (cron_job_id) {
|
|
where.push(`c.id = ?`);
|
|
values.push(cron_job_id);
|
|
}
|
|
|
|
const res = await BunSQLite.sql<CronJobWithNames>({
|
|
sql: `SELECT c.*, b.name AS bot_name, b.kind AS bot_kind, b.hue AS bot_hue, b.color AS bot_color, b.stone AS bot_stone, ${face.sql},
|
|
b.image_media_id AS bot_image_media_id, w.name AS workspace_name
|
|
FROM cron_jobs c
|
|
JOIN bots b ON b.id = c.bot_id
|
|
LEFT JOIN workspaces w ON w.id = c.workspace_id
|
|
WHERE ${where.join(" AND ")}
|
|
ORDER BY c.enabled DESC, c.next_run_at IS NULL, c.next_run_at ASC, c.id ASC`,
|
|
values: [...face.values, ...values],
|
|
});
|
|
|
|
return res.payload || [];
|
|
}
|