This commit is contained in:
DrSmoothl
2026-02-21 16:29:30 +08:00
parent eaef7f0e98
commit 6378bb2052
20 changed files with 57 additions and 69 deletions

View File

@@ -218,7 +218,7 @@ async def get_log_detail(chat_id: str, filename: str):
data = json.load(f)
return PlanLogDetail(**data)
except Exception as e:
raise HTTPException(status_code=500, detail=f"读取日志失败: {str(e)}")
raise HTTPException(status_code=500, detail=f"读取日志失败: {str(e)}") from e
# ========== 兼容旧接口 ==========

View File

@@ -232,7 +232,7 @@ async def get_reply_log_detail(chat_id: str, filename: str):
success=data.get("success", True),
)
except Exception as e:
raise HTTPException(status_code=500, detail=f"读取日志失败: {str(e)}")
raise HTTPException(status_code=500, detail=f"读取日志失败: {str(e)}") from e
# ========== 兼容接口 ==========

View File

@@ -333,7 +333,7 @@ async def get_social_network(year: int = 2025) -> SocialNetworkData:
statement = select(func.count()).where(
col(Messages.timestamp) >= datetime.fromtimestamp(start_ts),
col(Messages.timestamp) <= datetime.fromtimestamp(end_ts),
col(Messages.is_at) == True,
col(Messages.is_at),
)
data.at_count = int(session.exec(statement).first() or 0)
@@ -342,7 +342,7 @@ async def get_social_network(year: int = 2025) -> SocialNetworkData:
statement = select(func.count()).where(
col(Messages.timestamp) >= datetime.fromtimestamp(start_ts),
col(Messages.timestamp) <= datetime.fromtimestamp(end_ts),
col(Messages.is_mentioned) == True,
col(Messages.is_mentioned),
)
data.mentioned_count = int(session.exec(statement).first() or 0)
@@ -552,7 +552,7 @@ async def get_expression_vibe(year: int = 2025) -> ExpressionVibeData:
# 1. 表情包之王 - 使用次数最多的表情包
with get_db_session() as session:
statement = (
select(Images).where(col(Images.is_registered) == True).order_by(desc(col(Images.query_count))).limit(5)
select(Images).where(col(Images.is_registered)).order_by(desc(col(Images.query_count))).limit(5)
)
top_emojis = session.exec(statement).all()
if top_emojis:
@@ -636,7 +636,7 @@ async def get_expression_vibe(year: int = 2025) -> ExpressionVibeData:
statement = select(func.count()).where(
col(Messages.timestamp) >= datetime.fromtimestamp(start_ts),
col(Messages.timestamp) <= datetime.fromtimestamp(end_ts),
col(Messages.is_picture) == True,
col(Messages.is_picture),
)
data.image_processed_count = int(session.exec(statement).first() or 0)
@@ -781,12 +781,12 @@ async def get_achievements(year: int = 2025) -> AchievementData:
# 1. 新学到的黑话数量
# Jargon 表没有时间字段,统计全部已确认的黑话
with get_db_session() as session:
statement = select(func.count()).where(col(Jargon.is_jargon) == True)
statement = select(func.count()).where(col(Jargon.is_jargon))
data.new_jargon_count = int(session.exec(statement).first() or 0)
# 2. 代表性黑话示例
with get_db_session() as session:
statement = select(Jargon).where(col(Jargon.is_jargon) == True).order_by(desc(col(Jargon.count))).limit(5)
statement = select(Jargon).where(col(Jargon.is_jargon)).order_by(desc(col(Jargon.count))).limit(5)
jargon_samples = session.exec(statement).all()
data.sample_jargons = [
{

View File

@@ -532,7 +532,7 @@ async def get_emoji_stats(maibot_session: Optional[str] = Cookie(None), authoriz
.select_from(Images)
.where(
col(Images.image_type) == ImageType.EMOJI,
col(Images.is_registered) == True,
col(Images.is_registered),
)
)
banned_statement = (
@@ -540,7 +540,7 @@ async def get_emoji_stats(maibot_session: Optional[str] = Cookie(None), authoriz
.select_from(Images)
.where(
col(Images.image_type) == ImageType.EMOJI,
col(Images.is_banned) == True,
col(Images.is_banned),
)
)
@@ -1283,7 +1283,7 @@ async def preheat_thumbnail_cache(
select(Images)
.where(
col(Images.image_type) == ImageType.EMOJI,
col(Images.is_banned) == False,
col(Images.is_banned).is_(False),
)
.order_by(col(Images.query_count).desc())
.limit(limit * 2)

View File

@@ -315,15 +315,15 @@ async def get_jargon_stats():
total = session.exec(select(fn.count()).select_from(Jargon)).one()
confirmed_jargon = session.exec(
select(fn.count()).select_from(Jargon).where(col(Jargon.is_jargon) == True)
select(fn.count()).select_from(Jargon).where(col(Jargon.is_jargon))
).one()
confirmed_not_jargon = session.exec(
select(fn.count()).select_from(Jargon).where(col(Jargon.is_jargon) == False)
select(fn.count()).select_from(Jargon).where(col(Jargon.is_jargon).is_(False))
).one()
pending = session.exec(select(fn.count()).select_from(Jargon).where(col(Jargon.is_jargon).is_(None))).one()
complete_count = session.exec(
select(fn.count()).select_from(Jargon).where(col(Jargon.is_complete) == True)
select(fn.count()).select_from(Jargon).where(col(Jargon.is_complete))
).one()
chat_count = session.exec(

View File

@@ -370,7 +370,7 @@ async def get_person_stats(maibot_session: Optional[str] = Cookie(None), authori
with get_db_session() as session:
total = len(session.exec(select(PersonInfo.id)).all())
known = len(session.exec(select(PersonInfo.id).where(col(PersonInfo.is_known) == True)).all())
known = len(session.exec(select(PersonInfo.id).where(col(PersonInfo.is_known))).all())
unknown = total - known
# 按平台统计

View File

@@ -1762,7 +1762,7 @@ async def update_plugin_config_raw(
try:
tomlkit.loads(request.config)
except Exception as e:
raise HTTPException(status_code=400, detail=f"TOML 格式错误: {str(e)}")
raise HTTPException(status_code=400, detail=f"TOML 格式错误: {str(e)}") from e
# 备份旧配置
import shutil