Update utils.py
parent
b215143c49
commit
b8d192730a
50
src/utils.py
50
src/utils.py
|
|
@ -284,6 +284,7 @@ async def read_ban_list(
|
|||
) -> Tuple[List[BanUser], List[BanUser]]:
|
||||
"""
|
||||
从根目录下的data文件夹中的文件读取禁言列表。
|
||||
冷启动保护:如果 Napcat 群成员缓存未加载,暂不视为解除。
|
||||
同时自动更新已经失效禁言
|
||||
Returns:
|
||||
Tuple[
|
||||
|
|
@ -297,34 +298,39 @@ async def read_ban_list(
|
|||
ban_list = db_manager.get_ban_records()
|
||||
lifted_list: List[BanUser] = []
|
||||
logger.info("已经读取禁言列表")
|
||||
for ban_record in ban_list:
|
||||
for ban_record in list(ban_list):
|
||||
if ban_record.user_id == 0:
|
||||
fetched_group_info = await get_group_info(websocket, ban_record.group_id)
|
||||
if fetched_group_info is None:
|
||||
logger.warning(f"无法获取群信息,群号: {ban_record.group_id},默认禁言解除")
|
||||
lifted_list.append(ban_record)
|
||||
ban_list.remove(ban_record)
|
||||
try:
|
||||
fetched_group_info = await get_group_info(websocket, ban_record.group_id)
|
||||
except Exception as e:
|
||||
logger.warning(f"获取群信息失败(群号: {ban_record.group_id}):{e},保留全体禁言状态")
|
||||
continue
|
||||
group_all_shut: int = fetched_group_info.get("group_all_shut")
|
||||
if not fetched_group_info:
|
||||
logger.warning(f"群 {ban_record.group_id} 暂未返回群信息,跳过全体禁言检查")
|
||||
continue
|
||||
group_all_shut = fetched_group_info.get("group_all_shut")
|
||||
if group_all_shut == 0:
|
||||
lifted_list.append(ban_record)
|
||||
ban_list.remove(ban_record)
|
||||
continue
|
||||
else:
|
||||
continue
|
||||
try:
|
||||
fetched_member_info = await get_member_info(websocket, ban_record.group_id, ban_record.user_id)
|
||||
if fetched_member_info is None:
|
||||
logger.warning(
|
||||
f"无法获取群成员信息,用户ID: {ban_record.user_id}, 群号: {ban_record.group_id},默认禁言解除"
|
||||
)
|
||||
lifted_list.append(ban_record)
|
||||
ban_list.remove(ban_record)
|
||||
continue
|
||||
lift_ban_time: int = fetched_member_info.get("shut_up_timestamp")
|
||||
if lift_ban_time == 0:
|
||||
lifted_list.append(ban_record)
|
||||
ban_list.remove(ban_record)
|
||||
else:
|
||||
ban_record.lift_time = lift_ban_time
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"获取群成员信息失败(群号: {ban_record.group_id} 用户ID: {ban_record.user_id}):{e},保留禁言状态"
|
||||
)
|
||||
continue
|
||||
if fetched_member_info is None:
|
||||
logger.warning(
|
||||
f"群 {ban_record.group_id} 用户 {ban_record.user_id} 暂无成员信息(Napcat缓存未加载?),暂不视为解除"
|
||||
)
|
||||
continue
|
||||
lift_ban_time: int = fetched_member_info.get("shut_up_timestamp", 0)
|
||||
if lift_ban_time == 0:
|
||||
lifted_list.append(ban_record)
|
||||
ban_list.remove(ban_record)
|
||||
else:
|
||||
ban_record.lift_time = lift_ban_time
|
||||
db_manager.update_ban_record(ban_list)
|
||||
return ban_list, lifted_list
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Reference in New Issue