This commit is contained in:
tt-P607
2025-10-06 21:46:27 +08:00
7 changed files with 349239 additions and 35 deletions

View File

@@ -56,7 +56,9 @@ class ChineseTypoGenerator:
# 使用内置的词频文件
char_freq = defaultdict(int)
dict_path = os.path.join(os.path.dirname(rjieba.__file__), "dict.txt")
# 从当前文件向上返回三级目录到项目根目录,然后拼接路径
base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
dict_path = os.path.join(base_dir, "depends-data", "dict.txt")
# 读取rjieba的词典文件
with open(dict_path, encoding="utf-8") as f:

View File

@@ -48,35 +48,6 @@ class DatabaseProxy:
return result
class SQLAlchemyTransaction:
"""SQLAlchemy 异步事务上下文管理器 (兼容旧代码示例,推荐直接使用 get_db_session)。"""
def __init__(self):
self._ctx = None
self.session = None
async def __aenter__(self):
# get_db_session 是一个 async contextmanager
self._ctx = get_db_session()
self.session = await self._ctx.__aenter__()
return self.session
async def __aexit__(self, exc_type, exc_val, exc_tb):
try:
if self.session:
if exc_type is None:
try:
await self.session.commit()
except Exception:
await self.session.rollback()
raise
else:
await self.session.rollback()
finally:
if self._ctx:
await self._ctx.__aexit__(exc_type, exc_val, exc_tb)
# 创建全局数据库代理实例
db = DatabaseProxy()

View File

@@ -36,7 +36,7 @@ class IPermissionManager(ABC):
async def check_permission(self, user: UserInfo, permission_node: str) -> bool: ...
@abstractmethod
def is_master(self, user: UserInfo) -> bool: ... # 同步快速判断
async def is_master(self, user: UserInfo) -> bool: ... # 同步快速判断
@abstractmethod
async def register_permission_node(self, node: PermissionNode) -> bool: ...
@@ -82,9 +82,9 @@ class PermissionAPI:
self._ensure_manager()
return await self._permission_manager.check_permission(UserInfo(platform, user_id), permission_node)
def is_master(self, platform: str, user_id: str) -> bool:
async def is_master(self, platform: str, user_id: str) -> bool:
self._ensure_manager()
return self._permission_manager.is_master(UserInfo(platform, user_id))
return await self._permission_manager.is_master(UserInfo(platform, user_id))
async def register_permission_node(
self,

View File

@@ -231,7 +231,7 @@ class PermissionCommand(PlusCommand):
target_user_id = chat_stream.user_info.user_id
# 检查是否为Master用户
is_master = permission_api.is_master(chat_stream.platform, target_user_id)
is_master = await permission_api.is_master(chat_stream.platform, target_user_id)
# 获取用户权限
permissions = await permission_api.get_user_permissions(chat_stream.platform, target_user_id)