From 85d506db4555af9b9e9e0914f362eb1f8a65e36e Mon Sep 17 00:00:00 2001 From: admin <1065576641@qq.com> Date: Thu, 15 Aug 2024 20:23:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Egofity=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/module/notification/notification.py | 3 ++ .../module/notification/plugin/__init__.py | 1 + .../src/module/notification/plugin/gotify.py | 39 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 backend/src/module/notification/plugin/gotify.py diff --git a/backend/src/module/notification/notification.py b/backend/src/module/notification/notification.py index 909fc92ca..d480dec95 100644 --- a/backend/src/module/notification/notification.py +++ b/backend/src/module/notification/notification.py @@ -9,6 +9,7 @@ ServerChanNotification, TelegramNotification, WecomNotification, + GotifyNotification, ) logger = logging.getLogger(__name__) @@ -23,6 +24,8 @@ def getClient(type: str): return BarkNotification elif type.lower() == "wecom": return WecomNotification + elif type.lower() == "gotify": + return GotifyNotification else: return None diff --git a/backend/src/module/notification/plugin/__init__.py b/backend/src/module/notification/plugin/__init__.py index e9acda8f1..642a6f22d 100644 --- a/backend/src/module/notification/plugin/__init__.py +++ b/backend/src/module/notification/plugin/__init__.py @@ -2,3 +2,4 @@ from .server_chan import ServerChanNotification from .telegram import TelegramNotification from .wecom import WecomNotification +from .gotify import GotifyNotification \ No newline at end of file diff --git a/backend/src/module/notification/plugin/gotify.py b/backend/src/module/notification/plugin/gotify.py new file mode 100644 index 000000000..9be461faf --- /dev/null +++ b/backend/src/module/notification/plugin/gotify.py @@ -0,0 +1,39 @@ +import logging + +from module.models import Notification +from module.network import RequestContent + +logger = logging.getLogger(__name__) + + +class GotifyNotification(RequestContent): + """gotify推送 无图""" + + 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 + + @staticmethod + def gen_message(notify: Notification) -> str: + text = f""" + 番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n{notify.poster_path}\n + """ + return text.strip() + + def post_msg(self, notify: Notification) -> bool: + ##Change message format to match Gotify push better + title = "【番剧更新】" + notify.official_title + message = self.gen_message(notify) + data = { + "title": title, + "message": message, + } + if self.notification_url.find("?token=") != -1: + post_url = self.notification_url + else: + post_url = f"{self.notification_url}?token={self.token}" + resp = self.post_data(post_url, data) + logger.debug(f"Gotify notification: {resp.status_code}") + return resp.status_code == 200 \ No newline at end of file