chore: format code and remove redundant blank lines
This commit applies automated code formatting across the project. The changes primarily involve removing unnecessary blank lines and ensuring consistent code style, improving readability and maintainability without altering functionality.
This commit is contained in:
committed by
Windpicker-owo
parent
0172cf7b8b
commit
d66e04baff
@@ -53,7 +53,9 @@ class MaiZoneRefactoredPlugin(BasePlugin):
|
||||
"enable_reply": ConfigField(type=bool, default=True, description="完成后是否回复"),
|
||||
"ai_image_number": ConfigField(type=int, default=1, description="AI生成图片数量"),
|
||||
"image_number": ConfigField(type=int, default=1, description="本地配图数量(1-9张)"),
|
||||
"image_directory": ConfigField(type=str, default=(Path(__file__).parent / "images").as_posix(), description="图片存储目录")
|
||||
"image_directory": ConfigField(
|
||||
type=str, default=(Path(__file__).parent / "images").as_posix(), description="图片存储目录"
|
||||
),
|
||||
},
|
||||
"read": {
|
||||
"permission": ConfigField(type=list, default=[], description="阅读权限QQ号列表"),
|
||||
@@ -75,7 +77,9 @@ class MaiZoneRefactoredPlugin(BasePlugin):
|
||||
"forbidden_hours_end": ConfigField(type=int, default=6, description="禁止发送的结束小时(24小时制)"),
|
||||
},
|
||||
"cookie": {
|
||||
"http_fallback_host": ConfigField(type=str, default="127.0.0.1", description="备用Cookie获取服务的主机地址"),
|
||||
"http_fallback_host": ConfigField(
|
||||
type=str, default="127.0.0.1", description="备用Cookie获取服务的主机地址"
|
||||
),
|
||||
"http_fallback_port": ConfigField(type=int, default=9999, description="备用Cookie获取服务的端口"),
|
||||
"napcat_token": ConfigField(type=str, default="", description="Napcat服务的认证Token(可选)"),
|
||||
},
|
||||
@@ -95,14 +99,14 @@ class MaiZoneRefactoredPlugin(BasePlugin):
|
||||
image_service = ImageService(self.get_config)
|
||||
cookie_service = CookieService(self.get_config)
|
||||
reply_tracker_service = ReplyTrackerService()
|
||||
|
||||
|
||||
# 使用已创建的 reply_tracker_service 实例
|
||||
qzone_service = QZoneService(
|
||||
self.get_config,
|
||||
content_service,
|
||||
image_service,
|
||||
self.get_config,
|
||||
content_service,
|
||||
image_service,
|
||||
cookie_service,
|
||||
reply_tracker_service # 传入已创建的实例
|
||||
reply_tracker_service, # 传入已创建的实例
|
||||
)
|
||||
scheduler_service = SchedulerService(self.get_config, qzone_service)
|
||||
monitor_service = MonitorService(self.get_config, qzone_service)
|
||||
|
||||
@@ -272,8 +272,10 @@ class QZoneService:
|
||||
# 检查是否已经在持久化记录中标记为已回复
|
||||
if not self.reply_tracker.has_replied(fid, comment_tid):
|
||||
# 记录日志以便追踪
|
||||
logger.debug(f"发现新评论需要回复 - 说说ID: {fid}, 评论ID: {comment_tid}, "
|
||||
f"评论人: {comment.get('nickname', '')}, 内容: {comment.get('content', '')}")
|
||||
logger.debug(
|
||||
f"发现新评论需要回复 - 说说ID: {fid}, 评论ID: {comment_tid}, "
|
||||
f"评论人: {comment.get('nickname', '')}, 内容: {comment.get('content', '')}"
|
||||
)
|
||||
comments_to_reply.append(comment)
|
||||
|
||||
if not comments_to_reply:
|
||||
|
||||
@@ -41,7 +41,7 @@ class ReplyTrackerService:
|
||||
if not isinstance(data, dict):
|
||||
logger.error("加载的数据不是字典格式")
|
||||
return False
|
||||
|
||||
|
||||
for feed_id, comments in data.items():
|
||||
if not isinstance(feed_id, str):
|
||||
logger.error(f"无效的说说ID格式: {feed_id}")
|
||||
@@ -70,12 +70,14 @@ class ReplyTrackerService:
|
||||
logger.warning("回复记录文件为空,将创建新的记录")
|
||||
self.replied_comments = {}
|
||||
return
|
||||
|
||||
|
||||
data = json.loads(file_content)
|
||||
if self._validate_data(data):
|
||||
self.replied_comments = data
|
||||
logger.info(f"已加载 {len(self.replied_comments)} 条说说的回复记录,"
|
||||
f"总计 {sum(len(comments) for comments in self.replied_comments.values())} 条评论")
|
||||
logger.info(
|
||||
f"已加载 {len(self.replied_comments)} 条说说的回复记录,"
|
||||
f"总计 {sum(len(comments) for comments in self.replied_comments.values())} 条评论"
|
||||
)
|
||||
else:
|
||||
logger.error("加载的数据格式无效,将创建新的记录")
|
||||
self.replied_comments = {}
|
||||
@@ -112,12 +114,12 @@ class ReplyTrackerService:
|
||||
self._cleanup_old_records()
|
||||
|
||||
# 创建临时文件
|
||||
temp_file = self.reply_record_file.with_suffix('.tmp')
|
||||
|
||||
temp_file = self.reply_record_file.with_suffix(".tmp")
|
||||
|
||||
# 先写入临时文件
|
||||
with open(temp_file, "w", encoding="utf-8") as f:
|
||||
json.dump(self.replied_comments, f, ensure_ascii=False, indent=2)
|
||||
|
||||
|
||||
# 如果写入成功,重命名为正式文件
|
||||
if temp_file.stat().st_size > 0: # 确保写入成功
|
||||
# 在Windows上,如果目标文件已存在,需要先删除它
|
||||
@@ -128,7 +130,7 @@ class ReplyTrackerService:
|
||||
else:
|
||||
logger.error("临时文件写入失败,文件大小为0")
|
||||
temp_file.unlink() # 删除空的临时文件
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"保存回复记录失败: {e}", exc_info=True)
|
||||
# 尝试删除可能存在的临时文件
|
||||
@@ -204,7 +206,7 @@ class ReplyTrackerService:
|
||||
|
||||
# 确保将comment_id转换为字符串格式
|
||||
comment_id_str = str(comment_id)
|
||||
|
||||
|
||||
if feed_id not in self.replied_comments:
|
||||
self.replied_comments[feed_id] = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user