@@ -62,8 +62,9 @@ async def get_bot_status(
6262 list[tuple[str, bool]] | bool: bot状态
6363 """
6464 if not bot_id :
65- return await cls .all ().values_list ("bot_id" , "status" )
66- result = await cls .get_or_none (bot_id = bot_id )
65+ data = await BotMemoryCache .get_all ()
66+ return [(bot_id , snapshot .status ) for bot_id , snapshot in data .items ()]
67+ result = await BotMemoryCache .get (bot_id )
6768 return result .status if result else False
6869
6970 @overload
@@ -95,12 +96,13 @@ async def get_tasks(cls, bot_id: str | None = None, status: bool | None = True):
9596 list[tuple[str, str]] | str: 被动技能
9697 """
9798 if not bot_id :
98- task_field : Literal ["available_tasks" , "block_tasks" ] = (
99- "available_tasks" if status else "block_tasks"
100- )
101- data_list = await cls .all ().values_list ("bot_id" , task_field )
102- return {k : cls .convert_module_format (v ) for k , v in data_list }
103- result = await cls .get_or_none (bot_id = bot_id )
99+ data = await BotMemoryCache .get_all ()
100+ task_attr = "available_tasks" if status else "block_tasks"
101+ return {
102+ bot_id : cls .convert_module_format (getattr (snapshot , task_attr ))
103+ for bot_id , snapshot in data .items ()
104+ }
105+ result = await BotMemoryCache .get (bot_id )
104106 if result :
105107 tasks = result .available_tasks if status else result .block_tasks
106108 return cls .convert_module_format (tasks )
@@ -135,11 +137,14 @@ async def get_plugins(cls, bot_id: str | None = None, status: bool = True):
135137 list[tuple[str, str]] | str: 插件
136138 """
137139 if not bot_id :
138- plugin_field = "available_plugins" if status else "block_plugins"
139- data_list = await cls .all ().values_list ("bot_id" , plugin_field )
140- return {k : cls .convert_module_format (v ) for k , v in data_list }
141-
142- result = await cls .get_or_none (bot_id = bot_id )
140+ data = await BotMemoryCache .get_all ()
141+ plugin_attr = "available_plugins" if status else "block_plugins"
142+ return {
143+ bot_id : cls .convert_module_format (getattr (snapshot , plugin_attr ))
144+ for bot_id , snapshot in data .items ()
145+ }
146+
147+ result = await BotMemoryCache .get (bot_id )
143148 if result :
144149 plugins = result .available_plugins if status else result .block_plugins
145150 return cls .convert_module_format (plugins )
@@ -419,7 +424,9 @@ async def is_block_plugin(cls, bot_id: str, plugin_name: str) -> bool:
419424 返回:
420425 bool: 是否被禁用
421426 """
422- bot_data , _ = await cls .get_or_create (bot_id = bot_id )
427+ bot_data = await BotMemoryCache .get (bot_id )
428+ if not bot_data :
429+ return False
423430 return cls .format (plugin_name ) in bot_data .block_plugins
424431
425432 @classmethod
@@ -434,7 +441,9 @@ async def is_block_task(cls, bot_id: str, task_name: str) -> bool:
434441 返回:
435442 bool: 是否被禁用
436443 """
437- bot_data , _ = await cls .get_or_create (bot_id = bot_id )
444+ bot_data = await BotMemoryCache .get (bot_id )
445+ if not bot_data :
446+ return False
438447 return cls .format (task_name ) in bot_data .block_tasks
439448
440449 @classmethod
0 commit comments