Skip to content

Commit 0f8ceb0

Browse files
committed
fix warnings
1 parent a70bf18 commit 0f8ceb0

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

app/api/endpoints/mfa.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
包含 OTP 和 PassKey 相关功能
44
"""
55
from datetime import timedelta
6-
from typing import Any, Annotated, Optional, List, Union
6+
from typing import Any, Annotated, Optional
77

8+
from app.helper.sites import SitesHelper
89
from fastapi import APIRouter, Depends, HTTPException, Body
910
from sqlalchemy.ext.asyncio import AsyncSession
1011

@@ -14,10 +15,9 @@
1415
from app.db import get_async_db
1516
from app.db.models.passkey import PassKey
1617
from app.db.models.user import User
17-
from app.db.user_oper import get_current_active_user, get_current_active_user_async
1818
from app.db.systemconfig_oper import SystemConfigOper
19+
from app.db.user_oper import get_current_active_user, get_current_active_user_async
1920
from app.helper.passkey import PassKeyHelper
20-
from app.helper.sites import SitesHelper
2121
from app.log import logger
2222
from app.schemas.types import SystemConfigKey
2323
from app.utils.otp import OtpUtils
@@ -134,7 +134,6 @@ class PassKeyAuthenticationFinish(schemas.BaseModel):
134134

135135
@router.post("/passkey/register/start", summary="开始注册 PassKey", response_model=schemas.Response)
136136
def passkey_register_start(
137-
passkey_req: PassKeyRegistrationStart,
138137
current_user: Annotated[User, Depends(get_current_active_user)]
139138
) -> Any:
140139
"""开始注册 PassKey - 生成注册选项"""
@@ -351,7 +350,7 @@ def passkey_list(
351350
try:
352351
passkeys = PassKey.get_by_user_id(db=None, user_id=current_user.id)
353352

354-
passkey_list = [
353+
key_list = [
355354
{
356355
'id': pk.id,
357356
'name': pk.name,
@@ -365,7 +364,7 @@ def passkey_list(
365364

366365
return schemas.Response(
367366
success=True,
368-
data=passkey_list
367+
data=key_list
369368
)
370369
except Exception as e:
371370
logger.error(f"获取PassKey列表失败: {e}")

app/modules/discord/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ def message_parser(self, source: str, body: Any, form: Any, args: Any) -> Option
9191
return None
9292
try:
9393
msg_json: dict = json.loads(body)
94-
except Exception as err:
95-
logger.debug(f"解析 Discord 消息失败:{str(err)}")
94+
except Exception as e:
95+
logger.debug(f"解析 Discord 消息失败:{str(e)}")
9696
return None
9797

9898
if not msg_json:

app/modules/discord/discord.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self, DISCORD_BOT_TOKEN: Optional[str] = None,
5656
def _to_int(val: Optional[Union[str, int]]) -> Optional[int]:
5757
try:
5858
return int(val) if val is not None and str(val).strip() else None
59-
except Exception:
59+
except ValueError:
6060
return None
6161

6262
def _register_events(self):
@@ -96,8 +96,8 @@ async def on_interaction(interaction: discord.Interaction):
9696
return
9797
try:
9898
await interaction.response.defer(ephemeral=True)
99-
except Exception:
100-
pass
99+
except Exception as e:
100+
logger.error(f"处理 Discord 交互响应失败:{e}")
101101

102102
username = (interaction.user.display_name or interaction.user.global_name or interaction.user.name) \
103103
if interaction.user else None
@@ -126,8 +126,8 @@ def runner():
126126
finally:
127127
try:
128128
self._loop.run_until_complete(self._client.close())
129-
except Exception:
130-
pass
129+
except Exception as err:
130+
logger.debug(f"Discord Bot 关闭失败:{err}")
131131

132132
self._thread = threading.Thread(target=runner, daemon=True)
133133
self._thread.start()
@@ -142,8 +142,8 @@ def stop(self):
142142
finally:
143143
try:
144144
self._loop.call_soon_threadsafe(self._loop.stop)
145-
except Exception:
146-
pass
145+
except Exception as err:
146+
logger.error(f"停止 Discord 事件循环失败:{err}")
147147
self._ready_event.clear()
148148

149149
def get_state(self) -> bool:
@@ -313,7 +313,8 @@ async def _delete_message(self, message_id: Union[str, int], chat_id: Optional[s
313313
logger.error(f"删除 Discord 消息失败:{err}")
314314
return False
315315

316-
def _build_embed(self, title: str, text: Optional[str], image: Optional[str],
316+
@staticmethod
317+
def _build_embed(title: str, text: Optional[str], image: Optional[str],
317318
link: Optional[str]) -> discord.Embed:
318319
description = ""
319320
fields: List[Dict[str, str]] = []
@@ -337,7 +338,8 @@ def _build_embed(self, title: str, text: Optional[str], image: Optional[str],
337338
embed.set_image(url=image)
338339
return embed
339340

340-
def _build_media_embeds(self, medias: List[MediaInfo], title: str) -> List[discord.Embed]:
341+
@staticmethod
342+
def _build_media_embeds(medias: List[MediaInfo], title: str) -> List[discord.Embed]:
341343
embeds: List[discord.Embed] = []
342344
for index, media in enumerate(medias[:10], start=1):
343345
overview = media.get_overview_string(80)
@@ -358,7 +360,8 @@ def _build_media_embeds(self, medias: List[MediaInfo], title: str) -> List[disco
358360
embeds[0].set_author(name=title)
359361
return embeds
360362

361-
def _build_torrent_embeds(self, torrents: List[Context], title: str) -> List[discord.Embed]:
363+
@staticmethod
364+
def _build_torrent_embeds(torrents: List[Context], title: str) -> List[discord.Embed]:
362365
embeds: List[discord.Embed] = []
363366
for index, context in enumerate(torrents[:10], start=1):
364367
torrent = context.torrent_info
@@ -384,7 +387,8 @@ def _build_torrent_embeds(self, torrents: List[Context], title: str) -> List[dis
384387
embeds[0].set_author(name=title)
385388
return embeds
386389

387-
def _build_default_buttons(self, count: int) -> List[List[dict]]:
390+
@staticmethod
391+
def _build_default_buttons(count: int) -> List[List[dict]]:
388392
buttons: List[List[dict]] = []
389393
max_rows = 5
390394
max_per_row = 5
@@ -398,7 +402,8 @@ def _build_default_buttons(self, count: int) -> List[List[dict]]:
398402
logger.warn(f"按钮数量超过 Discord 限制,仅展示前 {capped} 个")
399403
return buttons
400404

401-
def _build_view(self, buttons: Optional[List[List[dict]]], link: Optional[str] = None) -> Optional[discord.ui.View]:
405+
@staticmethod
406+
def _build_view(buttons: Optional[List[List[dict]]], link: Optional[str] = None) -> Optional[discord.ui.View]:
402407
has_buttons = buttons and any(buttons)
403408
if not has_buttons and not link:
404409
return None
@@ -429,8 +434,8 @@ async def _resolve_channel(self, userid: Optional[str] = None, chat_id: Optional
429434
return channel
430435
try:
431436
return await self._client.fetch_channel(int(chat_id))
432-
except Exception:
433-
pass
437+
except Exception as err:
438+
logger.warn(f"通过 chat_id 获取 Discord 频道失败:{err}")
434439

435440
# 私聊
436441
if userid:
@@ -446,7 +451,8 @@ async def _resolve_channel(self, userid: Optional[str] = None, chat_id: Optional
446451
if not channel:
447452
try:
448453
channel = await self._client.fetch_channel(self._channel_id)
449-
except Exception:
454+
except Exception as err:
455+
logger.warn(f"通过配置的频道ID获取 Discord 频道失败:{err}")
450456
channel = None
451457
self._broadcast_channel = channel
452458
if channel:

0 commit comments

Comments
 (0)