mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-04 03:10:01 +08:00
bugfix:修复notice事件扩散问题 (#2132)
* bugfix:修复notice事件扩散问题 * 优化并发调度 * bugfix:修复签到样式 * bugfix:功能调用统计修复 * bugfix:修复私聊时功能调用统计显示已退群问题 * 提高插件适配兼容性 * 优化发送队列 * 修改权限检查设计 * 继续修改权限检查设计 * 完善权限检查设计 * 优化sqlite配置 * 优化数据库初始化 * 代码整理,无用代码清理 * bugfix:修复启动时数据库校验问题 * bugfix:修复预算裁剪过于激进问题
This commit is contained in:
+68
@@ -715,12 +715,22 @@ class PluginInfoMemoryCache:
|
||||
return
|
||||
await cls.refresh()
|
||||
|
||||
@classmethod
|
||||
def is_loaded(cls) -> bool:
|
||||
return cls._loaded
|
||||
|
||||
@classmethod
|
||||
async def get_by_module(cls, module: str) -> "PluginInfo | None":
|
||||
if not cls._loaded:
|
||||
await cls.ensure_loaded()
|
||||
return cls._to_model(cls._by_module.get(module))
|
||||
|
||||
@classmethod
|
||||
def get_by_module_if_ready(cls, module: str) -> "PluginInfo | None":
|
||||
if not cls._loaded:
|
||||
return None
|
||||
return cls._to_model(cls._by_module.get(module))
|
||||
|
||||
@classmethod
|
||||
async def get_all(cls) -> dict[str, "PluginInfo"]:
|
||||
if not cls._loaded:
|
||||
@@ -851,6 +861,10 @@ class BotMemoryCache:
|
||||
return
|
||||
await cls.refresh()
|
||||
|
||||
@classmethod
|
||||
def is_loaded(cls) -> bool:
|
||||
return cls._loaded
|
||||
|
||||
@classmethod
|
||||
async def get(cls, bot_id: str | None) -> BotSnapshot | None:
|
||||
bot_id = cls._normalize(bot_id)
|
||||
@@ -866,6 +880,19 @@ class BotMemoryCache:
|
||||
cls._mark_negative(bot_id)
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_if_ready(cls, bot_id: str | None) -> BotSnapshot | None:
|
||||
bot_id = cls._normalize(bot_id)
|
||||
if not bot_id or not cls._loaded:
|
||||
return None
|
||||
entry = cls._by_id.get(bot_id)
|
||||
if entry:
|
||||
return entry
|
||||
if cls._is_negative(bot_id):
|
||||
return None
|
||||
cls._mark_negative(bot_id)
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
async def get_all(cls) -> dict[str, BotSnapshot]:
|
||||
if not cls._loaded:
|
||||
@@ -1199,6 +1226,10 @@ class LevelUserMemoryCache:
|
||||
return
|
||||
await cls.refresh()
|
||||
|
||||
@classmethod
|
||||
def is_loaded(cls) -> bool:
|
||||
return cls._loaded
|
||||
|
||||
@classmethod
|
||||
async def ensure_fresh(cls) -> None:
|
||||
interval = LEVEL_MEM_REFRESH_INTERVAL
|
||||
@@ -1244,6 +1275,23 @@ class LevelUserMemoryCache:
|
||||
group_user = cls._by_key.get(group_key)
|
||||
return global_user, group_user
|
||||
|
||||
@classmethod
|
||||
def get_levels_if_ready(
|
||||
cls, user_id: str | None, group_id: str | None
|
||||
) -> tuple[LevelUserSnapshot | None, LevelUserSnapshot | None] | None:
|
||||
if not cls._loaded:
|
||||
return None
|
||||
global_user = None
|
||||
group_user = None
|
||||
global_key = cls._key(user_id, "")
|
||||
if global_key:
|
||||
global_user = cls._by_key.get(global_key)
|
||||
if group_id:
|
||||
group_key = cls._key(user_id, group_id)
|
||||
if group_key:
|
||||
group_user = cls._by_key.get(group_key)
|
||||
return global_user, group_user
|
||||
|
||||
@classmethod
|
||||
async def get_max_level(cls, user_id: str | None) -> int:
|
||||
user_id = cls._normalize(user_id)
|
||||
@@ -1576,6 +1624,10 @@ class PluginLimitMemoryCache:
|
||||
return
|
||||
await cls.refresh()
|
||||
|
||||
@classmethod
|
||||
def is_loaded(cls) -> bool:
|
||||
return cls._loaded
|
||||
|
||||
@classmethod
|
||||
async def get_limits(cls, module: str) -> list[PluginLimitSnapshot]:
|
||||
normalized = cls._normalize(module)
|
||||
@@ -1592,6 +1644,22 @@ class PluginLimitMemoryCache:
|
||||
cls._mark_negative(module)
|
||||
return []
|
||||
|
||||
@classmethod
|
||||
def get_limits_if_ready(cls, module: str) -> list[PluginLimitSnapshot] | None:
|
||||
normalized = cls._normalize(module)
|
||||
if not normalized:
|
||||
return []
|
||||
module = normalized
|
||||
if not cls._loaded:
|
||||
return None
|
||||
limits = cls._by_module.get(module)
|
||||
if limits is not None:
|
||||
return limits
|
||||
if cls._is_negative(module):
|
||||
return []
|
||||
cls._mark_negative(module)
|
||||
return []
|
||||
|
||||
@classmethod
|
||||
def get_all_limits(cls) -> list[PluginLimitSnapshot]:
|
||||
return list(cls._by_id.values())
|
||||
|
||||
Reference in New Issue
Block a user