diff --git a/config.yaml.template b/config.yaml.template index f4688ff..90a9734 100644 --- a/config.yaml.template +++ b/config.yaml.template @@ -41,6 +41,9 @@ logging: groups: enable: [] # 允许响应的群 roomId,大概长这样:2xxxxxxxxx3@chatroom +news: + receivers: [] # 定时新闻接收人(roomid 或者 wxid) + # 如果要使用 ChatGPT,取消下面的注释并填写相关内容 # chatgpt: # key: 填写你 ChatGPT 的 key diff --git a/configuration.py b/configuration.py index 8b6ccf4..b3dad0f 100644 --- a/configuration.py +++ b/configuration.py @@ -30,3 +30,4 @@ class Config(object): self.GROUPS = yconfig["groups"]["enable"] self.CHATGPT = yconfig.get("chatgpt") self.HTTP = yconfig.get("http") + self.NEWS = yconfig["news"]["receivers"] diff --git a/main.py b/main.py index f2f2a51..0b50f56 100644 --- a/main.py +++ b/main.py @@ -50,9 +50,12 @@ def main(): # 接收消息 robot.enableRecvMsg() - # 每天7点发送天气预报 + # 每天 7 点发送天气预报 robot.onEveryTime("07:00", weather_report, robot=robot) + # 每天 7:30 发送新闻 + robot.onEveryTime("07:30", robot.newsReport) + # 让机器人一直跑 robot.keepRunningAndBlockProcess() diff --git a/robot.py b/robot.py index 19f07cc..30320b9 100644 --- a/robot.py +++ b/robot.py @@ -11,6 +11,7 @@ from configuration import Config from func_chatgpt import ChatGPT from func_chengyu import cy from func_http import Http +from func_news import News from job_mgmt import Job @@ -200,3 +201,12 @@ class Robot(Job): description=f"Github: WeChatFerry",) Http.start(http, c["host"], c["port"]) self.LOG.info(f"HTTP listening on http://{c['host']}:{c['port']}") + + def newsReport(self) -> None: + receivers = self.config.NEWS + if not receivers: + return + + news = News().get_important_news() + for r in receivers: + self.sendTextMsg(news, r)