Add Wecom Notification

添加了企业微信推送通道
This commit is contained in:
umbor
2023-06-04 11:02:24 +08:00
parent 085fb35e4e
commit ddb89df40e
3 changed files with 39 additions and 1 deletions

View File

@@ -17,6 +17,8 @@ def getClient(type=settings.notification.type):
return ServerChanNotification
elif type.lower() == "bark":
return BarkNotification
elif type.lower() == "wecom":
return WecomNotification
else:
return None

View File

@@ -1,3 +1,4 @@
from .bark import BarkNotification
from .server_chan import ServerChanNotification
from .telegram import TelegramNotification
from .telegram import TelegramNotification
from .wecom import WecomNotification

View File

@@ -0,0 +1,35 @@
import logging
from module.network import RequestContent
logger = logging.getLogger(__name__)
class WecomNotification(RequestContent):
"""企业微信推送 基于图文消息"""
def __init__(self, token, chat_id, **kwargs):
super().__init__()
#Chat_id is used as noti_url in this push tunnel
self.notification_url = f"{chat_id}"
self.token = token
def post_msg(self, text: str) -> bool:
##Change message format to match Wecom push better
info = text.split("")
print(info)
title = "【番剧更新】" + info[1].split("\n")[0].strip()
msg = info[2].split("\n")[0].strip()+" "+info[3].split("\n")[0].strip()
picurl = info[3].split("\n")[1].strip()
#Default pic to avoid blank in message. Resolution:1068*455
if picurl == "":
picurl = "https://article.biliimg.com/bfs/article/d8bcd0408bf32594fd82f27de7d2c685829d1b2e.png"
data = {
"key":self.token,
"type": "news",
"title": title,
"msg": msg,
"picurl":picurl
}
resp = self.post_data(self.notification_url, data)
logger.debug(f"Wecom notification: {resp.status_code}")
return resp.status_code == 200