Message Store
Message Store

Lingchu Bot includes an optional message storage service that records event data, processing results, bot lifecycle events, and platform API call summaries. This page explains what is stored, how to configure it, and how to access stored data.
Overview
The message store is implemented in services/message_store.py. It hooks into NoneBot's event processing pipeline and records structured summaries rather than raw message content. Events are routed through repository-level model selection so high-volume platform/adapter/framework combinations can use dedicated ORM tables.
Optional feature
Message storage is enabled by default but can be disabled entirely by setting message_store_enabled = false in config.json5.
What is stored
| Record type | Description |
|---|---|
| Event receipt | When any adapter event is received by the bot |
| Processing result | The outcome of handling an event |
| Bot lifecycle | Startup, shutdown, and connection events |
| API call summary | Platform API calls made during event handling |
Each record includes platform, adapter, framework, event category, and adapter event type fields. QQ + OneBot V11 + NoneBot events are stored in dedicated partition tables; unsupported combinations fall back to the legacy global tables.
Configuration
Prop
Type
Data retention
Records are retained based on message_store_retention_days:
- When set to a positive number, records older than the specified days are cleaned up.
- When set to
0, day-based expiry is disabled; records are kept indefinitely. - Cleanup runs during bot shutdown when
message_store_cleanup_enabledistrue.
Platform identification
The platform field in stored records is derived from the adapter registry:
| Scenario | Platform value |
|---|---|
| OneBot V11 adapter enabled | qq |
| Unknown adapter | unknown |
Only the adapter selected by LINGCHUAdapter determines the platform value. Other registered adapters are ignored.
Storage backend
Message store uses nonebot-plugin-orm for database access. The ORM helper in database/orm_crud.py provides async CRUD operations that run in worker threads to avoid blocking the NoneBot event loop.
Blocking paths
File storage, JSON5 parsing, deepcopy, command parsing, and translation catalog loading are all moved to worker threads. Do not call synchronous storage methods directly from async handlers.
Disabling message store
To disable message storage entirely:
{
message_store_enabled: false,
}When disabled, no event hooks are registered and no records are written. Existing records are not automatically deleted.
Last updated on