From d6142b6c8c1fd70a537a9931d097b1c1f4af6688 Mon Sep 17 00:00:00 2001 From: mattuy Date: Sat, 7 Aug 2021 17:23:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E9=A3=9E=E4=B9=A6=E6=96=B0=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 11 ++++++----- wxbot.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index f31c4ea..2b9bb8f 100644 --- a/main.py +++ b/main.py @@ -84,8 +84,9 @@ if __name__ == "__main__": wxbot_instance['current'] = wxbot wxbot.DEBUG = args.debug wxbot.saveFolder = args.data_dir - WXBotThreadStarter(wxbot).start() - if args.serve: - start_server = websockets.serve(message_consumer, "localhost", 8083) - asyncio.get_event_loop().run_until_complete(start_server) - asyncio.get_event_loop().run_forever() + wxbot.start() + # WXBotThreadStarter(wxbot).start() + # if args.serve: + # start_server = websockets.serve(message_consumer, "localhost", 8083) + # asyncio.get_event_loop().run_until_complete(start_server) + # asyncio.get_event_loop().run_forever() diff --git a/wxbot.py b/wxbot.py index 181306a..dc40fd6 100644 --- a/wxbot.py +++ b/wxbot.py @@ -5,6 +5,8 @@ import queue import logging import os +import requests + class Subscription: def __init__(self, queue): @@ -234,6 +236,34 @@ class WXBot(WebWeixin): params["content"] = "[未识别消息]" + msg["Content"] self.db_conn.execute(sql, params) self.db_conn.commit() + + # 工作时间发送新消息提醒到飞书 + curr_time_struct = time.localtime(time.time()) + if curr_time_struct.tm_hour >= 10 and curr_time_struct.tm_hour < 19: + requests.post( + "https://open.feishu.cn/open-apis/bot/v2/hook/30bda541-46de-40b7-8881-31b77deadc35", + headers={"Content-Type": "application/json"}, + json={ + "msg_type": "post", + "content": { + "post": { + "zh_cn": { + "title": "【" + params["from_name"] + "】发来一条新消息", + "content": [ + [ + { + "tag": "text", + "text": "【微信】收到一条来自【" + + params["from_name"] + + "】的消息", + } + ] + ], + } + } + }, + }, + ) for subscription in self.subscriptions: if ( not subscription.queue.empty()