Bot Data
Bot Lifetime is not infinite, so you need someplace to store your data.
Note
Data is stored per conversation. In data_set it will only update the fields that you pass in.
main.py
from ugly_bot import *
@export("message_direct")
def example():
data = data_get()
data = data_set(
counter = data.counter + 1 if hasattr(data, "counter") else 0
)
message_send(text = data.counter)
start()
Note
Since data is stored per conversation and the conversation_start event is always triggered at the start of a conversation, you can use that event to initialize your data.
main.py
from ugly_bot import *
@export("conversation_start")
def init():
data = data_set(
counter = 100,
other_value = "Hello"
)
@export("message_direct")
def example():
data = data_get()
data = data_set(
counter = data.counter + 1
)
message_send(text = f"{data.other_value} {data.counter}")
start()
Glossary