-
Notifications
You must be signed in to change notification settings - Fork 269
Accessing and Writing memory.json
bot.memory.exists(["<keyname>", "<keyname>", ...])
- checks whether
memory["<keyname>"]["<keyname>"][...]
exists - returns
None
if the key path cannot be found
The bot supports per-user and per-conversation memory, meaning that you can store keys and their values for specific users or conversations.
bot.user_memory_set(event.user.id_.chat_id, <keyname>, <keyvalue>)
- automatically initialises the user memory in
memory.json
- stores
<keyvalue>
in<keyname>
bot.user_memory_get(event.user.id_.chat_id, '<keyname>')
- automatically initialises the user memory in
memory.json
- returns value stored in
<keyname>
orNone
if unset or null
bot.conversation_memory_set(event.conv_id, '<keyname>', <keyvalue>)
- automatically initialises the conversation memory in
memory.json
- stores
<keyvalue>
in<keyname>
bot.conversation_memory_get(event.conv_id, '<keyname>')
- automatically initialises the conversation memory in
memory.json
- returns value stored in
<keyname>
orNone
if unset or null
- An annotated structure
of
memory.json
with some comments on how the above functions interact with it. - There is also an [example of manually iterating/searching conversation memory] (https://gist.github.com/endofline/6b73591b69557ddc514d)
- An [example plugin] (https://github.com/nylonee/hangupsbot/blob/staging/hangupsbot/plugins/example_memory.py) demonstrating setting, retrieving and removing user and conversation memory
Low-level functionality require exception handling. The type of exceptions raised will be listed as part of the documentation here.
bot.memory.set_by_path(["<keyname>", "<keyname>", ...], <somevalue>)
- raises
TypeError
if it cannot create the path - can only create a new key if all the preceding keys are available
- use
bot.memory.exists(["<keyname>", "<keyname>", ...])
to check availability of the key path before executing this command
bot.memory.get_by_path(["<keyname>", "<keyname>", ...])
- raises
KeyError
orTypeError
if keys don't exist
bot.memory.pop_by_path(["<keyname>", "<keyname>", ...])
- deletes/removes the last key specified from the preceding path
- raises
KeyError
orTypeError
if keys don't exist
Plugin List | Developer Reference: [ Intro | Plugins | Sinks | In-built Functionality | Configuration ]