This commit is contained in:
jxxghp
2024-04-12 11:49:19 +08:00
parent d978ef6c14
commit 10a15d7b2d

View File

@@ -1,4 +1,5 @@
import json, requests
import json
import requests
from typing import Any, List, Dict, Tuple
@@ -7,6 +8,7 @@ from app.log import logger
from app.plugins import _PluginBase
from app.schemas.types import EventType, NotificationType
class NtfyClient:
def send(self, message: str, title: str = None, format_as_markdown: bool = False):
@@ -21,19 +23,21 @@ class NtfyClient:
return response
def __init__(
self,
topic: str,
server: str = "https://ntfy.sh",
user: str = "",
password: str = "",
self,
topic: str,
server: str = "https://ntfy.sh",
user: str = "",
password: str = "",
):
self._server = server
self._topic = topic
self.__set_url(server, topic)
self._auth = (user, password)
def __set_url(self, server, topic):
self.url = server.strip("/") + "/" + topic
class NtfyMsg(_PluginBase):
# 插件名称
plugin_name = "ntfy 消息通知"
@@ -220,11 +224,10 @@ class NtfyMsg(_PluginBase):
'msgtypes': [],
'server': 'https://ntfy.sh',
'topic': 'MoviePilot',
'user':'',
'password':'',
'user': '',
'password': '',
}
def get_page(self) -> List[dict]:
pass
@@ -264,7 +267,7 @@ class NtfyMsg(_PluginBase):
if not self._server or not self._topic:
return False, "参数未配置"
ntfy = NtfyClient(server=self._server, topic=self._topic, user=self._user, password=self._password)
ntfy.send(title=title, message=text,format_as_markdown=True)
ntfy.send(title=title, message=text, format_as_markdown=True)
except Exception as msg_e:
logger.error(f"ntfy消息发送失败错误信息{str(msg_e)}")