Skip to content

Commit

Permalink
fix: fix the Notification Type is not applied after changing it from …
Browse files Browse the repository at this point in the history
…WebUI
  • Loading branch information
zthxxx committed Jun 3, 2023
1 parent 5309ebe commit 220dccb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/module/manager/renamer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from typing import List
from module.downloader import DownloadClient

from module.parser import TitleParser
Expand Down Expand Up @@ -139,12 +140,12 @@ def rename_subtitles(
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)
Expand Down
15 changes: 11 additions & 4 deletions src/module/notification/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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":
Expand All @@ -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
)
Expand All @@ -48,12 +49,18 @@ def _gen_message(notify: Notification) -> str:
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(
Expand Down

0 comments on commit 220dccb

Please sign in to comment.