diff --git a/src/assets/right-behind-you.ogg b/src/assets/right-behind-you.ogg new file mode 100644 index 0000000..a61a064 Binary files /dev/null and b/src/assets/right-behind-you.ogg differ diff --git a/src/cogs/ffmeta.py b/src/cogs/ffmeta.py index 0469a3f..4ae020a 100644 --- a/src/cogs/ffmeta.py +++ b/src/cogs/ffmeta.py @@ -226,7 +226,7 @@ class FFMeta(commands.Cog): if not fs: await ctx.respond("Failed to convert audio. See below.") else: - await ctx.respond(file=discord.File(file, filename=filename)) + return await ctx.respond(file=discord.File(file, filename=filename)) paginator = commands.Paginator() for line in stderr.splitlines(): @@ -236,6 +236,56 @@ class FFMeta(commands.Cog): for page in paginator.pages: await ctx.respond(page, ephemeral=True) + + @commands.slash_command(name="right-behind-you") + async def right_behind_you(self, ctx: discord.ApplicationContext, image: discord.Attachment): + await ctx.defer() + if not Path("assets/right-behind-you.ogg").exists(): + return await ctx.respond("The file `right-behind-you.ogg` is missing.") + if not image.content_type.startswith("image"): + return await ctx.respond("That's not an image!") + with tempfile.NamedTemporaryFile(suffix=Path(image.filename).suffix) as temp: + await image.save(temp.name) + process = await asyncio.create_subprocess_exec( + "ffmpeg", + "-hide_banner", + "-v", + "warning", + "-stats", + "-loop", + "1", + "-i", + temp.name, + "-i", + "assets/right-behind-you.ogg", + "-c:v", + "libx264", + "-tune", + "stillimage", + "-pix_fmt", + "yuv420p", + "-shortest", + "-y", + "pipe:1", + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.PIPE, + ) + stdout, stderr = await process.communicate() + file = io.BytesIO(stdout) + 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)) + if not fs: + await ctx.respond("Failed to convert audio. See below.") + else: + return await ctx.respond(file=discord.File(file, filename="right-behind-you.mp4")) + paginator = commands.Paginator() + for line in stderr.splitlines(): + if line.strip().startswith(":"): + continue + paginator.add_line(f"{line}"[:2000]) + + for page in paginator.pages: + await ctx.respond(page, ephemeral=True) def setup(bot: commands.Bot):