mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-09-23 23:32:05 +00:00
fix send gif
This commit is contained in:
@@ -52,6 +52,11 @@ async def url_media(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
media,
|
||||
caption=tweet.message_text,
|
||||
reply_to_message_id=update.message.message_id,
|
||||
) if not tweet.is_single_gif else await update.effective_message.reply_animation(
|
||||
media[0][0],
|
||||
caption=tweet.message_text,
|
||||
reply_to_message_id=update.message.message_id,
|
||||
has_spoiler=media[0][1]
|
||||
)
|
||||
url = tweet.url
|
||||
if context.user_data.get('edit_before_forward', False):
|
||||
|
||||
@@ -7,8 +7,7 @@ from telegram import (
|
||||
InlineQueryResultVideo,
|
||||
InlineQueryResultMpeg4Gif,
|
||||
InputMediaPhoto,
|
||||
InputMediaVideo,
|
||||
InputMediaAnimation
|
||||
InputMediaVideo
|
||||
)
|
||||
|
||||
from common import x_url_regex, x_media_regex, x_tco_regex, logger
|
||||
@@ -125,6 +124,7 @@ class TGTweet(Tweet):
|
||||
def __init__(self, url: str):
|
||||
self._url: str = url
|
||||
self._api_param: tuple[str] = self._tweet_id
|
||||
self._is_single_gif: bool = False
|
||||
assert self._api_param
|
||||
|
||||
async def __aenter__(self):
|
||||
@@ -179,6 +179,10 @@ class TGTweet(Tweet):
|
||||
sensitive = self._tweet['possibly_sensitive']
|
||||
return id, author, author_id, text, media, sensitive
|
||||
|
||||
@property
|
||||
def is_single_gif(self) -> bool:
|
||||
return self._is_single_gif
|
||||
|
||||
@property
|
||||
def message_text(self) -> str:
|
||||
return message_raw_text.format(
|
||||
@@ -219,7 +223,7 @@ class TGTweet(Tweet):
|
||||
)
|
||||
|
||||
@property
|
||||
def pm_media_generator(self) -> Generator[InputMediaPhoto | InputMediaVideo | InputMediaAnimation, None, None]:
|
||||
def pm_media_generator(self) -> Generator[InputMediaPhoto | InputMediaVideo | tuple[str, bool], None, None]:
|
||||
for tweet_media in self.media:
|
||||
logger.info(str(tweet_media))
|
||||
if tweet_media.type == "image":
|
||||
@@ -234,7 +238,10 @@ class TGTweet(Tweet):
|
||||
thumbnail=tweet_media.thumb
|
||||
)
|
||||
elif tweet_media.type == "gif":
|
||||
yield InputMediaAnimation(
|
||||
if len(self.media) == 1:
|
||||
self._is_single_gif = True
|
||||
yield tweet_media.url, self.sensitive
|
||||
yield InputMediaVideo(
|
||||
media=tweet_media.url,
|
||||
has_spoiler=self.sensitive,
|
||||
thumbnail=tweet_media.thumb
|
||||
|
||||
Reference in New Issue
Block a user