def send(self, sender: PytgbotApiBot, receiver, reply_id)->PytgbotApiMessage:
if self.receiver:
receiver = self.receiver
# end if
if self.reply_id is not DEFAULT_MESSAGE_ID:
reply_id = self.reply_id
# end if
self.prepare_file()
assert isinstance(self.file, (InputFile, InputFileFromDisk, InputFileFromURL))
if not any([self.file.file_name.endswith(x) for x in [".jpg", ".jpeg", ".gif", ".png", ".tif", ".bmp"]]):
if self.file.file_mime in ["image/jpg", "image/jpeg", "image/jpe"]: # manually, to avoid .jpe ending.
self.file.file_name+=".jpg"
else:
import mimetypes
ext = mimetypes.guess_extension(self.file.file_mime) # automatically
if ext not in [".jpg", ".jpeg", ".gif", ".png", ".tif", ".bmp"]:
ext = ".unknown-file-type.png" # At least we can try setting it as .png
self.file.file_name += ext
try:
return sender.send_photo(
receiver, self.file, caption=self.caption, reply_to_message_id=reply_id, reply_markup=self.reply_markup,
disable_notification = self.disable_notification
)
except TgApiServerException as e:
should_backoff(e) # checks if it should raise an DoRetryException
raise # else it just raises as usual
# end try
# end def send
# end class PhotoMessage
评论列表
文章目录