IdentityStateTrait
{@see \NHA\StateStore} slice: the stable operational config — the default agent id + token, the per-Discord-user identity map, the autoplay on/off flag, and the registered slash-command signatures.
Relies on the host's array $data and save().
Tags
Table of Contents
Methods
- getCommandSignatures() : array<string, string>
- The signature of the last successfully registered slash command by name.
- getDefaultAgent() : int|null
- The stored default agent id, or null when none has been registered.
- getDefaultAgentToken() : string|null
- Gets the NHA action token for the default agent, if known.
- getDiscordUserAgent() : array{agent_id: int, name: string, token: string}|null
- Gets the NHA identity assigned to a Discord user.
- isAutoplayEnabled() : bool
- Whether the autonomous LLM play loop is currently enabled. Persisted so a `!nha autoplay on` survives a restart.
- setAutoplay() : void
- Turns the autonomous LLM play loop on or off.
- setCommandSignature() : void
- Records that `$name` was registered with definition signature `$hash`.
- setDefaultAgent() : void
- Sets the default agent id and, when known, its NHA action token.
- setDiscordUserAgent() : void
- Saves a Discord user's NHA identity for later turns.
Methods
getCommandSignatures()
The signature of the last successfully registered slash command by name.
public
getCommandSignatures() : array<string, string>
Used to decide whether a command's definition changed since the last boot and needs pushing to Discord (a rate-limited write).
Return values
array<string, string> —command name => sha1(definition)
getDefaultAgent()
The stored default agent id, or null when none has been registered.
public
getDefaultAgent() : int|null
Return values
int|nullgetDefaultAgentToken()
Gets the NHA action token for the default agent, if known.
public
getDefaultAgentToken() : string|null
Return values
string|nullgetDiscordUserAgent()
Gets the NHA identity assigned to a Discord user.
public
getDiscordUserAgent(string $discord_user_id) : array{agent_id: int, name: string, token: string}|null
Parameters
- $discord_user_id : string
Return values
array{agent_id: int, name: string, token: string}|nullisAutoplayEnabled()
Whether the autonomous LLM play loop is currently enabled. Persisted so a `!nha autoplay on` survives a restart.
public
isAutoplayEnabled() : bool
Return values
boolsetAutoplay()
Turns the autonomous LLM play loop on or off.
public
setAutoplay(bool $enabled) : void
Parameters
- $enabled : bool
setCommandSignature()
Records that `$name` was registered with definition signature `$hash`.
public
setCommandSignature(string $name, string $hash) : void
Parameters
- $name : string
- $hash : string
setDefaultAgent()
Sets the default agent id and, when known, its NHA action token.
public
setDefaultAgent(int $agent_id[, string|null $token = null ]) : void
Passing null for $token leaves any previously stored token intact,
so callers that only know the agent id don't clobber it.
Parameters
- $agent_id : int
- $token : string|null = null
setDiscordUserAgent()
Saves a Discord user's NHA identity for later turns.
public
setDiscordUserAgent(string $discord_user_id, int $agent_id, string $name, string $token) : void
Parameters
- $discord_user_id : string
- $agent_id : int
- $name : string
- $token : string