🐛 Add more twitter domains

This commit is contained in:
xtaodada 2023-09-10 12:58:42 +08:00
parent 3015a68b64
commit 43456033b8
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
3 changed files with 21 additions and 11 deletions

View File

@ -51,7 +51,7 @@ def twitter_media(tweet_media_lists: List[FixTweetMedia], text: str):
if media.type == "photo":
media_lists.append(
InputMediaPhoto(
media.media_url,
media.url,
caption=text if idx == 0 else None,
parse_mode=ParseMode.HTML,
)
@ -59,15 +59,17 @@ def twitter_media(tweet_media_lists: List[FixTweetMedia], text: str):
elif media.type == "gif":
media_lists.append(
InputMediaAnimation(
media.media_url,
media.url,
caption=text if idx == 0 else None,
parse_mode=ParseMode.HTML,
)
)
else:
elif media.type == "video":
media_lists.append(
InputMediaVideo(
media.media_url,
media.url,
thumb=media.thumbnail_url,
duration=media.duration,
caption=text if idx == 0 else None,
parse_mode=ParseMode.HTML,
)

View File

@ -40,6 +40,9 @@ class User(BaseModel):
class FixTweetMedia(BaseModel):
type: str
url: str
thumbnail_url: str = ""
duration: float = 0
format: str = ""
width: int = 0
height: int = 0
altText: str = ""

View File

@ -15,34 +15,34 @@ from defs.fix_twitter_api import (
twitter_medias,
)
from init import bot
from models.apis.twitter.model import MediaItem
from models.apis.fxtwitter.model import FixTweetMedia
async def send_single_tweet(message: Message, media: MediaItem, text: str, button):
async def send_single_tweet(message: Message, media: FixTweetMedia, text: str, button):
if media.type == "photo":
await message.reply_photo(
media.media_url,
media.url,
quote=True,
caption=text,
reply_markup=button,
)
elif media.type == "video":
await message.reply_video(
media.media_url,
media.url,
quote=True,
caption=text,
reply_markup=button,
)
elif media.type == "gif":
await message.reply_animation(
media.media_url,
media.url,
quote=True,
caption=text,
reply_markup=button,
)
else:
await message.reply_document(
media.media_url,
media.url,
quote=True,
caption=text,
reply_markup=button,
@ -87,7 +87,12 @@ async def process_user(message: Message, username: str):
async def process_url(url: str, message: Message):
url = urlparse(url)
if url.hostname and url.hostname in ["twitter.com", "vxtwitter.com"]:
if url.hostname and url.hostname in [
"twitter.com",
"vxtwitter.com",
"fxtwitter.com",
"x.com",
]:
if url.path.find("status") >= 0:
status_id = str(
url.path[url.path.find("status") + 7 :].split("/")[0]