Improve ScraperBot.send_medias message

This commit is contained in:
AlberLC
2022-12-17 10:16:02 +01:00
parent 770e599eca
commit 9bb1e480f7

View File

@@ -130,18 +130,15 @@ class ScraperBot(MultiBot, ABC):
async def _search_medias(self, message: Message, audio_only=False, timeout_for_media: int | float = None) -> OrderedSet[Media]:
medias = OrderedSet()
tweet_ids, instagram_ids, reddit_ids, tiktok_users_and_ids, tiktok_download_urls = await self._find_ids(message.text)
ids = await self._find_ids(message.text)
media_urls = ()
if (
not any((tweet_ids, instagram_ids, reddit_ids, tiktok_users_and_ids, tiktok_download_urls))
and
not (media_urls := flanautils.find_urls(message.text))
):
if not any(ids) and not (media_urls := flanautils.find_urls(message.text)):
return medias
bot_state_message = await self.send(random.choice(constants.SCRAPING_PHRASES), message)
tweet_ids, instagram_ids, reddit_ids, tiktok_users_and_ids, tiktok_download_urls = ids
gather_result = asyncio.gather(
twitter.get_medias(tweet_ids, audio_only),
instagram.get_medias(instagram_ids, audio_only),
@@ -207,7 +204,16 @@ class ScraperBot(MultiBot, ABC):
if message.chat.is_group:
sended_info_message = await self.send(f"{message.author.name.split('#')[0]} compartió{self._medias_sended_info(medias)}", message, reply_to=message.replied_message)
user_text = ' '.join([word for word in message.text.split() if not any(await self._find_ids(word)) and not flanautils.find_urls(word)])
user_text = ' '.join(
[word for word in message.text.split()
if (
not any(await self._find_ids(word))
and
not flanautils.find_urls(word)
and
not flanautils.cartesian_product_string_matching(word, (*multibot_constants.KEYWORDS['audio'], *constants.KEYWORDS['scraping']))
)]
)
if user_text:
user_text_bot_message = await self.send(user_text, message, reply_to=message.replied_message)