tools.stargazer_ban module
Stargazer ban tool — revoke STARGAZER_USE for the interacting user.
Star calls this when she decides a user should lose access. The
user_id parameter is exposed to the LLM for UX but is always
overridden by ctx.user_id to prevent the model from being tricked
into banning someone other than the person she’s talking to.
An optional duration_days makes the ban temporary: a background
asyncio task restores the bit after the timer expires. Without it
the ban is permanent until an admin manually grants the bit back.
- async tools.stargazer_ban.run(user_id, reason='', duration_days=None, ctx=None)[source]
Revoke the global
STARGAZER_USEprivilege bit for the interacting user.This is the
stargazer_bantool entry point. It is the LLM’s lever for cutting off a user it is conversing with: it clears bit 63 in the user’s GLOBAL privilege mask so the bot stops serving them. The model-supplieduser_idis intentionally ignored in favor ofctx.user_idso the ban can never be redirected at a third party, and admins are refused outright.Reads and writes Redis directly: it fetches the current mask via
get_user_privilegesand persists the bit-cleared mask withredis.setunder_redis_key(both fromtools.alter_privileges), and uses_is_adminfrom the same module to enforce the admin exemption. When a positiveduration_daysis given it schedules_restore_after()as a detachedasynciotask to auto-lift the ban; otherwise the ban is permanent. All actions are logged. As a tool, it is dispatched by name through the tool registry:tool_loader.pyregisters this module’srunas the handler forstargazer_banand the inference worker invokes it when the LLM emits that tool call; it has no in-repo direct callers.- Parameters:
user_id (
str) – Cosmetic only — the user the model thinks it is banning. The real target is alwaysctx.user_id.reason (
str) – Optional free-text reason, included in the log line and the returned confirmation.duration_days (
float|None) – Optional ban length in days (fractional allowed). If set and positive, the ban auto-expires via_restore_after(); otherwise it is permanent.ctx (
ToolContext|None) – The tool context supplyinguser_id,redis, andconfig.
- Returns:
A human-readable result — a confirmation with the old/new mask, or an error string when context,
user_id, or Redis is missing, when the target is an admin, or when the user is already banned.- Return type: