Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/src/module/notification/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ServerChanNotification,
TelegramNotification,
WecomNotification,
GotifyNotification,
)

logger = logging.getLogger(__name__)
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions backend/src/module/notification/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .server_chan import ServerChanNotification
from .telegram import TelegramNotification
from .wecom import WecomNotification
from .gotify import GotifyNotification
39 changes: 39 additions & 0 deletions backend/src/module/notification/plugin/gotify.py
Original file line number Diff line number Diff line change
@@ -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