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