fix: fix the Notification Type is not applied after changing it from WebUI

This commit is contained in:
zthxxx
2023-06-03 21:11:00 +08:00
parent 5309ebecb8
commit 25f3471161
3 changed files with 15 additions and 8 deletions

View File

@@ -139,12 +139,12 @@ class Renamer(DownloadClient):
if not renamed:
logger.warning(f"[Renamer] {subtitle_path} rename failed")
def rename(self):
def rename(self) -> list[Notification]:
# Get torrent info
logger.debug("[Renamer] Start rename process.")
rename_method = settings.bangumi_manage.rename_method
torrents_info = self.get_torrent_info()
renamed_info = []
renamed_info: list[Notification] = []
for info in torrents_info:
media_list, subtitle_list = self.check_files(info)
bangumi_name, season = self._path_to_bangumi(info.save_path)

View File

@@ -42,11 +42,11 @@ class RequestContent(RequestURL):
_url: str,
_filter: str = "|".join(settings.rss_parser.filter),
retry: int = 3,
) -> [TorrentInfo]:
) -> list[TorrentInfo]:
try:
soup = self.get_xml(_url, retry)
torrent_titles, torrent_urls, torrent_homepage = mikan_parser(soup)
torrents = []
torrents: list[TorrentInfo] = []
for _title, torrent_url, homepage in zip(
torrent_titles, torrent_urls, torrent_homepage
):

View File

@@ -10,7 +10,7 @@ from module.database import BangumiDatabase
logger = logging.getLogger(__name__)
def getClient(type=settings.notification.type):
def getClient(type: str):
if type.lower() == "telegram":
return TelegramNotification
elif type.lower() == "server-chan":
@@ -23,9 +23,10 @@ def getClient(type=settings.notification.type):
return None
class PostNotification(getClient()):
class PostNotification:
def __init__(self):
super().__init__(
Notifier = getClient(settings.notification.type)
self.notifier = Notifier(
token=settings.notification.token,
chat_id=settings.notification.chat_id
)
@@ -48,12 +49,18 @@ class PostNotification(getClient()):
def send_msg(self, notify: Notification) -> bool:
text = self._gen_message(notify)
try:
self.post_msg(text)
self.notifier.post_msg(text)
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)
if __name__ == "__main__":
info = Notification(