mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-05 11:49:59 +08:00
bugfix:更换数据库初始化超时路径以修复连接超时问题 (#2137)
* bugfix:更换数据库初始化超时路径以修复连接超时问题 * 移除部分观测链路 * 细节修改 * 权限检查细节修改2 * bugfix:修复金币懒加载造成插件金币消耗不了的问题 * bugfix:整理鉴权逻辑 * 完善缓存系统 * 优化官端使用 * bugfix:增加官机和频道的前导统一剥离,新增获取群列表自愈 * bugfix:修复导入问题
This commit is contained in:
@@ -39,6 +39,7 @@ if TYPE_CHECKING:
|
||||
class EventContext:
|
||||
bot_id: str
|
||||
platform: str
|
||||
platform_scope: str
|
||||
event_type: str
|
||||
message_id: str | int | None
|
||||
entity: EntityIDs
|
||||
@@ -170,6 +171,7 @@ def event_cache_key(
|
||||
*,
|
||||
bot_id: str,
|
||||
platform: str,
|
||||
platform_scope: str | None = None,
|
||||
entity: EntityIDs,
|
||||
) -> str:
|
||||
msg_id = _event_message_id(event)
|
||||
@@ -177,7 +179,11 @@ def event_cache_key(
|
||||
msg_id = id(event)
|
||||
group_id = entity.group_id or ""
|
||||
channel_id = entity.channel_id or ""
|
||||
return f"{platform}:{bot_id}:{entity.user_id}:{group_id}:{channel_id}:{msg_id}"
|
||||
scope = platform_scope or platform
|
||||
return (
|
||||
f"{scope}:{platform}:{bot_id}:{entity.user_id}:"
|
||||
f"{group_id}:{channel_id}:{msg_id}"
|
||||
)
|
||||
|
||||
|
||||
def get_event_cache(
|
||||
@@ -185,11 +191,18 @@ def get_event_cache(
|
||||
*,
|
||||
bot_id: str,
|
||||
platform: str,
|
||||
platform_scope: str | None = None,
|
||||
entity: EntityIDs,
|
||||
) -> dict[str, Any] | None:
|
||||
if not EVENT_CACHE:
|
||||
return None
|
||||
key = event_cache_key(event, bot_id=bot_id, platform=platform, entity=entity)
|
||||
key = event_cache_key(
|
||||
event,
|
||||
bot_id=bot_id,
|
||||
platform=platform,
|
||||
platform_scope=platform_scope,
|
||||
entity=entity,
|
||||
)
|
||||
try:
|
||||
return EVENT_CACHE[key]
|
||||
except KeyError:
|
||||
@@ -255,6 +268,7 @@ def get_or_create_event_context(
|
||||
entity = resolve_entity_ids(event, session)
|
||||
|
||||
platform = PlatformUtils.get_platform(session)
|
||||
platform_scope = PlatformUtils.get_platform_scope(session)
|
||||
bot_id = str(bot.self_id)
|
||||
event_cache = state.get(STATE_EVENT_CACHE)
|
||||
if not isinstance(event_cache, dict):
|
||||
@@ -262,6 +276,7 @@ def get_or_create_event_context(
|
||||
event,
|
||||
bot_id=bot_id,
|
||||
platform=platform,
|
||||
platform_scope=platform_scope,
|
||||
entity=entity,
|
||||
)
|
||||
|
||||
@@ -292,6 +307,7 @@ def get_or_create_event_context(
|
||||
context = EventContext(
|
||||
bot_id=bot_id,
|
||||
platform=platform,
|
||||
platform_scope=platform_scope,
|
||||
event_type=event.get_type(),
|
||||
message_id=_event_message_id(event),
|
||||
entity=entity,
|
||||
|
||||
Reference in New Issue
Block a user