add notification link
This commit is contained in:
@ -202,7 +202,7 @@ class SlackModule(_ModuleBase):
|
||||
:return: 成功或失败
|
||||
"""
|
||||
self.slack.send_msg(title=message.title, text=message.text,
|
||||
image=message.image, userid=message.userid)
|
||||
image=message.image, userid=message.userid, link=message.link)
|
||||
|
||||
@checkMessage(MessageChannel.Slack)
|
||||
def post_medias_message(self, message: Notification, medias: List[MediaInfo]) -> Optional[bool]:
|
||||
|
@ -93,13 +93,13 @@ class Slack:
|
||||
"""
|
||||
return True if self._client else False
|
||||
|
||||
def send_msg(self, title: str, text: str = "", image: str = "", url: str = "", userid: str = ""):
|
||||
def send_msg(self, title: str, text: str = "", image: str = "", link: str = "", userid: str = ""):
|
||||
"""
|
||||
发送Telegram消息
|
||||
:param title: 消息标题
|
||||
:param text: 消息内容
|
||||
:param image: 消息图片地址
|
||||
:param url: 点击消息转转的URL
|
||||
:param link: 点击消息转转的URL
|
||||
:param userid: 用户ID,如有则只发消息给该用户
|
||||
:user_id: 发送消息的目标用户ID,为空则发给管理员
|
||||
"""
|
||||
@ -132,7 +132,7 @@ class Slack:
|
||||
"alt_text": f"{title}"
|
||||
}})
|
||||
# 链接
|
||||
if url:
|
||||
if link:
|
||||
blocks.append({
|
||||
"type": "actions",
|
||||
"elements": [
|
||||
@ -144,7 +144,7 @@ class Slack:
|
||||
"emoji": True
|
||||
},
|
||||
"value": "click_me_url",
|
||||
"url": f"{url}",
|
||||
"url": f"{link}",
|
||||
"action_id": "actionId-url"
|
||||
}
|
||||
]
|
||||
|
@ -74,7 +74,7 @@ class SynologyChatModule(_ModuleBase):
|
||||
:return: 成功或失败
|
||||
"""
|
||||
self.synologychat.send_msg(title=message.title, text=message.text,
|
||||
image=message.image, userid=message.userid)
|
||||
image=message.image, userid=message.userid, link=message.link)
|
||||
|
||||
@checkMessage(MessageChannel.SynologyChat)
|
||||
def post_medias_message(self, message: Notification, medias: List[MediaInfo]) -> Optional[bool]:
|
||||
@ -95,4 +95,5 @@ class SynologyChatModule(_ModuleBase):
|
||||
:param torrents: 种子列表
|
||||
:return: 成功或失败
|
||||
"""
|
||||
return self.synologychat.send_torrents_msg(title=message.title, torrents=torrents, userid=message.userid)
|
||||
return self.synologychat.send_torrents_msg(title=message.title, torrents=torrents,
|
||||
userid=message.userid, link=message.link)
|
||||
|
@ -36,7 +36,8 @@ class SynologyChat:
|
||||
return True
|
||||
return False
|
||||
|
||||
def send_msg(self, title: str, text: str = "", image: str = "", userid: str = "") -> Optional[bool]:
|
||||
def send_msg(self, title: str, text: str = "", image: str = "",
|
||||
userid: str = "", link: str = None) -> Optional[bool]:
|
||||
"""
|
||||
发送Telegram消息
|
||||
:param title: 消息标题
|
||||
@ -44,6 +45,7 @@ class SynologyChat:
|
||||
:param image: 消息图片地址
|
||||
:param userid: 用户ID,如有则只发消息给该用户
|
||||
:user_id: 发送消息的目标用户ID,为空则发给管理员
|
||||
:param link: 链接地址
|
||||
"""
|
||||
if not title and not text:
|
||||
logger.error("标题和内容不能同时为空")
|
||||
@ -64,6 +66,10 @@ class SynologyChat:
|
||||
caption = "*%s*\n%s" % (title, text.replace("\n\n", "\n"))
|
||||
else:
|
||||
caption = title
|
||||
|
||||
if link:
|
||||
caption = f"{caption}\n[查看详情]({link})"
|
||||
|
||||
payload_data = {'text': quote(caption)}
|
||||
if image:
|
||||
payload_data['file_url'] = quote(image)
|
||||
@ -127,7 +133,7 @@ class SynologyChat:
|
||||
return False
|
||||
|
||||
def send_torrents_msg(self, torrents: List[Context],
|
||||
userid: str = "", title: str = "") -> Optional[bool]:
|
||||
userid: str = "", title: str = "", link: str = None) -> Optional[bool]:
|
||||
"""
|
||||
发送列表消息
|
||||
"""
|
||||
@ -157,6 +163,9 @@ class SynologyChat:
|
||||
f"_{description}_"
|
||||
index += 1
|
||||
|
||||
if link:
|
||||
caption = f"{caption}\n[查看详情]({link})"
|
||||
|
||||
if userid:
|
||||
userids = [int(userid)]
|
||||
else:
|
||||
|
@ -110,7 +110,7 @@ class TelegramModule(_ModuleBase):
|
||||
:return: 成功或失败
|
||||
"""
|
||||
self.telegram.send_msg(title=message.title, text=message.text,
|
||||
image=message.image, userid=message.userid)
|
||||
image=message.image, userid=message.userid, link=message.link)
|
||||
|
||||
@checkMessage(MessageChannel.Telegram)
|
||||
def post_medias_message(self, message: Notification, medias: List[MediaInfo]) -> Optional[bool]:
|
||||
@ -121,7 +121,7 @@ class TelegramModule(_ModuleBase):
|
||||
:return: 成功或失败
|
||||
"""
|
||||
return self.telegram.send_meidas_msg(title=message.title, medias=medias,
|
||||
userid=message.userid)
|
||||
userid=message.userid, link=message.link)
|
||||
|
||||
@checkMessage(MessageChannel.Telegram)
|
||||
def post_torrents_message(self, message: Notification, torrents: List[Context]) -> Optional[bool]:
|
||||
@ -131,7 +131,8 @@ class TelegramModule(_ModuleBase):
|
||||
:param torrents: 种子列表
|
||||
:return: 成功或失败
|
||||
"""
|
||||
return self.telegram.send_torrents_msg(title=message.title, torrents=torrents, userid=message.userid)
|
||||
return self.telegram.send_torrents_msg(title=message.title, torrents=torrents,
|
||||
userid=message.userid, link=message.link)
|
||||
|
||||
def register_commands(self, commands: Dict[str, dict]):
|
||||
"""
|
||||
|
@ -67,13 +67,15 @@ class Telegram:
|
||||
"""
|
||||
return self._bot is not None
|
||||
|
||||
def send_msg(self, title: str, text: str = "", image: str = "", userid: str = "") -> Optional[bool]:
|
||||
def send_msg(self, title: str, text: str = "", image: str = "",
|
||||
userid: str = "", link: str = None) -> Optional[bool]:
|
||||
"""
|
||||
发送Telegram消息
|
||||
:param title: 消息标题
|
||||
:param text: 消息内容
|
||||
:param image: 消息图片地址
|
||||
:param userid: 用户ID,如有则只发消息给该用户
|
||||
:param link: 跳转链接
|
||||
:userid: 发送消息的目标用户ID,为空则发给管理员
|
||||
"""
|
||||
if not self._telegram_token or not self._telegram_chat_id:
|
||||
@ -89,6 +91,9 @@ class Telegram:
|
||||
else:
|
||||
caption = f"*{title}*"
|
||||
|
||||
if link:
|
||||
caption = f"{caption}\n[查看详情]({link})"
|
||||
|
||||
if userid:
|
||||
chat_id = userid
|
||||
else:
|
||||
@ -100,7 +105,8 @@ class Telegram:
|
||||
logger.error(f"发送消息失败:{msg_e}")
|
||||
return False
|
||||
|
||||
def send_meidas_msg(self, medias: List[MediaInfo], userid: str = "", title: str = "") -> Optional[bool]:
|
||||
def send_meidas_msg(self, medias: List[MediaInfo], userid: str = "",
|
||||
title: str = "", link: str = None) -> Optional[bool]:
|
||||
"""
|
||||
发送媒体列表消息
|
||||
"""
|
||||
@ -127,6 +133,9 @@ class Telegram:
|
||||
f"类型:{media.type.value}")
|
||||
index += 1
|
||||
|
||||
if link:
|
||||
caption = f"{caption}\n[查看详情]({link})"
|
||||
|
||||
if userid:
|
||||
chat_id = userid
|
||||
else:
|
||||
@ -139,7 +148,7 @@ class Telegram:
|
||||
return False
|
||||
|
||||
def send_torrents_msg(self, torrents: List[Context],
|
||||
userid: str = "", title: str = "") -> Optional[bool]:
|
||||
userid: str = "", title: str = "", link: str = None) -> Optional[bool]:
|
||||
"""
|
||||
发送列表消息
|
||||
"""
|
||||
@ -168,6 +177,9 @@ class Telegram:
|
||||
f"{StringUtils.str_filesize(torrent.size)} {free} {seeder}"
|
||||
index += 1
|
||||
|
||||
if link:
|
||||
caption = f"{caption}\n[查看详情]({link})"
|
||||
|
||||
if userid:
|
||||
chat_id = userid
|
||||
else:
|
||||
|
@ -103,7 +103,8 @@ class VoceChatModule(_ModuleBase):
|
||||
:param message: 消息内容
|
||||
:return: 成功或失败
|
||||
"""
|
||||
self.vocechat.send_msg(title=message.title, text=message.text, userid=message.userid)
|
||||
self.vocechat.send_msg(title=message.title, text=message.text,
|
||||
userid=message.userid, link=message.link)
|
||||
|
||||
@checkMessage(MessageChannel.VoceChat)
|
||||
def post_medias_message(self, message: Notification, medias: List[MediaInfo]) -> Optional[bool]:
|
||||
@ -116,7 +117,8 @@ class VoceChatModule(_ModuleBase):
|
||||
# 先发送标题
|
||||
self.vocechat.send_msg(title=message.title, userid=message.userid)
|
||||
# 再发送内容
|
||||
return self.vocechat.send_medias_msg(title=message.title, medias=medias, userid=message.userid)
|
||||
return self.vocechat.send_medias_msg(title=message.title, medias=medias,
|
||||
userid=message.userid, link=message.link)
|
||||
|
||||
@checkMessage(MessageChannel.VoceChat)
|
||||
def post_torrents_message(self, message: Notification, torrents: List[Context]) -> Optional[bool]:
|
||||
@ -126,7 +128,8 @@ class VoceChatModule(_ModuleBase):
|
||||
:param torrents: 种子列表
|
||||
:return: 成功或失败
|
||||
"""
|
||||
return self.vocechat.send_torrents_msg(title=message.title, torrents=torrents, userid=message.userid)
|
||||
return self.vocechat.send_torrents_msg(title=message.title, torrents=torrents,
|
||||
userid=message.userid, link=message.link)
|
||||
|
||||
def register_commands(self, commands: Dict[str, dict]):
|
||||
pass
|
||||
|
@ -58,12 +58,14 @@ class VoceChat:
|
||||
if result and result.status_code == 200:
|
||||
return result.json()
|
||||
|
||||
def send_msg(self, title: str, text: str = "", userid: str = None) -> Optional[bool]:
|
||||
def send_msg(self, title: str, text: str = "",
|
||||
userid: str = None, link: str = None) -> Optional[bool]:
|
||||
"""
|
||||
微信消息发送入口,支持文本、图片、链接跳转、指定发送对象
|
||||
:param title: 消息标题
|
||||
:param text: 消息内容
|
||||
:param userid: 消息发送对象的ID,为空则发给所有人
|
||||
:param link: 消息链接
|
||||
:return: 发送状态,错误信息
|
||||
"""
|
||||
if not self._client:
|
||||
@ -79,6 +81,9 @@ class VoceChat:
|
||||
else:
|
||||
caption = f"**{title}**"
|
||||
|
||||
if link:
|
||||
caption = f"{caption}\n[查看详情]({link})"
|
||||
|
||||
if userid:
|
||||
chat_id = userid
|
||||
else:
|
||||
@ -90,7 +95,8 @@ class VoceChat:
|
||||
logger.error(f"发送消息失败:{msg_e}")
|
||||
return False
|
||||
|
||||
def send_medias_msg(self, title: str, medias: List[MediaInfo], userid: str = "") -> Optional[bool]:
|
||||
def send_medias_msg(self, title: str, medias: List[MediaInfo],
|
||||
userid: str = "", link: str = None) -> Optional[bool]:
|
||||
"""
|
||||
发送列表类消息
|
||||
"""
|
||||
@ -115,6 +121,9 @@ class VoceChat:
|
||||
f"类型:{media.type.value}")
|
||||
index += 1
|
||||
|
||||
if link:
|
||||
caption = f"{caption}\n[查看详情]({link})"
|
||||
|
||||
if userid:
|
||||
chat_id = userid
|
||||
else:
|
||||
@ -127,7 +136,7 @@ class VoceChat:
|
||||
return False
|
||||
|
||||
def send_torrents_msg(self, torrents: List[Context],
|
||||
userid: str = "", title: str = "") -> Optional[bool]:
|
||||
userid: str = "", title: str = "", link: str = None) -> Optional[bool]:
|
||||
"""
|
||||
发送列表消息
|
||||
"""
|
||||
@ -155,6 +164,9 @@ class VoceChat:
|
||||
f"{StringUtils.str_filesize(torrent.size)} {free} {seeder}"
|
||||
index += 1
|
||||
|
||||
if link:
|
||||
caption = f"{caption}\n[查看详情]({link})"
|
||||
|
||||
if userid:
|
||||
chat_id = userid
|
||||
else:
|
||||
|
@ -141,7 +141,7 @@ class WechatModule(_ModuleBase):
|
||||
:return: 成功或失败
|
||||
"""
|
||||
self.wechat.send_msg(title=message.title, text=message.text,
|
||||
image=message.image, userid=message.userid)
|
||||
image=message.image, userid=message.userid, link=message.link)
|
||||
|
||||
@checkMessage(MessageChannel.Wechat)
|
||||
def post_medias_message(self, message: Notification, medias: List[MediaInfo]) -> Optional[bool]:
|
||||
@ -152,7 +152,7 @@ class WechatModule(_ModuleBase):
|
||||
:return: 成功或失败
|
||||
"""
|
||||
# 先发送标题
|
||||
self.wechat.send_msg(title=message.title, userid=message.userid)
|
||||
self.wechat.send_msg(title=message.title, userid=message.userid, link=message.link)
|
||||
# 再发送内容
|
||||
return self.wechat.send_medias_msg(medias=medias, userid=message.userid)
|
||||
|
||||
@ -164,7 +164,8 @@ class WechatModule(_ModuleBase):
|
||||
:param torrents: 种子列表
|
||||
:return: 成功或失败
|
||||
"""
|
||||
return self.wechat.send_torrents_msg(title=message.title, torrents=torrents, userid=message.userid)
|
||||
return self.wechat.send_torrents_msg(title=message.title, torrents=torrents,
|
||||
userid=message.userid, link=message.link)
|
||||
|
||||
def register_commands(self, commands: Dict[str, dict]):
|
||||
"""
|
||||
|
@ -88,12 +88,14 @@ class WeChat:
|
||||
return None
|
||||
return self._access_token
|
||||
|
||||
def __send_message(self, title: str, text: str = None, userid: str = None) -> Optional[bool]:
|
||||
def __send_message(self, title: str, text: str = None,
|
||||
userid: str = None, link: str = None) -> Optional[bool]:
|
||||
"""
|
||||
发送文本消息
|
||||
:param title: 消息标题
|
||||
:param text: 消息内容
|
||||
:param userid: 消息发送对象的ID,为空则发给所有人
|
||||
:param link: 跳转链接
|
||||
:return: 发送状态,错误信息
|
||||
"""
|
||||
message_url = self._send_msg_url % self.__get_access_token()
|
||||
@ -102,8 +104,12 @@ class WeChat:
|
||||
else:
|
||||
conent = title
|
||||
|
||||
if link:
|
||||
conent = f"{conent}\n点击查看:{link}"
|
||||
|
||||
if not userid:
|
||||
userid = "@all"
|
||||
|
||||
req_json = {
|
||||
"touser": userid,
|
||||
"msgtype": "text",
|
||||
@ -148,13 +154,15 @@ class WeChat:
|
||||
}
|
||||
return self.__post_request(message_url, req_json)
|
||||
|
||||
def send_msg(self, title: str, text: str = "", image: str = "", userid: str = None) -> Optional[bool]:
|
||||
def send_msg(self, title: str, text: str = "", image: str = "",
|
||||
userid: str = None, link: str = None) -> Optional[bool]:
|
||||
"""
|
||||
微信消息发送入口,支持文本、图片、链接跳转、指定发送对象
|
||||
:param title: 消息标题
|
||||
:param text: 消息内容
|
||||
:param image: 图片地址
|
||||
:param userid: 消息发送对象的ID,为空则发给所有人
|
||||
:param link: 跳转链接
|
||||
:return: 发送状态,错误信息
|
||||
"""
|
||||
if not self.__get_access_token():
|
||||
@ -162,9 +170,9 @@ class WeChat:
|
||||
return None
|
||||
|
||||
if image:
|
||||
ret_code = self.__send_image_message(title, text, image, userid)
|
||||
ret_code = self.__send_image_message(title=title, text=text, image_url=image, userid=userid)
|
||||
else:
|
||||
ret_code = self.__send_message(title, text, userid)
|
||||
ret_code = self.__send_message(title=title, text=text, userid=userid, link=link)
|
||||
|
||||
return ret_code
|
||||
|
||||
@ -205,7 +213,7 @@ class WeChat:
|
||||
return self.__post_request(message_url, req_json)
|
||||
|
||||
def send_torrents_msg(self, torrents: List[Context],
|
||||
userid: str = "", title: str = "") -> Optional[bool]:
|
||||
userid: str = "", title: str = "", link: str = None) -> Optional[bool]:
|
||||
"""
|
||||
发送列表消息
|
||||
"""
|
||||
@ -215,7 +223,7 @@ class WeChat:
|
||||
|
||||
# 先发送标题
|
||||
if title:
|
||||
self.__send_message(title=title, userid=userid)
|
||||
self.__send_message(title=title, userid=userid, link=link)
|
||||
|
||||
# 发送列表
|
||||
message_url = self._send_msg_url % self.__get_access_token()
|
||||
|
Reference in New Issue
Block a user