mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-02-02 17:59:27 +08:00
- Fix search store exports to match component expectations (inputValue, bangumiList, onSearch) and transform data to SearchResult format - Fix poster endpoint path check that incorrectly blocked all requests - Add resolvePosterUrl utility to handle both external URLs and local paths - Move tags into hover overlay on homepage cards and calendar cards - Show title and tags on poster hover with dark semi-transparent styling - Add downloader API, store, and page - Update backend to async patterns and uv migration changes - Remove .claude/settings.local.json from tracking Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import logging
|
|
|
|
from module.models import Notification
|
|
from module.network import RequestContent
|
|
from module.utils import load_image
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class TelegramNotification(RequestContent):
|
|
def __init__(self, token, chat_id):
|
|
super().__init__()
|
|
self.photo_url = f"https://api.telegram.org/bot{token}/sendPhoto"
|
|
self.message_url = f"https://api.telegram.org/bot{token}/sendMessage"
|
|
self.chat_id = chat_id
|
|
|
|
@staticmethod
|
|
def gen_message(notify: Notification) -> str:
|
|
text = f"""
|
|
番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集
|
|
"""
|
|
return text.strip()
|
|
|
|
async def post_msg(self, notify: Notification) -> bool:
|
|
text = self.gen_message(notify)
|
|
data = {
|
|
"chat_id": self.chat_id,
|
|
"caption": text,
|
|
"text": text,
|
|
"disable_notification": True,
|
|
}
|
|
photo = load_image(notify.poster_path)
|
|
if photo:
|
|
resp = await self.post_files(self.photo_url, data, files={"photo": photo})
|
|
else:
|
|
resp = await self.post_data(self.message_url, data)
|
|
logger.debug(f"Telegram notification: {resp.status_code}")
|
|
return resp.status_code == 200
|