From f10fbaa38a5a8cc5b641b5c1dd06556fb78ce32f Mon Sep 17 00:00:00 2001 From: AlberLC Date: Sun, 14 Aug 2022 08:56:44 +0200 Subject: [PATCH] Update file names --- multibot/bots/discord_bot.py | 6 ++++-- multibot/bots/telegram_bot.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/multibot/bots/discord_bot.py b/multibot/bots/discord_bot.py index a91bed0..fb0e2ca 100644 --- a/multibot/bots/discord_bot.py +++ b/multibot/bots/discord_bot.py @@ -220,12 +220,14 @@ async def _prepare_media_to_send(media: Media) -> discord.File | None: if not media: return + file_name = f"{media.title or 'bot_media'}.{media.extension}" + if media.url: if pathlib.Path(media.url).is_file(): if (path_suffix := pathlib.Path(media.url).suffix) and len(path_suffix) <= constants.MAX_FILE_EXTENSION_LENGHT: return discord.File(media.url) else: - return discord.File(media.url, filename=f'bot_media.{media.extension}') + return discord.File(media.url, filename=file_name) elif not media.bytes_: media.bytes_ = await flanautils.get_request(media.url) @@ -234,7 +236,7 @@ async def _prepare_media_to_send(media: Media) -> discord.File | None: bytes_ = await flanautils.to_gif(bytes_) if len(bytes_) > constants.DISCORD_MEDIA_MAX_BYTES: raise LimitError - file = discord.File(fp=io.BytesIO(bytes_), filename=f'bot_media.{media.extension}') + file = discord.File(fp=io.BytesIO(bytes_), filename=file_name) else: return diff --git a/multibot/bots/telegram_bot.py b/multibot/bots/telegram_bot.py index 9d235bf..61aaad2 100644 --- a/multibot/bots/telegram_bot.py +++ b/multibot/bots/telegram_bot.py @@ -226,9 +226,9 @@ async def bytes_file() -> io.BytesIO | None: bytes_ = media.bytes_ if inline_ and media.type_ is MediaType.AUDIO: - bytes_ = await flanautils.add_metadata(bytes_, {'title': 'Audio'}, overwrite=False) + bytes_ = await flanautils.add_metadata(bytes_, {'title': 'bot_media.mp3'}, overwrite=False) file_ = io.BytesIO(bytes_) - file_.name = f'bot_media.{media.extension}' + file_.name = f"{media.title or 'bot_media'}.{media.extension}" return file_ if prefer_bytes: