Skip to content

Commit c84e32b

Browse files
authored
feat(bot): 支持设置事件队列的最大缓冲区大小 (#158)
1 parent b2aebdc commit c84e32b

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

alicebot/bot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ async def _init(self) -> None:
202202
self._should_exit = anyio.Event()
203203
self._condition = anyio.Condition()
204204
self._event_send_stream, self._event_receive_stream = (
205-
anyio.create_memory_object_stream()
205+
anyio.create_memory_object_stream(
206+
max_buffer_size=self.config.bot.event_queue_size
207+
)
206208
)
207209

208210
# 加载配置文件

alicebot/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ class BotConfig(ConfigModel):
4545
"""Bot 配置。
4646
4747
Attributes:
48+
event_queue_size: 事件队列的最大缓冲区大小。
4849
plugins: 将被加载的插件列表,将被 `Bot` 类的 `load_plugins()` 方法加载。
4950
plugin_dirs: 将被加载的插件目录列表,将被 `Bot` 类的 `load_plugins_from_dirs()` 方法加载。
5051
adapters: 将被加载的适配器列表,将依次被 `Bot` 类的 `load_adapters()` 方法加载。
5152
log: AliceBot 日志相关设置。
5253
"""
5354

55+
event_queue_size: int = Field(default=0, ge=0)
5456
plugins: set[str] = Field(default_factory=set)
5557
plugin_dirs: set[DirectoryPath] = Field(default_factory=set)
5658
adapters: set[str] = Field(default_factory=set)

tests/config_files/raw_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"bot": {
3+
"event_queue_size": 0,
34
"plugins": [],
45
"plugin_dirs": ["plugins"],
56
"adapters": [],

0 commit comments

Comments
 (0)