Improve file naming

This commit is contained in:
Nexus 2024-02-07 17:04:58 +00:00
parent eb55f0a3cb
commit af5166767f

View file

@ -4,6 +4,7 @@ import json
import logging import logging
import tempfile import tempfile
import typing import typing
from pathlib import Path
import PIL.Image import PIL.Image
@ -140,10 +141,12 @@ class FFMeta(commands.Cog):
] = False ] = False
): ):
"""Converts a given URL or attachment to an Opus file""" """Converts a given URL or attachment to an Opus file"""
filename = "opusinated.ogg"
if url is None: if url is None:
if attachment is None: if attachment is None:
return await ctx.respond("No URL or attachment provided") return await ctx.respond("No URL or attachment provided")
url = attachment.url url = attachment.url
filename = str(Path(attachment.filename).with_suffix(".ogg"))
await ctx.defer() await ctx.defer()
channels = 2 if not mono else 1 channels = 2 if not mono else 1
@ -219,7 +222,7 @@ class FFMeta(commands.Cog):
file = io.BytesIO(stdout) file = io.BytesIO(stdout)
if (fs := len(file.getvalue())) > (24.75 * 1024 * 1024): if (fs := len(file.getvalue())) > (24.75 * 1024 * 1024):
return await ctx.respond("The file is too large to send ({:,.2f} MiB).".format(fs / 1024 / 1024)) return await ctx.respond("The file is too large to send ({:,.2f} MiB).".format(fs / 1024 / 1024))
await ctx.respond(file=discord.File(file, filename="opusinated.ogg")) await ctx.respond(file=discord.File(file, filename=filename))
def setup(bot: commands.Bot): def setup(bot: commands.Bot):