mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-25 02:50:27 +08:00
Add telegram and server-chan notification
This commit is contained in:
@@ -31,7 +31,6 @@ async def restart():
|
||||
logger.info("Restarted")
|
||||
return {"status": "success"}
|
||||
|
||||
|
||||
@router.get("/api/v1/stop", tags=["program"])
|
||||
async def stop():
|
||||
global main_process
|
||||
|
||||
@@ -7,6 +7,7 @@ from module.core.download_client import DownloadClient
|
||||
|
||||
from module.conf import settings
|
||||
from module.parser import TitleParser
|
||||
from module.network import PostNotification
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -15,6 +16,7 @@ class Renamer:
|
||||
def __init__(self, download_client: DownloadClient):
|
||||
self.client = download_client
|
||||
self._renamer = TitleParser()
|
||||
self.notification = PostNotification()
|
||||
|
||||
@staticmethod
|
||||
def print_result(torrent_count, rename_count):
|
||||
@@ -50,6 +52,7 @@ class Renamer:
|
||||
if compare_name != new_path:
|
||||
try:
|
||||
self.client.rename_torrent_file(_hash=info.hash, old_path=media_path, new_path=new_path)
|
||||
self.notification.send_msg(folder_name, "update")
|
||||
except Exception as e:
|
||||
logger.warning(f"{old_name} rename failed")
|
||||
logger.warning(f"Folder name: {folder_name}, Season: {season}, Suffix: {suffix}")
|
||||
|
||||
@@ -17,7 +17,7 @@ class PostNotification:
|
||||
def getClient():
|
||||
if settings.notification.type.lower() == "telegram":
|
||||
return TelegramNotification()
|
||||
elif settings.notification.type.lower() == "serverchan":
|
||||
elif settings.notification.type.lower() == "server-chan":
|
||||
return ServerChanNotification()
|
||||
else:
|
||||
return None
|
||||
@@ -32,16 +32,19 @@ class PostNotification:
|
||||
|
||||
class TelegramNotification:
|
||||
def __init__(self):
|
||||
self.token = settings.notification_token
|
||||
self.token = settings.notification.token
|
||||
self.chat_id = settings.notification.chat_id
|
||||
self.notification_url = f"https://api.telegram.org/bot{self.token}/sendMessage"
|
||||
|
||||
def send_msg(self, title: str, desp: str) -> bool:
|
||||
if not settings.notification_enable:
|
||||
return False
|
||||
def send_msg(self, title: str, desp: str):
|
||||
data = {
|
||||
"chat_id": settings.notification_chat_id,
|
||||
"text": f"{title}\n{desp}",
|
||||
"disable_notification": True,
|
||||
}
|
||||
with RequestContent() as req:
|
||||
resp = req.post_data(self.notification_url, data)
|
||||
return resp.status_code == 200
|
||||
|
||||
|
||||
class ServerChanNotification:
|
||||
@@ -51,8 +54,6 @@ class ServerChanNotification:
|
||||
self.notification_url = f"https://sctapi.ftqq.com/{self.token}.send"
|
||||
|
||||
def send_msg(self, title: str, desp: str) -> bool:
|
||||
if not settings.notification.enable:
|
||||
return False
|
||||
data = {
|
||||
"title": title,
|
||||
"desp": desp,
|
||||
|
||||
Reference in New Issue
Block a user