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 .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
"mikan",
"starlette"
],
"python.analysis.extraPaths": [
"backend/src"
],
}
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ sqlmodel==0.0.8
sse-starlette==1.6.5
semver==3.0.1
openai==0.28.1
apprise==1.9.4
5 changes: 4 additions & 1 deletion backend/src/module/conf/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
"username": "",
"password": "",
},
"notification": {"enable": False, "type": "telegram", "token": "", "chat_id": ""},
"notification": {
"enable": False,
"entry": "",
},
}


Expand Down
12 changes: 3 additions & 9 deletions backend/src/module/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,11 @@ def password(self):

class Notification(BaseModel):
enable: bool = Field(False, description="Enable notification")
type: str = Field("telegram", description="Notification type")
token_: str = Field("", alias="token", description="Notification token")
chat_id_: str = Field("", alias="chat_id", description="Notification chat id")
entry_: str = Field("", alias="entry", description="Notification entry(check https://github.com/caronc/apprise/wiki for details)")

@property
def token(self):
return expandvars(self.token_)

@property
def chat_id(self):
return expandvars(self.chat_id_)
def entry(self):
return expandvars(self.entry_)


class ExperimentalOpenAI(BaseModel):
Expand Down
42 changes: 14 additions & 28 deletions backend/src/module/notification/notification.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,43 @@
import logging
import apprise
import os

from module.conf import settings
from module.database import Database
from module.models import Notification

from .plugin import (
BarkNotification,
ServerChanNotification,
TelegramNotification,
WecomNotification,
)

logger = logging.getLogger(__name__)


def getClient(type: str):
if type.lower() == "telegram":
return TelegramNotification
elif type.lower() == "server-chan":
return ServerChanNotification
elif type.lower() == "bark":
return BarkNotification
elif type.lower() == "wecom":
return WecomNotification
else:
return None


class PostNotification:
def __init__(self):
Notifier = getClient(settings.notification.type)
self.notifier = Notifier(
token=settings.notification.token, chat_id=settings.notification.chat_id
)
self.apobj = apprise.Apprise()
self.apobj.add(settings.notification.entry)

@staticmethod
def _get_poster(notify: Notification):
with Database() as db:
poster_path = db.bangumi.match_poster(notify.official_title)
poster_path = f"data/{poster_path}"
if not os.path.isfile(poster_path):
poster_path = None
notify.poster_path = poster_path

def send_msg(self, notify: Notification) -> bool:
self._get_poster(notify)

try:
self.notifier.post_msg(notify)
self.apobj.notify(
title=f'番剧更新:{notify.official_title}',
body=f'第 {notify.season} 季,第 {notify.episode} 话',
attach=notify.poster_path
)
logger.debug(f"Send notification: {notify.official_title}")
except Exception as e:
logger.warning(f"Failed to send notification: {e}")
return False

def __enter__(self):
self.notifier.__enter__()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.notifier.__exit__(exc_type, exc_val, exc_tb)
pass
4 changes: 0 additions & 4 deletions backend/src/module/notification/plugin/__init__.py

This file was deleted.

27 changes: 0 additions & 27 deletions backend/src/module/notification/plugin/bark.py

This file was deleted.

31 changes: 0 additions & 31 deletions backend/src/module/notification/plugin/server_chan.py

This file was deleted.

27 changes: 0 additions & 27 deletions backend/src/module/notification/plugin/slack.py

This file was deleted.

38 changes: 0 additions & 38 deletions backend/src/module/notification/plugin/telegram.py

This file was deleted.

42 changes: 0 additions & 42 deletions backend/src/module/notification/plugin/wecom.py

This file was deleted.

1 change: 1 addition & 0 deletions webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"husky": "^8.0.3",
"prettier": "^2.8.8",
"radash": "^12.1.0",
"sass": "^1.90.0",
"sass-embedded": "^1.79.3",
"storybook": "^7.6.20",
"typescript": "^4.9.5",
Expand Down
32 changes: 4 additions & 28 deletions webui/src/components/setting/config-notification.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
<script lang="ts" setup>
import type { Notification, NotificationType } from '#/config';
import type { Notification } from '#/config';
import type { SettingItem } from '#/components';

const { t } = useMyI18n();
const { getSettingGroup } = useConfigStore();

const notification = getSettingGroup('notification');
const notificationType: NotificationType = [
'telegram',
'server-chan',
'bark',
'wecom',
];

const items: SettingItem<Notification>[] = [
{
Expand All @@ -21,30 +15,12 @@ const items: SettingItem<Notification>[] = [
bottomLine: true,
},
{
configKey: 'type',
label: () => t('config.notification_set.type'),
type: 'select',
css: 'w-140',
prop: {
items: notificationType,
},
},
{
configKey: 'token',
label: () => t('config.notification_set.token'),
type: 'input',
prop: {
type: 'text',
placeholder: 'token',
},
},
{
configKey: 'chat_id',
label: () => t('config.notification_set.chat_id'),
configKey: 'entry',
label: () => t('config.notification_set.entry'),
type: 'input',
prop: {
type: 'text',
placeholder: 'chat id',
placeholder: 'entry',
},
},
];
Expand Down
4 changes: 1 addition & 3 deletions webui/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@
"web_port": "WebUI Port"
},
"notification_set": {
"chat_id": "Chat ID",
"enable": "Enable",
"title": "Notification Setting",
"token": "Token",
"type": "Type"
"entry": "Notification service entry"
},
"parser_set": {
"enable": "Enable",
Expand Down
4 changes: 1 addition & 3 deletions webui/src/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@
"web_port": "网页端口"
},
"notification_set": {
"chat_id": "Chat ID",
"enable": "启用",
"title": "通知设置",
"token": "Token",
"type": "类型"
"entry": "通知服务地址"
},
"parser_set": {
"enable": "启用",
Expand Down
Loading