From 9f1359fbeb01e370cdaa3886f7aea4eeb2fb0247 Mon Sep 17 00:00:00 2001 From: liuwei Date: Thu, 22 May 2025 11:01:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E7=B3=BB=E7=BB=9F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=94=BE=E5=88=B0yaml=E9=87=8C=E9=9D=A2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 9 +++++++++ configuration.py | 3 +++ robot.py | 14 +++++++------- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/config.yaml b/config.yaml index 3478916..b855246 100644 --- a/config.yaml +++ b/config.yaml @@ -141,3 +141,12 @@ redis_config: db: 0 decode_responses: true + +# 邮件发送配置 +email_config: + smtp_server: "smtp.163.com" + smtp_port: 465 + sender_email: "bovine_liu@163.com" + sender_password: "LTS9BhmX9XhS36QS" + alert_recipient: "bovine_liu@163.com" # 警报邮件接收者 + diff --git a/configuration.py b/configuration.py index 959b193..765ccc4 100644 --- a/configuration.py +++ b/configuration.py @@ -44,3 +44,6 @@ class Config(object): # DB config self.mariadb = yconfig.get("db_config", {}) self.redis = yconfig.get("redis_config", {}) + + # Email config + self.email = yconfig.get("email_config", {}) diff --git a/robot.py b/robot.py index b8d14f6..41956cc 100644 --- a/robot.py +++ b/robot.py @@ -95,10 +95,10 @@ class Robot: # 加载插件 self.LOG.info("插件系统初始化完成") self.email_sender = EmailSender( - smtp_server="smtp.163.com", - smtp_port=465, - sender_email="bovine_liu@163.com", - sender_password="LTS9BhmX9XhS36QS" + smtp_server=self.config.email.get("smtp_server", "smtp.163.com"), + smtp_port=self.config.email.get("smtp_port", 465), + sender_email=self.config.email.get("sender_email", "bovine_liu@163.com"), + sender_password=self.config.email.get("sender_password", "LTS9BhmX9XhS36QS") ) def init_wechat_ipad(self): @@ -222,7 +222,7 @@ class Robot: self.LOG.error(f"获取新消息失败 {e}") if "用户可能退出" in str(e): self.LOG.error(f"用户可能退出: {e}") - self.email_sender.send_wechat_alert("bovine_liu@163.com", f"用户可能退出: {e}", self.wxid, + self.email_sender.send_wechat_alert(self.config.email.get("alert_recipient"), f"用户可能退出: {e}", self.wxid, self.nickname) await self.login_twice_auto_auth() await asyncio.sleep(5) @@ -324,7 +324,7 @@ class Robot: self.LOG.error(f"wechat_ipad heartbeat: {e}") if "用户可能退出" in str(e): self.LOG.error(f"用户可能退出: {e}") - self.email_sender.send_wechat_alert("bovine_liu@163.com", f"用户可能退出: {e}", self.wxid, + self.email_sender.send_wechat_alert(self.config.email.get("alert_recipient"), f"用户可能退出: {e}", self.wxid, self.nickname) await self.login_twice_auto_auth() await asyncio.sleep(60) @@ -343,7 +343,7 @@ class Robot: self.LOG.error(f"wechat_ipad heartbeat long: {e}") if "用户可能退出" in str(e): self.LOG.error(f"用户可能退出: {e}") - self.email_sender.send_wechat_alert("bovine_liu@163.com", f"用户可能退出: {e}", self.wxid, + self.email_sender.send_wechat_alert(self.config.email.get("alert_recipient"), f"用户可能退出: {e}", self.wxid, self.nickname) await self.login_twice_auto_auth() await asyncio.sleep(120)