Skip to content

Commit

Permalink
Merge pull request #2938 from InfinityPacer/feature/push
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp authored Oct 25, 2024
2 parents 1651f46 + eff8a6c commit be785f3
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 96 deletions.
8 changes: 4 additions & 4 deletions app/modules/telegram/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,15 @@ def __send_request(self, userid: str = None, image="", caption="") -> bool:
"""
向Telegram发送报文
"""

if image:
res = RequestUtils(proxies=settings.PROXY).get_res(image)
if res is None:
raise Exception("获取图片失败")
if res.content:
# 使用随机标识构建图片文件的完整路径,并写入图片内容到文件
image_file = Path(settings.TEMP_PATH) / str(uuid.uuid4())
image_file = Path(settings.TEMP_PATH) / "telegram" / str(uuid.uuid4())
if not image_file.parent.exists():
image_file.parent.mkdir(parents=True, exist_ok=True)
image_file.write_bytes(res.content)
photo = InputFile(image_file)
# 发送图片到Telegram
Expand All @@ -223,8 +224,7 @@ def __send_request(self, userid: str = None, image="", caption="") -> bool:
parse_mode="Markdown")
if ret is None:
raise Exception("发送图片消息失败")
if ret:
return True
return True
# 按4096分段循环发送消息
ret = None
if len(caption) > 4095:
Expand Down
Loading

0 comments on commit be785f3

Please sign in to comment.