Give every user their own bot face
A bot's face and status line live in bot_user_faces, one row per bot and user, set by jobs for the user whose conversation they're in. Needs-you and working only show to that user; every bot read overlays the viewer's face (botFaceSql) and pushes go to the user a face change is for. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import type { SqlCondition } from "./crew-access/types";
|
||||
|
||||
type Params = {
|
||||
user_id: number | string;
|
||||
/**
|
||||
* The bots table alias.
|
||||
*/
|
||||
alias?: string;
|
||||
/**
|
||||
* Put before the column names, e.g. `bot_` for `bot_face`.
|
||||
*/
|
||||
prefix?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Select columns for a bot's face and status line as one user sees them
|
||||
* (`bot_user_faces`): idle and no status line when the bot has none for
|
||||
* them. Faces are per user, so a job one user's waiting on never shows
|
||||
* on anyone else's screen.
|
||||
*/
|
||||
export default function botFaceSql({ user_id, alias = "b", prefix = "" }: Params): SqlCondition {
|
||||
const column = (name: string) =>
|
||||
`(SELECT f.${name} FROM bot_user_faces f WHERE f.bot_id = ${alias}.id AND f.user_id = ?)`;
|
||||
|
||||
return {
|
||||
sql: `COALESCE(${column("face")}, 'idle') AS ${prefix}face, COALESCE(${column("status_line")}, '') AS ${prefix}status_line`,
|
||||
values: [Number(user_id), Number(user_id)],
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user