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,
DiscordNotification,
)

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() == "discord":
return DiscordNotification
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 .discord import DiscordNotification
44 changes: 44 additions & 0 deletions backend/src/module/notification/plugin/discord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import logging

from module.models import Notification
from module.network import RequestContent

logger = logging.getLogger(__name__)


class DiscordNotification(RequestContent):
"""Use Discord Webhook send notification"""
API_ENDPOINT = "https://discord.com/api"

def __init__(self, token, chat_id, **kwargs):
super().__init__()
self.notification_url = f"{self.API_ENDPOINT}/webhooks/{chat_id}/{token}"
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:
title = "【番剧更新】" + notify.official_title
msg = self.gen_message(notify)
picurl = notify.poster_path

data = {
"content": msg,
"embeds": [
{
"title": title,
"image": {
"url": picurl
}
}
]
}

resp = self.post_data(self.notification_url, data)
logger.debug(f"Discord notification: {resp.status_code}")
return resp.status_code == 200
3 changes: 2 additions & 1 deletion docs/config/notifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Wecom
- Bark
- ServerChan
- Discord
- **Chat ID** 仅在使用 `telegram` 通知时需要填写。[Telegram Bot 获取 Chat ID][1]
- **Wecom**,chat_id参数框填写自建推送的url地址,同时需要在服务端增加[图文消息][2]类型。[Wecom酱配置说明][3]

Expand All @@ -31,4 +32,4 @@

[1]: https://core.telegram.org/bots#6-botfather
[2]: https://github.com/umbors/wecomchan-alifun
[3]: https://github.com/easychen/wecomchan
[3]: https://github.com/easychen/wecomchan
1 change: 1 addition & 0 deletions webui/src/components/setting/config-notification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const notificationType: NotificationType = [
'server-chan',
'bark',
'wecom',
'discord'
];

const items: SettingItem<Notification>[] = [
Expand Down
2 changes: 1 addition & 1 deletion webui/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface Config {
};
notification: {
enable: boolean;
type: 'telegram' | 'server-chan' | 'bark' | 'wecom';
type: 'telegram' | 'server-chan' | 'bark' | 'wecom' | 'discord';
token: string;
chat_id: string;
};
Expand Down