Skip to content

Commit

Permalink
Update file names
Browse files Browse the repository at this point in the history
  • Loading branch information
AlberLC committed Aug 14, 2022
1 parent b3c8814 commit f10fbaa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions multibot/bots/discord_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions multibot/bots/telegram_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f10fbaa

Please sign in to comment.